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,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"
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 if test $cppcompiler = ''; then
217 echo "ERROR: Unknown compiler: $ccompiler"
218 exit $ERROR_EXIT_CODE
222 # Determine OS family
223 if test $OS_FAMILY = 'unknown'; then
224 OS_FAMILY=`uname |tr [A-Z] [a-z]|sed "s/-//"`
236 linux|sunos|hpux|aix|freebsd|mingw|darwin)
239 echo "Warning: Unknown operation system: $OS_FAMILY"
240 #exit $ERROR_EXIT_CODE
245 # Determine processor architecture
246 if test $processor_arch = 'unknown'; then
247 processor_arch=`uname -m|tr [A-Z] [a-z]`
249 case $processor_arch in
251 if test $bitsToBuild = 64; then
252 processor_arch='amd64'
258 if test $bitsToBuild = 64; then
259 processor_arch='amd64'
265 processor_arch='sparc'
267 amd64|x86|ia64|sparc)
270 processor_arch=`uname -p|tr [A-Z] [a-z]`
271 case $processor_arch in
275 echo "Warning: Unknown processor architecture: $processor_arch"
276 #exit ${ERROR_EXIT_CODE}
282 # Determine compiler flags
285 case $processor_arch in
288 linux|freebsd|darwin)
289 buildCXXflags="-m64 -fPIC -march=$ArchFlag $amd64_cxx_options"
290 buildCflags="-m64 -fPIC -march=$ArchFlag $amd64_cxx_options"
291 buildLDflags="-m64 -fPIC"
292 buildTestLDflags="-m64 -fPIC"
295 buildCXXflags="-m64 -march=$ArchFlag $amd64_cxx_options"
296 buildCflags="-m64 -march=$ArchFlag $amd64_cxx_options"
298 buildTestLDflags="-m64"
302 echo "Warning: cannot determine compiler flags for processor $processor_arch, OS $OS_FAMILY, and compiler $ccompiler"
303 #exit ${ERROR_EXIT_CODE}
309 linux|freebsd|darwin)
310 buildCXXflags="-m32 -fPIC -march=$ArchFlag"
311 buildCflags="-m32 -fPIC -march=$ArchFlag"
312 buildLDflags="-m32 -fPIC"
313 buildTestLDflags="-m32 -fPIC"
316 buildCXXflags="-m32 -march=$ArchFlag"
317 buildCflags="-m32 -march=$ArchFlag"
319 buildTestLDflags="-m32"
323 echo "Warning: cannot determine compiler flags for processor $processor_arch, OS $OS_FAMILY, and compiler $ccompiler"
324 #exit ${ERROR_EXIT_CODE}
332 buildCXXflags="-mtune=itanium2 -fPIC"
333 buildCflags="-mtune=itanium2 -fPIC"
334 buildLDflags="-mtune=itanium2 -fPIC"
335 buildTestLDflags="-mtune=itanium2 -fPIC"
338 buildCXXflags="-mlp64 -mtune=itanium2 -fPIC"
339 buildCflags="-mlp64 -mtune=itanium2 -fPIC"
340 buildLDflags="-mlp64 -mtune=itanium2 -fPIC"
341 buildTestLDflags="-mlp64 -mtune=itanium2 -fPIC"
344 echo "Warning: cannot determine compiler flags for processor $processor_arch, OS $OS_FAMILY, and compiler $ccompiler"
345 #exit ${ERROR_EXIT_CODE}
353 buildCXXflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC -pthreads"
354 buildCflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC -pthreads"
355 buildLDflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC -pthreads"
356 buildTestLDflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC -pthreads"
357 cxx_test_release_options="-fPIC"
358 ld_test_release_options="-fPIC"
361 buildCXXflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC"
362 buildCflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC"
363 buildLDflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC"
364 buildTestLDflags="-mcpu=v9 -mtune=ultrasparc3 -m64 -fPIC"
365 cxx_test_release_options="-fPIC"
366 ld_test_release_options="-fPIC"
369 echo "Warning: cannot determine compiler flags for processor $processor_arch, OS $OS_FAMILY, and compiler $ccompiler"
370 #exit ${ERROR_EXIT_CODE}
378 buildCXXflags="-maix64 -pthread -fPIC"
379 buildCflags="-maix64 -pthread -fPIC"
380 buildLDflags="-maix64 -pthread -fPIC"
381 buildTestLDflags="-maix64 -pthread -fPIC"
382 cxx_test_release_options="-fPIC"
383 ld_test_release_options="-fPIC"
386 echo "Warning: cannot determine compiler flags for processor $processor_arch, OS $OS_FAMILY, and compiler $ccompiler"
387 #exit ${ERROR_EXIT_CODE}
392 echo "Warning: cannot determine compiler flags for processor $processor_arch and compiler $ccompiler"
393 #exit ${ERROR_EXIT_CODE}
397 #cppcompiler_version=`$cppcompiler -dumpversion`
398 #echo compiler version=$cppcompiler $cppcompiler_version
400 # Setup target options
401 # buildCXXflags="-std=gnu++0x $buildCXXflags"
402 #cxx_debug_options="-D_DEBUG -O0 -g $cxx_debug_options"
403 #cxx_release_options="-DNDEBUG $cxx_release_optimization $cxx_release_options"
406 case $processor_arch in
410 buildCXXflags="-fPIC -march=$ArchFlag $amd64_cxx_options"
411 buildCflags="-fPIC -march=$ArchFlag $amd64_cxx_options"
413 buildTestLDflags="-fPIC"
416 echo "Warning: cannot determine compiler flags for processor $processor_arch, OS $OS_FAMILY, and compiler $ccompiler"
417 #exit ${ERROR_EXIT_CODE}
424 buildCXXflags="-fPIC -march=$ArchFlag"
425 buildCflags="-fPIC -march=$ArchFlag"
427 buildTestLDflags="-fPIC"
430 echo "Warning: cannot determine compiler flags for processor $processor_arch, OS $OS_FAMILY, and compiler $ccompiler"
431 #exit ${ERROR_EXIT_CODE}
436 echo "Warning: cannot determine compiler flags for processor $processor_arch and compiler $ccompiler"
437 #exit ${ERROR_EXIT_CODE}
442 echo "ERROR: Unknown compiler: $ccompiler"
443 exit ${ERROR_EXIT_CODE}
447 cppcompiler_version=`$cppcompiler -dumpversion`
448 echo compiler version=$cppcompiler $cppcompiler_version
450 # Setup target options
451 # buildCXXflags="-std=gnu++0x $buildCXXflags"
452 cxx_debug_options="-D_DEBUG -O0 -g $cxx_debug_options"
453 cxx_release_options="-DNDEBUG $cxx_release_optimization $cxx_release_options"
456 if test 'x$BOOST_INCLUDE_PATH' != 'x'; then
457 buildCXXflags="$buildCXXflags -I$BOOST_INCLUDE_PATH"
460 if test 'x$buildTestLDflags' = 'x'; then
461 buildTestLDflags=$buildLDflags
465 EXTRA_CXXFLAGS="$buildCXXflags $EXTRA_CXXFLAGS"
466 EXTRA_CFLAGS="$buildCflags $EXTRA_CFLAGS"
467 EXTRA_LDFLAGS="$buildLDflags $EXTRA_LDFLAGS"
469 EXTRA_TEST_LDFLAGS="$buildTestLDflags $EXTRA_TEST_LDFLAGS"
472 echo "Building with the following options ..."
473 echo "Processor: $processor_arch"
474 echo "Platform: $OS_FAMILY"
475 echo "C Compiler: $ccompiler"
476 echo "C++ Compiler: $cppcompiler"
477 echo "C++ Compiler version: $cppcompiler_version"
478 echo "Bits to build: $bitsToBuild"
479 echo "Compile options: $compileroptions $EXTRA_CXXFLAGS"
480 echo "Link options: $linkeroptions $EXTRA_LDFLAGS"
481 echo "Link options (for test cds-unit app): $linkeroptions $EXTRA_TEST_LDFLAGS"
483 BITSTOBUILD=$bitsToBuild
487 # Set the C compiler and C++ compiler environment variables
498 GOAL_DIR=$ccompiler$TOOLSET_SUFFIX-$processor_arch-$OS_FAMILY$OS_VERSION-$bitsToBuild
499 BIN_PATH=$ROOT_DIR/bin/$GOAL_DIR
502 OBJ_PATH=$ROOT_DIR/obj/$GOAL_DIR
506 echo LD_LIBRARY_PATH=$LD_LIBRARY_PATH
507 echo BIN_PATH=$BIN_PATH
508 echo OBJ_PATH=$OBJ_PATH
509 echo `${CXX} --version | head -1`
513 if test $makeclean = 'on'; then
515 $MAKE -f Makefile clean platform=$OS_FAMILY BIN_PATH=$BIN_PATH OBJ_PATH=$OBJ_PATH
518 echo ---------------------------------
519 echo Make debug library
520 #CXXFLAGS="$compileroptions $cxx_debug_options $EXTRA_CXXFLAGS"
522 #CFLAGS="$compileroptions $cxx_debug_options $EXTRA_CFLAGS $debugflag "
524 #LDFLAGS="$linkeroptions -shared $ld_debug_options $EXTRA_LDFLAGS "
527 mkdir -p $OBJ_PATH/debug
529 CXXFLAGS="$compileroptions $cxx_debug_options $EXTRA_CXXFLAGS" \
530 CFLAGS="$compileroptions $cxx_debug_options $EXTRA_CFLAGS $debugflag " \
532 LDFLAGS="$linkeroptions -shared $ld_debug_options $EXTRA_LDFLAGS " \
534 platform=$OS_FAMILY \
536 OBJ_PATH=$OBJ_PATH/debug \
539 if test $? -gt 0; then
543 echo ---------------------------------
544 echo Make release library
546 #CXXFLAGS="$compileroptions $cxx_release_options $EXTRA_CXXFLAGS "
548 #CFLAGS="$compileroptions $cxx_release_options $EXTRA_CFLAGS "
550 #LDFLAGS="$linkeroptions -shared $ld_resease_options $ld_libs $EXTRA_LDFLAGS "
553 mkdir -p $OBJ_PATH/release
555 CXXFLAGS="$compileroptions $cxx_release_options $EXTRA_CXXFLAGS " \
556 CFLAGS="$compileroptions $cxx_release_options $EXTRA_CFLAGS " \
557 LDFLAGS="$linkeroptions -shared $ld_resease_options $EXTRA_LDFLAGS " \
560 platform=$OS_FAMILY \
562 OBJ_PATH=$OBJ_PATH/release \
565 if test $? -gt 0; then
570 echo ---------------------------------
573 if test $MAKE_DEBUG_TEST = '0'; then
574 CXXFLAGS="$compileroptions $cxx_release_options $cxx_test_release_options $EXTRA_CXXFLAGS "
576 CFLAGS="$compileroptions $cxx_release_options $EXTRA_CFLAGS "
578 LDFLAGS="$linkeroptions $ld_release_options $ld_test_release_options $ld_libs $EXTRA_TEST_LDFLAGS "
581 $MAKE -f Makefile -j $makejobs \
582 platform=$OS_FAMILY \
584 OBJ_PATH=$OBJ_PATH/test \
587 if test $? -gt 0; then
592 echo ---------------------------------
593 echo Make tests debug
595 if test $MAKE_DEBUG_TEST = '1'; then
596 CXXFLAGS="$compileroptions $cxx_debug_options $cxx_test_release_options $EXTRA_CXXFLAGS "
598 CFLAGS="$compileroptions $cxx_debug_options $EXTRA_CFLAGS "
600 LDFLAGS="$linkeroptions $ld_debug_options $ld_test_release_options $ld_libs $EXTRA_TEST_LDFLAGS "
603 $MAKE -f Makefile -j $makejobs \
604 platform=$OS_FAMILY \
606 OBJ_PATH=$OBJ_PATH/test-debug \
609 if test $? -gt 0; then