-
-
Notifications
You must be signed in to change notification settings - Fork 231
/
Copy pathbuild.sh
executable file
·519 lines (470 loc) · 16.6 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
#!/usr/bin/env sh
#~ Copyright 2002-2020 Rene Rivera.
#~ Distributed under the Boost Software License, Version 1.0.
#~ (See accompanying file LICENSE_1_0.txt or copy at
#~ http://www.boost.org/LICENSE_1_0.txt)
FALSE=1
TRUE=0
# Reset the toolset.
B2_TOOLSET=
B2_SETUP=
# Internal options.
B2_VERBOSE_OPT=${B2_VERBOSE_OPT:=${FALSE}}
B2_DEBUG_OPT=${B2_DEBUG_OPT:=${FALSE}}
B2_GUESS_TOOLSET_OPT=${FALSE}
B2_HELP_OPT=${FALSE}
B2_CXX_OPT=
B2_CXXFLAGS_OPT=
# We need to calculate and set SCRIPT_PATH and SCRIPT_DIR to reference this
# script so that we can refer to file relative to it.
SCRIPT_PATH=""
if test "${BASH_SOURCE}" ; then
SCRIPT_PATH=${BASH_SOURCE}
fi
if test "${SCRIPT_PATH}" = "" ; then
SCRIPT_PATH=$0
fi
SCRIPT_DIR="$( cd "$( dirname "${SCRIPT_PATH}" )" && pwd )"
# This script needs to operate at engine source directory.
SAVED_PWD="${PWD}"
cd "${SCRIPT_DIR}"
test_true ()
{
if test $1 -eq ${TRUE} ; then
return ${TRUE}
fi
return ${FALSE}
}
# Run a command, and echo before doing so. Also checks the exit status and quits
# if there was an error.
echo_run ()
{
if test_true ${B2_VERBOSE_OPT} ; then echo "> $@" ; fi
$@
r=$?
if test $r -ne ${TRUE} ; then
exit $r
fi
}
# Print an error message, and exit with a status of 1.
error_exit ()
{
echo "
${@}
You can specify the toolset as the argument, i.e.:
./build.sh [options] gcc
Toolsets supported by this script are:
acc, clang, como, gcc, ibmcxx-clang, intel-darwin, intel-linux,
kcc, kylix, mipspro, pathscale, pgi, qcc, sun, sunpro, tru64cxx
For any toolset you can override the path to the compiler with the '--cxx'
option. You can also use additional flags for the compiler with the
'--cxxflags' option.
A special toolset; cxx, is available which is used as a fallback when a more
specific toolset is not found and the cxx command is detected. The 'cxx'
toolset will use the '--cxx' and '--cxxflags' options, if present.
Options:
--help Show this help message.
--verbose Show messages about what this script is doing.
--debug Build b2 with debug information, and no
optimizations.
--guess-toolset Print the toolset we can detect for building.
--cxx=CXX The compiler exec to use instead of the detected
compiler exec.
--cxxflags=CXXFLAGS The compiler flags to use in addition to the
flags for the detected compiler.
" 1>&2
exit 1
}
# Check that a command is in the PATH.
test_path ()
{
if `command -v command 1>/dev/null 2>/dev/null`; then
command -v $1 1>/dev/null 2>/dev/null
else
hash $1 1>/dev/null 2>/dev/null
fi
}
# Check that the OS name, as returned by "uname", is as given.
test_uname ()
{
if test_path uname; then
test `uname` = $*
fi
}
test_compiler ()
{
EXE="${B2_CXX_OPT:-$1}"
shift
CMD="${EXE} $@ ${B2_CXXFLAGS_OPT:-}"
SETUP=${B2_SETUP:-true}
if test_true ${B2_VERBOSE_OPT} ; then
echo "> ${CMD} check_clib.cpp check_cxx11.cpp"
( ${SETUP} ; ${CMD} check_clib.cpp check_cxx11.cpp )
else
( ${SETUP} ; ${CMD} check_clib.cpp check_cxx11.cpp ) 1>/dev/null 2>/dev/null
fi
CHECK_RESULT=$?
if test_true ${CHECK_RESULT} ; then
B2_CXX=${CMD}
fi
rm -rf check_clib.o* check_cxx11.o* a.out a.exe 1>/dev/null 2>/dev/null
return ${CHECK_RESULT}
}
test_toolset ()
{
if test "${TOOLSET}" = "" ; then return ${TRUE} ; fi
if test "${TOOLSET}" = "$1" -o "${TOOLSET}" = "$2" -o "${TOOLSET}" = "$3" ; then return ${TRUE} ; fi
return 1
}
# Check the toolset to bootstrap the build with. The one optional argument to
# the function is a toolset name. This operates as follows based on these
# contextual vars, if set, and if an arg is given:
#
# No vars set:
# Checks, in some priority order, possible toolset commands. Upon finding the
# first working command sets B2_TOOLSET to the toolset and B2_CXX to the
# compile command with any base options.
#
# B2_TOOLSET set:
# Checks that toolset for possible compile commands and sets B2_CXX to the
# command that works for the toolset.
#
check_toolset ()
{
TOOLSET=${B2_TOOLSET%%-[0-9]*}
TOOLSET_SUFFIX=${B2_TOOLSET##$TOOLSET}
# Prefer Clang (clang) on macOS..
if test_toolset clang && test_uname Darwin && test_compiler clang++$TOOLSET_SUFFIX -x c++ -std=c++11 ; then B2_TOOLSET=clang$TOOLSET_SUFFIX ; return ${TRUE} ; fi
# GCC (gcc) with -pthread arg (for AIX and others)..
if test_toolset gcc && test_compiler g++$TOOLSET_SUFFIX -x c++ -std=c++11 -pthread ; then B2_TOOLSET=gcc$TOOLSET_SUFFIX ; return ${TRUE} ; fi
# GCC (gcc)..
if test_toolset gcc && test_compiler g++$TOOLSET_SUFFIX -x c++ -std=c++11 ; then B2_TOOLSET=gcc$TOOLSET_SUFFIX ; return ${TRUE} ; fi
if test_toolset gcc && test_compiler g++$TOOLSET_SUFFIX -x c++ -std=c++11 -D_GNU_SOURCE ; then B2_TOOLSET=gcc$TOOLSET_SUFFIX ; return ${TRUE} ; fi
# Clang (clang) with -pthread arg (for FreeBSD and others)..
if test_toolset clang && test_compiler clang++$TOOLSET_SUFFIX -x c++ -std=c++11 -pthread ; then B2_TOOLSET=clang$TOOLSET_SUFFIX ; return ${TRUE} ; fi
# Clang (clang)..
if test_toolset clang && test_compiler clang++$TOOLSET_SUFFIX -x c++ -std=c++11 ; then B2_TOOLSET=clang$TOOLSET_SUFFIX ; return ${TRUE} ; fi
# Intel macOS (intel-darwin)
if test_toolset intel-darwin && test -r "${HOME}/intel/oneapi/setvars.sh" && test_uname Darwin ; then
B2_SETUP="source ${HOME}/intel/oneapi/setvars.sh"
if test_toolset intel-darwin && test_compiler icpx -x c++ -std=c++11 ; then B2_TOOLSET=intel-darwin ; return ${TRUE} ; fi
if test_toolset intel-darwin && test_compiler icc -x c++ -std=c++11 ; then B2_TOOLSET=intel-darwin ; return ${TRUE} ; fi
B2_SETUP=
fi
if test_toolset intel-darwin && test -r "/opt/intel/oneapi/setvars.sh" && test_uname Darwin ; then
B2_SETUP="source /opt/intel/oneapi/setvars.sh"
if test_toolset intel-darwin && test_compiler icpx -x c++ -std=c++11 ; then B2_TOOLSET=intel-darwin ; return ${TRUE} ; fi
if test_toolset intel-darwin && test_compiler icc -x c++ -std=c++11 ; then B2_TOOLSET=intel-darwin ; return ${TRUE} ; fi
B2_SETUP=
fi
# Intel oneAPI (intel-linux)
if test_toolset intel-linux && test_path icpx ; then
if test_compiler icpx -x c++ -std=c++11 ; then B2_TOOLSET=intel-linux ; return ${TRUE} ; fi
fi
if test_toolset intel-linux && test_path icc ; then
if test_compiler icc -x c++ -std=c++11 ; then B2_TOOLSET=intel-linux ; return ${TRUE} ; fi
fi
if test_toolset intel-linux && test -r "${HOME}/intel/oneapi/setvars.sh" ; then
B2_SETUP="source ${HOME}/intel/oneapi/setvars.sh"
if test_toolset intel-linux && test_compiler icpx -x c++ -std=c++11 ; then B2_TOOLSET=intel-linux ; return ${TRUE} ; fi
if test_toolset intel-linux && test_compiler icc -x c++ -std=c++11 ; then B2_TOOLSET=intel-linux ; return ${TRUE} ; fi
B2_SETUP=
fi
if test_toolset intel-linux && test -r "/opt/intel/oneapi/setvars.sh" ; then
B2_SETUP="source /opt/intel/oneapi/setvars.sh"
if test_toolset intel-linux && test_compiler icpx -x c++ -std=c++11 ; then B2_TOOLSET=intel-linux ; return ${TRUE} ; fi
if test_toolset intel-linux && test_compiler icc -x c++ -std=c++11 ; then B2_TOOLSET=intel-linux ; return ${TRUE} ; fi
B2_SETUP=
fi
# Intel Pro (intel-linux)
if test_toolset intel-linux && test_path icpc ; then
if test_compiler icpc -x c++ -std=c++11 ; then B2_TOOLSET=intel-linux ; return ${TRUE} ; fi
fi
if test_toolset intel-linux && test -r "/opt/intel/inteloneapi/setvars.sh" ; then
B2_SETUP="source /opt/intel/inteloneapi/setvars.sh"
if test_compiler icpc -x c++ -std=c++11 ; then B2_TOOLSET=intel-linux ; return ${TRUE} ; fi
B2_SETUP=
fi
if test_toolset intel-linux && test -r "/opt/intel/cc/9.0/bin/iccvars.sh" ; then
B2_SETUP="source /opt/intel/cc/9.0/bin/iccvars.sh"
if test_compiler icpc -x c++ -std=c++11 ; then B2_TOOLSET=intel-linux ; return ${TRUE} ; fi
B2_SETUP=
fi
if test_toolset intel-linux && test -r "/opt/intel_cc_80/bin/iccvars.sh" ; then
B2_SETUP="source /opt/intel_cc_80/bin/iccvars.sh"
if test_compiler icpc -x c++ -std=c++11 ; then B2_TOOLSET=intel-linux ; return ${TRUE} ; fi
B2_SETUP=
fi
# Mips Pro (mipspro)
if test_toolset mipspro && test_uname IRIX && test_compiler CC -FE:template_in_elf_section -ptused ; then B2_TOOLSET=mipspro ; return ${TRUE} ; fi
if test_toolset mipspro && test_uname IRIX64 && test_compiler CC -FE:template_in_elf_section -ptused ; then B2_TOOLSET=mipspro ; return ${TRUE} ; fi
# OSF Tru64 C++ (tru64cxx)
if test_toolset tru64cxx && test_uname OSF1 && test_compiler cc ; then B2_TOOLSET=mipspro ; return ${TRUE} ; fi
# QNX (qcc)
if test_toolset qcc && test_uname QNX && test_compiler QCC ; then B2_TOOLSET=qcc ; return ${TRUE} ; fi
# AIX IBM Open XL (ibmcxx-clang)
IBMCXX=`ls -1 -r /opt/IBM/openxlC/17.*/bin/ibm-clang++_r`
if test_toolset ibmcxx-clang && test_uname AIX && test "" != "${IBMCXX}" && test_compiler "${IBMCXX}" ; then B2_TOOLSET=ibmcxx-clang ; return ${TRUE} ; fi
# PGI (pgi)
if test_toolset pgi && test_compiler pgc++ -std=c++11 ; then B2_TOOLSET=pgi ; return ${TRUE} ; fi
# Pathscale C++ (pathscale)
if test_toolset pathscale && test_compiler pathCC ; then B2_TOOLSET=pathscale ; return ${TRUE} ; fi
# Como (como)
if test_toolset como && test_compiler como ; then B2_TOOLSET=como ; return ${TRUE} ; fi
# Borland C++ (kylix)
if test_toolset kylix && test_compiler bc++ -tC -q ; then B2_TOOLSET=kylix ; return ${TRUE} ; fi
# aCC (acc)
if test_toolset acc && test_compiler aCC -AA ; then B2_TOOLSET=acc ; return ${TRUE} ; fi
# Sun Pro C++ (sunpro)
if test_toolset sunpro && test_compiler /opt/SUNWspro/bin/CC -std=c++11 ; then B2_TOOLSET=sunpro ; return ${TRUE} ; fi
# Generic (cxx)
if test_toolset cxx && test_compiler cxx ; then B2_TOOLSET=cxx ; return ${TRUE} ; fi
if test_toolset cxx && test_compiler c++ ; then B2_TOOLSET=cxx ; return ${TRUE} ; fi
if test_toolset cxx && test_compiler CC ; then B2_TOOLSET=cxx ; return ${TRUE} ; fi
# Nothing found.
if test "${B2_TOOLSET}" = "" ; then
error_exit "Could not find a suitable toolset."
fi
return ${FALSE}
}
# Handle command options and args.
while test $# -gt 0
do
case "$1" in
--verbose) B2_VERBOSE_OPT=${TRUE} ;;
--debug) B2_DEBUG_OPT=${TRUE} ;;
--guess-toolset) B2_GUESS_TOOLSET_OPT=${TRUE} ;;
--help) B2_HELP_OPT=${TRUE} ;;
--cxx=*) B2_CXX_OPT=`expr "x$1" : "x--cxx=\(.*\)"` ;;
--cxxflags=*) B2_CXXFLAGS_OPT=`expr "x$1" : "x--cxxflags=\(.*\)"` ;;
-*) ;;
?*) B2_TOOLSET=$1 ;;
esac
shift
done
# Show some help, if requested.
if test_true ${B2_HELP_OPT} ; then
error_exit
fi
# If we have a CXX but no B2_TOOLSET specified by the user we assume they meant
# "cxx" as the toolset.
if test "${B2_CXX_OPT}" != "" -a "${B2_TOOLSET}" = "" ; then
B2_TOOLSET=cxx
fi
# If we have B2_TOOLSET=cxx but no B2_CXX_OPT nor B2_CXXFLAGS_OPT specified by the user
# we assume they meant $CXX and $CXXFLAGS.
if test "${B2_TOOLSET}" = "cxx" -a "${B2_CXX_OPT}" = "" -a "${B2_CXXFLAGS_OPT}" = "" ; then
B2_CXX_OPT="${CXX}"
B2_CXXFLAGS_OPT="${CXXFLAGS}"
fi
# Guess toolset, or toolset commands.
check_toolset
TOOLSET_CHECK=$?
# We can bail from the rest of the checks and build if we are just guessing
# the toolset.
if test_true ${B2_GUESS_TOOLSET_OPT} ; then
echo "${B2_TOOLSET}"
exit 0
fi
# We need a viable compiler. Check here and give some feedback about it.
if ! test_true ${TOOLSET_CHECK} ; then
echo "
A C++11 capable compiler is required for building the B2 engine.
Toolset '${B2_TOOLSET}' does not appear to support C++11.
"
(B2_VERBOSE_OPT=${TRUE} check_toolset)
error_exit "
** Note, the C++11 capable compiler is _only_ required for building the B2
** engine. The B2 build system allows for using any C++ level and any other
** supported language and resource in your projects.
"
fi
# Set the additional options needed to build the engine based on the toolset.
case "${B2_TOOLSET}" in
gcc|gcc-*)
CXX_VERSION_OPT=${CXX_VERSION_OPT:---version}
B2_CXXFLAGS_RELEASE="-O2 -s"
B2_CXXFLAGS_DEBUG="-O0 -g"
;;
intel-*)
CXX_VERSION_OPT=${CXX_VERSION_OPT:---version}
B2_CXXFLAGS_RELEASE="-O3 -static-intel"
B2_CXXFLAGS_DEBUG="-O0 -g -static-intel"
;;
ibmcxx-clang)
CXX_VERSION_OPT=${CXX_VERSION_OPT:---version}
B2_CXXFLAGS_RELEASE="-O3 -Wl,-s -Wno-deprecated-declarations"
B2_CXXFLAGS_DEBUG="-O0 -fno-inline -g -Wno-deprecated-declarations"
;;
como)
CXX_VERSION_OPT=${CXX_VERSION_OPT:---version}
B2_CXXFLAGS_RELEASE="-O3 --inlining"
B2_CXXFLAGS_DEBUG="-O0 -g --no_inlining --long_long"
;;
kcc)
CXX_VERSION_OPT=${CXX_VERSION_OPT:---version}
B2_CXXFLAGS_RELEASE="+K2 -s"
B2_CXXFLAGS_DEBUG="+K0 -g"
;;
kylix)
CXX_VERSION_OPT=${CXX_VERSION_OPT:---version}
B2_CXXFLAGS_RELEASE="-O2 -vi -w-inl -s"
B2_CXXFLAGS_DEBUG="-Od -v -vi-"
;;
mipspro)
CXX_VERSION_OPT=${CXX_VERSION_OPT:---version}
B2_CXXFLAGS_RELEASE="-Ofast -g0 \"-INLINE:none\" -s"
B2_CXXFLAGS_DEBUG="-O0 -INLINE -g"
;;
pathscale)
CXX_VERSION_OPT=${CXX_VERSION_OPT:---version}
B2_CXXFLAGS_RELEASE="-O3 -inline -s"
B2_CXXFLAGS_DEBUG="-O0 -noinline -ggdb"
;;
pgi)
CXX_VERSION_OPT=${CXX_VERSION_OPT:---version}
B2_CXXFLAGS_RELEASE="-fast -s"
B2_CXXFLAGS_DEBUG="-O0 -gopt"
;;
sun*)
CXX_VERSION_OPT=${CXX_VERSION_OPT:--V}
B2_CXXFLAGS_RELEASE="-xO4 -s"
B2_CXXFLAGS_DEBUG="-g"
;;
clang|clang-*)
CXX_VERSION_OPT=${CXX_VERSION_OPT:---version}
B2_CXXFLAGS_RELEASE="-O3 -s -Wno-deprecated-declarations"
B2_CXXFLAGS_DEBUG="-O0 -fno-inline -g -Wno-deprecated-declarations"
;;
tru64cxx)
CXX_VERSION_OPT=${CXX_VERSION_OPT:---version}
B2_CXXFLAGS_RELEASE="-O5 -inline speed -s"
B2_CXXFLAGS_DEBUG="-O0 -pg -g"
;;
acc)
CXX_VERSION_OPT=${CXX_VERSION_OPT:---version}
B2_CXXFLAGS_RELEASE="-O3 -s"
B2_CXXFLAGS_DEBUG="+d -g"
;;
qcc)
CXX_VERSION_OPT=""
B2_CXXFLAGS_RELEASE="-O3 -Wc,-finline-functions"
B2_CXXFLAGS_DEBUG="O0 -Wc,-fno-inline -gstabs+"
;;
cxx)
CXX_VERSION_OPT=${CXX_VERSION_OPT:---version}
;;
*)
error_exit "Unknown toolset: ${B2_TOOLSET}"
;;
esac
build_b2 ()
{
echo "
###
###
### Using '${B2_TOOLSET}' toolset.
###
###
"
if test "${CXX_VERSION_OPT}" != ""; then
echo_run ${B2_CXX} ${CXX_VERSION_OPT}
fi
echo "
###
###
"
B2_SOURCES="\
bindjam.cpp \
builtins.cpp \
class.cpp \
command.cpp \
compile.cpp \
constants.cpp \
cwd.cpp \
debug.cpp \
debugger.cpp \
events.cpp \
execcmd.cpp \
execnt.cpp \
execunix.cpp \
filent.cpp \
filesys.cpp \
fileunix.cpp \
frames.cpp \
function.cpp \
glob.cpp \
hash.cpp \
hcache.cpp \
hdrmacro.cpp \
headers.cpp \
jam_strings.cpp \
jam.cpp \
jamgram.cpp \
lists.cpp \
make.cpp \
make1.cpp \
md5.cpp \
mem.cpp \
modules.cpp \
native.cpp \
output.cpp \
parse.cpp \
pathnt.cpp \
pathsys.cpp \
pathunix.cpp \
regexp.cpp \
rules.cpp \
scan.cpp \
search.cpp \
startup.cpp \
tasks.cpp \
timestamp.cpp \
value.cpp \
variable.cpp \
w32_getreg.cpp \
mod_args.cpp \
mod_command_db.cpp \
mod_db.cpp \
mod_jam_builtin.cpp \
mod_jam_class.cpp \
mod_jam_errors.cpp \
mod_jam_modules.cpp \
mod_order.cpp \
mod_path.cpp \
mod_property_set.cpp \
mod_regex.cpp \
mod_sequence.cpp \
mod_set.cpp \
mod_string.cpp \
mod_summary.cpp \
mod_sysinfo.cpp \
mod_version.cpp \
"
if test_true ${B2_DEBUG_OPT} ; then B2_CXXFLAGS="${B2_CXXFLAGS_DEBUG}"
else B2_CXXFLAGS="${B2_CXXFLAGS_RELEASE} -DNDEBUG"
fi
if [ -z "$B2_DONT_EMBED_MANIFEST" ] ; then
case "$(${B2_CXX} ${B2_CXXFLAGS} -dumpmachine 2>/dev/null)" in
*-windows*|*-mingw*|*-msys*|*-cygnus*|*-cygwin*)
WINDRES="$(${B2_CXX} ${B2_CXXFLAGS} -print-prog-name=windres 2>/dev/null)"
;;
esac
if [ -n "${WINDRES}" ] ; then
B2_CXXFLAGS="${B2_CXXFLAGS} -Wl,res.o"
( B2_VERBOSE_OPT=${TRUE} echo_run ${WINDRES} --input res.rc --output res.o )
fi
fi
( B2_VERBOSE_OPT=${TRUE} echo_run ${B2_CXX} ${B2_CXXFLAGS} ${B2_SOURCES} -o b2 )
}
if test_true ${B2_VERBOSE_OPT} ; then
(
${B2_SETUP}
build_b2
)
else
(
${B2_SETUP} 1>/dev/null 2>/dev/null
build_b2
)
fi