3 # cds library build script
4 # Maxim Khiszinsky 04.01.2009
6 # The following variables are defined and exported at the end of this script.
17 echo "Build helper script for one of the supported platforms"
18 echo "Usage: build.sh \"options\""
19 echo " where options may be any of the following:"
20 echo " -t make target"
21 echo " -c <C compiler name> Possible values are: gcc,clang"
22 echo " -x <C++ compiler name> (e.g. g++, CC)"
23 echo " -p <Processor architecture> Possible values are:"
24 echo " x86, amd64 (x86_64), sparc, ia64"
25 echo " -o <OS family> Possible values are:"
26 echo " linux, sunos (solaris), hpux, darwin"
27 echo " -D <define> define"
28 echo " -b <bitsToBuild> (accepts '64', '32')"
29 echo " -l <extra linker options>"
30 echo " -z <extra compiler options>"
31 echo " -j <number of make jobs. default 2>"
32 echo " -h (to get help on the above commands)"
33 echo " --with-boost <path to boost include>"
34 echo " --debug-cxx-options <extra compiler options for debug target>"
35 echo " --debug-ld-options <extra linker options for debug target>"
36 echo " --release-cxx-options <extra compiler options for release target>"
37 echo " --release-ld-options <extra linker options for release target>"
38 echo " --clean clean all before building"
39 echo " --debug-test make unit test in debug mode"
40 echo " --amd64-use-128bit use 128bit (16byte) CAS on amd64"
41 echo " --arch-tune march flag (only for x86/amd64), default = native"
42 echo " --nodefaultlibs - no default libs (pthread, stdc++)"
43 echo " --optimize-flags - optimization level flags for release target, default -O3"
50 # Set up the default values for each parameter
51 debug=off # by default debug is off
52 bitsToBuild=0 # unknown
56 processor_arch=unknown
65 ld_libs="-lpthread -ldl -lstdc++"
73 cxx_test_release_options=
74 ls_test_release_options=
76 cxx_release_optimization="-fno-strict-aliasing"
77 cxx_release_optimization_level="-O3"
106 processor_arch=$2; shift 2
113 linkeroptions="$linkeroptions $2"
117 compileroptions="$compileroptions $2"
126 exit $ERROR_EXIT_CODE;;
133 BOOST_INCLUDE_PATH=$2
144 --release-cxx-options)
145 cxx_release_options=$2
149 cxx_release_optimization_level=$2
152 --release-ld-options)
153 ld_release_options=$2
174 if test $target = 'test'; then
180 amd64_cxx_options='-mcx16'
191 echo "unknown option $1"
193 exit $ERROR_EXIT_CODE;;
197 cxx_release_optimization="$cxx_release_optimization_level $cxx_release_optimization"
202 if test $cppcompiler = ''; then
207 if test $cppcompiler = ''; then
212 echo "ERROR: Unknown compiler: $ccompiler"
213 exit $ERROR_EXIT_CODE
217 # Determine OS family
218 if test $OS_FAMILY = 'unknown'; then
219 OS_FAMILY=`uname |tr [A-Z] [a-z]|sed "s/-//"`
231 linux|sunos|hpux|aix|freebsd|mingw|darwin)
234 echo "Warning: Unknown operation system: $OS_FAMILY"
235 #exit $ERROR_EXIT_CODE
240 # Determine processor architecture
241 if test $processor_arch = 'unknown'; then
242 processor_arch=`uname -m|tr [A-Z] [a-z]`
244 case $processor_arch in
246 if test $bitsToBuild = 64; then
247 processor_arch='amd64'
253 if test $bitsToBuild = 64; then
254 processor_arch='amd64'
260 processor_arch='sparc'
262 amd64|x86|ia64|sparc)
265 processor_arch=`uname -p|tr [A-Z] [a-z]`
266 case $processor_arch in
270 echo "Warning: Unknown processor architecture: $processor_arch"
271 #exit ${ERROR_EXIT_CODE}
277 # Determine compiler flags
280 case $processor_arch in
283 linux|freebsd|darwin)
284 buildCXXflags="-m64 -fPIC -march=$ArchFlag $amd64_cxx_options"
285 buildCflags="-m64 -fPIC -march=$ArchFlag $amd64_cxx_options"
286 buildLDflags="-m64 -fPIC"
287 buildTestLDflags="-m64 -fPIC"
290 buildCXXflags="-m64 -march=$ArchFlag $amd64_cxx_options"
291 buildCflags="-m64 -march=$ArchFlag $amd64_cxx_options"
293 buildTestLDflags="-m64"
297 echo "Warning: cannot determine compiler flags for processor $processor_arch, OS $OS_FAMILY, and compiler $ccompiler"
298 #exit ${ERROR_EXIT_CODE}
304 linux|freebsd|darwin)
305 buildCXXflags="-m32 -fPIC -march=$ArchFlag"
306 buildCflags="-m32 -fPIC -march=$ArchFlag"
307 buildLDflags="-m32 -fPIC"
308 buildTestLDflags="-m32 -fPIC"
311 buildCXXflags="-m32 -march=$ArchFlag"
312 buildCflags="-m32 -march=$ArchFlag"
314 buildTestLDflags="-m32"
318 echo "Warning: cannot determine compiler flags for processor $processor_arch, OS $OS_FAMILY, and compiler $ccompiler"
319 #exit ${ERROR_EXIT_CODE}
327 buildCXXflags="-mtune=itanium2 -fPIC"
328 buildCflags="-mtune=itanium2 -fPIC"
329 buildLDflags="-mtune=itanium2 -fPIC"
330 buildTestLDflags="-mtune=itanium2 -fPIC"
333 buildCXXflags="-mlp64 -mtune=itanium2 -fPIC"
334 buildCflags="-mlp64 -mtune=itanium2 -fPIC"
335 buildLDflags="-mlp64 -mtune=itanium2 -fPIC"
336 buildTestLDflags="-mlp64 -mtune=itanium2 -fPIC"
339 echo "Warning: cannot determine compiler flags for processor $processor_arch, OS $OS_FAMILY, and compiler $ccompiler"
340 #exit ${ERROR_EXIT_CODE}
348 buildCXXflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC -pthreads"
349 buildCflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC -pthreads"
350 buildLDflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC -pthreads"
351 buildTestLDflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC -pthreads"
352 cxx_test_release_options="-fPIC"
353 ld_test_release_options="-fPIC"
356 buildCXXflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC"
357 buildCflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC"
358 buildLDflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC"
359 buildTestLDflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC"
360 cxx_test_release_options="-fPIC"
361 ld_test_release_options="-fPIC"
364 echo "Warning: cannot determine compiler flags for processor $processor_arch, OS $OS_FAMILY, and compiler $ccompiler"
365 #exit ${ERROR_EXIT_CODE}
373 buildCXXflags="-maix64 -pthread -fPIC"
374 buildCflags="-maix64 -pthread -fPIC"
375 buildLDflags="-maix64 -pthread -fPIC"
376 buildTestLDflags="-maix64 -pthread -fPIC"
377 cxx_test_release_options="-fPIC"
378 ld_test_release_options="-fPIC"
381 echo "Warning: cannot determine compiler flags for processor $processor_arch, OS $OS_FAMILY, and compiler $ccompiler"
382 #exit ${ERROR_EXIT_CODE}
387 echo "Warning: cannot determine compiler flags for processor $processor_arch and compiler $ccompiler"
388 #exit ${ERROR_EXIT_CODE}
392 cppcompiler_version=`$cppcompiler -dumpversion`
393 echo g++ version=$gcc_version
395 # Setup target options
396 # buildCXXflags="-std=gnu++0x $buildCXXflags"
397 cxx_debug_options="-D_DEBUG -O0 -g $cxx_debug_options"
398 cxx_release_options="-DNDEBUG $cxx_release_optimization $cxx_release_options"
401 echo "ERROR: Unknown compiler: $ccompiler"
402 exit ${ERROR_EXIT_CODE}
406 if test $BOOST_INCLUDE_PATH != ''; then
407 buildCXXflags="$buildCXXflags -I$BOOST_INCLUDE_PATH"
410 if test 'x$buildTestLDflags' = 'x'; then
411 buildTestLDflags=$buildLDflags
415 EXTRA_CXXFLAGS="$buildCXXflags $EXTRA_CXXFLAGS"
416 EXTRA_CFLAGS="$buildCflags $EXTRA_CFLAGS"
417 EXTRA_LDFLAGS="$buildLDflags $EXTRA_LDFLAGS"
419 EXTRA_TEST_LDFLAGS="$buildTestLDflags $EXTRA_TEST_LDFLAGS"
422 echo "Building with the following options ..."
423 echo "Processor: $processor_arch"
424 echo "Platform: $OS_FAMILY"
425 echo "C Compiler: $ccompiler"
426 echo "C++ Compiler: $cppcompiler"
427 echo "C++ Compiler version: $cppcompiler_version"
428 echo "Bits to build: $bitsToBuild"
429 echo "Compile options: $compileroptions $EXTRA_CXXFLAGS"
430 echo "Link options: $linkeroptions $EXTRA_LDFLAGS"
431 echo "Link options (for test cds-unit app): $linkeroptions $EXTRA_TEST_LDFLAGS"
433 BITSTOBUILD=$bitsToBuild
437 # Set the C compiler and C++ compiler environment variables
448 GOAL_DIR=$ccompiler$TOOLSET_SUFFIX-$processor_arch-$OS_FAMILY$OS_VERSION-$bitsToBuild
449 BIN_PATH=$ROOT_DIR/bin/$GOAL_DIR
452 OBJ_PATH=$ROOT_DIR/obj/$GOAL_DIR
456 echo LD_LIBRARY_PATH=$LD_LIBRARY_PATH
457 echo BIN_PATH=$BIN_PATH
458 echo OBJ_PATH=$OBJ_PATH
459 echo `${CXX} --version | head -1`
463 if test $makeclean = 'on'; then
465 $MAKE -f Makefile clean platform=$OS_FAMILY BIN_PATH=$BIN_PATH OBJ_PATH=$OBJ_PATH
468 echo ---------------------------------
469 echo Make debug library
470 CXXFLAGS="$compileroptions $cxx_debug_options $EXTRA_CXXFLAGS"
472 CFLAGS="$compileroptions $cxx_debug_options $EXTRA_CFLAGS $debugflag "
474 LDFLAGS="$linkeroptions -shared $ld_debug_options $ld_libs $EXTRA_LDFLAGS "
477 mkdir -p $OBJ_PATH/debug
480 platform=$OS_FAMILY \
482 OBJ_PATH=$OBJ_PATH/debug \
485 if test $? -gt 0; then
489 echo ---------------------------------
490 echo Make release library
492 CXXFLAGS="$compileroptions $cxx_release_options $EXTRA_CXXFLAGS "
494 CFLAGS="$compileroptions $cxx_release_options $EXTRA_CFLAGS "
496 LDFLAGS="$linkeroptions -shared $ld_resease_options $ld_libs $EXTRA_LDFLAGS "
499 mkdir -p $OBJ_PATH/release
502 platform=$OS_FAMILY \
504 OBJ_PATH=$OBJ_PATH/release \
507 if test $? -gt 0; then
512 echo ---------------------------------
515 if test $MAKE_DEBUG_TEST = '0'; then
516 CXXFLAGS="$compileroptions $cxx_release_options $cxx_test_release_options $EXTRA_CXXFLAGS "
518 CFLAGS="$compileroptions $cxx_release_options $EXTRA_CFLAGS "
520 LDFLAGS="$linkeroptions $ld_release_options $ld_test_release_options $ld_libs $EXTRA_TEST_LDFLAGS "
523 $MAKE -f Makefile -j $makejobs \
524 platform=$OS_FAMILY \
526 OBJ_PATH=$OBJ_PATH/test \
529 if test $? -gt 0; then
534 echo ---------------------------------
535 echo Make tests debug
537 if test $MAKE_DEBUG_TEST = '1'; then
538 CXXFLAGS="$compileroptions $cxx_debug_options $cxx_test_release_options $EXTRA_CXXFLAGS "
540 CFLAGS="$compileroptions $cxx_debug_options $EXTRA_CFLAGS "
542 LDFLAGS="$linkeroptions $ld_debug_options $ld_test_release_options $ld_libs $EXTRA_TEST_LDFLAGS "
545 $MAKE -f Makefile -j $makejobs \
546 platform=$OS_FAMILY \
548 OBJ_PATH=$OBJ_PATH/test-debug \
551 if test $? -gt 0; then