forked from fibjs/fibjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·224 lines (206 loc) · 4.34 KB
/
build
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/bin/bash
usage()
{
echo ""
echo "Usage: `basename $0` [options] [-jn] [-v] [-h]"
echo "Options:"
echo " release, debug: "
echo " Specifies the build type."
echo " i386, amd64, arm, arm64, mips, mips64, ppc, ppc64:"
echo " Specifies the architecture for code generation."
echo " clean: "
echo " Clean the build folder."
echo " ci: "
echo " Specifies the environment is CI."
echo " -h, --help:"
echo " Print this message and exit."
echo " -j: enable make '-j' option."
echo " if 'n' is not given, will set jobs to auto detected core count, otherwise n is used."
echo " -v: verbose make"
echo ""
exit 0
}
HOST_OS=`uname`
HOST_ARCH=`uname -m`
case ${HOST_ARCH} in
i386|i686) HOST_ARCH="i386"
;;
x86_64|amd64) HOST_ARCH="amd64"
;;
armv6|armv7|armv7s|armv7l) HOST_ARCH="arm"
;;
aarch64) HOST_ARCH="arm64"
;;
mips|mipsel) HOST_ARCH="mips"
;;
mips64) HOST_ARCH="mips64"
;;
powerpc) HOST_ARCH="ppc"
;;
ppc64) HOST_ARCH="ppc64"
;;
esac
TARGET_OS=$HOST_OS
TARGET_ARCH=$HOST_ARCH
BUILD_TYPE="release"
BUILD_PREFIX=""
BUILD_OPTION=""
for i in "$@"
do
case $i in
i386|amd64|arm|arm64|mips|mips64|ppc|ppc64) TARGET_ARCH=$i
;;
release|debug|clean) BUILD_TYPE=$i
;;
ci) CI="ci"
;;
-j*) ENABLE_JOBS=1; BUILD_JOBS="${i#-j}"
;;
-v) BUILD_VERBOSE='VERBOSE=1'
;;
--help|-h) usage
;;
*) echo "illegal option $i"
usage
;;
esac
done
if [ $TARGET_ARCH != $HOST_ARCH ] || [ $TARGET_OS != $HOST_OS ]; then
case $TARGET_ARCH in
i386)
if [ $HOST_ARCH = "amd64" ]; then
BUILD_OPTION="-m32"
else
usage
fi
;;
amd64)
if [ $TARGET_OS = "Linux" ]; then
BUILD_PREFIX="x86_64-linux-gnu-"
else
usage
fi
;;
arm)
if [ $TARGET_OS = "Linux" ]; then
BUILD_PREFIX="arm-linux-gnueabihf-"
BUILD_OPTION="-march=armv7-a -mfpu=vfp3 -marm"
else
usage
fi
;;
arm64)
if [ $TARGET_OS = "Linux" ]; then
BUILD_PREFIX="aarch64-linux-gnu-"
else
usage
fi
;;
mips)
if [ $TARGET_OS = "Linux" ]; then
BUILD_PREFIX="mips-linux-gnu-"
else
usage
fi
;;
mips64)
if [ $TARGET_OS = "Linux" ]; then
BUILD_PREFIX="mips64-linux-gnuabi64-"
else
usage
fi
;;
ppc)
if [ $TARGET_OS = "Linux" ]; then
BUILD_PREFIX="powerpc-linux-gnu-"
else
usage
fi
;;
ppc64)
if [ $TARGET_OS = "Linux" ]; then
BUILD_PREFIX="powerpc64-linux-gnu-"
else
usage
fi
;;
esac
fi
if [ "$BUILD_PREFIX" != "" ]; then
export CC=${BUILD_PREFIX}gcc
export CXX=${BUILD_PREFIX}g++
fi
inform()
{
echo ""
echo "submodule vender is not existed!"
echo "you can execute the given command to init and update it."
echo " \$ git submodule init"
echo " \$ git submodule update"
echo ""
exit 1
}
if [ "$ENABLE_JOBS" = "1" -a "$BUILD_JOBS" = "" ]; then
#get cpu core count
CPU_CORE=1
case ${HOST_OS} in
Darwin)
CPU_CORE=$(sysctl hw.ncpu | awk '{print $2}')
;;
Linux)
CPU_CORE=$(cat /proc/cpuinfo | grep processor | wc -l)
;;
Windows)
CPU_CORE=$(echo $NUMBER_OF_PROCESSORS)
;;
esac
echo "host machine has ${CPU_CORE} core"
if [ "$CPU_CORE" = "1" ]; then
BUILD_JOBS=""
else
# set build jobs with cpu core count
BUILD_JOBS=${CPU_CORE}
fi
fi
export BUILD_JOBS
export BUILD_VERBOSE
if [ -d vender ]; then
cd vender
sh build $BUILD_TYPE $TARGET_ARCH
if [ $? != 0 ]; then
exit 1
fi
cd ..
else
inform
fi
cd fibjs
sh build $BUILD_TYPE $TARGET_ARCH $CI
if [ $? != 0 ]; then
exit 1
fi
cd ..
cd fibjs/program
sh build $BUILD_TYPE $TARGET_ARCH $CI
if [ $? != 0 ]; then
exit 1
fi
cd ../..
txtbld=$(tput bold)
bldred=${txtbld}$(tput setaf 1)
txtrst=$(tput sgr0)
printf "\n\n${bldred}"
printf "\t _______ _________ ______ _________ _______ \n"
printf "\t( ____ \\\\\\__ __/( ___ \\ \\__ _/( ____ \\\\\n"
printf "\t| ( \\/ ) ( | ( ) ) ) ( | ( \\/\n"
printf "\t| (__ | | | (__/ / | | | (_____ \n"
printf "\t| __) | | | __ ( | | (_____ )\n"
printf "\t| ( | | | ( \\ \\ | | ) |\n"
printf "\t| (_ ___) (___|(___) )/\\_) ) /\\____) |\n"
printf "\t(__/ \\_______/(______/ \\____/ \\_______)\n"
printf "${txtrst}"
printf "\\n\\tFIBJS has been successfully built.\\n\\n"
printf "\\tFor more information:\\n\\n"
printf "\\twebsite: http://fibjs.org\\n"
printf "\\trepository: https://github.com/fibjs\\n"
printf "\n\n"