forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·270 lines (236 loc) · 7.24 KB
/
build.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
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/bin/bash
#-------------------------------------------------------------------------------------------------------
# Copyright (C) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
#-------------------------------------------------------------------------------------------------------
SAFE_RUN() {
local SF_RETURN_VALUE=$($1 2>&1)
if [[ $? != 0 ]]; then
>&2 echo $SF_RETURN_VALUE
exit 1
fi
echo $SF_RETURN_VALUE
}
PRINT_USAGE() {
echo ""
echo "[ChakraCore Build Script Help]"
echo ""
echo "build.sh [options]"
echo ""
echo "options:"
echo " --cxx=PATH Path to Clang++ (see example below)"
echo " --cc=PATH Path to Clang (see example below)"
echo " -d, --debug Debug build (by default Release build)"
echo " -h, --help Show help"
echo " --icu=PATH Path to ICU include folder (see example below)"
echo " -j [N], --jobs[=N] Multicore build, allow N jobs at once"
echo " -n, --ninja Build with ninja instead of make"
echo " --xcode Generate XCode project"
echo " -t, --test-build Test build (by default Release build)"
echo " --static Build as static library (by default shared library)"
echo " -v, --verbose Display verbose output including all options"
echo " --create-deb=V Create .deb package with given V version"
echo " --without=FEATURE,FEATURE,..."
echo " Disable FEATUREs from JSRT experimental"
echo " features."
echo ""
echo "example:"
echo " ./build.sh --cxx=/path/to/clang++ --cc=/path/to/clang -j"
echo "with icu:"
echo " ./build.sh --icu=/usr/local/Cellar/icu4c/version/include/"
echo ""
}
CHAKRACORE_DIR=`dirname $0`
_CXX=""
_CC=""
VERBOSE=""
BUILD_TYPE="Release"
CMAKE_GEN=
MAKE=make
MULTICORE_BUILD=""
ICU_PATH=""
STATIC_LIBRARY=""
WITHOUT_FEATURES=""
CREATE_DEB=0
while [[ $# -gt 0 ]]; do
case "$1" in
--cxx=*)
_CXX=$1
_CXX=${_CXX:6}
;;
--cc=*)
_CC=$1
_CC=${_CC:5}
;;
-h | --help)
PRINT_USAGE
exit
;;
-v | --verbose)
_VERBOSE="verbose"
;;
-d | --debug)
BUILD_TYPE="Debug"
;;
-t | --test-build)
BUILD_TYPE="Test"
;;
-j | --jobs)
if [[ "$1" == "-j" && "$2" =~ ^[^-] ]]; then
MULTICORE_BUILD="-j $2"
shift
else
MULTICORE_BUILD="-j $(nproc)"
fi
;;
-j=* | --jobs=*) # -j=N syntax used in CI
MULTICORE_BUILD=$1
if [[ "$1" =~ ^-j= ]]; then
MULTICORE_BUILD="-j ${MULTICORE_BUILD:3}"
else
MULTICORE_BUILD="-j ${MULTICORE_BUILD:7}"
fi
;;
--icu=*)
ICU_PATH=$1
ICU_PATH="-DICU_INCLUDE_PATH=${ICU_PATH:6}"
;;
-n | --ninja)
CMAKE_GEN="-G Ninja"
MAKE=ninja
;;
--xcode)
CMAKE_GEN="-G Xcode -DCC_XCODE_PROJECT=1"
MAKE=0
;;
--create-deb=*)
CREATE_DEB=$1
CREATE_DEB="${CREATE_DEB:13}"
;;
--static)
STATIC_LIBRARY="-DSTATIC_LIBRARY=1"
;;
--without=*)
FEATURES=$1
FEATURES=${FEATURES:10} # value after --without=
for x in ${FEATURES//,/ } # replace comma with space then split
do
if [[ "$WITHOUT_FEATURES" == "" ]]; then
WITHOUT_FEATURES="-DWITHOUT_FEATURES="
else
WITHOUT_FEATURES="$WITHOUT_FEATURES;"
fi
WITHOUT_FEATURES="${WITHOUT_FEATURES}-DCOMPILE_DISABLE_${x}=1"
done
;;
*)
echo "Unknown option $1"
PRINT_USAGE
exit -1
;;
esac
shift
done
if [[ ${#_VERBOSE} > 0 ]]; then
# echo options back to the user
echo "Printing command line options back to the user:"
echo "_CXX=${_CXX}"
echo "_CC=${_CC}"
echo "BUILD_TYPE=${BUILD_TYPE}"
echo "MULTICORE_BUILD=${MULTICORE_BUILD}"
echo "ICU_PATH=${ICU_PATH}"
echo "CMAKE_GEN=${CMAKE_GEN}"
echo "MAKE=${MAKE}"
echo ""
fi
CLANG_PATH=
if [[ ${#_CXX} > 0 || ${#_CC} > 0 ]]; then
if [[ ${#_CXX} == 0 || ${#_CC} == 0 ]]; then
echo "ERROR: '-cxx' and '-cc' options must be used together."
exit 1
fi
echo "Custom CXX ${_CXX}"
echo "Custom CC ${_CC}"
if [[ ! -f $_CXX || ! -f $_CC ]]; then
echo "ERROR: Custom compiler not found on given path"
exit 1
fi
CLANG_PATH=$_CXX
else
RET_VAL=$(SAFE_RUN 'c++ --version')
if [[ ! $RET_VAL =~ "clang" ]]; then
echo "Searching for Clang..."
if [[ -f /usr/bin/clang++ ]]; then
echo "Clang++ found at /usr/bin/clang++"
_CXX=/usr/bin/clang++
_CC=/usr/bin/clang
CLANG_PATH=$_CXX
else
echo "ERROR: clang++ not found at /usr/bin/clang++"
echo ""
echo "You could use clang++ from a custom location."
PRINT_USAGE
exit 1
fi
else
CLANG_PATH=c++
fi
fi
# check clang version (min required 3.7)
VERSION=$($CLANG_PATH --version | grep "version [0-9]*\.[0-9]*" --o -i | grep "[0-9]\.[0-9]*" --o)
VERSION=${VERSION/./}
if [[ $VERSION -lt 37 ]]; then
echo "ERROR: Minimum required Clang version is 3.7"
exit 1
fi
CC_PREFIX=""
if [[ ${#_CXX} > 0 ]]; then
CC_PREFIX="-DCMAKE_CXX_COMPILER=$_CXX -DCMAKE_C_COMPILER=$_CC"
fi
build_directory="$CHAKRACORE_DIR/BuildLinux/${BUILD_TYPE:0}"
if [ ! -d "$build_directory" ]; then
SAFE_RUN `mkdir -p $build_directory`
fi
pushd $build_directory > /dev/null
echo Generating $BUILD_TYPE makefiles
cmake $CMAKE_GEN $CC_PREFIX $ICU_PATH $STATIC_LIBRARY -DCMAKE_BUILD_TYPE=$BUILD_TYPE $WITHOUT_FEATURES ../..
_RET=$?
if [[ $? == 0 ]]; then
if [[ $MAKE != 0 ]]; then
$MAKE $MULTICORE_BUILD 2>&1 | tee build.log
_RET=${PIPESTATUS[0]}
else
echo "Visit given folder above for xcode project file ----^"
fi
fi
if [[ $_RET != 0 ]]; then
echo "See error details above. Exit code was $_RET"
else
if [[ $CREATE_DEB != 0 ]]; then
DEB_FOLDER=`realpath .`
DEB_FOLDER="${DEB_FOLDER}/chakracore_${CREATE_DEB}"
mkdir -p $DEB_FOLDER/usr/local/bin
mkdir -p $DEB_FOLDER/DEBIAN
cp $DEB_FOLDER/../ch $DEB_FOLDER/usr/local/bin/
if [[ $STATIC_LIBRARY == "" ]]; then
cp $DEB_FOLDER/../*.so $DEB_FOLDER/usr/local/bin/
fi
echo -e "Package: ChakraCore"\
"\nVersion: ${CREATE_DEB}"\
"\nSection: base"\
"\nPriority: optional"\
"\nArchitecture: amd64"\
"\nDepends: libc6 (>= 2.19), uuid-dev (>> 0), libunwind-dev (>> 0), libicu-dev (>> 0)"\
"\nMaintainer: ChakraCore <[email protected]>"\
"\nDescription: Chakra Core"\
"\n Open source Core of Chakra Javascript Engine"\
> $DEB_FOLDER/DEBIAN/control
dpkg-deb --build $DEB_FOLDER
_RET=$?
if [[ $_RET == 0 ]]; then
echo ".deb package is available under $build_directory"
fi
fi
fi
popd > /dev/null
exit $_RET