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:
48 echo "#####################################################################################"
56 echo "#####################################################################################"
59 command_not_found_handle
()
61 warn
"$@: command not found"
67 while caller
$frame; do
78 echo "$BASH_SOURCE:$BASH_LINENO: $@" >&2
83 echo "$BASH_SOURCE:$BASH_LINENO: $@" >&2
89 echo "$BASH_SOURCE:$BASH_LINENO: $@"
90 #echo "$BASH_SOURCE:$BASH_LINENO: $@" >&1
95 local param_name
=\$
"$1"
96 local param_value
="$(eval "expr \"$param_name\" ")"
98 if [ -n "$param_value" ]; then
99 echo "$bash_source:$bash_lineno: assert($param_name) had value of "$param_value"" >&2
106 local param_name
=\$
"$1"
107 local param_value
="$(eval "expr \"$param_name\" ")"
109 if [ -z "$param_value" ]; then
110 echo "$bash_source:$bash_lineno: assert($param_name)" >&2
117 if [ ! -f "$1" ]; then
118 echo "$BASH_SOURCE:$BASH_LINENO: assert($1) does not exist: $2" >&2
126 echo "$BASH_SOURCE:$BASH_LINENO: assert($1) file exists: $2" >&2
131 assert_no_directory
()
134 echo "$BASH_SOURCE:$BASH_LINENO: assert($1) directory exists: $2" >&2
141 if [ ! -f "$1" ]; then
142 echo "$BASH_SOURCE:$BASH_LINENO: assert($1) does not exist: $2" >&2
146 if [ ! -x "$1" ]; then
147 echo "$BASH_SOURCE:$BASH_LINENO: assert($1) exists but is not executable: $2" >&2
154 type "$1" &> /dev
/null
;
159 HOST_OS
="${UNAME_MACHINE_ARCH}-${VENDOR}-${VENDOR_DISTRIBUTION}-${VENDOR_RELEASE}-${UNAME_KERNEL}-${UNAME_KERNEL_RELEASE}"
162 echo "HOST_OS=$HOST_OS"
167 # Validate the distribution name, or toss an erro
168 # values: darwin,fedora,rhel,ubuntu,debian,opensuse
169 set_VENDOR_DISTRIBUTION
()
171 local dist
="$(echo "$1" | tr '[:upper:]' '[:lower:]')"
174 VENDOR_DISTRIBUTION
='darwin'
177 VENDOR_DISTRIBUTION
='fedora'
180 VENDOR_DISTRIBUTION
='rhel'
183 VENDOR_DISTRIBUTION
='debian'
186 VENDOR_DISTRIBUTION
='ubuntu'
189 VENDOR_DISTRIBUTION
='opensuse'
192 VENDOR_DISTRIBUTION
='opensuse'
195 die
"attempt to set an invalid VENDOR_DISTRIBUTION=$dist"
200 # Validate a Vendor's release name/number
201 set_VENDOR_RELEASE
()
203 local release
="$(echo "$1" | tr '[:upper:]' '[:lower:]')"
206 echo "VENDOR_DISTRIBUTION:$VENDOR_DISTRIBUTION"
207 echo "VENDOR_RELEASE:$release"
210 case $VENDOR_DISTRIBUTION in
214 VENDOR_RELEASE
='snow_leopard'
217 VENDOR_RELEASE
='mountain'
220 VENDOR_RELEASE
='mountain'
224 VENDOR_RELEASE
='mountain_lion'
228 VENDOR_RELEASE
='unknown'
233 VENDOR_RELEASE
="$release"
234 if [[ "x$VENDOR_RELEASE" == '18' ]]; then
235 VENDOR_RELEASE
='sphericalcow'
239 VENDOR_RELEASE
="$release"
242 VENDOR_RELEASE
="$release"
245 VENDOR_RELEASE
="$release"
246 if [[ "x$VENDOR_RELEASE" == 'x12.04' ]]; then
247 VENDOR_RELEASE
="precise"
248 elif [[ "x$VENDOR_RELEASE" == 'x12.10' ]]; then
249 VENDOR_RELEASE
="quantal"
250 elif [[ "x$VENDOR_RELEASE" == 'x13.04' ]]; then
251 VENDOR_RELEASE
="raring"
255 VENDOR_RELEASE
="$release"
258 die
"attempt to set VENDOR_RELEASE without setting VENDOR_DISTRIBUTION"
261 die
"attempt to set with an invalid VENDOR_DISTRIBUTION=$VENDOR_DISTRIBUTION"
267 # Valid values are: apple, redhat, centos, canonical, oracle, suse
270 local vendor
="$(echo "$1" | tr '[:upper:]' '[:lower:]')"
282 redhat-release-server-
*)
285 enterprise-release-
*)
307 die
"An attempt was made to set an invalid VENDOR=$_vendor"
311 set_VENDOR_DISTRIBUTION
"$2"
312 set_VENDOR_RELEASE
"$3"
314 # Set which vendor/versions we trust for autoreconf
315 case $VENDOR_DISTRIBUTION in
317 if [[ "x$VENDOR_RELEASE" == 'x18' ]]; then
318 AUTORECONF_REBUILD_HOST
=true
319 elif [[ "x$VENDOR_RELEASE" == 'xsphericalcow' ]]; then
320 AUTORECONF_REBUILD_HOST
=true
321 elif [[ "x$VENDOR_RELEASE" == 'x19' ]]; then
322 AUTORECONF_REBUILD_HOST
=true
326 if [[ "x$VENDOR_RELEASE" == 'xprecise' ]]; then
327 AUTORECONF_REBUILD_HOST
=true
328 elif [[ "x$VENDOR_RELEASE" == 'xquantal' ]]; then
329 AUTORECONF_REBUILD_HOST
=true
336 determine_target_platform
()
338 UNAME_MACHINE_ARCH
="$(uname -m 2>/dev/null)" || UNAME_MACHINE_ARCH
=unknown
339 UNAME_KERNEL
="$(uname -s 2>/dev/null)" || UNAME_SYSTEM
=unknown
340 UNAME_KERNEL_RELEASE
="$(uname -r 2>/dev/null)" || UNAME_KERNEL_RELEASE
=unknown
342 if [[ -x '/usr/bin/sw_vers' ]]; then
343 local _VERSION
="$(/usr/bin/sw_vers -productVersion)"
344 set_VENDOR
'apple' 'darwin' $_VERSION
345 elif [[ $
(uname
) == 'Darwin' ]]; then
346 set_VENDOR
'apple' 'darwin' 'mountain'
347 elif [[ -f '/etc/fedora-release' ]]; then
348 local fedora_version
="$(awk ' { print $3 } ' < /etc/fedora-release)"
349 set_VENDOR
'redhat' 'fedora' $fedora_version
350 elif [[ -f '/etc/centos-release' ]]; then
351 local centos_version
="$(awk ' { print $7 } ' < /etc/centos-release)"
352 set_VENDOR
'centos' 'rhel' $centos_version
353 elif [[ -f '/etc/SuSE-release' ]]; then
354 local suse_distribution
="$(head -1 /etc/SuSE-release | awk ' { print $1 } ')"
355 local suse_version
="$(head -1 /etc/SuSE-release | awk ' { print $2 } ')"
356 set_VENDOR
'suse' $suse_distribution $suse_version
357 elif [[ -f '/etc/redhat-release' ]]; then
358 local rhel_version
="$(awk ' { print $7 } ' < /etc/redhat-release)"
359 local _vendor
="$(rpm -qf /etc/redhat-release)"
360 set_VENDOR
$_vendor 'rhel' $rhel_version
361 elif [[ -f '/etc/os-release' ]]; then
362 source '/etc/os-release'
363 set_VENDOR
$ID $ID $VERSION_ID
364 elif [[ -x '/usr/bin/lsb_release' ]]; then
365 local _ID
="$(/usr/bin/lsb_release -s -i)"
366 local _VERSION
="$(/usr/bin/lsb_release -s -r)"
367 set_VENDOR
$_ID $_ID $_VERSION_ID
368 elif [[ -f '/etc/lsb-release' ]]; then
369 source '/etc/lsb-release'
370 set_VENDOR
'canonical' $DISTRIB_ID $DISTRIB_CODENAME
378 # We will run autoreconf if we are required
379 run_autoreconf_if_required
381 # We always begin at the root of our build
383 die
"Programmer error, we entered run_configure with a stacked directory"
386 if ! command_exists
"$CONFIGURE"; then
387 die
"$CONFIGURE does not exist"
391 if [[ -n "$BUILD_DIR" ]]; then
396 # Arguments for configure
397 local BUILD_CONFIGURE_ARG
=''
399 # If debug is set we enable both debug and asssert, otherwise we see if this is a VCS checkout and if so enable assert
400 # Set ENV ASSERT in order to enable assert.
401 # If we are doing a valgrind run, we always compile with assert disabled
402 if $valgrind_run; then
403 BUILD_CONFIGURE_ARG
="--enable-assert=no $BUILD_CONFIGURE_ARG"
406 BUILD_CONFIGURE_ARG
="--enable-debug --enable-assert $BUILD_CONFIGURE_ARG"
407 elif [[ -n "$VCS_CHECKOUT" ]]; then
408 BUILD_CONFIGURE_ARG
="--enable-assert $BUILD_CONFIGURE_ARG"
412 if [[ -n "$CONFIGURE_ARG" ]]; then
413 BUILD_CONFIGURE_ARG
="$CONFIGURE_ARG $BUILD_CONFIGURE_ARG"
416 if [[ -n "$PREFIX_ARG" ]]; then
417 BUILD_CONFIGURE_ARG
="$PREFIX_ARG $BUILD_CONFIGURE_ARG"
421 # If we are executing on OSX use CLANG, otherwise only use it if we find it in the ENV
424 run CC
=clang CXX
=clang
++ $CONFIGURE "$BUILD_CONFIGURE_ARG" || die
"Cannot execute CC=clang CXX=clang++ configure $BUILD_CONFIGURE_ARG"
428 command_exists
'gcc44' || die
"Could not locate gcc44"
429 run CC
=gcc44 CXX
=gcc44
$top_srcdir/configure
"$BUILD_CONFIGURE_ARG" || die
"Cannot execute CC=gcc44 CXX=gcc44 configure $BUILD_CONFIGURE_ARG"
433 run
$CONFIGURE "$BUILD_CONFIGURE_ARG"
438 if [ $ret -ne 0 ]; then
439 die
"Could not execute $CONFIGURE $BUILD_CONFIGURE_ARG"
442 if [ ! -f 'Makefile' ]; then
443 die
"Programmer error, configure was run but no Makefile existed after $CONFIGURE was run"
449 GDB_TMPFILE
=$
(mktemp
/tmp
/gdb.XXXXXXXXXX
)
450 echo 'set logging overwrite on' > "$GDB_TMPFILE"
451 echo 'set logging on' >> "$GDB_TMPFILE"
452 echo 'set environment LIBTEST_IN_GDB=1' >> "$GDB_TMPFILE"
453 echo 'run' >> "$GDB_TMPFILE"
454 echo 'thread apply all bt' >> "$GDB_TMPFILE"
455 echo 'quit' >> "$GDB_TMPFILE"
456 GDB_COMMAND
="gdb -f -batch -x $GDB_TMPFILE"
459 setup_valgrind_command
()
461 VALGRIND_PROGRAM
="$(type -p valgrind)"
462 if [[ -n "$VALGRIND_PROGRAM" ]]; then
463 VALGRIND_COMMAND
="$VALGRIND_PROGRAM --error-exitcode=1 --leak-check=yes --malloc-fill=A5 --free-fill=DE --xml=yes --xml-file=\"valgrind-%p.xml\""
469 if [[ -n "$OLD_CONFIGURE" ]]; then
470 die
"OLD_CONFIGURE($OLD_CONFIGURE) was set on push, programmer error!"
473 if [[ -n "$OLD_CONFIGURE_ARG" ]]; then
474 die
"OLD_CONFIGURE_ARG($OLD_CONFIGURE_ARG) was set on push, programmer error!"
477 if [[ -n "$OLD_PREFIX" ]]; then
478 die
"OLD_PREFIX($OLD_PREFIX) was set on push, programmer error!"
481 if [[ -n "$OLD_MAKE" ]]; then
482 die
"OLD_MAKE($OLD_MAKE) was set on push, programmer error!"
485 if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
486 die
"OLD_TESTS_ENVIRONMENT($OLD_TESTS_ENVIRONMENT) was set on push, programmer error!"
489 if [[ -n "$CONFIGURE" ]]; then
490 OLD_CONFIGURE
=$CONFIGURE
493 if [[ -n "$CONFIGURE_ARG" ]]; then
494 OLD_CONFIGURE_ARG
=$CONFIGURE_ARG
497 if [[ -n "$MAKE" ]]; then
501 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
502 OLD_TESTS_ENVIRONMENT
=$TESTS_ENVIRONMENT
508 if [[ -n "$OLD_CONFIGURE" ]]; then
509 CONFIGURE
=$OLD_CONFIGURE
512 if [[ -n "$OLD_CONFIGURE_ARG" ]]; then
513 CONFIGURE_ARG
=$OLD_CONFIGURE_ARG
516 if [[ -n "$OLD_PREFIX" ]]; then
517 PREFIX_ARG
=$OLD_PREFIX
520 if [[ -n "$OLD_MAKE" ]]; then
524 if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
525 TESTS_ENVIRONMENT
=$OLD_TESTS_ENVIRONMENT
532 OLD_TESTS_ENVIRONMENT
=
539 # If the env VALGRIND_COMMAND is set then we assume it is valid
540 local valgrind_was_set
=false
541 if [[ -z "$VALGRIND_COMMAND" ]]; then
542 setup_valgrind_command
543 if [[ -n "$VALGRIND_COMMAND" ]]; then
544 valgrind_was_set
=true
547 valgrind_was_set
=true
550 # If valgrind_was_set is set to no we bail
551 if ! $valgrind_was_set; then
552 echo 'valgrind was not present'
560 # If we are required to run configure, do so now
563 # If we don't have a configure, then most likely we will be missing libtool
564 assert_file
'configure'
565 if [[ -x 'libtool' ]]; then
566 TESTS_ENVIRONMENT
="./libtool --mode=execute $VALGRIND_COMMAND"
568 TESTS_ENVIRONMENT
="$VALGRIND_COMMAND"
579 if [ "$ret" -ne 0 ]; then
584 make_install_system
()
586 local INSTALL_LOCATION
="$(mktemp -d /tmp/XXXXXXXXXX)"
589 PREFIX_ARG
="--prefix=$INSTALL_LOCATION"
591 if [ ! -d $INSTALL_LOCATION ] ; then
592 die
"ASSERT temp directory not found '$INSTALL_LOCATION'"
595 run_configure
#install_buid_dir
597 make_target
'install'
599 make_target
'installcheck'
601 make_target
'uninstall'
603 rm -r -f $INSTALL_LOCATION
606 if [ -f 'Makefile' ]; then
607 die
"ASSERT Makefile should not exist"
613 make_darwin_malloc
()
615 run_configure_if_required
617 old_MallocGuardEdges
=$MallocGuardEdges
619 old_MallocErrorAbort
=$MallocErrorAbort
621 old_MallocScribble
=$MallocScribble
626 MallocGuardEdges
=$old_MallocGuardEdges
627 MallocErrorAbort
=$old_MallocErrorAbort
628 MallocScribble
=$old_MallocScribble
631 # This will reset our environment, and make sure built files are available.
634 # Lets make sure we have a clean environment
635 assert_no_file
'Makefile'
636 assert_no_file
'configure'
637 assert_no_directory
'autom4te.cache'
641 make_target
'distclean'
643 # We should have a configure, but no Makefile at the end of this exercise
644 assert_no_file
'Makefile'
645 assert_exec_file
'configure'
650 command_exists
'mingw64-configure'
652 if [ "$ret" -ne 0 ]; then
656 command_exists
'mingw64-make'
658 if [ "$ret" -ne 0 ]; then
667 command_exists
'clang'
669 if [ "$ret" -ne 0 ]; then
676 check_clang_analyzer
()
678 command_exists
'scan-build'
680 if [ "$ret" -ne 0 ]; then
692 if [ $ret -eq 0 ]; then
693 assert_file
'Makefile'
695 make_target
'all' 'warn'
697 if [ $ret -ne 0 ]; then
700 if [[ -n "$DISPLAY" ]]; then
701 if command_exists
'wine'; then
702 TESTS_ENVIRONMENT
='wine'
706 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
707 make_target
'check' 'warn' || warn
"$MAKE check failed"
712 if $jenkins_build_environment; then
713 make_target
'clean' 'warn'
722 if ! check_mingw
; then
726 # Make sure it is clean
727 if [ -f Makefile
-o -f configure
]; then
728 make_maintainer_clean
735 CONFIGURE
='mingw64-configure'
737 CONFIGURE_ARGS
='--enable-static --disable-shared'
749 if ! check_clang
; then
753 # Make sure it is clean
754 if [ -f Makefile
-o -f configure
]; then
755 make_maintainer_clean
775 make_for_clang_analyzer
()
777 if ! check_clang
; then
781 if ! check_clang_analyzer
; then
782 die
'clang-analyzer was not found'
785 # Make sure it is clean
786 if [ -f Makefile
-o -f configure
]; then
787 make_maintainer_clean
796 CONFIGURE
='scan-build ./configure'
797 CONFIGURE_ARGS
='--enable-debug'
801 scan-build
-o clang-html
make -j4 -k
806 # If we are locally testing, we should make sure the environment is setup correctly
809 if ! $jenkins_build_environment; then
810 echo "Not inside of jenkins, simulating environment"
812 if [ -f 'configure' ]; then
813 make_maintainer_clean
816 if $BOOTSTRAP_SNAPSHOT; then
824 use_banner
'make maintainer-clean'
825 make_maintainer_clean
827 use_banner
'snapshot'
830 use_banner
'valgrind'
842 use_banner
'clang analyzer'
843 make_for_clang_analyzer
847 if [ $?
-eq 0 ]; then
851 use_banner
'make distcheck'
854 use_banner
'make install'
860 if [ -n "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then
861 assert_file
"$BOOTSTRAP_SNAPSHOT_CHECK" 'snapshot check failed'
865 make_for_continuus_integration
()
867 # Setup the environment if we are local
870 # No matter then evironment, we should not have a Makefile at this point
871 assert_no_file
'Makefile'
873 # Platforms which require bootstrap should have some setup done before we hit this stage.
874 # If we are building locally, skip this step, unless we are just testing locally.
875 if $BOOTSTRAP_SNAPSHOT; then
876 if $BOOTSTRAP_SNAPSHOT; then
877 assert_file
'configure'
882 # If we didn't require a snapshot, then we should not have a configure
883 assert_no_file
'configure'
888 assert_no_file
'Makefile' 'Programmer error, Makefile existed where build state should have been clean'
896 make_maintainer_clean
899 # The point to this test is to test bootstrap.sh itself
902 # We start off with a clean env
903 make_maintainer_clean
905 # eval "./bootstrap.sh jenkins" || die "failed 'jenkins'"
906 # eval "./bootstrap.sh all" || die "failed 'all'"
907 # eval "./bootstrap.sh gdb" || die "failed 'gdb'"
908 # eval "./bootstrap.sh maintainer-clean" || die "failed 'maintainer-clean'"
913 run_configure_if_required
914 assert_file
'configure'
916 make_target
'install-html'
923 if command_exists
'gdb'; then
924 run_configure_if_required
926 # Set ENV GDB_COMMAND
927 if [[ -z "$GDB_COMMAND" ]]; then
931 # If we don't have a configure, then most likely we will be missing libtool
932 assert_file
'configure'
933 if [[ -f 'libtool' ]]; then
934 TESTS_ENVIRONMENT
="./libtool --mode=execute $GDB_COMMAND"
936 TESTS_ENVIRONMENT
="$GDB_COMMAND"
941 if [ -f 'gdb.txt' ]; then
945 if [ -f '.gdb_history' ]; then
949 if $jenkins_build_environment; then
953 echo 'gdb was not present'
960 # $1 target to compile
961 # $2 to die, or not to die, based on contents
965 die
"Programmer error, no target provided for make"
968 if [ ! -f 'Makefile' ]; then
969 die
"Programmer error, make was called before configure"
973 if [ -n "$TESTS_ENVIRONMENT" ]; then
975 echo "TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT"
979 if [ -z "$MAKE" ]; then
980 die
"MAKE was not set"
983 # $2 represents error or warn
987 if [ $ret -ne 0 ]; then
989 warn
"Failed to execute $MAKE $1: $ret"
990 elif [ $ret -eq 2 ]; then
991 die
"Failed to execute $MAKE $1"
993 die
"Failed to execute $MAKE $1: $ret"
1002 make_target
'distcheck'
1007 if command_exists
'rpmbuild'; then
1008 if [ -f 'rpm.am' -o -d 'rpm' ]; then
1009 mkdir
-p ~
/rpmbuild
/{BUILD
,RPMS
,SOURCES
,SPECS
,SRPMS
}
1010 mkdir
-p ~
/rpmbuild
/RPMS
/{i386
,i486
,i586
,i686
,noarch
,athlon
}
1012 run_configure_if_required
1015 if $jenkins_build_environment; then
1023 make_maintainer_clean
()
1025 run_configure_if_required
1026 make_target
'maintainer-clean' 'no_error'
1028 # Lets make sure we really cleaned up the environment
1029 assert_no_file
'Makefile'
1030 assert_no_file
'configure'
1031 assert_no_directory
'autom4te.cache'
1036 run_configure_if_required
1037 make_target
'distclean' 'no_error'
1039 # Lets make sure we really cleaned up the environment
1040 assert_no_file
'Makefile'
1041 assert_file
'configure'
1049 make_jenkins_default
()
1057 run_configure_if_required
1061 run_configure_if_required
()
1063 run_autoreconf_if_required
1065 if [ ! -f 'Makefile' ]; then
1069 assert_file
'Makefile' 'configure did not produce a Makefile'
1072 run_make_maintainer_clean_if_possible
()
1074 if [ -f 'Makefile' ]; then
1075 make_maintainer_clean
1079 run_autoreconf_if_required
()
1081 if [ ! -x 'configure' ]; then
1085 assert_exec_file
'configure'
1091 if [[ -z "$AUTORECONF" ]]; then
1092 die
"Programmer error, tried to call run_autoreconf () but AUTORECONF was not set"
1095 if $use_libtool; then
1096 assert
$BOOTSTRAP_LIBTOOLIZE
1097 run
"$BOOTSTRAP_LIBTOOLIZE" '--copy' '--install' '--force' || die
"Cannot execute $BOOTSTRAP_LIBTOOLIZE"
1100 run
"$AUTORECONF" "$AUTORECONF_ARGS" || die
"Cannot execute $AUTORECONF"
1102 eval 'bash -n configure' || die
"autoreconf generated a malformed configure"
1111 if [ -z "$1" ]; then
1118 parse_command_line_options
()
1120 local SHORTOPTS
=':apcmt:dvh'
1124 while getopts "$SHORTOPTS" opt
; do
1127 AUTORECONF_OPTION
=true
1128 OPT_TARGET
+='autoreconf'
1131 print_setup_opt
=true
1134 CONFIGURE_OPTION
=true
1135 OPT_TARGET
+='configure'
1137 m
) # maintainer-clean
1141 CONFIGURE_ARG
="$OPTARG"
1145 TARGET_OPTION_ARG
="$OPTARG"
1146 OPT_TARGET
+="$OPTARG"
1153 echo "bootstrap.sh [options] optional_target ..."
1154 echo " -a # Just run autoreconf";
1155 echo " -p # Print ENV";
1156 echo " -c # Just run configure";
1157 echo " -m # Just run maintainer-clean";
1158 echo " -o # Specify configure arguments";
1159 echo " -t # Make target";
1160 echo " -d # Enable debug";
1161 echo " -h # Show help";
1162 echo " -v # Be more verbose in output";
1170 echo "Option -$OPTARG requires an argument." >&2
1174 echo "$0: error - unrecognized option $1" 1>&2
1182 if [ -n "$1" ]; then
1189 if [[ -d '.git' ]]; then
1191 elif [[ -d '.bzr' ]]; then
1193 elif [[ -d '.svn' ]]; then
1195 elif [[ -d '.hg' ]]; then
1201 if [[ -n "$VCS_CHECKOUT" ]]; then
1206 require_libtoolise
()
1208 grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac
>/dev
/null \
1210 grep '^[ ]*LT_INIT' configure.ac
>/dev
/null \
1216 # Set ENV MAKE in order to override "make"
1217 if [[ -z "$MAKE" ]]; then
1218 if command_exists
'gmake'; then
1219 MAKE
="$(type -p gmake)"
1221 if command_exists
'make'; then
1222 MAKE
="$(type -p make)"
1226 if [ "$VCS_CHECKOUT" ]; then
1228 MAKE
="$MAKE --warn-undefined-variables"
1237 if [[ -z "$GNU_BUILD_FLAGS" ]]; then
1238 GNU_BUILD_FLAGS
="--install --force"
1242 GNU_BUILD_FLAGS
="$GNU_BUILD_FLAGS --verbose"
1245 if [ -z "$ACLOCAL_PATH" ]; then
1246 ACLOCAL_PATH
="/usr/local/share/aclocal $ACLOCAL_PATH"
1249 if [[ -z "$WARNINGS" ]]; then
1250 if [[ -n "$VCS_CHECKOUT" ]]; then
1251 WARNINGS
="all,error"
1257 if $use_libtool; then
1258 if [[ -n "$LIBTOOLIZE" ]]; then
1259 BOOTSTRAP_LIBTOOLIZE
="$(type -p $LIBTOOLIZE)"
1261 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1262 echo "Couldn't find user supplied libtoolize, it is required"
1266 # If we are using OSX, we first check to see glibtoolize is available
1267 if [[ "$VENDOR_DISTRIBUTION" == "darwin" ]]; then
1268 BOOTSTRAP_LIBTOOLIZE
="$(type -p glibtoolize)"
1270 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1271 echo "Couldn't find glibtoolize, it is required on OSX"
1275 BOOTSTRAP_LIBTOOLIZE
="$(type -p libtoolize)"
1277 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1278 echo "Couldn't find libtoolize, it is required"
1285 LIBTOOLIZE_OPTIONS
="--verbose $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
1289 LIBTOOLIZE_OPTIONS
="--debug $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
1292 # Here we set LIBTOOLIZE to true since we are going to invoke it via BOOTSTRAP_LIBTOOLIZE
1296 # Test the ENV AUTOMAKE if it exists
1297 if [[ -n "$AUTOMAKE" ]]; then
1298 run
"$AUTOMAKE" '--help' &> /dev
/null || die
"Failed to run AUTOMAKE:$AUTOMAKE"
1301 # Test the ENV AUTOCONF if it exists
1302 if [[ -n "$AUTOCONF" ]]; then
1303 run
"$AUTOCONF" '--help' &> /dev
/null || die
"Failed to run AUTOCONF:$AUTOCONF"
1306 # Test the ENV AUTOHEADER if it exists
1307 if [[ -n "$AUTOHEADER" ]]; then
1308 run
"$AUTOHEADER" '--help' &> /dev
/null || die
"Failed to run AUTOHEADER:$AUTOHEADER"
1311 # Test the ENV AUTOM4TE if it exists
1312 if [[ -n "$AUTOM4TE" ]]; then
1313 run
"$AUTOM4TE" '--help' &> /dev
/null || die
"Failed to run AUTOM4TE:$AUTOM4TE"
1316 # Test the ENV AUTOHEADER if it exists, if not we add one and add --install
1317 if [[ -z "$ACLOCAL" ]]; then
1318 ACLOCAL
="aclocal --install"
1320 run
"$ACLOCAL" '--help' &> /dev
/null || die
"Failed to run ACLOCAL:$ACLOCAL"
1322 if [[ -z "$AUTORECONF" ]]; then
1323 AUTORECONF
="$(type -p autoreconf)"
1325 if [[ -z "$AUTORECONF" ]]; then
1326 die
"Couldn't find autoreconf"
1329 if [[ -n "$GNU_BUILD_FLAGS" ]]; then
1330 AUTORECONF_ARGS
="$GNU_BUILD_FLAGS"
1334 run
"$AUTORECONF" '--help' &> /dev
/null || die
"Failed to run AUTORECONF:$AUTORECONF"
1339 local saved_debug_status
=$debug
1344 echo '----------------------------------------------'
1345 echo 'BOOTSTRAP ENV'
1346 echo "AUTORECONF=$AUTORECONF"
1347 echo "HOST_OS=$HOST_OS"
1348 echo "VENDOR=$VENDOR"
1349 echo "VENDOR_DISTRIBUTION=$VENDOR_DISTRIBUTION"
1350 echo "VENDOR_RELEASE=$VENDOR_RELEASE"
1353 if $AUTORECONF_OPTION; then
1357 if $CLEAN_OPTION; then
1361 if $CONFIGURE_OPTION; then
1369 if $print_setup_opt; then
1373 if $TARGET_OPTION; then
1374 echo "--target=$TARGET_OPTION_ARG"
1377 if $opt_verbose; then
1381 if [[ -n "$MAKE" ]]; then
1385 if [[ -n "$MAKE_TARGET" ]]; then
1386 echo "MAKE_TARGET=$MAKE_TARGET"
1389 if [[ -n "$PREFIX" ]]; then
1390 echo "PREFIX=$PREFIX"
1393 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
1394 echo "TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT"
1397 if [[ -n "$VCS_CHECKOUT" ]]; then
1398 echo "VCS_CHECKOUT=$VCS_CHECKOUT"
1405 if [[ -n "$WARNINGS" ]]; then
1406 echo "WARNINGS=$WARNINGS"
1409 if $saved_debug_status; then
1413 echo '----------------------------------------------'
1415 if $saved_debug_status; then
1420 make_clean_option
()
1422 run_configure_if_required
1424 make_maintainer_clean
1426 if [[ "$VCS_CHECKOUT" == 'git' ]]; then
1427 run
"$VCS_CHECKOUT" status
--ignored
1428 elif [[ -n "$VCS_CHECKOUT" ]]; then
1429 run
"$VCS_CHECKOUT" status
1433 make_for_autoreconf
()
1435 if [ -f 'Makefile' ]; then
1436 make_maintainer_clean
1441 assert_no_file
'Makefile'
1499 echo "Matched default"
1509 # We should always have a target by this point
1512 determine_target_platform
1516 # Set up whatever we need to do to use autoreconf later
1519 if ! autoreconf_setup
; then
1523 if $print_setup_opt -o $debug; then
1528 # Exit if all we were looking for were the currently used options
1529 if $print_setup_opt; then
1534 # Use OLD_TESTS_ENVIRONMENT for tracking the state of the variable
1535 local OLD_TESTS_ENVIRONMENT
=
1537 # Set ENV PREFIX in order to set --prefix for ./configure
1538 if [[ -n "$PREFIX" ]]; then
1539 PREFIX_ARG
="--prefix=$PREFIX"
1542 if $CLEAN_OPTION; then
1543 make_maintainer_clean
1546 local MAKE_TARGET_ARRAY
1547 MAKE_TARGET_ARRAY
=( $MAKE_TARGET )
1549 for target
in "${MAKE_TARGET_ARRAY[@]}"
1551 # If we are running inside of Jenkins, we want to only run some of the possible tests
1552 if $jenkins_build_environment; then
1553 check_make_target
$target
1555 if [ $ret -ne 0 ]; then
1556 die
"Unknown MAKE_TARGET option: $target"
1560 if $jenkins_build_environment; then
1564 local snapshot_run
=false
1565 local valgrind_run
=false
1594 if ! check_clang
; then
1595 die
"clang was not found"
1598 if ! make_for_clang
; then
1599 die
"Failed to build clang: $?"
1604 if ! check_clang_analyzer
; then
1605 die
"clang-analyzer was not found"
1607 if ! check_clang
; then
1608 die
"clang was not found"
1611 if ! make_for_clang_analyzer
; then
1612 die
"Failed to build clang-analyzer: $?"
1617 if ! make_for_mingw
; then
1618 die
"Failed to build mingw: $?"
1639 make_for_continuus_integration
1642 run_configure_if_required
1643 make_target
"$target"
1651 # Are we running inside of Jenkins?
1652 if [[ -n "$JENKINS_HOME" ]]; then
1653 declare -r jenkins_build_environment
=true
1655 declare -r jenkins_build_environment
=false
1658 # Variables we export
1659 declare -x VCS_CHECKOUT
=
1661 # Variables we control globally
1662 local -a MAKE_TARGET
=
1664 local use_libtool
=false
1668 local opt_debug
=false
1669 local opt_verbose
=false
1671 if [[ -n "$VERBOSE" ]]; then
1675 # Options for getopt
1676 local AUTORECONF_OPTION
=false
1677 local CLEAN_OPTION
=false
1678 local CONFIGURE_OPTION
=false
1679 local print_setup_opt
=false
1680 local TARGET_OPTION
=false
1681 local TARGET_OPTION_ARG
=
1683 local OLD_CONFIGURE
=
1684 local OLD_CONFIGURE_ARG
=
1687 local OLD_TESTS_ENVIRONMENT
=
1689 # If we call autoreconf on the platform or not
1690 local AUTORECONF_REBUILD_HOST
=false
1691 local AUTORECONF_REBUILD
=false
1693 local -r top_srcdir
="$(pwd)"
1696 if [ -z "$CONFIGURE" ]; then
1697 CONFIGURE
="$top_srcdir/configure"
1701 # Variables for determine_target_platform () and rebuild_host_os ()
1702 # UNAME_MACHINE_ARCH= uname -m
1703 # VENDOR= apple, redhat, centos, canonical
1705 # RHEL{rhel,Tikanga,Santiago}
1706 # Ubuntu{ubuntu,Lucid,Maverick,Natty,Oneiric,Precise,Quantal}
1707 # Fedora{fedora,Verne,Beefy}
1708 # OSX{osx,lion,snow,mountain}
1709 # VENDOR_DISTRIBUTION= darwin,fedora,rhel,ubuntu
1710 # UNAME_KERNEL= Linux, Darwin,...
1711 # UNAME_KERNEL_RELEASE= Linux, Darwin,...
1712 local UNAME_MACHINE_ARCH
=unknown
1713 local VENDOR
=unknown
1714 local VENDOR_RELEASE
=unknown
1715 local VENDOR_DISTRIBUTION
=unknown
1716 local UNAME_KERNEL
=unknown
1717 local UNAME_KERNEL_RELEASE
=unknown
1720 rebuild_host_os no_output
1723 parse_command_line_options
"$@"
1727 if [ -n "$OPT_TARGET" ]; then
1728 MAKE_TARGET
="$OPT_TARGET"
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 "$JENKINS_TARGET" ]]; then
1737 MAKE_TARGET
="$JENKINS_TARGET"
1739 if [[ -n "$label" ]]; then
1740 check_make_target
$label
1741 if [ $?
-eq 0 ]; then
1742 MAKE_TARGET
="$label"
1746 if [[ -n "$LABEL" ]]; then
1747 check_make_target
$LABEL
1748 if [ $?
-eq 0 ]; then
1749 MAKE_TARGET
="$LABEL"
1753 if [ -z "$MAKE_TARGET" ]; then
1754 MAKE_TARGET
='jenkins'
1760 if [ -z "$MAKE_TARGET" ]; then
1761 MAKE_TARGET
="make_default"
1764 # We should always have a target by this point
1778 if [ -z "$BRANCH" ]; then
1779 if [ -z "$CI_PROJECT_TEAM" ]; then
1780 die
"Variable CI_PROJECT_TEAM has not been set"
1782 if [ -z "$PROJECT" ]; then
1783 die
"Variable PROJECT has not been set"
1785 if [ -z "$BUILD_TAG" ]; then
1786 die
"Variable BUILD_TAG has not been set"
1789 BRANCH
="lp:~$CI_PROJECT_TEAM/$PROJECT/$BUILD_TAG"
1793 if [ -z "$BRANCH" ]; then
1794 die
"Missing values required to build BRANCH variable."
1800 if [ -z "$VCS_CHECKOUT" ]; then
1801 die
"Merges require VCS_CHECKOUT."
1806 if [[ "$VCS_CHECKOUT" == 'bzr' ]]; then
1807 if test -n "$BRANCH_TO_MERGE"; then
1808 bzr merge
$BRANCH_TO_MERGE
1809 bzr commit
--message="Merge $BRANCH_TO_MERGE Build: $BUILD_TAG" --unchanged
1813 elif [[ -n "$VCS_CHECKOUT" ]]; then
1814 die
"Merge attempt occured, current VCS setup does not support this"
1821 local caller_loc
="$(caller)"
1822 if [[ -n "$1" ]]; then
1823 echo "$caller_loc Enabling debug: $1"
1825 echo "$caller_loc Enabling debug"
1835 Usage: $program_name [OPTION]..
1837 Bootstrap this package from the checked-out sources, and optionally walk through CI run.
1852 if [ -x '/usr/local/bin/shellcheck' ]; then
1853 /usr
/local
/bin
/shellcheck
"$1"
1856 if [ "$ret" -ne 0 ]; then
1857 die
"$1 failed shellcheck"
1864 check_shell
'bootstrap.sh'
1865 local env_debug_enabled
=false
1874 export CONFIGURE_ARG
1876 export GNU_BUILD_FLAGS
1878 export LIBTOOLIZE_OPTIONS
1881 export TESTS_ENVIRONMENT
1887 export MallocGuardEdges
1888 export MallocErrorAbort
1889 export MallocScribble
1893 # We check for DEBUG twice, once before we source the config file, and once afterward
1894 if [[ -n "$DEBUG" ]]; then
1895 env_debug_enabled
=true
1898 # Variables which only can be set by .bootstrap
1899 BOOTSTRAP_SNAPSHOT
=false
1900 BOOTSTRAP_SNAPSHOT_CHECK
=
1902 if [ -f '.bootstrap' ]; then
1906 # We do this in order to protect the case where DEBUG that came from the ENV (i.e. it overrides what is found in .bootstrap
1907 if $env_debug_enabled; then
1909 elif [[ -n "$DEBUG" ]]; then
1910 enable_debug
"Enabling DEBUG from '.bootstrap'"
1913 if $env_debug_enabled; then
1921 # Script begins here
1922 declare -r program_name
="$0"