Skip to content

Commit 7497f61

Browse files
committed
Rework build.sh to use options instead of env vars.
The CXX/FLAGS env vars caused a variety of issues, mainliy for Cloud CI. This change replaces the env vars with some extra options.
1 parent e52464b commit 7497f61

File tree

2 files changed

+46
-35
lines changed

2 files changed

+46
-35
lines changed

doc/src/history.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ command is expanded to include the options directly.
4747
-- _Gei0r_
4848
* Fix building b2 engine with Intel Linux icpc.
4949
-- _Alain Miniussi_
50+
* Reword `build.sh` to fix many bugs and to avoid use of common env vars.
51+
-- _René Ferdinand Rivera Morell_
5052

5153
== Version 4.3.0
5254

src/engine/build.sh

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ B2_TOOLSET=
1313
B2_SETUP=
1414

1515
# Internal options.
16-
B2_VERBOSE=${B2_VERBOSE:=${FALSE}}
17-
B2_DEBUG=${B2_DEBUG:=${FALSE}}
18-
B2_GUESS_TOOLSET=${FALSE}
16+
B2_VERBOSE_OPT=${B2_VERBOSE_OPT:=${FALSE}}
17+
B2_DEBUG_OPT=${B2_DEBUG_OPT:=${FALSE}}
18+
B2_GUESS_TOOLSET_OPT=${FALSE}
19+
B2_HELP_OPT=${FALSE}
20+
B2_CXX_OPT=
21+
B2_CXXFLAGS_OPT=
1922

2023
# We need to calculate and set SCRIPT_PATH and SCRIPT_DIR to reference this
2124
# script so that we can refer to file relative to it.
@@ -44,7 +47,7 @@ test_true ()
4447
# if there was an error.
4548
echo_run ()
4649
{
47-
if test_true ${B2_VERBOSE} ; then echo "> $@" ; fi
50+
if test_true ${B2_VERBOSE_OPT} ; then echo "> $@" ; fi
4851
$@
4952
r=$?
5053
if test $r -ne ${TRUE} ; then
@@ -59,24 +62,31 @@ error_exit ()
5962
${@}
6063
6164
You can specify the toolset as the argument, i.e.:
62-
./build.sh gcc
65+
./build.sh [options] gcc
6366
6467
Toolsets supported by this script are:
6568
acc, clang, como, gcc, intel-darwin, intel-linux, kcc, kylix, mipspro,
6669
pathscale, pgi, qcc, sun, sunpro, tru64cxx, vacpp
6770
68-
For any toolset you can override the path to the compiler with the CXX
69-
environment variable. You can also use additional flags for the compiler
70-
with the CXXFLAGS environment variable.
71+
For any toolset you can override the path to the compiler with the '--cxx'
72+
option. You can also use additional flags for the compiler with the
73+
'--cxxflags' option.
7174
7275
A special toolset; cxx, is available which is used as a fallback when a more
7376
specific toolset is not found and the cxx command is detected. The 'cxx'
74-
toolset will use the CXX, CXXFLAGS, and LIBS environment variables, if present.
77+
toolset will use the '--cxx' and '--cxxflags' options, if present.
78+
79+
Options:
80+
--help Show this help message.
81+
--verbose Show messages about what this script is doing.
82+
--debug Build b2 with debug information, and no
83+
optimizations.
84+
--guess-toolset Print the toolset we can detect for building.
85+
--cxx=CXX The compiler exec to use instead of the detected
86+
compiler exec.
87+
--cxxflags=CXXFLAGS The compiler flags to use in addition to the
88+
flags for the detected compiler.
7589
76-
Similarly, the cross-cxx toolset is available for cross-compiling by using the
77-
BUILD_CXX, BUILD_CXXFLAGS, and BUILD_LDFLAGS environment variables to compile
78-
binaries that will be executed on the build system. This allows CXX etc. to be
79-
set for cross-compilers to be propagated to subprocesses.
8090
" 1>&2
8191
exit 1
8292
}
@@ -101,13 +111,13 @@ test_uname ()
101111

102112
test_compiler ()
103113
{
104-
local EXE="${CXX:-$1}"
114+
local EXE="${B2_CXX_OPT:-$1}"
105115
local CMD
106116
local SETUP
107117
shift
108-
CMD="${EXE} $@ ${CXXFLAGS:-}"
118+
CMD="${EXE} $@ ${B2_CXXFLAGS_OPT:-}"
109119
SETUP=${B2_SETUP:-true}
110-
if test_true ${B2_VERBOSE} ; then
120+
if test_true ${B2_VERBOSE_OPT} ; then
111121
echo "> ${CMD} check_cxx11.cpp"
112122
( ${SETUP} ; ${CMD} check_cxx11.cpp )
113123
else
@@ -236,10 +246,6 @@ check_toolset ()
236246
if test_toolset cxx && test_compiler cxx ; then B2_TOOLSET=cxx ; return ${TRUE} ; fi
237247
if test_toolset cxx && test_compiler cpp ; then B2_TOOLSET=cxx ; return ${TRUE} ; fi
238248
if test_toolset cxx && test_compiler CC ; then B2_TOOLSET=cxx ; return ${TRUE} ; fi
239-
# Generic cross compile (cross-cxx)
240-
if test_toolset cross-cxx && test_compiler ${BUILD_CXX:-cxx} ; then B2_TOOLSET=cross-cxx ; return ${TRUE} ; fi
241-
if test_toolset cross-cxx && test_compiler ${BUILD_CXX:-cpp} ; then B2_TOOLSET=cross-cxx ; return ${TRUE} ; fi
242-
if test_toolset cross-cxx && test_compiler ${BUILD_CXX:-CC} ; then B2_TOOLSET=cross-cxx ; return ${TRUE} ; fi
243249

244250
# Nothing found.
245251
if test "${B2_TOOLSET}" = "" ; then
@@ -252,18 +258,26 @@ check_toolset ()
252258
while test $# -gt 0
253259
do
254260
case "$1" in
255-
--verbose) B2_VERBOSE=${TRUE} ;;
256-
--debug) B2_DEBUG=${TRUE} ;;
257-
--guess-toolset) B2_GUESS_TOOLSET=${TRUE} ;;
261+
--verbose) B2_VERBOSE_OPT=${TRUE} ;;
262+
--debug) B2_DEBUG_OPT=${TRUE} ;;
263+
--guess-toolset) B2_GUESS_TOOLSET_OPT=${TRUE} ;;
264+
--help) B2_HELP_OPT=${TRUE} ;;
265+
--cxx=*) B2_CXX_OPT=`expr "x$1" : "x--cxx=\(.*\)"` ;;
266+
--cxxflags=*) B2_CXXFLAGS_OPT=`expr "x$1" : "x--cxxflags=\(.*\)"` ;;
258267
-*) ;;
259268
?*) B2_TOOLSET=$1 ;;
260269
esac
261270
shift
262271
done
263272

273+
# Show some help, if requested.
274+
if test_true ${B2_HELP_OPT} ; then
275+
error_exit
276+
fi
277+
264278
# If we have a CXX but no B2_TOLSET specified by the user we assume they meant
265279
# "cxx" as the toolset.
266-
if test "${CXX}" != "" -a "${B2_TOOLSET}" = "" ; then
280+
if test "${B2_CXX_OPT}" != "" -a "${B2_TOOLSET}" = "" ; then
267281
B2_TOOLSET=cxx
268282
fi
269283

@@ -273,7 +287,7 @@ TOOLSET_CHECK=$?
273287

274288
# We can bail from the rest of the checks and build if we are just guessing
275289
# the toolset.
276-
if test_true ${B2_GUESS_TOOLSET} ; then
290+
if test_true ${B2_GUESS_TOOLSET_OPT} ; then
277291
echo "${B2_TOOLSET}"
278292
exit 0
279293
fi
@@ -284,7 +298,7 @@ if ! test_true ${TOOLSET_CHECK} ; then
284298
A C++11 capable compiler is required for building the B2 engine.
285299
Toolset '${B2_TOOLSET}' does not appear to support C++11.
286300
"
287-
(B2_VERBOSE=${TRUE} check_toolset)
301+
(B2_VERBOSE_OPT=${TRUE} check_toolset)
288302
error_exit "
289303
** Note, the C++11 capable compiler is _only_ required for building the B2
290304
** engine. The B2 build system allows for using any C++ level and any other
@@ -402,11 +416,6 @@ case "${B2_TOOLSET}" in
402416
CXX_VERSION_OPT=${CXX_VERSION_OPT:---version}
403417
;;
404418

405-
cross-cxx)
406-
CXXFLAGS=${BUILD_CXXFLAGS}
407-
CXX_VERSION_OPT=${CXX_VERSION_OPT:---version}
408-
;;
409-
410419
*)
411420
error_exit "Unknown toolset: ${B2_TOOLSET}"
412421
;;
@@ -483,14 +492,14 @@ modules/sequence.cpp \
483492
modules/set.cpp \
484493
"
485494

486-
if test_true ${B2_DEBUG} ; then B2_CXXFLAGS="${B2_CXXFLAGS_DEBUG}"
495+
if test_true ${B2_DEBUG_OPT} ; then B2_CXXFLAGS="${B2_CXXFLAGS_DEBUG}"
487496
else B2_CXXFLAGS="${B2_CXXFLAGS_RELEASE} -DNDEBUG"
488497
fi
489-
( B2_VERBOSE=${TRUE} echo_run ${B2_CXX} ${CXXFLAGS} ${B2_CXXFLAGS} ${B2_SOURCES} -o b2 )
490-
( B2_VERBOSE=${TRUE} echo_run cp b2 bjam )
498+
( B2_VERBOSE_OPT=${TRUE} echo_run ${B2_CXX} ${B2_CXXFLAGS} ${B2_SOURCES} -o b2 )
499+
( B2_VERBOSE_OPT=${TRUE} echo_run cp b2 bjam )
491500
}
492501

493-
if test_true ${B2_VERBOSE} ; then
502+
if test_true ${B2_VERBOSE_OPT} ; then
494503
(
495504
${B2_SETUP}
496505
build_b2

0 commit comments

Comments
 (0)