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 <target> make target"
21 echo " -c <C compiler name> Possible values are: gcc,clang,icc"
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"
125 EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS -D$2"
130 exit $ERROR_EXIT_CODE;;
137 BOOST_INCLUDE_PATH=$2
148 --release-cxx-options)
149 cxx_release_options=$2
153 cxx_release_optimization_level=$2
156 --release-ld-options)
157 ld_release_options=$2
178 if test $target = 'test'; then
184 amd64_cxx_options='-mcx16'
195 echo "unknown option $1"
197 exit $ERROR_EXIT_CODE;;
201 cxx_release_optimization="$cxx_release_optimization_level $cxx_release_optimization"
206 if test $cppcompiler = ''; then
211 if test $cppcompiler = ''; then
216 if test $cppcompiler = ''; then
221 echo "ERROR: Unknown compiler: $ccompiler"
222 exit $ERROR_EXIT_CODE
226 # Determine OS family
227 if test $OS_FAMILY = 'unknown'; then
228 OS_FAMILY=`uname |tr [A-Z] [a-z]|sed "s/-//"`
240 linux|sunos|hpux|aix|freebsd|mingw|darwin)
243 echo "Warning: Unknown operation system: $OS_FAMILY"
244 #exit $ERROR_EXIT_CODE
249 # Determine processor architecture
250 if test $processor_arch = 'unknown'; then
251 processor_arch=`uname -m|tr [A-Z] [a-z]`
253 case $processor_arch in
255 if test $bitsToBuild = 64; then
256 processor_arch='amd64'
262 if test $bitsToBuild = 64; then
263 processor_arch='amd64'
269 processor_arch='sparc'
271 amd64|x86|ia64|sparc)
274 processor_arch=`uname -p|tr [A-Z] [a-z]`
275 case $processor_arch in
279 echo "Warning: Unknown processor architecture: $processor_arch"
280 #exit ${ERROR_EXIT_CODE}
286 # Determine compiler flags
289 case $processor_arch in
292 linux|freebsd|darwin)
293 buildCXXflags="-m64 -fPIC -march=$ArchFlag $amd64_cxx_options"
294 buildCflags="-m64 -fPIC -march=$ArchFlag $amd64_cxx_options"
295 buildLDflags="-m64 -fPIC"
296 buildTestLDflags="-m64 -fPIC"
299 buildCXXflags="-m64 -march=$ArchFlag $amd64_cxx_options"
300 buildCflags="-m64 -march=$ArchFlag $amd64_cxx_options"
302 buildTestLDflags="-m64"
306 echo "Warning: cannot determine compiler flags for processor $processor_arch, OS $OS_FAMILY, and compiler $ccompiler"
307 #exit ${ERROR_EXIT_CODE}
313 linux|freebsd|darwin)
314 buildCXXflags="-m32 -fPIC -march=$ArchFlag"
315 buildCflags="-m32 -fPIC -march=$ArchFlag"
316 buildLDflags="-m32 -fPIC"
317 buildTestLDflags="-m32 -fPIC"
320 buildCXXflags="-m32 -march=$ArchFlag"
321 buildCflags="-m32 -march=$ArchFlag"
323 buildTestLDflags="-m32"
327 echo "Warning: cannot determine compiler flags for processor $processor_arch, OS $OS_FAMILY, and compiler $ccompiler"
328 #exit ${ERROR_EXIT_CODE}
336 buildCXXflags="-mtune=itanium2 -fPIC"
337 buildCflags="-mtune=itanium2 -fPIC"
338 buildLDflags="-mtune=itanium2 -fPIC"
339 buildTestLDflags="-mtune=itanium2 -fPIC"
342 buildCXXflags="-mlp64 -mtune=itanium2 -fPIC"
343 buildCflags="-mlp64 -mtune=itanium2 -fPIC"
344 buildLDflags="-mlp64 -mtune=itanium2 -fPIC"
345 buildTestLDflags="-mlp64 -mtune=itanium2 -fPIC"
348 echo "Warning: cannot determine compiler flags for processor $processor_arch, OS $OS_FAMILY, and compiler $ccompiler"
349 #exit ${ERROR_EXIT_CODE}
357 buildCXXflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC -pthreads"
358 buildCflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC -pthreads"
359 buildLDflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC -pthreads"
360 buildTestLDflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC -pthreads"
361 cxx_test_release_options="-fPIC"
362 ld_test_release_options="-fPIC"
365 buildCXXflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC"
366 buildCflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC"
367 buildLDflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC"
368 buildTestLDflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC"
369 cxx_test_release_options="-fPIC"
370 ld_test_release_options="-fPIC"
373 echo "Warning: cannot determine compiler flags for processor $processor_arch, OS $OS_FAMILY, and compiler $ccompiler"
374 #exit ${ERROR_EXIT_CODE}
382 buildCXXflags="-maix64 -pthread -fPIC"
383 buildCflags="-maix64 -pthread -fPIC"
384 buildLDflags="-maix64 -pthread -fPIC"
385 buildTestLDflags="-maix64 -pthread -fPIC"
386 cxx_test_release_options="-fPIC"
387 ld_test_release_options="-fPIC"
390 echo "Warning: cannot determine compiler flags for processor $processor_arch, OS $OS_FAMILY, and compiler $ccompiler"
391 #exit ${ERROR_EXIT_CODE}
396 echo "Warning: cannot determine compiler flags for processor $processor_arch and compiler $ccompiler"
397 #exit ${ERROR_EXIT_CODE}
401 #cppcompiler_version=`$cppcompiler -dumpversion`
402 #echo compiler version=$cppcompiler $cppcompiler_version
404 # Setup target options
405 # buildCXXflags="-std=gnu++0x $buildCXXflags"
406 #cxx_debug_options="-D_DEBUG -O0 -g $cxx_debug_options"
407 #cxx_release_options="-DNDEBUG $cxx_release_optimization $cxx_release_options"
410 case $processor_arch in
414 buildCXXflags="-fPIC -march=$ArchFlag $amd64_cxx_options"
415 buildCflags="-fPIC -march=$ArchFlag $amd64_cxx_options"
417 buildTestLDflags="-fPIC"
420 echo "Warning: cannot determine compiler flags for processor $processor_arch, OS $OS_FAMILY, and compiler $ccompiler"
421 #exit ${ERROR_EXIT_CODE}
428 buildCXXflags="-fPIC -march=$ArchFlag"
429 buildCflags="-fPIC -march=$ArchFlag"
431 buildTestLDflags="-fPIC"
434 echo "Warning: cannot determine compiler flags for processor $processor_arch, OS $OS_FAMILY, and compiler $ccompiler"
435 #exit ${ERROR_EXIT_CODE}
440 echo "Warning: cannot determine compiler flags for processor $processor_arch and compiler $ccompiler"
441 #exit ${ERROR_EXIT_CODE}
446 echo "ERROR: Unknown compiler: $ccompiler"
447 exit ${ERROR_EXIT_CODE}
451 cppcompiler_version=`$cppcompiler -dumpversion`
452 echo compiler version=$cppcompiler $cppcompiler_version
454 # Setup target options
455 # buildCXXflags="-std=gnu++0x $buildCXXflags"
456 cxx_debug_options="-D_DEBUG -O0 -g $cxx_debug_options"
457 cxx_release_options="-DNDEBUG $cxx_release_optimization $cxx_release_options"
460 if test "x$BOOST_INCLUDE_PATH" != "x"; then
461 buildCXXflags="$buildCXXflags -I$BOOST_INCLUDE_PATH"
464 if test "x$buildTestLDflags" = "x"; then
465 buildTestLDflags=$buildLDflags
469 EXTRA_CXXFLAGS="$buildCXXflags $EXTRA_CXXFLAGS"
470 EXTRA_CFLAGS="$buildCflags $EXTRA_CFLAGS"
471 EXTRA_LDFLAGS="$buildLDflags $EXTRA_LDFLAGS"
473 EXTRA_TEST_LDFLAGS="$buildTestLDflags $EXTRA_TEST_LDFLAGS"
476 echo "Building with the following options ..."
477 echo "Processor: $processor_arch"
478 echo "Platform: $OS_FAMILY"
479 echo "C Compiler: $ccompiler"
480 echo "C++ Compiler: $cppcompiler"
481 echo "C++ Compiler version: $cppcompiler_version"
482 echo "Bits to build: $bitsToBuild"
483 echo "Compile options: $compileroptions $EXTRA_CXXFLAGS"
484 echo "Link options: $linkeroptions $EXTRA_LDFLAGS"
485 echo "Link options (for test cds-unit app): $linkeroptions $EXTRA_TEST_LDFLAGS"
487 BITSTOBUILD=$bitsToBuild
491 # Set the C compiler and C++ compiler environment variables
502 GOAL_DIR=$ccompiler$TOOLSET_SUFFIX-$processor_arch-$OS_FAMILY$OS_VERSION-$bitsToBuild
503 BIN_PATH=$ROOT_DIR/bin/$GOAL_DIR
506 OBJ_PATH=$ROOT_DIR/obj/$GOAL_DIR
510 echo LD_LIBRARY_PATH=$LD_LIBRARY_PATH
511 echo BIN_PATH=$BIN_PATH
512 echo OBJ_PATH=$OBJ_PATH
513 echo `${CXX} --version | head -1`
517 if test $makeclean = 'on'; then
519 $MAKE -f Makefile clean platform=$OS_FAMILY BIN_PATH=$BIN_PATH OBJ_PATH=$OBJ_PATH
522 echo ---------------------------------
523 echo Make debug library
524 #CXXFLAGS="$compileroptions $cxx_debug_options $EXTRA_CXXFLAGS"
526 #CFLAGS="$compileroptions $cxx_debug_options $EXTRA_CFLAGS $debugflag "
528 #LDFLAGS="$linkeroptions -shared $ld_debug_options $EXTRA_LDFLAGS "
531 mkdir -p $OBJ_PATH/debug
533 CXXFLAGS="$compileroptions $cxx_debug_options $EXTRA_CXXFLAGS" \
534 CFLAGS="$compileroptions $cxx_debug_options $EXTRA_CFLAGS $debugflag " \
536 LDFLAGS="$linkeroptions -shared $ld_debug_options $EXTRA_LDFLAGS " \
538 platform=$OS_FAMILY \
540 OBJ_PATH=$OBJ_PATH/debug \
544 echo ---------------------------------
545 echo Make release library
547 #CXXFLAGS="$compileroptions $cxx_release_options $EXTRA_CXXFLAGS "
549 #CFLAGS="$compileroptions $cxx_release_options $EXTRA_CFLAGS "
551 #LDFLAGS="$linkeroptions -shared $ld_resease_options $ld_libs $EXTRA_LDFLAGS "
554 mkdir -p $OBJ_PATH/release
556 CXXFLAGS="$compileroptions $cxx_release_options $EXTRA_CXXFLAGS " \
557 CFLAGS="$compileroptions $cxx_release_options $EXTRA_CFLAGS " \
558 LDFLAGS="$linkeroptions -shared $ld_resease_options $EXTRA_LDFLAGS " \
561 platform=$OS_FAMILY \
563 OBJ_PATH=$OBJ_PATH/release \
568 echo ---------------------------------
571 if test $MAKE_DEBUG_TEST = '0'; then
572 CXXFLAGS="$compileroptions $cxx_release_options $cxx_test_release_options $EXTRA_CXXFLAGS "
574 CFLAGS="$compileroptions $cxx_release_options $EXTRA_CFLAGS "
576 LDFLAGS="$linkeroptions $ld_release_options $ld_test_release_options $ld_libs $EXTRA_TEST_LDFLAGS "
579 $MAKE -f Makefile -j $makejobs \
580 platform=$OS_FAMILY \
582 OBJ_PATH=$OBJ_PATH/test \
587 echo ---------------------------------
588 echo Make tests debug
590 if test $MAKE_DEBUG_TEST = '1'; then
591 CXXFLAGS="$compileroptions $cxx_debug_options $cxx_test_release_options $EXTRA_CXXFLAGS "
593 CFLAGS="$compileroptions $cxx_debug_options $EXTRA_CFLAGS "
595 LDFLAGS="$linkeroptions $ld_debug_options $ld_test_release_options $ld_libs $EXTRA_TEST_LDFLAGS "
598 $MAKE -f Makefile -j $makejobs \
599 platform=$OS_FAMILY \
601 OBJ_PATH=$OBJ_PATH/test-debug \