3 # Copyright (C) 2012-2013 Brian Aker
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above
14 # copyright notice, this list of conditions and the following disclaimer
15 # in the documentation and/or other materials provided with the
18 # * The names of its contributors may not be used to endorse or
19 # promote products derived from this software without specific prior
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 # Environment Variables that will influence the build:
46 command_not_found_handle
()
48 warn
"$@: command not found"
54 while caller
$frame; do
65 echo "$BASH_SOURCE:$BASH_LINENO: $@" >&2
70 echo "$BASH_SOURCE:$BASH_LINENO: $@" >&2
76 echo "$BASH_SOURCE:$BASH_LINENO: $@"
77 #echo "$BASH_SOURCE:$BASH_LINENO: $@" >&1
82 local param_name
=\$
"$1"
83 local param_value
=`eval "expr \"$param_name\" "`
85 if [ -n "$param_value" ]; then
86 echo "$bash_source:$bash_lineno: assert($param_name) had value of "$param_value"" >&2
93 local param_name
=\$
"$1"
94 local param_value
=`eval "expr \"$param_name\" "`
96 if [ -z "$param_value" ]; then
97 echo "$bash_source:$bash_lineno: assert($param_name)" >&2
102 function assert_file
()
104 if [ ! -f "$1" ]; then
105 echo "$BASH_SOURCE:$BASH_LINENO: assert($1) does not exist: $2" >&2
110 function assert_no_file
()
113 echo "$BASH_SOURCE:$BASH_LINENO: assert($1) file exists: $2" >&2
118 function assert_no_directory
()
121 echo "$BASH_SOURCE:$BASH_LINENO: assert($1) directory exists: $2" >&2
126 function assert_exec_file
()
128 if [ ! -f "$1" ]; then
129 echo "$BASH_SOURCE:$BASH_LINENO: assert($1) does not exist: $2" >&2
133 if [ ! -x "$1" ]; then
134 echo "$BASH_SOURCE:$BASH_LINENO: assert($1) exists but is not executable: $2" >&2
139 function command_exists
()
141 type "$1" &> /dev
/null
;
144 function rebuild_host_os
()
146 HOST_OS
="${UNAME_MACHINE_ARCH}-${VENDOR}-${VENDOR_DISTRIBUTION}-${VENDOR_RELEASE}-${UNAME_KERNEL}-${UNAME_KERNEL_RELEASE}"
149 echo "HOST_OS=$HOST_OS"
154 # Validate the distribution name, or toss an erro
155 # values: darwin,fedora,rhel,ubuntu,debian,opensuse
156 function set_VENDOR_DISTRIBUTION
()
158 local dist
=`echo "$1" | tr '[A-Z]' '[a-z]'`
161 VENDOR_DISTRIBUTION
='darwin'
164 VENDOR_DISTRIBUTION
='fedora'
167 VENDOR_DISTRIBUTION
='rhel'
170 VENDOR_DISTRIBUTION
='debian'
173 VENDOR_DISTRIBUTION
='ubuntu'
176 VENDOR_DISTRIBUTION
='opensuse'
179 VENDOR_DISTRIBUTION
='opensuse'
182 die
"attempt to set an invalid VENDOR_DISTRIBUTION=$dist"
187 # Validate a Vendor's release name/number
188 function set_VENDOR_RELEASE
()
190 local release
=`echo "$1" | tr '[A-Z]' '[a-z]'`
193 echo "VENDOR_DISTRIBUTION:$VENDOR_DISTRIBUTION"
194 echo "VENDOR_RELEASE:$release"
197 case $VENDOR_DISTRIBUTION in
201 VENDOR_RELEASE
='snow_leopard'
204 VENDOR_RELEASE
='mountain'
207 VENDOR_RELEASE
='mountain'
211 VENDOR_RELEASE
='mountain_lion'
215 VENDOR_RELEASE
='unknown'
220 VENDOR_RELEASE
="$release"
221 if [[ "x$VENDOR_RELEASE" == '18' ]]; then
222 VENDOR_RELEASE
='sphericalcow'
226 VENDOR_RELEASE
="$release"
229 VENDOR_RELEASE
="$release"
232 VENDOR_RELEASE
="$release"
233 if [[ "x$VENDOR_RELEASE" == 'x12.04' ]]; then
234 VENDOR_RELEASE
="precise"
235 elif [[ "x$VENDOR_RELEASE" == 'x12.10' ]]; then
236 VENDOR_RELEASE
="quantal"
237 elif [[ "x$VENDOR_RELEASE" == 'x13.04' ]]; then
238 VENDOR_RELEASE
="raring"
242 VENDOR_RELEASE
="$release"
245 die
"attempt to set VENDOR_RELEASE without setting VENDOR_DISTRIBUTION"
248 die
"attempt to set with an invalid VENDOR_DISTRIBUTION=$VENDOR_DISTRIBUTION"
254 # Valid values are: apple, redhat, centos, canonical, oracle, suse
255 function set_VENDOR
()
257 local vendor
=`echo "$1" | tr '[A-Z]' '[a-z]'`
269 redhat-release-server-
*)
272 enterprise-release-
*)
294 die
"An attempt was made to set an invalid VENDOR=$_vendor"
298 set_VENDOR_DISTRIBUTION
$2
299 set_VENDOR_RELEASE
$3
301 # Set which vendor/versions we trust for autoreconf
302 case $VENDOR_DISTRIBUTION in
304 if [[ "x$VENDOR_RELEASE" == 'x18' ]]; then
305 AUTORECONF_REBUILD_HOST
=true
306 elif [[ "x$VENDOR_RELEASE" == 'xsphericalcow' ]]; then
307 AUTORECONF_REBUILD_HOST
=true
308 elif [[ "x$VENDOR_RELEASE" == 'x19' ]]; then
309 AUTORECONF_REBUILD_HOST
=true
313 if [[ "x$VENDOR_RELEASE" == 'xprecise' ]]; then
314 AUTORECONF_REBUILD_HOST
=true
315 elif [[ "x$VENDOR_RELEASE" == 'xquantal' ]]; then
316 AUTORECONF_REBUILD_HOST
=true
323 function determine_target_platform
()
325 UNAME_MACHINE_ARCH
=`(uname -m) 2>/dev/null` || UNAME_MACHINE_ARCH
=unknown
326 UNAME_KERNEL
=`(uname -s) 2>/dev/null` || UNAME_SYSTEM
=unknown
327 UNAME_KERNEL_RELEASE
=`(uname -r) 2>/dev/null` || UNAME_KERNEL_RELEASE
=unknown
329 if [[ -x '/usr/bin/sw_vers' ]]; then
330 local _VERSION
=`/usr/bin/sw_vers -productVersion`
331 set_VENDOR
'apple' 'darwin' $_VERSION
332 elif [[ $
(uname
) == 'Darwin' ]]; then
333 set_VENDOR
'apple' 'darwin' 'mountain'
334 elif [[ -f '/etc/fedora-release' ]]; then
335 local fedora_version
=`cat /etc/fedora-release | awk ' { print $3 } '`
336 set_VENDOR
'redhat' 'fedora' $fedora_version
337 elif [[ -f '/etc/centos-release' ]]; then
338 local centos_version
=`cat /etc/centos-release | awk ' { print $7 } '`
339 set_VENDOR
'centos' 'rhel' $centos_version
340 elif [[ -f '/etc/SuSE-release' ]]; then
341 local suse_distribution
=`head -1 /etc/SuSE-release | awk ' { print $1 } '`
342 local suse_version
=`head -1 /etc/SuSE-release | awk ' { print $2 } '`
343 set_VENDOR
'suse' $suse_distribution $suse_version
344 elif [[ -f '/etc/redhat-release' ]]; then
345 local rhel_version
=`cat /etc/redhat-release | awk ' { print $7 } '`
346 local _vendor
=`rpm -qf /etc/redhat-release`
347 set_VENDOR
$_vendor 'rhel' $rhel_version
348 elif [[ -f '/etc/os-release' ]]; then
349 source '/etc/os-release'
350 set_VENDOR
$ID $ID $VERSION_ID
351 elif [[ -x '/usr/bin/lsb_release' ]]; then
352 local _ID
=`/usr/bin/lsb_release -s -i`
353 local _VERSION
=`/usr/bin/lsb_release -s -r`
354 set_VENDOR
$_ID $_ID $_VERSION_ID
355 elif [[ -f '/etc/lsb-release' ]]; then
356 source '/etc/lsb-release'
357 set_VENDOR
'canonical' $DISTRIB_ID $DISTRIB_CODENAME
363 function run_configure
()
365 # We will run autoreconf if we are required
366 run_autoreconf_if_required
368 # We always begin at the root of our build
370 die
"Programmer error, we entered run_configure with a stacked directory"
373 if ! command_exists
"$CONFIGURE"; then
374 die
"$CONFIGURE does not exist"
378 if [[ -n "$BUILD_DIR" ]]; then
381 safe_pushd
$BUILD_DIR
384 # Arguments for configure
385 local BUILD_CONFIGURE_ARG
=
387 # If ENV DEBUG is set we enable both debug and asssert, otherwise we see if this is a VCS checkout and if so enable assert
388 # Set ENV ASSERT in order to enable assert.
389 # If we are doing a valgrind run, we always compile with assert disabled
390 if $valgrind_run; then
391 BUILD_CONFIGURE_ARG
+= " CXXFLAGS=-DNDEBUG "
392 BUILD_CONFIGURE_ARG
+= " CFLAGS=-DNDEBUG "
395 BUILD_CONFIGURE_ARG
+=' --enable-debug --enable-assert'
396 elif [[ -n "$VCS_CHECKOUT" ]]; then
397 BUILD_CONFIGURE_ARG
+=' --enable-assert'
401 if [[ -n "$CONFIGURE_ARG" ]]; then
402 BUILD_CONFIGURE_ARG
+=" $CONFIGURE_ARG"
405 if [[ -n "$PREFIX_ARG" ]]; then
406 BUILD_CONFIGURE_ARG
+=" $PREFIX_ARG"
410 # If we are executing on OSX use CLANG, otherwise only use it if we find it in the ENV
413 CC
=clang CXX
=clang
++ $top_srcdir/configure
$BUILD_CONFIGURE_ARG || die
"Cannot execute CC=clang CXX=clang++ configure $BUILD_CONFIGURE_ARG"
417 command_exists
'gcc44' || die
"Could not locate gcc44"
418 CC
=gcc44 CXX
=gcc44
$top_srcdir/configure
$BUILD_CONFIGURE_ARG || die
"Cannot execute CC=gcc44 CXX=gcc44 configure $BUILD_CONFIGURE_ARG"
422 $CONFIGURE $BUILD_CONFIGURE_ARG
427 if [ $ret -ne 0 ]; then
428 die
"Could not execute $CONFIGURE $BUILD_CONFIGURE_ARG"
431 if [ ! -f 'Makefile' ]; then
432 die
"Programmer error, configure was run but no Makefile existed after $CONFIGURE was run"
436 function setup_gdb_command
() {
437 GDB_TMPFILE
=$
(mktemp
/tmp
/gdb.XXXXXXXXXX
)
438 echo 'set logging overwrite on' > $GDB_TMPFILE
439 echo 'set logging on' >> $GDB_TMPFILE
440 echo 'set environment LIBTEST_IN_GDB=1' >> $GDB_TMPFILE
441 echo 'run' >> $GDB_TMPFILE
442 echo 'thread apply all bt' >> $GDB_TMPFILE
443 echo 'quit' >> $GDB_TMPFILE
444 GDB_COMMAND
="gdb -f -batch -x $GDB_TMPFILE"
447 function setup_valgrind_command
() {
448 VALGRIND_PROGRAM
=`type -p valgrind`
449 if [[ -n "$VALGRIND_PROGRAM" ]]; then
450 VALGRIND_COMMAND
="$VALGRIND_PROGRAM --error-exitcode=1 --leak-check=yes --malloc-fill=A5 --free-fill=DE --xml=yes --xml-file=\"valgrind-%p.xml\""
454 function save_BUILD
()
456 if [[ -n "$OLD_CONFIGURE" ]]; then
457 die
"OLD_CONFIGURE($OLD_CONFIGURE) was set on push, programmer error!"
460 if [[ -n "$OLD_CONFIGURE_ARG" ]]; then
461 die
"OLD_CONFIGURE_ARG($OLD_CONFIGURE_ARG) was set on push, programmer error!"
464 if [[ -n "$OLD_PREFIX" ]]; then
465 die
"OLD_PREFIX($OLD_PREFIX) was set on push, programmer error!"
468 if [[ -n "$OLD_MAKE" ]]; then
469 die
"OLD_MAKE($OLD_MAKE) was set on push, programmer error!"
472 if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
473 die
"OLD_TESTS_ENVIRONMENT($OLD_TESTS_ENVIRONMENT) was set on push, programmer error!"
476 if [[ -n "$CONFIGURE" ]]; then
477 OLD_CONFIGURE
=$CONFIGURE
480 if [[ -n "$CONFIGURE_ARG" ]]; then
481 OLD_CONFIGURE_ARG
=$CONFIGURE_ARG
484 if [[ -n "$MAKE" ]]; then
488 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
489 OLD_TESTS_ENVIRONMENT
=$TESTS_ENVIRONMENT
493 function restore_BUILD
()
495 if [[ -n "$OLD_CONFIGURE" ]]; then
496 CONFIGURE
=$OLD_CONFIGURE
499 if [[ -n "$OLD_CONFIGURE_ARG" ]]; then
500 CONFIGURE_ARG
=$OLD_CONFIGURE_ARG
503 if [[ -n "$OLD_PREFIX" ]]; then
504 PREFIX_ARG
=$OLD_PREFIX
507 if [[ -n "$OLD_MAKE" ]]; then
511 if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
512 TESTS_ENVIRONMENT
=$OLD_TESTS_ENVIRONMENT
519 OLD_TESTS_ENVIRONMENT
=
524 function safe_pushd
()
526 pushd $1 &> /dev
/null
;
528 if [ -n "$BUILD_DIR" ]; then
530 echo "BUILD_DIR=$BUILD_DIR"
535 function safe_popd
()
537 local directory_to_delete
=`pwd`
539 if [ $?
-eq 0 ]; then
540 if [[ "$top_srcdir" == "$directory_to_delete" ]]; then
541 die
"We almost deleted top_srcdir($top_srcdir), programmer error"
544 rm -r -f "$directory_to_delete"
548 function make_valgrind
()
550 # If the env VALGRIND_COMMAND is set then we assume it is valid
551 local valgrind_was_set
=false
552 if [[ -z "$VALGRIND_COMMAND" ]]; then
553 setup_valgrind_command
554 if [[ -n "$VALGRIND_COMMAND" ]]; then
555 valgrind_was_set
=true
558 valgrind_was_set
=true
561 # If valgrind_was_set is set to no we bail
562 if ! $valgrind_was_set; then
563 echo 'valgrind was not present'
571 # If we are required to run configure, do so now
574 # If we don't have a configure, then most likely we will be missing libtool
575 assert_file
'configure'
576 if [[ -f 'libtool' ]]; then
577 TESTS_ENVIRONMENT
="./libtool --mode=execute $VALGRIND_COMMAND"
579 TESTS_ENVIRONMENT
="$VALGRIND_COMMAND"
585 # If we aren't going to error, we will clean up our environment
586 if [ "$ret" -eq 0 ]; then
594 if [ "$ret" -ne 0 ]; then
599 function make_install_system
()
601 local INSTALL_LOCATION
=$
(mktemp
-d /tmp
/XXXXXXXXXX
)
604 PREFIX_ARG
="--prefix=$INSTALL_LOCATION"
606 if [ ! -d $INSTALL_LOCATION ] ; then
607 die
"ASSERT temp directory not found '$INSTALL_LOCATION'"
610 run_configure
#install_buid_dir
612 make_target
'install'
614 make_target
'installcheck'
616 make_target
'uninstall'
618 rm -r -f $INSTALL_LOCATION
621 if [ -f 'Makefile' ]; then
622 die
"ASSERT Makefile should not exist"
629 function make_darwin_malloc
()
631 run_configure_if_required
633 old_MallocGuardEdges
=$MallocGuardEdges
635 old_MallocErrorAbort
=$MallocErrorAbort
637 old_MallocScribble
=$MallocScribble
642 MallocGuardEdges
=$old_MallocGuardEdges
643 MallocErrorAbort
=$old_MallocErrorAbort
644 MallocScribble
=$old_MallocScribble
647 # This will reset our environment, and make sure built files are available.
648 function make_for_snapshot
()
650 # Lets make sure we have a clean environment
651 assert_no_file
'Makefile'
652 assert_no_file
'configure'
653 assert_no_directory
'autom4te.cache'
657 make_target
'distclean'
659 # We should have a configure, but no Makefile at the end of this exercise
660 assert_no_file
'Makefile'
661 assert_exec_file
'configure'
664 function check_mingw
()
666 command_exists
'mingw64-configure'
668 if [ "$ret" -ne 0 ]; then
672 command_exists
'mingw64-make'
674 if [ "$ret" -ne 0 ]; then
681 function check_clang
()
683 command_exists
'clang'
685 if [ "$ret" -ne 0 ]; then
692 function check_clang_analyzer
()
694 command_exists
'scan-build'
696 if [ "$ret" -ne 0 ]; then
703 function make_skeleton
()
708 if [ $ret -eq 0 ]; then
709 assert_file
'Makefile'
711 make_target
'all' 'warn'
713 if [ $ret -ne 0 ]; then
716 if [[ -n "$DISPLAY" ]]; then
717 if command_exists
'wine'; then
718 TESTS_ENVIRONMENT
='wine'
722 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
723 make_target
'check' 'warn' || warn
"$MAKE check failed"
728 if $jenkins_build_environment; then
729 make_target
'clean' 'warn'
736 function make_for_mingw
()
738 if ! check_mingw
; then
742 # Make sure it is clean
743 if [ -f Makefile
-o -f configure
]; then
744 make_maintainer_clean
751 CONFIGURE
='mingw64-configure'
753 CONFIGURE_ARGS
='--enable-static --disable-shared'
763 function make_for_clang
()
765 if ! check_clang
; then
769 # Make sure it is clean
770 if [ -f Makefile
-o -f configure
]; then
771 make_maintainer_clean
791 function make_for_clang_analyzer
()
793 if ! check_clang
; then
797 if ! check_clang_analyzer
; then
798 die
'clang-analyzer was not found'
801 # Make sure it is clean
802 if [ -f Makefile
-o -f configure
]; then
803 make_maintainer_clean
812 CONFIGURE_ARGS
='--enable-debug'
817 make_target
'clean' 'warn'
819 scan-build
-o clang-html
make -j4 -k
826 # If we are locally testing, we should make sure the environment is setup correctly
827 function check_for_jenkins
()
829 if ! $jenkins_build_environment; then
830 echo "Not inside of jenkins, simulating environment"
832 if [ -f 'configure' ]; then
833 make_maintainer_clean
836 if $BOOTSTRAP_SNAPSHOT; then
842 function make_universe
()
849 make_for_clang_analyzer
851 if [ check_mingw
-eq 0 ]; then
859 function make_for_continuus_integration
()
861 # Setup the environment if we are local
864 # No matter then evironment, we should not have a Makefile at this point
865 assert_no_file
'Makefile'
867 # Platforms which require bootstrap should have some setup done before we hit this stage.
868 # If we are building locally, skip this step, unless we are just testing locally.
869 if $BOOTSTRAP_SNAPSHOT; then
870 if $BOOTSTRAP_SNAPSHOT; then
871 assert_file
'configure'
874 if [ -n "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then
875 assert_file
"$BOOTSTRAP_SNAPSHOT_CHECK" 'snapshot check failed'
878 # If we didn't require a snapshot, then we should not have a configure
879 assert_no_file
'configure'
884 assert_no_file
'Makefile' 'Programmer error, Makefile existed where build state should have been clean'
890 assert_exec_file
'configure'
891 assert_file
'Makefile'
893 # make rpm includes "make distcheck"
894 if [[ -f rpm.am
]]; then
897 elif [[ -d rpm
]]; then
907 assert_exec_file
'configure'
908 assert_file
'Makefile'
915 assert_exec_file
'configure'
916 assert_file
'Makefile'
923 assert_exec_file
'configure'
924 assert_file
'Makefile'
933 make_maintainer_clean
938 # The point to this test is to test bootstrap.sh itself
939 function self_test
()
941 # We start off with a clean env
942 make_maintainer_clean
944 eval "./bootstrap.sh jenkins" || die
"failed 'jenkins'"
945 eval "./bootstrap.sh all" || die
"failed 'all'"
946 eval "./bootstrap.sh gdb" || die
"failed 'gdb'"
947 eval "./bootstrap.sh maintainer-clean" || die
"failed 'maintainer-clean'"
950 function make_install_html
()
952 run_configure_if_required
953 assert_file
'configure'
955 make_target
'install-html'
962 if command_exists
'gdb'; then
963 run_configure_if_required
965 # Set ENV GDB_COMMAND
966 if [[ -z "$GDB_COMMAND" ]]; then
970 # If we don't have a configure, then most likely we will be missing libtool
971 assert_file
'configure'
972 if [[ -f 'libtool' ]]; then
973 TESTS_ENVIRONMENT
="./libtool --mode=execute $GDB_COMMAND"
975 TESTS_ENVIRONMENT
="$GDB_COMMAND"
980 if [ -f 'gdb.txt' ]; then
984 if [ -f '.gdb_history' ]; then
988 if $jenkins_build_environment; then
992 echo 'gdb was not present'
999 # $1 target to compile
1000 # $2 to die, or not to die, based on contents
1001 function make_target
()
1003 if [ -z "$1" ]; then
1004 die
"Programmer error, no target provided for make"
1007 if [ ! -f 'Makefile' ]; then
1008 die
"Programmer error, make was called before configure"
1012 if [ -n "$TESTS_ENVIRONMENT" ]; then
1014 echo "TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT"
1018 if [ -z "$MAKE" ]; then
1019 die
"MAKE was not set"
1022 # $2 represents error or warn
1026 if [ $ret -ne 0 ]; then
1027 if [ -n "$2" ]; then
1028 warn
"Failed to execute $MAKE $1: $ret"
1030 die
"Failed to execute $MAKE $1: $ret"
1037 function make_distcheck
()
1039 make_target
'distcheck'
1042 function make_rpm
()
1044 if command_exists
'rpmbuild'; then
1045 if [ -f 'rpm.am' -o -d 'rpm' ]; then
1046 run_configure_if_required
1049 if $jenkins_build_environment; then
1057 function make_maintainer_clean
()
1059 run_configure_if_required
1060 make_target
'maintainer-clean' 'no_error'
1062 # Lets make sure we really cleaned up the environment
1063 assert_no_file
'Makefile'
1064 assert_no_file
'configure'
1065 assert_no_directory
'autom4te.cache'
1068 function make_check
()
1073 function make_jenkins_default
()
1079 function make_default
()
1081 run_configure_if_required
1085 function run_configure_if_required
()
1087 run_autoreconf_if_required
1089 if [ ! -f 'Makefile' ]; then
1093 assert_file
'Makefile' 'configure did not produce a Makefile'
1096 function run_make_maintainer_clean_if_possible
()
1098 if [ -f 'Makefile' ]; then
1099 make_maintainer_clean
1103 function run_autoreconf_if_required
()
1105 if [ ! -x 'configure' ]; then
1109 assert_exec_file
'configure'
1113 function run_autoreconf
()
1115 if [[ -z "$AUTORECONF" ]]; then
1116 die
"Programmer error, tried to call run_autoreconf () but AUTORECONF was not set"
1119 if test $use_libtool = 1; then
1120 assert
$BOOTSTRAP_LIBTOOLIZE
1121 run
$BOOTSTRAP_LIBTOOLIZE '--copy' '--install' '--force' || die
"Cannot execute $BOOTSTRAP_LIBTOOLIZE"
1124 run
$AUTORECONF $AUTORECONF_ARGS || die
"Cannot execute $AUTORECONF"
1126 eval 'bash -n configure' || die
"autoreconf generated a malformed configure"
1135 if [ -z "$1" ]; then
1142 function parse_command_line_options
()
1144 local SHORTOPTS
=':apcmt:dvh'
1148 while getopts "$SHORTOPTS" opt
; do
1151 AUTORECONF_OPTION
=true
1152 MAKE_TARGET
='autoreconf'
1155 PRINT_SETUP_OPTION
=true
1158 CONFIGURE_OPTION
=true
1159 MAKE_TARGET
='configure'
1161 m
) # maintainer-clean
1163 MAKE_TARGET
='clean_op'
1167 TARGET_OPTION_ARG
="$OPTARG"
1168 MAKE_TARGET
="$OPTARG"
1175 echo "bootstrap.sh [options] optional_target ..."
1176 echo " -a # Just run autoreconf";
1177 echo " -p # Print ENV";
1178 echo " -c # Just run configure";
1179 echo " -m # Just run maintainer-clean";
1180 echo " -t # Make target";
1181 echo " -d # Enable debug";
1182 echo " -h # Show help";
1183 echo " -v # Be more verbose in output";
1191 echo "Option -$OPTARG requires an argument." >&2
1195 echo "$0: error - unrecognized option $1" 1>&2
1203 if [ -n "$1" ]; then
1208 function determine_vcs
()
1210 if [[ -d '.git' ]]; then
1212 elif [[ -d '.bzr' ]]; then
1214 elif [[ -d '.svn' ]]; then
1216 elif [[ -d '.hg' ]]; then
1222 if [[ -n "$VCS_CHECKOUT" ]]; then
1227 function require_libtoolise
()
1230 grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac
>/dev
/null \
1232 grep '^[ ]*LT_INIT' configure.ac
>/dev
/null \
1236 function autoreconf_setup
()
1238 # Set ENV MAKE in order to override "make"
1239 if [[ -z "$MAKE" ]]; then
1240 if command_exists
'gmake'; then
1241 MAKE
=`type -p gmake`
1243 if command_exists
'make'; then
1248 if [ "$VCS_CHECKOUT" ]; then
1250 MAKE
="$MAKE --warn-undefined-variables"
1259 if [[ -z "$GNU_BUILD_FLAGS" ]]; then
1260 GNU_BUILD_FLAGS
="--install --force"
1264 GNU_BUILD_FLAGS
="$GNU_BUILD_FLAGS --verbose"
1267 if [ -z "$ACLOCAL_PATH" ]; then
1268 ACLOCAL_PATH
="/usr/local/share/aclocal $ACLOCAL_PATH"
1271 if [[ -z "$WARNINGS" ]]; then
1272 if [[ -n "$VCS_CHECKOUT" ]]; then
1273 WARNINGS
="all,error"
1279 if test $use_libtool = 1; then
1280 if [[ -n "$LIBTOOLIZE" ]]; then
1281 BOOTSTRAP_LIBTOOLIZE
=`type -p $LIBTOOLIZE`
1283 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1284 echo "Couldn't find user supplied libtoolize, it is required"
1288 # If we are using OSX, we first check to see glibtoolize is available
1289 if [[ "$VENDOR_DISTRIBUTION" == "darwin" ]]; then
1290 BOOTSTRAP_LIBTOOLIZE
=`type -p glibtoolize`
1292 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1293 echo "Couldn't find glibtoolize, it is required on OSX"
1297 BOOTSTRAP_LIBTOOLIZE
=`type -p libtoolize`
1299 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1300 echo "Couldn't find libtoolize, it is required"
1307 LIBTOOLIZE_OPTIONS
="--verbose $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
1311 LIBTOOLIZE_OPTIONS
="--debug $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
1314 # Here we set LIBTOOLIZE to true since we are going to invoke it via BOOTSTRAP_LIBTOOLIZE
1318 # Test the ENV AUTOMAKE if it exists
1319 if [[ -n "$AUTOMAKE" ]]; then
1320 run
$AUTOMAKE '--help' &> /dev
/null || die
"Failed to run AUTOMAKE:$AUTOMAKE"
1323 # Test the ENV AUTOCONF if it exists
1324 if [[ -n "$AUTOCONF" ]]; then
1325 run
$AUTOCONF '--help' &> /dev
/null || die
"Failed to run AUTOCONF:$AUTOCONF"
1328 # Test the ENV AUTOHEADER if it exists
1329 if [[ -n "$AUTOHEADER" ]]; then
1330 run
$AUTOHEADER '--help' &> /dev
/null || die
"Failed to run AUTOHEADER:$AUTOHEADER"
1333 # Test the ENV AUTOM4TE if it exists
1334 if [[ -n "$AUTOM4TE" ]]; then
1335 run
$AUTOM4TE '--help' &> /dev
/null || die
"Failed to run AUTOM4TE:$AUTOM4TE"
1338 # Test the ENV AUTOHEADER if it exists, if not we add one and add --install
1339 if [[ -z "$ACLOCAL" ]]; then
1340 ACLOCAL
="aclocal --install"
1342 run
$ACLOCAL '--help' &> /dev
/null || die
"Failed to run ACLOCAL:$ACLOCAL"
1344 if [[ -z "$AUTORECONF" ]]; then
1345 AUTORECONF
=`type -p autoreconf`
1347 if [[ -z "$AUTORECONF" ]]; then
1348 die
"Couldn't find autoreconf"
1351 if [[ -n "$GNU_BUILD_FLAGS" ]]; then
1352 AUTORECONF_ARGS
="$GNU_BUILD_FLAGS"
1356 run
$AUTORECONF '--help' &> /dev
/null || die
"Failed to run AUTORECONF:$AUTORECONF"
1359 function print_setup
()
1361 saved_debug_status
=$DEBUG
1366 echo '----------------------------------------------'
1367 echo 'BOOTSTRAP ENV'
1368 echo "AUTORECONF=$AUTORECONF"
1369 echo "HOST_OS=$HOST_OS"
1370 echo "VENDOR=$VENDOR"
1371 echo "VENDOR_DISTRIBUTION=$VENDOR_DISTRIBUTION"
1372 echo "VENDOR_RELEASE=$VENDOR_RELEASE"
1375 if $AUTORECONF_OPTION; then
1379 if $CLEAN_OPTION; then
1383 if $CONFIGURE_OPTION; then
1387 if $DEBUG_OPTION; then
1391 if $PRINT_SETUP_OPTION; then
1395 if $TARGET_OPTION; then
1396 echo "--target=$TARGET_OPTION_ARG"
1399 if $VERBOSE_OPTION; then
1403 if [[ -n "$MAKE" ]]; then
1407 if [[ -n "$MAKE_TARGET" ]]; then
1408 echo "MAKE_TARGET=$MAKE_TARGET"
1411 if [[ -n "$PREFIX" ]]; then
1412 echo "PREFIX=$PREFIX"
1415 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
1416 echo "TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT"
1419 if [[ -n "$VCS_CHECKOUT" ]]; then
1420 echo "VCS_CHECKOUT=$VCS_CHECKOUT"
1431 if [[ -n "$WARNINGS" ]]; then
1432 echo "WARNINGS=$WARNINGS"
1434 echo '----------------------------------------------'
1436 if $saved_debug_status; then
1441 function make_clean_option
()
1443 run_configure_if_required
1445 make_maintainer_clean
1447 if [[ "$VCS_CHECKOUT" == 'git' ]]; then
1448 run
"$VCS_CHECKOUT" status
--ignored
1449 elif [[ -n "$VCS_CHECKOUT" ]]; then
1450 run
"$VCS_CHECKOUT" status
1454 function make_for_autoreconf
()
1456 if [ -f 'Makefile' ]; then
1457 make_maintainer_clean
1462 assert_no_file
'Makefile'
1465 function check_make_target
()
1519 echo "Matched default"
1527 function bootstrap
()
1529 determine_target_platform
1533 # Set up whatever we need to do to use autoreconf later
1535 if ! autoreconf_setup
; then
1539 if [ -z "$MAKE_TARGET" ]; then
1540 MAKE_TARGET
="make_default"
1543 if $PRINT_SETUP_OPTION -o $DEBUG; then
1548 # Exit if all we were looking for were the currently used options
1549 if $PRINT_SETUP_OPTION; then
1554 # Use OLD_TESTS_ENVIRONMENT for tracking the state of the variable
1555 local OLD_TESTS_ENVIRONMENT
=
1557 # Set ENV PREFIX in order to set --prefix for ./configure
1558 if [[ -n "$PREFIX" ]]; then
1559 PREFIX_ARG
="--prefix=$PREFIX"
1562 # We should always have a target by this point
1565 local MAKE_TARGET_ARRAY
=($MAKE_TARGET)
1567 for target
in "${MAKE_TARGET_ARRAY[@]}"
1569 # If we are running inside of Jenkins, we want to only run some of the possible tests
1570 if $jenkins_build_environment; then
1571 check_make_target
$target
1573 if [ $ret -ne 0 ]; then
1574 die
"Unknown MAKE_TARGET option: $target"
1578 local snapshot_run
=false
1579 local valgrind_run
=false
1607 if ! check_clang
; then
1608 die
"clang was not found"
1611 if ! make_for_clang
; then
1612 die
"Failed to build clang: $?"
1616 if ! check_clang_analyzer
; then
1617 die
"clang-analyzer was not found"
1619 if ! check_clang
; then
1620 die
"clang was not found"
1623 if ! make_for_clang_analyzer
; then
1624 die
"Failed to build clang-analyzer: $?"
1628 if ! check_mingw
; then
1629 die
"mingw was not found"
1632 if ! make_for_mingw
; then
1633 die
"Failed to build mingw: $?"
1647 make_maintainer_clean
1654 make_for_continuus_integration
1657 run_configure_if_required
1658 make_target
"$target"
1662 if $jenkins_build_environment; then
1663 if ! $snapshot_run; then
1664 run_make_maintainer_clean_if_possible
1673 # Variables we export
1674 declare -x VCS_CHECKOUT
=
1676 # Variables we control globally
1680 # Options for getopt
1681 local AUTORECONF_OPTION
=false
1682 local CLEAN_OPTION
=false
1683 local CONFIGURE_OPTION
=false
1684 local DEBUG_OPTION
=false
1685 local PRINT_SETUP_OPTION
=false
1686 local TARGET_OPTION
=false
1687 local TARGET_OPTION_ARG
=
1688 local VERBOSE_OPTION
=false
1690 local OLD_CONFIGURE
=
1691 local OLD_CONFIGURE_ARG
=
1694 local OLD_TESTS_ENVIRONMENT
=
1696 # If we call autoreconf on the platform or not
1697 local AUTORECONF_REBUILD_HOST
=false
1698 local AUTORECONF_REBUILD
=false
1700 local -r top_srcdir
=`pwd`
1703 if [ -z "$CONFIGURE" ]; then
1704 CONFIGURE
="$top_srcdir/configure"
1708 # Variables for determine_target_platform () and rebuild_host_os ()
1709 # UNAME_MACHINE_ARCH= uname -m
1710 # VENDOR= apple, redhat, centos, canonical
1712 # RHEL{rhel,Tikanga,Santiago}
1713 # Ubuntu{ubuntu,Lucid,Maverick,Natty,Oneiric,Precise,Quantal}
1714 # Fedora{fedora,Verne,Beefy}
1715 # OSX{osx,lion,snow,mountain}
1716 # VENDOR_DISTRIBUTION= darwin,fedora,rhel,ubuntu
1717 # UNAME_KERNEL= Linux, Darwin,...
1718 # UNAME_KERNEL_RELEASE= Linux, Darwin,...
1719 local UNAME_MACHINE_ARCH
=unknown
1720 local VENDOR
=unknown
1721 local VENDOR_RELEASE
=unknown
1722 local VENDOR_DISTRIBUTION
=unknown
1723 local UNAME_KERNEL
=unknown
1724 local UNAME_KERNEL_RELEASE
=unknown
1727 rebuild_host_os no_output
1729 parse_command_line_options $@
1731 # If we are running under Jenkins we predetermine what tests we will run against
1732 # This MAKE_TARGET can be overridden by parse_command_line_options based MAKE_TARGET changes.
1733 # We don't want Jenkins overriding other variables, so we NULL them.
1734 if [ -z "$MAKE_TARGET" ]; then
1735 if $jenkins_build_environment; then
1736 if [[ -n "$label" ]]; then
1737 check_make_target
$label
1738 if [ $?
-eq 0 ]; then
1739 MAKE_TARGET
="$label"
1743 if [ -z "$MAKE_TARGET" ]; then
1744 MAKE_TARGET
='jenkins'
1757 function set_branch
()
1759 if [ -z "$BRANCH" ]; then
1760 if [ -z "$CI_PROJECT_TEAM" ]; then
1761 die
"Variable CI_PROJECT_TEAM has not been set"
1763 if [ -z "$PROJECT" ]; then
1764 die
"Variable PROJECT has not been set"
1766 if [ -z "$BUILD_TAG" ]; then
1767 die
"Variable BUILD_TAG has not been set"
1770 BRANCH
="lp:~$CI_PROJECT_TEAM/$PROJECT/$BUILD_TAG"
1774 if [ -z "$BRANCH" ]; then
1775 die
"Missing values required to build BRANCH variable."
1781 if [ -z "$VCS_CHECKOUT" ]; then
1782 die
"Merges require VCS_CHECKOUT."
1787 if [[ "$VCS_CHECKOUT" == 'bzr' ]]; then
1788 if test -n "$BRANCH_TO_MERGE"; then
1789 bzr merge
$BRANCH_TO_MERGE
1790 bzr commit
--message="Merge $BRANCH_TO_MERGE Build: $BUILD_TAG" --unchanged
1794 elif [[ -n "$VCS_CHECKOUT" ]]; then
1795 die
"Merge attempt occured, current VCS setup does not support this"
1799 function enable_debug
()
1802 local caller_loc
=`caller`
1804 echo "$caller_loc Enabling debug: $1"
1806 echo "$caller_loc Enabling debug"
1816 Usage: $program_name [OPTION]..
1818 Bootstrap this package from the checked-out sources, and optionally walk through CI run.
1825 function disable_debug
()
1831 # Script begins here
1835 env_debug_enabled
=false
1836 if [[ -n "$JENKINS_HOME" ]]; then
1837 declare -r jenkins_build_environment
=true
1839 declare -r jenkins_build_environment
=false
1848 export CONFIGURE_ARG
1850 export GNU_BUILD_FLAGS
1852 export LIBTOOLIZE_OPTIONS
1855 export TESTS_ENVIRONMENT
1861 export MallocGuardEdges
1862 export MallocErrorAbort
1863 export MallocScribble
1867 # We check for DEBUG twice, once before we source the config file, and once afterward
1868 env_debug_enabled
=false
1869 if [[ -n "$DEBUG" ]]; then
1870 env_debug_enabled
=true
1875 # Variables which only can be set by .bootstrap
1876 BOOTSTRAP_SNAPSHOT
=false
1877 BOOTSTRAP_SNAPSHOT_CHECK
=
1879 if [ -f '.bootstrap' ]; then
1883 if $env_debug_enabled; then
1886 if [[ -n "$DEBUG" ]]; then
1887 enable_debug
"Enabling DEBUG from '.bootstrap'"
1892 # We do this in order to protect the case where DEBUG
1893 if ! $env_debug_enabled; then