-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcreate_env.sh
executable file
·157 lines (137 loc) · 4.82 KB
/
create_env.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/bash
echo " "
echo "*********************************************************************"
echo "* MT7688 Cross-environment for building native node modules/add-ons *"
echo "* Tested on: *"
echo "* Host: Ubuntu 14.04LTS x86_64 (MTK cross-tools) *"
echo "* Target: MT7688 MIPS24KEc little endian, OpenWRT *"
echo "* *"
echo "* Author: Simen Li ([email protected]) *"
echo "* GitHub: https://github.com/simenkid/mt7688-cross *"
echo "* License: MIT *"
echo "*********************************************************************"
echo " "
echo "<!> Please make sure you have installed the following packages on you host: "
echo " >> subversion, build-essential, gcc-multilib, g++-multilib"
echo " "
read -n1 -p "Are you sure to create the cross environment? [Y/n]" sure
echo " "
sure=${sure:-y}
if [ "${sure}" != "y" -a "${sure}" != "Y" ]; then
exit 0
fi
node_ver=`node -v`
npm_ver=`npm -v`
# Check version of node and npm
if [ ${node_ver} != 'v0.12.7' ]; then
echo "Node version on host should be v0.12.7, yours is ${node_ver}."
echo "If you are using n, run: "
echo "$ sudo n 0.12.7"
exit 0
else
echo "node version: ${node_ver}, ok!"
fi
if [ ${npm_ver} != '2.11.3' ]; then
echo "Npm version on host should be 2.11.3, yours is ${npm_ver}."
echo "To install the matched version, run: "
echo "$ sudo npm install -g [email protected]"
exit 0
else
echo "npm version: ${npm_ver}, ok!"
# if [ ! -d $(pwd)/node_modules ] || [ ! -d $(pwd)/node_modules/node-gyp ]; then
# echo "Install node-gyp..."
# sudo npm install --prefix $(pwd) node-gyp
# fi
fi
echo " "
echo "Create target folder..."
if [ ! -d $(pwd)/linkit ]; then
mkdir $(pwd)/linkit
if [ ! -d $(pwd)/linkit/opt ]; then
mkdir $(pwd)/linkit/opt
fi
fi
echo " "
echo "Get MT7688 OpenWrt SDK and decompress it into /mt7688sdk..."
if [ ! -f OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2 ]; then
wget http://download.labs.mediatek.com/MediaTek_LinkIt_Smart_7688_Openwrt_sdk_Linux -O OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2
fi
if [ ! -d mt7688sdk ]; then
tar xjvf OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2 > /dev/null
mv OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/ mt7688sdk
fi
echo " "
echo "Get node source and decompress it into /node-v0.12.7-mips..."
if [ ! -f node-v0.12.7.tar.gz ]; then
wget https://nodejs.org/dist/v0.12.7/node-v0.12.7.tar.gz
fi
if [ ! -d node-v0.12.7-mips ]; then
tar xzvf node-v0.12.7.tar.gz > /dev/null
mv node-v0.12.7/ node-v0.12.7-mips
fi
echo " "
echo "Get depot tools for google chromium repository..."
if [ ! -d depot_tools ]; then
if [ -f .gclient ]; then
rm .gclient
fi
if [ -f .gclient_entries ]; then
rm .gclient_entries
fi
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
fi
# source env.sh to export environment varaible for cross-toolchain
. $(pwd)/env.sh
echo " "
echo "Get v8 source into /v8"
echo "Takes few minutes, please wait..."
echo " "
# Fetch and build V8
if [ ! -d v8 ]; then
if [ -f .gclient ]; then
rm .gclient
fi
if [ -f .gclient_entries ]; then
rm .gclient_entries
fi
fetch v8
cd v8
git fetch origin
# checkout to v8 version: 3.28.71 (patch 19)
git checkout -b 3.28.71.19 4dbc223b1e4d
git branch
mv ../DEPS DEPS
gclient sync
cd ..
fi
echo " "
echo "Build v8 for mips platform..."
echo "Takes around 10 minutes, please wait..."
echo " "
cd v8/
make clean
make distclean
make dependencies
make mipsel.release werror=no library=shared snapshot=off -j4
cp ${BASEDIR}/v8/out/mipsel.release/lib.target/libicui18n.so ${LIBPATH}
cp ${BASEDIR}/v8/out/mipsel.release/lib.target/libicuuc.so ${LIBPATH}
cd ..
# Build Node.js
echo " "
echo "Build node.js for mips platform..."
echo "Takes few minutes, please wait..."
echo " "
cd node-v0.12.7-mips/
make clean
make distclean
./configure --prefix=${TARGET_PATH} --dest-cpu=mipsel --dest-os=linux --without-snapshot --shared-v8 --shared-v8-includes=${V8SOURCE}/include/ --shared-v8-libpath=${V8SOURCE}/out/mipsel.release/lib.target/
make snapshot=off -j4
make install
echo " "
echo "*********************************************"
echo "* Cross-environment done! *"
echo "* *"
echo "* Use ./npm_install.sh module_name *"
echo "* Or ./npm_install.sh module_name@version *"
echo "* to compile the node module *"
echo "*********************************************"