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
='mavericks'
232 VENDOR_RELEASE
='mavericks'
236 VENDOR_RELEASE
='unknown'
241 VENDOR_RELEASE
="$release"
242 if [[ "x$VENDOR_RELEASE" == '18' ]]; then
243 VENDOR_RELEASE
='sphericalcow'
247 VENDOR_RELEASE
="$release"
250 VENDOR_RELEASE
="$release"
253 VENDOR_RELEASE
="$release"
254 if [[ "x$VENDOR_RELEASE" == 'x12.04' ]]; then
255 VENDOR_RELEASE
="precise"
256 elif [[ "x$VENDOR_RELEASE" == 'x12.10' ]]; then
257 VENDOR_RELEASE
="quantal"
258 elif [[ "x$VENDOR_RELEASE" == 'x13.04' ]]; then
259 VENDOR_RELEASE
="raring"
263 VENDOR_RELEASE
="$release"
266 die
"attempt to set VENDOR_RELEASE without setting VENDOR_DISTRIBUTION"
269 die
"attempt to set with an invalid VENDOR_DISTRIBUTION=$VENDOR_DISTRIBUTION"
275 # Valid values are: apple, redhat, centos, canonical, oracle, suse
278 local vendor
="$(echo "$1" | tr '[:upper:]' '[:lower:]')"
290 redhat-release-server-
*)
293 enterprise-release-
*)
315 die
"An attempt was made to set an invalid VENDOR=$_vendor"
319 set_VENDOR_DISTRIBUTION
"$2"
320 set_VENDOR_RELEASE
"$3"
322 # Set which vendor/versions we trust for autoreconf
323 case $VENDOR_DISTRIBUTION in
325 if [[ "x$VENDOR_RELEASE" == 'x18' ]]; then
326 AUTORECONF_REBUILD_HOST
=true
327 elif [[ "x$VENDOR_RELEASE" == 'xsphericalcow' ]]; then
328 AUTORECONF_REBUILD_HOST
=true
329 elif [[ "x$VENDOR_RELEASE" == 'x19' ]]; then
330 AUTORECONF_REBUILD_HOST
=true
334 if [[ "x$VENDOR_RELEASE" == 'xprecise' ]]; then
335 AUTORECONF_REBUILD_HOST
=true
336 elif [[ "x$VENDOR_RELEASE" == 'xquantal' ]]; then
337 AUTORECONF_REBUILD_HOST
=true
344 determine_target_platform
()
346 UNAME_MACHINE_ARCH
="$(uname -m 2>/dev/null)" || UNAME_MACHINE_ARCH
=unknown
347 UNAME_KERNEL
="$(uname -s 2>/dev/null)" || UNAME_SYSTEM
=unknown
348 UNAME_KERNEL_RELEASE
="$(uname -r 2>/dev/null)" || UNAME_KERNEL_RELEASE
=unknown
350 if [[ -x '/usr/bin/sw_vers' ]]; then
351 local _VERSION
="$(/usr/bin/sw_vers -productVersion)"
352 set_VENDOR
'apple' 'darwin' $_VERSION
353 elif [[ $
(uname
) == 'Darwin' ]]; then
354 set_VENDOR
'apple' 'darwin' 'mountain'
355 elif [[ -f '/etc/fedora-release' ]]; then
356 local fedora_version
="$(awk ' { print $3 } ' < /etc/fedora-release)"
357 set_VENDOR
'redhat' 'fedora' $fedora_version
358 elif [[ -f '/etc/centos-release' ]]; then
359 local centos_version
="$(awk ' { print $7 } ' < /etc/centos-release)"
360 set_VENDOR
'centos' 'rhel' $centos_version
361 elif [[ -f '/etc/SuSE-release' ]]; then
362 local suse_distribution
="$(head -1 /etc/SuSE-release | awk ' { print $1 } ')"
363 local suse_version
="$(head -1 /etc/SuSE-release | awk ' { print $2 } ')"
364 set_VENDOR
'suse' $suse_distribution $suse_version
365 elif [[ -f '/etc/redhat-release' ]]; then
366 local rhel_version
="$(awk ' { print $7 } ' < /etc/redhat-release)"
367 local _vendor
="$(rpm -qf /etc/redhat-release)"
368 set_VENDOR
$_vendor 'rhel' $rhel_version
369 elif [[ -f '/etc/os-release' ]]; then
370 source '/etc/os-release'
371 set_VENDOR
$ID $ID $VERSION_ID
372 elif [[ -x '/usr/bin/lsb_release' ]]; then
373 local _ID
="$(/usr/bin/lsb_release -s -i)"
374 local _VERSION
="$(/usr/bin/lsb_release -s -r)"
375 set_VENDOR
$_ID $_ID $_VERSION_ID
376 elif [[ -f '/etc/lsb-release' ]]; then
377 source '/etc/lsb-release'
378 set_VENDOR
'canonical' $DISTRIB_ID $DISTRIB_CODENAME
386 # We will run autoreconf if we are required
387 run_autoreconf_if_required
389 # We always begin at the root of our build
391 die
"Programmer error, we entered run_configure with a stacked directory"
394 if ! command_exists
"$CONFIGURE"; then
395 die
"$CONFIGURE does not exist"
399 if [[ -n "$BUILD_DIR" ]]; then
404 # Arguments for configure
405 local BUILD_CONFIGURE_ARG
=''
407 # If debug is set we enable both debug and asssert, otherwise we see if this is a VCS checkout and if so enable assert
408 # Set ENV ASSERT in order to enable assert.
409 # If we are doing a valgrind run, we always compile with assert disabled
410 if $valgrind_run; then
411 BUILD_CONFIGURE_ARG
="--enable-assert=no $BUILD_CONFIGURE_ARG"
414 BUILD_CONFIGURE_ARG
="--enable-debug --enable-assert $BUILD_CONFIGURE_ARG"
415 elif [[ -n "$VCS_CHECKOUT" ]]; then
416 BUILD_CONFIGURE_ARG
="--enable-assert $BUILD_CONFIGURE_ARG"
420 if [[ -n "$CONFIGURE_ARG" ]]; then
421 BUILD_CONFIGURE_ARG
="$CONFIGURE_ARG $BUILD_CONFIGURE_ARG"
424 if [[ -n "$PREFIX_ARG" ]]; then
425 BUILD_CONFIGURE_ARG
="$PREFIX_ARG $BUILD_CONFIGURE_ARG"
429 # If we are executing on OSX use CLANG, otherwise only use it if we find it in the ENV
432 command_exists
'gcc44' || die
"Could not locate gcc44"
433 run CC
=gcc44 CXX
=gcc44
$top_srcdir/configure
"$BUILD_CONFIGURE_ARG" || die
"Cannot execute CC=gcc44 CXX=gcc44 configure $BUILD_CONFIGURE_ARG"
437 run
$CONFIGURE "$BUILD_CONFIGURE_ARG"
442 if [ $ret -ne 0 ]; then
443 die
"Could not execute $CONFIGURE $BUILD_CONFIGURE_ARG"
446 if [ ! -f 'Makefile' ]; then
447 die
"Programmer error, configure was run but no Makefile existed after $CONFIGURE was run"
453 GDB_TMPFILE
=$
(mktemp
/tmp
/gdb.XXXXXXXXXX
)
454 echo 'set logging overwrite on' > "$GDB_TMPFILE"
455 echo 'set logging on' >> "$GDB_TMPFILE"
456 echo 'set environment LIBTEST_IN_GDB=1' >> "$GDB_TMPFILE"
457 echo 'run' >> "$GDB_TMPFILE"
458 echo 'thread apply all bt' >> "$GDB_TMPFILE"
459 echo 'quit' >> "$GDB_TMPFILE"
460 GDB_COMMAND
="gdb -f -batch -x $GDB_TMPFILE"
463 setup_valgrind_command
()
465 VALGRIND_PROGRAM
="$(type -p valgrind)"
466 if [[ -n "$VALGRIND_PROGRAM" ]]; then
467 VALGRIND_COMMAND
="$VALGRIND_PROGRAM --error-exitcode=1 --leak-check=yes --malloc-fill=A5 --free-fill=DE --xml=yes --xml-file=\"valgrind-%p.xml\""
473 if [[ -n "$OLD_CONFIGURE" ]]; then
474 die
"OLD_CONFIGURE($OLD_CONFIGURE) was set on push, programmer error!"
477 if [[ -n "$OLD_CONFIGURE_ARG" ]]; then
478 die
"OLD_CONFIGURE_ARG($OLD_CONFIGURE_ARG) was set on push, programmer error!"
481 if [[ -n "$OLD_PREFIX" ]]; then
482 die
"OLD_PREFIX($OLD_PREFIX) was set on push, programmer error!"
485 if [[ -n "$OLD_MAKE" ]]; then
486 die
"OLD_MAKE($OLD_MAKE) was set on push, programmer error!"
489 if [[ -n "$OLD_LOG_COMPILER" ]]; then
490 die
"OLD_LOG_COMPILER($OLD_LOG_COMPILER) was set on push, programmer error!"
493 if [[ -n "$CONFIGURE" ]]; then
494 OLD_CONFIGURE
=$CONFIGURE
497 if [[ -n "$CONFIGURE_ARG" ]]; then
498 OLD_CONFIGURE_ARG
=$CONFIGURE_ARG
501 if [[ -n "$MAKE" ]]; then
505 if [[ -n "$LOG_COMPILER" ]]; then
506 OLD_LOG_COMPILER
=$LOG_COMPILER
512 if [[ -n "$OLD_CONFIGURE" ]]; then
513 CONFIGURE
=$OLD_CONFIGURE
516 if [[ -n "$OLD_CONFIGURE_ARG" ]]; then
517 CONFIGURE_ARG
=$OLD_CONFIGURE_ARG
520 if [[ -n "$OLD_PREFIX" ]]; then
521 PREFIX_ARG
=$OLD_PREFIX
524 if [[ -n "$OLD_MAKE" ]]; then
528 if [[ -n "$OLD_LOG_COMPILER" ]]; then
529 LOG_COMPILER
=$OLD_LOG_COMPILER
543 # If the env VALGRIND_COMMAND is set then we assume it is valid
544 local valgrind_was_set
=false
545 if [[ -z "$VALGRIND_COMMAND" ]]; then
546 setup_valgrind_command
547 if [[ -n "$VALGRIND_COMMAND" ]]; then
548 valgrind_was_set
=true
551 valgrind_was_set
=true
554 # If valgrind_was_set is set to no we bail
555 if ! $valgrind_was_set; then
556 echo 'valgrind was not present'
564 # If we are required to run configure, do so now
567 # If we don't have a configure, then most likely we will be missing libtool
568 assert_file
'configure'
569 if [[ -x 'libtool' ]]; then
570 LOG_COMPILER
="./libtool --mode=execute $VALGRIND_COMMAND"
572 LOG_COMPILER
="$VALGRIND_COMMAND"
583 if [ "$ret" -ne 0 ]; then
588 make_install_system
()
590 local INSTALL_LOCATION
="$(mktemp -d /tmp/XXXXXXXXXX)"
593 PREFIX_ARG
="--prefix=$INSTALL_LOCATION"
595 if [ ! -d $INSTALL_LOCATION ] ; then
596 die
"ASSERT temp directory not found '$INSTALL_LOCATION'"
599 run_configure
#install_buid_dir
601 make_target
'install'
603 make_target
'installcheck'
605 make_target
'uninstall'
607 rm -r -f $INSTALL_LOCATION
610 if [ -f 'Makefile' ]; then
611 die
"ASSERT Makefile should not exist"
617 make_darwin_malloc
()
619 run_configure_if_required
621 old_MallocGuardEdges
=$MallocGuardEdges
623 old_MallocErrorAbort
=$MallocErrorAbort
625 old_MallocScribble
=$MallocScribble
630 MallocGuardEdges
=$old_MallocGuardEdges
631 MallocErrorAbort
=$old_MallocErrorAbort
632 MallocScribble
=$old_MallocScribble
635 # This will reset our environment, and make sure built files are available.
638 # Lets make sure we have a clean environment
639 assert_no_file
'Makefile'
640 assert_no_file
'configure'
641 assert_no_directory
'autom4te.cache'
645 make_target
'distclean'
647 # We should have a configure, but no Makefile at the end of this exercise
648 assert_no_file
'Makefile'
649 assert_exec_file
'configure'
654 command_exists
'mingw64-configure'
656 if [ "$ret" -ne 0 ]; then
660 command_exists
'mingw64-make'
662 if [ "$ret" -ne 0 ]; then
671 command_exists
'clang'
673 if [ "$ret" -ne 0 ]; then
680 check_clang_analyzer
()
682 command_exists
'scan-build'
684 if [ "$ret" -ne 0 ]; then
696 if [ $ret -eq 0 ]; then
697 assert_file
'Makefile'
699 make_target
'all' 'warn'
701 if [ $ret -ne 0 ]; then
704 if [[ -n "$DISPLAY" ]]; then
705 if command_exists
'wine'; then
710 if [[ -n "$LOG_COMPILER" ]]; then
711 make_target
'check' 'warn' || warn
"$MAKE check failed"
716 if $jenkins_build_environment; then
717 make_target
'clean' 'warn'
726 if ! check_mingw
; then
730 # Make sure it is clean
731 if [ -f Makefile
-o -f configure
]; then
732 make_maintainer_clean
739 CONFIGURE
='mingw64-configure'
741 CONFIGURE_ARGS
='--enable-static --disable-shared'
753 if ! check_clang
; then
757 # Make sure it is clean
758 if [ -f Makefile
-o -f configure
]; then
759 make_maintainer_clean
779 make_for_clang_analyzer
()
781 if ! check_clang
; then
785 if ! check_clang_analyzer
; then
786 die
'clang-analyzer was not found'
789 # Make sure it is clean
790 if [ -f Makefile
-o -f configure
]; then
791 make_maintainer_clean
800 CONFIGURE
='scan-build ./configure'
801 CONFIGURE_ARGS
='--enable-debug'
805 scan-build
-o clang-html
make -j4 -k
810 # If we are locally testing, we should make sure the environment is setup correctly
813 if ! $jenkins_build_environment; then
814 echo "Not inside of jenkins, simulating environment"
816 if [ -f 'configure' ]; then
817 make_maintainer_clean
820 if $BOOTSTRAP_SNAPSHOT; then
828 use_banner
'make maintainer-clean'
829 make_maintainer_clean
831 use_banner
'snapshot'
834 use_banner
'valgrind'
846 use_banner
'clang analyzer'
847 make_for_clang_analyzer
851 if [ $?
-eq 0 ]; then
855 use_banner
'make distcheck'
858 use_banner
'make install'
864 if [ -n "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then
865 assert_file
"$BOOTSTRAP_SNAPSHOT_CHECK" 'snapshot check failed'
869 make_for_continuus_integration
()
871 # Setup the environment if we are local
874 # No matter then evironment, we should not have a Makefile at this point
875 assert_no_file
'Makefile'
877 # Platforms which require bootstrap should have some setup done before we hit this stage.
878 # If we are building locally, skip this step, unless we are just testing locally.
879 if $BOOTSTRAP_SNAPSHOT; then
880 if $BOOTSTRAP_SNAPSHOT; then
881 assert_file
'configure'
886 # If we didn't require a snapshot, then we should not have a configure
887 assert_no_file
'configure'
892 assert_no_file
'Makefile' 'Programmer error, Makefile existed where build state should have been clean'
900 make_maintainer_clean
903 # The point to this test is to test bootstrap.sh itself
906 # We start off with a clean env
907 make_maintainer_clean
909 # eval "./bootstrap.sh jenkins" || die "failed 'jenkins'"
910 # eval "./bootstrap.sh all" || die "failed 'all'"
911 # eval "./bootstrap.sh gdb" || die "failed 'gdb'"
912 # eval "./bootstrap.sh maintainer-clean" || die "failed 'maintainer-clean'"
917 run_configure_if_required
918 assert_file
'configure'
920 make_target
'install-html'
927 if command_exists
'gdb'; then
928 run_configure_if_required
930 # Set ENV GDB_COMMAND
931 if [[ -z "$GDB_COMMAND" ]]; then
935 # If we don't have a configure, then most likely we will be missing libtool
936 assert_file
'configure'
937 if [[ -f 'libtool' ]]; then
938 LOG_COMPILER
="./libtool --mode=execute $GDB_COMMAND"
940 LOG_COMPILER
="$GDB_COMMAND"
945 if [ -f 'gdb.txt' ]; then
949 if [ -f '.gdb_history' ]; then
953 if $jenkins_build_environment; then
957 echo 'gdb was not present'
964 # $1 target to compile
965 # $2 to die, or not to die, based on contents
969 die
"Programmer error, no target provided for make"
972 if [ ! -f 'Makefile' ]; then
973 die
"Programmer error, make was called before configure"
977 if [ -n "$LOG_COMPILER" ]; then
979 echo "LOG_COMPILER=$LOG_COMPILER"
983 if [ -z "$MAKE" ]; then
984 die
"MAKE was not set"
987 # $2 represents error or warn
991 if [ $ret -ne 0 ]; then
993 warn
"Failed to execute $MAKE $1: $ret"
994 elif [ $ret -eq 2 ]; then
995 die
"Failed to execute $MAKE $1"
997 die
"Failed to execute $MAKE $1: $ret"
1006 make_target
'distcheck'
1011 if command_exists
'rpmbuild'; then
1012 if [ -f 'rpm.am' -o -d 'rpm' ]; then
1013 run_configure_if_required
1014 make_target
'dist-rpm'
1016 if $jenkins_build_environment; then
1018 mv *.
tar.gz
*.rpm artifacts
1020 make_target
'maintainer-clean'
1029 make_maintainer_clean
()
1031 run_configure_if_required
1032 make_target
'maintainer-clean' 'no_error'
1034 # Lets make sure we really cleaned up the environment
1035 assert_no_file
'Makefile'
1036 assert_no_file
'configure'
1037 assert_no_directory
'autom4te.cache'
1042 run_configure_if_required
1043 make_target
'distclean' 'no_error'
1045 # Lets make sure we really cleaned up the environment
1046 assert_no_file
'Makefile'
1047 assert_file
'configure'
1055 make_jenkins_default
()
1063 run_configure_if_required
1067 run_configure_if_required
()
1069 run_autoreconf_if_required
1071 if [ ! -f 'Makefile' ]; then
1075 assert_file
'Makefile' 'configure did not produce a Makefile'
1078 run_make_maintainer_clean_if_possible
()
1080 if [ -f 'Makefile' ]; then
1081 make_maintainer_clean
1085 run_autoreconf_if_required
()
1087 if [ ! -x 'configure' ]; then
1091 assert_exec_file
'configure'
1097 if [[ -z "$AUTORECONF" ]]; then
1098 die
"Programmer error, tried to call run_autoreconf () but AUTORECONF was not set"
1101 if $use_libtool; then
1102 assert
$BOOTSTRAP_LIBTOOLIZE
1103 if $jenkins_build_environment; then
1104 run
"$BOOTSTRAP_LIBTOOLIZE" '--copy' '--install' || die
"Cannot execute $BOOTSTRAP_LIBTOOLIZE"
1106 run
"$BOOTSTRAP_LIBTOOLIZE" '--copy' '--install' '--force' || die
"Cannot execute $BOOTSTRAP_LIBTOOLIZE"
1110 run
"$AUTORECONF" "$AUTORECONF_ARGS" || die
"Cannot execute $AUTORECONF"
1112 eval 'bash -n configure' || die
"autoreconf generated a malformed configure"
1121 if [ -z "$1" ]; then
1128 parse_command_line_options
()
1130 local SHORTOPTS
=':apcmt:dvh'
1134 while getopts "$SHORTOPTS" opt
; do
1137 AUTORECONF_OPTION
=true
1138 OPT_TARGET
+='autoreconf'
1141 print_setup_opt
=true
1144 CONFIGURE_OPTION
=true
1145 OPT_TARGET
+='configure'
1147 m
) # maintainer-clean
1151 CONFIGURE_ARG
="$OPTARG"
1155 TARGET_OPTION_ARG
="$OPTARG"
1156 OPT_TARGET
+="$OPTARG"
1163 echo "bootstrap.sh [options] optional_target ..."
1164 echo " -a # Just run autoreconf";
1165 echo " -p # Print ENV";
1166 echo " -c # Just run configure";
1167 echo " -m # Just run maintainer-clean";
1168 echo " -o # Specify configure arguments";
1169 echo " -t # Make target";
1170 echo " -d # Enable debug";
1171 echo " -h # Show help";
1172 echo " -v # Be more verbose in output";
1180 echo "Option -$OPTARG requires an argument." >&2
1184 echo "$0: error - unrecognized option $1" 1>&2
1192 if [ -n "$1" ]; then
1199 if [[ -d '.git' ]]; then
1201 elif [[ -d '.bzr' ]]; then
1203 elif [[ -d '.svn' ]]; then
1205 elif [[ -d '.hg' ]]; then
1211 if [[ -n "$VCS_CHECKOUT" ]]; then
1216 require_libtoolise
()
1218 grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac
>/dev
/null \
1220 grep '^[ ]*LT_INIT' configure.ac
>/dev
/null \
1226 # Set ENV MAKE in order to override "make"
1227 if [[ -z "$MAKE" ]]; then
1228 if command_exists
'gmake'; then
1229 MAKE
="$(type -p gmake)"
1231 if command_exists
'make'; then
1232 MAKE
="$(type -p make)"
1236 if [ "$VCS_CHECKOUT" ]; then
1238 MAKE
="$MAKE --warn-undefined-variables"
1247 if [[ -z "$GNU_BUILD_FLAGS" ]]; then
1248 if $jenkins_build_environment; then
1249 GNU_BUILD_FLAGS
="--install"
1251 GNU_BUILD_FLAGS
="--install --force"
1256 GNU_BUILD_FLAGS
="$GNU_BUILD_FLAGS --verbose"
1259 if [ -z "$ACLOCAL_PATH" ]; then
1260 ACLOCAL_PATH
="/usr/local/share/aclocal $ACLOCAL_PATH"
1263 if [[ -z "$WARNINGS" ]]; then
1264 if [[ -n "$VCS_CHECKOUT" ]]; then
1265 WARNINGS
="all,error"
1271 if $use_libtool; then
1272 if [[ -n "$LIBTOOLIZE" ]]; then
1273 BOOTSTRAP_LIBTOOLIZE
="$(type -p $LIBTOOLIZE)"
1275 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1276 echo "Couldn't find user supplied libtoolize, it is required"
1280 # If we are using OSX, we first check to see glibtoolize is available
1281 if [[ "$VENDOR_DISTRIBUTION" == "darwin" ]]; then
1282 BOOTSTRAP_LIBTOOLIZE
="$(type -p glibtoolize)"
1284 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1285 echo "Couldn't find glibtoolize, it is required on OSX"
1289 BOOTSTRAP_LIBTOOLIZE
="$(type -p libtoolize)"
1291 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1292 echo "Couldn't find libtoolize, it is required"
1299 LIBTOOLIZE_OPTIONS
="--verbose $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
1303 LIBTOOLIZE_OPTIONS
="--debug $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
1306 # Here we set LIBTOOLIZE to true since we are going to invoke it via BOOTSTRAP_LIBTOOLIZE
1310 # Test the ENV AUTOMAKE if it exists
1311 if [[ -n "$AUTOMAKE" ]]; then
1312 run
"$AUTOMAKE" '--help' &> /dev
/null || die
"Failed to run AUTOMAKE:$AUTOMAKE"
1315 # Test the ENV AUTOCONF if it exists
1316 if [[ -n "$AUTOCONF" ]]; then
1317 run
"$AUTOCONF" '--help' &> /dev
/null || die
"Failed to run AUTOCONF:$AUTOCONF"
1320 # Test the ENV AUTOHEADER if it exists
1321 if [[ -n "$AUTOHEADER" ]]; then
1322 run
"$AUTOHEADER" '--help' &> /dev
/null || die
"Failed to run AUTOHEADER:$AUTOHEADER"
1325 # Test the ENV AUTOM4TE if it exists
1326 if [[ -n "$AUTOM4TE" ]]; then
1327 run
"$AUTOM4TE" '--help' &> /dev
/null || die
"Failed to run AUTOM4TE:$AUTOM4TE"
1330 # Test the ENV AUTOHEADER if it exists, if not we add one and add --install
1331 if [[ -z "$ACLOCAL" ]]; then
1332 ACLOCAL
="aclocal --install"
1334 run
"$ACLOCAL" '--help' &> /dev
/null || die
"Failed to run ACLOCAL:$ACLOCAL"
1336 if [[ -z "$AUTORECONF" ]]; then
1337 AUTORECONF
="$(type -p autoreconf)"
1339 if [[ -z "$AUTORECONF" ]]; then
1340 die
"Couldn't find autoreconf"
1343 if [[ -n "$GNU_BUILD_FLAGS" ]]; then
1344 AUTORECONF_ARGS
="$GNU_BUILD_FLAGS"
1348 run
"$AUTORECONF" '--help' &> /dev
/null || die
"Failed to run AUTORECONF:$AUTORECONF"
1353 local saved_debug_status
=$debug
1358 echo '----------------------------------------------'
1359 echo 'BOOTSTRAP ENV'
1360 echo "AUTORECONF=$AUTORECONF"
1361 echo "HOST_OS=$HOST_OS"
1362 echo "VENDOR=$VENDOR"
1363 echo "VENDOR_DISTRIBUTION=$VENDOR_DISTRIBUTION"
1364 echo "VENDOR_RELEASE=$VENDOR_RELEASE"
1367 if $AUTORECONF_OPTION; then
1371 if $CLEAN_OPTION; then
1375 if $CONFIGURE_OPTION; then
1383 if $print_setup_opt; then
1387 if $TARGET_OPTION; then
1388 echo "--target=$TARGET_OPTION_ARG"
1391 if $opt_verbose; then
1395 if [[ -n "$MAKE" ]]; then
1399 if [[ -n "$BOOTSTRAP_TARGET" ]]; then
1400 echo "BOOTSTRAP_TARGET=$BOOTSTRAP_TARGET"
1403 if [[ -n "$PREFIX" ]]; then
1404 echo "PREFIX=$PREFIX"
1407 if [[ -n "$LOG_COMPILER" ]]; then
1408 echo "LOG_COMPILER=$LOG_COMPILER"
1411 if [[ -n "$VCS_CHECKOUT" ]]; then
1412 echo "VCS_CHECKOUT=$VCS_CHECKOUT"
1419 if [[ -n "$WARNINGS" ]]; then
1420 echo "WARNINGS=$WARNINGS"
1423 if $saved_debug_status; then
1427 echo '----------------------------------------------'
1429 if $saved_debug_status; then
1434 make_clean_option
()
1436 run_configure_if_required
1438 make_maintainer_clean
1440 if [[ "$VCS_CHECKOUT" == 'git' ]]; then
1441 run
"$VCS_CHECKOUT" status
--ignored
1442 elif [[ -n "$VCS_CHECKOUT" ]]; then
1443 run
"$VCS_CHECKOUT" status
1447 make_for_autoreconf
()
1449 if [ -f 'Makefile' ]; then
1450 make_maintainer_clean
1455 assert_no_file
'Makefile'
1513 echo "Matched default"
1523 # We should always have a target by this point
1524 assert BOOTSTRAP_TARGET
1526 determine_target_platform
1530 # Set up whatever we need to do to use autoreconf later
1533 if ! autoreconf_setup
; then
1537 if $print_setup_opt -o $debug; then
1542 # Exit if all we were looking for were the currently used options
1543 if $print_setup_opt; then
1548 # Use OLD_LOG_COMPILER for tracking the state of the variable
1549 local OLD_LOG_COMPILER
=
1551 # Set ENV PREFIX in order to set --prefix for ./configure
1552 if [[ -n "$PREFIX" ]]; then
1553 PREFIX_ARG
="--prefix=$PREFIX"
1556 if $CLEAN_OPTION; then
1557 make_maintainer_clean
1560 local BOOTSTRAP_TARGET_ARRAY
1561 BOOTSTRAP_TARGET_ARRAY
=( $BOOTSTRAP_TARGET )
1563 for target
in "${BOOTSTRAP_TARGET_ARRAY[@]}"
1565 # If we are running inside of Jenkins, we want to only run some of the possible tests
1566 if $jenkins_build_environment; then
1567 check_make_target
$target
1569 if [ $ret -ne 0 ]; then
1570 warn
"Unknown BOOTSTRAP_TARGET option: $target"
1575 if $jenkins_build_environment; then
1579 local snapshot_run
=false
1580 local valgrind_run
=false
1609 if ! check_clang
; then
1610 die
"clang was not found"
1613 if ! make_for_clang
; then
1614 die
"Failed to build clang: $?"
1619 if ! check_clang_analyzer
; then
1620 die
"clang-analyzer was not found"
1622 if ! check_clang
; then
1623 die
"clang was not found"
1626 if ! make_for_clang_analyzer
; then
1627 die
"Failed to build clang-analyzer: $?"
1632 if ! make_for_mingw
; then
1633 die
"Failed to build mingw: $?"
1654 make_for_continuus_integration
1657 run_configure_if_required
1658 make_target
"$target"
1666 # Are we running inside of Jenkins?
1667 if [[ -n "$JENKINS_HOME" ]]; then
1668 declare -r jenkins_build_environment
=true
1670 declare -r jenkins_build_environment
=false
1673 # Variables we export
1674 declare -x VCS_CHECKOUT
=
1676 # Variables we control globally
1677 local -a BOOTSTRAP_TARGET
=
1679 local use_libtool
=false
1683 local opt_debug
=false
1684 local opt_verbose
=false
1686 if [[ -n "$VERBOSE" ]]; then
1690 # Options for getopt
1691 local AUTORECONF_OPTION
=false
1692 local CLEAN_OPTION
=false
1693 local CONFIGURE_OPTION
=false
1694 local print_setup_opt
=false
1695 local TARGET_OPTION
=false
1696 local TARGET_OPTION_ARG
=
1698 local OLD_CONFIGURE
=
1699 local OLD_CONFIGURE_ARG
=
1702 local OLD_LOG_COMPILER
=
1704 # If we call autoreconf on the platform or not
1705 local AUTORECONF_REBUILD_HOST
=false
1706 local AUTORECONF_REBUILD
=false
1708 local -r top_srcdir
="$(pwd)"
1711 if [ -z "$CONFIGURE" ]; then
1712 CONFIGURE
="$top_srcdir/configure"
1716 # Variables for determine_target_platform () and rebuild_host_os ()
1717 # UNAME_MACHINE_ARCH= uname -m
1718 # VENDOR= apple, redhat, centos, canonical
1720 # RHEL{rhel,Tikanga,Santiago}
1721 # Ubuntu{ubuntu,Lucid,Maverick,Natty,Oneiric,Precise,Quantal}
1722 # Fedora{fedora,Verne,Beefy}
1723 # OSX{osx,lion,snow,mountain}
1724 # VENDOR_DISTRIBUTION= darwin,fedora,rhel,ubuntu
1725 # UNAME_KERNEL= Linux, Darwin,...
1726 # UNAME_KERNEL_RELEASE= Linux, Darwin,...
1727 local UNAME_MACHINE_ARCH
=unknown
1728 local VENDOR
=unknown
1729 local VENDOR_RELEASE
=unknown
1730 local VENDOR_DISTRIBUTION
=unknown
1731 local UNAME_KERNEL
=unknown
1732 local UNAME_KERNEL_RELEASE
=unknown
1735 rebuild_host_os no_output
1738 parse_command_line_options
"$@"
1740 nassert BOOTSTRAP_TARGET
1742 if [ -n "$OPT_TARGET" ]; then
1743 BOOTSTRAP_TARGET
="$OPT_TARGET"
1746 if [ -z "$BOOTSTRAP_TARGET" ]; then
1747 BOOTSTRAP_TARGET
="make_default"
1750 # We should always have a target by this point
1751 assert BOOTSTRAP_TARGET
1764 if [ -z "$BRANCH" ]; then
1765 if [ -z "$CI_PROJECT_TEAM" ]; then
1766 die
"Variable CI_PROJECT_TEAM has not been set"
1768 if [ -z "$PROJECT" ]; then
1769 die
"Variable PROJECT has not been set"
1771 if [ -z "$BUILD_TAG" ]; then
1772 die
"Variable BUILD_TAG has not been set"
1775 BRANCH
="lp:~$CI_PROJECT_TEAM/$PROJECT/$BUILD_TAG"
1779 if [ -z "$BRANCH" ]; then
1780 die
"Missing values required to build BRANCH variable."
1786 if [ -z "$VCS_CHECKOUT" ]; then
1787 die
"Merges require VCS_CHECKOUT."
1792 if [[ "$VCS_CHECKOUT" == 'bzr' ]]; then
1793 if test -n "$BRANCH_TO_MERGE"; then
1794 bzr merge
$BRANCH_TO_MERGE
1795 bzr commit
--message="Merge $BRANCH_TO_MERGE Build: $BUILD_TAG" --unchanged
1799 elif [[ -n "$VCS_CHECKOUT" ]]; then
1800 die
"Merge attempt occured, current VCS setup does not support this"
1807 local caller_loc
="$(caller)"
1808 if [[ -n "$1" ]]; then
1809 echo "$caller_loc Enabling debug: $1"
1811 echo "$caller_loc Enabling debug"
1821 Usage: $program_name [OPTION]..
1823 Bootstrap this package from the checked-out sources, and optionally walk through CI run.
1838 if [ -x '/usr/local/bin/shellcheck' ]; then
1839 /usr
/local
/bin
/shellcheck
"$1"
1842 if [ "$ret" -ne 0 ]; then
1843 die
"$1 failed shellcheck"
1850 check_shell
'bootstrap.sh'
1851 local env_debug_enabled
=false
1860 export CONFIGURE_ARG
1862 export GNU_BUILD_FLAGS
1864 export LIBTOOLIZE_OPTIONS
1873 export MallocGuardEdges
1874 export MallocErrorAbort
1875 export MallocScribble
1879 # We check for DEBUG twice, once before we source the config file, and once afterward
1880 if [[ -n "$DEBUG" ]]; then
1881 env_debug_enabled
=true
1884 # Variables which only can be set by .bootstrap
1885 BOOTSTRAP_SNAPSHOT
=false
1886 BOOTSTRAP_SNAPSHOT_CHECK
=
1888 if [ -f '.bootstrap' ]; then
1892 # 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
1893 if $env_debug_enabled; then
1895 elif [[ -n "$DEBUG" ]]; then
1896 enable_debug
"Enabling DEBUG from '.bootstrap'"
1899 if $env_debug_enabled; then
1907 # Script begins here
1908 declare -r program_name
="$0"