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 VENDOR_DISTRIBUTION
='arch'
198 die
"attempt to set an invalid VENDOR_DISTRIBUTION=$dist"
203 # Validate a Vendor's release name/number
204 set_VENDOR_RELEASE
()
206 local release
="$(echo "$1" | tr '[:upper:]' '[:lower:]')"
209 echo "VENDOR_DISTRIBUTION:$VENDOR_DISTRIBUTION"
210 echo "VENDOR_RELEASE:$release"
213 case $VENDOR_DISTRIBUTION in
217 VENDOR_RELEASE
='snow_leopard'
220 VENDOR_RELEASE
='mountain'
223 VENDOR_RELEASE
='mountain'
227 VENDOR_RELEASE
='mountain_lion'
231 VENDOR_RELEASE
='mavericks'
235 VENDOR_RELEASE
='mavericks'
239 VENDOR_RELEASE
='unknown'
244 VENDOR_RELEASE
="$release"
245 if [[ "x$VENDOR_RELEASE" == '18' ]]; then
246 VENDOR_RELEASE
='sphericalcow'
250 VENDOR_RELEASE
="$release"
253 VENDOR_RELEASE
="$release"
256 VENDOR_RELEASE
="$release"
257 if [[ "x$VENDOR_RELEASE" == 'x12.04' ]]; then
258 VENDOR_RELEASE
="precise"
259 elif [[ "x$VENDOR_RELEASE" == 'x12.10' ]]; then
260 VENDOR_RELEASE
="quantal"
261 elif [[ "x$VENDOR_RELEASE" == 'x13.04' ]]; then
262 VENDOR_RELEASE
="raring"
266 VENDOR_RELEASE
="$release"
272 die
"attempt to set VENDOR_RELEASE without setting VENDOR_DISTRIBUTION"
275 die
"attempt to set VENDOR_RELEASE with an invalid VENDOR_DISTRIBUTION=$VENDOR_DISTRIBUTION"
281 # Valid values are: apple, redhat, centos, canonical, oracle, suse
284 local vendor
="$(echo "$1" | tr '[:upper:]' '[:lower:]')"
296 redhat-release-server-
*)
299 enterprise-release-
*)
324 die
"An attempt was made to set an invalid VENDOR=$vendor"
328 set_VENDOR_DISTRIBUTION
"$2"
329 set_VENDOR_RELEASE
"$3"
331 # Set which vendor/versions we trust for autoreconf
332 case $VENDOR_DISTRIBUTION in
334 if [[ "x$VENDOR_RELEASE" == 'x18' ]]; then
335 AUTORECONF_REBUILD_HOST
=true
336 elif [[ "x$VENDOR_RELEASE" == 'xsphericalcow' ]]; then
337 AUTORECONF_REBUILD_HOST
=true
338 elif [[ "x$VENDOR_RELEASE" == 'x19' ]]; then
339 AUTORECONF_REBUILD_HOST
=true
343 if [[ "x$VENDOR_RELEASE" == 'xprecise' ]]; then
344 AUTORECONF_REBUILD_HOST
=true
345 elif [[ "x$VENDOR_RELEASE" == 'xquantal' ]]; then
346 AUTORECONF_REBUILD_HOST
=true
353 determine_target_platform
()
355 UNAME_MACHINE_ARCH
="$(uname -m 2>/dev/null)" || UNAME_MACHINE_ARCH
=unknown
356 UNAME_KERNEL
="$(uname -s 2>/dev/null)" || UNAME_SYSTEM
=unknown
357 UNAME_KERNEL_RELEASE
="$(uname -r 2>/dev/null)" || UNAME_KERNEL_RELEASE
=unknown
359 if [[ -x '/usr/bin/sw_vers' ]]; then
360 local _VERSION
="$(/usr/bin/sw_vers -productVersion)"
361 set_VENDOR
'apple' 'darwin' $_VERSION
362 elif [[ $
(uname
) == 'Darwin' ]]; then
363 set_VENDOR
'apple' 'darwin' 'mountain'
364 elif [[ -f '/etc/fedora-release' ]]; then
365 local fedora_version
="$(awk ' { print $3 } ' < /etc/fedora-release)"
366 set_VENDOR
'redhat' 'fedora' $fedora_version
367 elif [[ -f '/etc/centos-release' ]]; then
368 local centos_version
="$(awk ' { print $7 } ' < /etc/centos-release)"
369 set_VENDOR
'centos' 'rhel' $centos_version
370 elif [[ -f '/etc/SuSE-release' ]]; then
371 local suse_distribution
="$(head -1 /etc/SuSE-release | awk ' { print $1 } ')"
372 local suse_version
="$(head -1 /etc/SuSE-release | awk ' { print $2 } ')"
373 set_VENDOR
'suse' $suse_distribution $suse_version
374 elif [[ -f '/etc/redhat-release' ]]; then
375 local rhel_version
="$(awk ' { print $7 } ' < /etc/redhat-release)"
376 local _vendor
="$(rpm -qf /etc/redhat-release)"
377 set_VENDOR
$_vendor 'rhel' $rhel_version
378 elif [[ -f '/etc/os-release' ]]; then
379 source '/etc/os-release'
380 set_VENDOR
$ID $ID $VERSION_ID
381 elif [[ -x '/usr/bin/lsb_release' ]]; then
382 local _ID
="$(/usr/bin/lsb_release -s -i)"
383 local _VERSION
="$(/usr/bin/lsb_release -s -r)"
384 set_VENDOR
$_ID $_ID $_VERSION
385 elif [[ -f '/etc/lsb-release' ]]; then
386 source '/etc/lsb-release'
387 set_VENDOR
'canonical' $DISTRIB_ID $DISTRIB_CODENAME
395 # We will run autoreconf if we are required
396 run_autoreconf_if_required
398 # We always begin at the root of our build
400 die
"Programmer error, we entered run_configure with a stacked directory"
403 if ! command_exists
"$CONFIGURE"; then
404 die
"$CONFIGURE does not exist"
408 if [[ -n "$BUILD_DIR" ]]; then
413 # Arguments for configure
414 local BUILD_CONFIGURE_ARG
=''
416 # If debug is set we enable both debug and asssert, otherwise we see if this is a VCS checkout and if so enable assert
417 # Set ENV ASSERT in order to enable assert.
418 # If we are doing a valgrind run, we always compile with assert disabled
419 if $valgrind_run; then
420 BUILD_CONFIGURE_ARG
="--enable-assert=no $BUILD_CONFIGURE_ARG"
423 BUILD_CONFIGURE_ARG
="--enable-debug --enable-assert $BUILD_CONFIGURE_ARG"
424 elif [[ -n "$VCS_CHECKOUT" ]]; then
425 BUILD_CONFIGURE_ARG
="--enable-assert $BUILD_CONFIGURE_ARG"
429 if [[ -n "$CONFIGURE_ARG" ]]; then
430 BUILD_CONFIGURE_ARG
="$CONFIGURE_ARG $BUILD_CONFIGURE_ARG"
433 if [[ -n "$PREFIX_ARG" ]]; then
434 BUILD_CONFIGURE_ARG
="$PREFIX_ARG $BUILD_CONFIGURE_ARG"
438 # If we are executing on OSX use CLANG, otherwise only use it if we find it in the ENV
441 command_exists
'gcc44' || die
"Could not locate gcc44"
442 run CC
=gcc44 CXX
=gcc44
$top_srcdir/configure
"$BUILD_CONFIGURE_ARG" || die
"Cannot execute CC=gcc44 CXX=gcc44 configure $BUILD_CONFIGURE_ARG"
446 run
$CONFIGURE "$BUILD_CONFIGURE_ARG"
451 if [ $ret -ne 0 ]; then
452 die
"Could not execute $CONFIGURE $BUILD_CONFIGURE_ARG"
455 if [ ! -f 'Makefile' ]; then
456 die
"Programmer error, configure was run but no Makefile existed after $CONFIGURE was run"
462 GDB_TMPFILE
=$
(mktemp
/tmp
/gdb.XXXXXXXXXX
)
463 echo 'set logging overwrite on' > "$GDB_TMPFILE"
464 echo 'set logging on' >> "$GDB_TMPFILE"
465 echo 'set environment LIBTEST_IN_GDB=1' >> "$GDB_TMPFILE"
466 echo 'run' >> "$GDB_TMPFILE"
467 echo 'thread apply all bt' >> "$GDB_TMPFILE"
468 echo 'quit' >> "$GDB_TMPFILE"
469 GDB_COMMAND
="gdb -f -batch -x $GDB_TMPFILE"
472 setup_valgrind_command
()
474 VALGRIND_PROGRAM
="$(type -p valgrind)"
475 if [[ -n "$VALGRIND_PROGRAM" ]]; then
476 VALGRIND_COMMAND
="$VALGRIND_PROGRAM --error-exitcode=1 --leak-check=yes --malloc-fill=A5 --free-fill=DE --xml=yes --xml-file=\"valgrind-%p.xml\""
482 if [[ -n "$OLD_CONFIGURE" ]]; then
483 die
"OLD_CONFIGURE($OLD_CONFIGURE) was set on push, programmer error!"
486 if [[ -n "$OLD_CONFIGURE_ARG" ]]; then
487 die
"OLD_CONFIGURE_ARG($OLD_CONFIGURE_ARG) was set on push, programmer error!"
490 if [[ -n "$OLD_PREFIX" ]]; then
491 die
"OLD_PREFIX($OLD_PREFIX) was set on push, programmer error!"
494 if [[ -n "$OLD_MAKE" ]]; then
495 die
"OLD_MAKE($OLD_MAKE) was set on push, programmer error!"
498 if [[ -n "$OLD_LOG_COMPILER" ]]; then
499 die
"OLD_LOG_COMPILER($OLD_LOG_COMPILER) was set on push, programmer error!"
502 if [[ -n "$CONFIGURE" ]]; then
503 OLD_CONFIGURE
=$CONFIGURE
506 if [[ -n "$CONFIGURE_ARG" ]]; then
507 OLD_CONFIGURE_ARG
=$CONFIGURE_ARG
510 if [[ -n "$MAKE" ]]; then
514 if [[ -n "$LOG_COMPILER" ]]; then
515 OLD_LOG_COMPILER
=$LOG_COMPILER
521 if [[ -n "$OLD_CONFIGURE" ]]; then
522 CONFIGURE
=$OLD_CONFIGURE
525 if [[ -n "$OLD_CONFIGURE_ARG" ]]; then
526 CONFIGURE_ARG
=$OLD_CONFIGURE_ARG
529 if [[ -n "$OLD_PREFIX" ]]; then
530 PREFIX_ARG
=$OLD_PREFIX
533 if [[ -n "$OLD_MAKE" ]]; then
537 if [[ -n "$OLD_LOG_COMPILER" ]]; then
538 LOG_COMPILER
=$OLD_LOG_COMPILER
552 # If the env VALGRIND_COMMAND is set then we assume it is valid
553 local valgrind_was_set
=false
554 if [[ -z "$VALGRIND_COMMAND" ]]; then
555 setup_valgrind_command
556 if [[ -n "$VALGRIND_COMMAND" ]]; then
557 valgrind_was_set
=true
560 valgrind_was_set
=true
563 # If valgrind_was_set is set to no we bail
564 if ! $valgrind_was_set; then
565 echo 'valgrind was not present'
573 # If we are required to run configure, do so now
576 # If we don't have a configure, then most likely we will be missing libtool
577 assert_file
'configure'
578 if [[ -x 'libtool' ]]; then
579 LOG_COMPILER
="./libtool --mode=execute $VALGRIND_COMMAND"
581 LOG_COMPILER
="$VALGRIND_COMMAND"
592 if [ "$ret" -ne 0 ]; then
597 make_install_system
()
599 local INSTALL_LOCATION
="$(mktemp -d /tmp/XXXXXXXXXX)"
602 PREFIX_ARG
="--prefix=$INSTALL_LOCATION"
604 if [ ! -d $INSTALL_LOCATION ] ; then
605 die
"ASSERT temp directory not found '$INSTALL_LOCATION'"
608 run_configure
#install_buid_dir
610 make_target
'install'
612 make_target
'installcheck'
614 make_target
'uninstall'
616 rm -r -f $INSTALL_LOCATION
619 if [ -f 'Makefile' ]; then
620 die
"ASSERT Makefile should not exist"
626 make_darwin_malloc
()
628 run_configure_if_required
630 old_MallocGuardEdges
=$MallocGuardEdges
632 old_MallocErrorAbort
=$MallocErrorAbort
634 old_MallocScribble
=$MallocScribble
639 MallocGuardEdges
=$old_MallocGuardEdges
640 MallocErrorAbort
=$old_MallocErrorAbort
641 MallocScribble
=$old_MallocScribble
644 # This will reset our environment, and make sure built files are available.
647 # Lets make sure we have a clean environment
648 assert_no_file
'Makefile'
649 assert_no_file
'configure'
650 assert_no_directory
'autom4te.cache'
654 make_target
'distclean'
656 # We should have a configure, but no Makefile at the end of this exercise
657 assert_no_file
'Makefile'
658 assert_exec_file
'configure'
663 command_exists
'mingw64-configure'
665 if [ "$ret" -ne 0 ]; then
669 command_exists
'mingw64-make'
671 if [ "$ret" -ne 0 ]; then
680 command_exists
'clang'
682 if [ "$ret" -ne 0 ]; then
689 check_clang_analyzer
()
691 command_exists
'scan-build'
693 if [ "$ret" -ne 0 ]; then
705 if [ $ret -eq 0 ]; then
706 assert_file
'Makefile'
708 make_target
'all' 'warn'
710 if [ $ret -ne 0 ]; then
713 if [[ -n "$DISPLAY" ]]; then
714 if command_exists
'wine'; then
719 if [[ -n "$LOG_COMPILER" ]]; then
720 make_target
'check' 'warn' || warn
"$MAKE check failed"
725 if $jenkins_build_environment; then
726 make_target
'clean' 'warn'
735 if ! check_mingw
; then
739 # Make sure it is clean
740 if [ -f Makefile
-o -f configure
]; then
741 make_maintainer_clean
748 CONFIGURE
='mingw64-configure'
750 CONFIGURE_ARGS
='--enable-static --disable-shared'
762 if ! check_clang
; then
766 # Make sure it is clean
767 if [ -f Makefile
-o -f configure
]; then
768 make_maintainer_clean
788 make_for_clang_analyzer
()
790 if ! check_clang
; then
794 if ! check_clang_analyzer
; then
795 die
'clang-analyzer was not found'
798 # Make sure it is clean
799 if [ -f Makefile
-o -f configure
]; then
800 make_maintainer_clean
809 CONFIGURE
='scan-build ./configure'
810 CONFIGURE_ARGS
='--enable-debug'
814 scan-build
-o clang-html
make -j4 -k
819 # If we are locally testing, we should make sure the environment is setup correctly
822 if ! $jenkins_build_environment; then
823 echo "Not inside of jenkins, simulating environment"
825 if [ -f 'configure' ]; then
826 make_maintainer_clean
829 if $BOOTSTRAP_SNAPSHOT; then
837 use_banner
'make maintainer-clean'
838 make_maintainer_clean
840 use_banner
'snapshot'
843 use_banner
'valgrind'
855 use_banner
'clang analyzer'
856 make_for_clang_analyzer
860 if [ $?
-eq 0 ]; then
864 use_banner
'make distcheck'
867 use_banner
'make install'
873 if [ -n "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then
874 assert_file
"$BOOTSTRAP_SNAPSHOT_CHECK" 'snapshot check failed'
878 make_for_continuus_integration
()
880 # Setup the environment if we are local
883 # No matter then evironment, we should not have a Makefile at this point
884 assert_no_file
'Makefile'
886 # Platforms which require bootstrap should have some setup done before we hit this stage.
887 # If we are building locally, skip this step, unless we are just testing locally.
888 if $BOOTSTRAP_SNAPSHOT; then
889 if $BOOTSTRAP_SNAPSHOT; then
890 assert_file
'configure'
895 # If we didn't require a snapshot, then we should not have a configure
896 assert_no_file
'configure'
901 assert_no_file
'Makefile' 'Programmer error, Makefile existed where build state should have been clean'
909 make_maintainer_clean
912 # The point to this test is to test bootstrap.sh itself
915 # We start off with a clean env
916 make_maintainer_clean
918 # eval "./bootstrap.sh jenkins" || die "failed 'jenkins'"
919 # eval "./bootstrap.sh all" || die "failed 'all'"
920 # eval "./bootstrap.sh gdb" || die "failed 'gdb'"
921 # eval "./bootstrap.sh maintainer-clean" || die "failed 'maintainer-clean'"
926 run_configure_if_required
927 assert_file
'configure'
929 make_target
'install-html'
936 if command_exists
'gdb'; then
937 run_configure_if_required
939 # Set ENV GDB_COMMAND
940 if [[ -z "$GDB_COMMAND" ]]; then
944 # If we don't have a configure, then most likely we will be missing libtool
945 assert_file
'configure'
946 if [[ -f 'libtool' ]]; then
947 LOG_COMPILER
="./libtool --mode=execute $GDB_COMMAND"
949 LOG_COMPILER
="$GDB_COMMAND"
954 if [ -f 'gdb.txt' ]; then
958 if [ -f '.gdb_history' ]; then
962 if $jenkins_build_environment; then
966 echo 'gdb was not present'
973 # $1 target to compile
974 # $2 to die, or not to die, based on contents
978 die
"Programmer error, no target provided for make"
981 if [ ! -f 'Makefile' ]; then
982 die
"Programmer error, make was called before configure"
986 if [ -n "$LOG_COMPILER" ]; then
988 echo "LOG_COMPILER=$LOG_COMPILER"
992 if [ -z "$MAKE" ]; then
993 die
"MAKE was not set"
996 # $2 represents error or warn
1000 if [ $ret -ne 0 ]; then
1001 if [ -n "$2" ]; then
1002 warn
"Failed to execute $MAKE $1: $ret"
1003 elif [ $ret -eq 2 ]; then
1004 die
"Failed to execute $MAKE $1"
1006 die
"Failed to execute $MAKE $1: $ret"
1015 make_target
'distcheck'
1020 if command_exists
'rpmbuild'; then
1021 if [ -f 'rpm.am' -o -d 'rpm' ]; then
1022 run_configure_if_required
1023 make_target
'dist-rpm'
1025 if $jenkins_build_environment; then
1027 mv *.
tar.gz
*.rpm artifacts
1029 make_target
'maintainer-clean'
1038 make_maintainer_clean
()
1040 run_configure_if_required
1041 make_target
'maintainer-clean' 'no_error'
1043 # Lets make sure we really cleaned up the environment
1044 assert_no_file
'Makefile'
1045 assert_no_file
'configure'
1046 assert_no_directory
'autom4te.cache'
1051 run_configure_if_required
1052 make_target
'distclean' 'no_error'
1054 # Lets make sure we really cleaned up the environment
1055 assert_no_file
'Makefile'
1056 assert_file
'configure'
1064 make_jenkins_default
()
1072 run_configure_if_required
1076 run_configure_if_required
()
1078 run_autoreconf_if_required
1080 if [ ! -f 'Makefile' ]; then
1084 assert_file
'Makefile' 'configure did not produce a Makefile'
1087 run_make_maintainer_clean_if_possible
()
1089 if [ -f 'Makefile' ]; then
1090 make_maintainer_clean
1094 run_autoreconf_if_required
()
1096 if [ ! -x 'configure' ]; then
1100 assert_exec_file
'configure'
1106 if [[ -z "$AUTORECONF" ]]; then
1107 die
"Programmer error, tried to call run_autoreconf () but AUTORECONF was not set"
1110 if $use_libtool; then
1111 assert
$BOOTSTRAP_LIBTOOLIZE
1112 if $jenkins_build_environment; then
1113 run
"$BOOTSTRAP_LIBTOOLIZE" '--copy' '--install' || die
"Cannot execute $BOOTSTRAP_LIBTOOLIZE"
1115 run
"$BOOTSTRAP_LIBTOOLIZE" '--copy' '--install' '--force' || die
"Cannot execute $BOOTSTRAP_LIBTOOLIZE"
1119 run
"$AUTORECONF" "$AUTORECONF_ARGS" || die
"Cannot execute $AUTORECONF"
1121 eval 'bash -n configure' || die
"autoreconf generated a malformed configure"
1130 if [ -z "$1" ]; then
1137 parse_command_line_options
()
1139 local SHORTOPTS
=':apcmt:dvh'
1143 while getopts "$SHORTOPTS" opt
; do
1146 AUTORECONF_OPTION
=true
1147 OPT_TARGET
+='autoreconf'
1150 print_setup_opt
=true
1153 CONFIGURE_OPTION
=true
1154 OPT_TARGET
+='configure'
1156 m
) # maintainer-clean
1160 CONFIGURE_ARG
="$OPTARG"
1164 TARGET_OPTION_ARG
="$OPTARG"
1165 OPT_TARGET
+="$OPTARG"
1172 echo "bootstrap.sh [options] optional_target ..."
1173 echo " -a # Just run autoreconf";
1174 echo " -p # Print ENV";
1175 echo " -c # Just run configure";
1176 echo " -m # Just run maintainer-clean";
1177 echo " -o # Specify configure arguments";
1178 echo " -t # Make target";
1179 echo " -d # Enable debug";
1180 echo " -h # Show help";
1181 echo " -v # Be more verbose in output";
1189 echo "Option -$OPTARG requires an argument." >&2
1193 echo "$0: error - unrecognized option $1" 1>&2
1201 if [ -n "$1" ]; then
1208 if [[ -d '.git' ]]; then
1210 elif [[ -d '.bzr' ]]; then
1212 elif [[ -d '.svn' ]]; then
1214 elif [[ -d '.hg' ]]; then
1220 if [[ -n "$VCS_CHECKOUT" ]]; then
1225 require_libtoolise
()
1227 grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac
>/dev
/null \
1229 grep '^[ ]*LT_INIT' configure.ac
>/dev
/null \
1235 # Set ENV MAKE in order to override "make"
1236 if [[ -z "$MAKE" ]]; then
1237 if command_exists
'gmake'; then
1238 MAKE
="$(type -p gmake)"
1240 if command_exists
'make'; then
1241 MAKE
="$(type -p make)"
1245 if [ "$VCS_CHECKOUT" ]; then
1247 MAKE
="$MAKE --warn-undefined-variables"
1256 if [[ -z "$GNU_BUILD_FLAGS" ]]; then
1257 if $jenkins_build_environment; then
1258 GNU_BUILD_FLAGS
="--install"
1260 GNU_BUILD_FLAGS
="--install --force"
1265 GNU_BUILD_FLAGS
="$GNU_BUILD_FLAGS --verbose"
1268 if [ -z "$ACLOCAL_PATH" ]; then
1269 ACLOCAL_PATH
="/usr/local/share/aclocal $ACLOCAL_PATH"
1272 if [[ -z "$WARNINGS" ]]; then
1273 if [[ -n "$VCS_CHECKOUT" ]]; then
1274 WARNINGS
="all,error"
1280 if $use_libtool; then
1281 if [[ -n "$LIBTOOLIZE" ]]; then
1282 BOOTSTRAP_LIBTOOLIZE
="$(type -p $LIBTOOLIZE)"
1284 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1285 echo "Couldn't find user supplied libtoolize, it is required"
1289 # If we are using OSX, we first check to see glibtoolize is available
1290 if [[ "$VENDOR_DISTRIBUTION" == "darwin" ]]; then
1291 BOOTSTRAP_LIBTOOLIZE
="$(type -p glibtoolize)"
1293 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1294 echo "Couldn't find glibtoolize, it is required on OSX"
1298 BOOTSTRAP_LIBTOOLIZE
="$(type -p libtoolize)"
1300 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1301 echo "Couldn't find libtoolize, it is required"
1308 LIBTOOLIZE_OPTIONS
="--verbose $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
1312 LIBTOOLIZE_OPTIONS
="--debug $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
1315 # Here we set LIBTOOLIZE to true since we are going to invoke it via BOOTSTRAP_LIBTOOLIZE
1319 # Test the ENV AUTOMAKE if it exists
1320 if [[ -n "$AUTOMAKE" ]]; then
1321 run
"$AUTOMAKE" '--help' &> /dev
/null || die
"Failed to run AUTOMAKE:$AUTOMAKE"
1324 # Test the ENV AUTOCONF if it exists
1325 if [[ -n "$AUTOCONF" ]]; then
1326 run
"$AUTOCONF" '--help' &> /dev
/null || die
"Failed to run AUTOCONF:$AUTOCONF"
1329 # Test the ENV AUTOHEADER if it exists
1330 if [[ -n "$AUTOHEADER" ]]; then
1331 run
"$AUTOHEADER" '--help' &> /dev
/null || die
"Failed to run AUTOHEADER:$AUTOHEADER"
1334 # Test the ENV AUTOM4TE if it exists
1335 if [[ -n "$AUTOM4TE" ]]; then
1336 run
"$AUTOM4TE" '--help' &> /dev
/null || die
"Failed to run AUTOM4TE:$AUTOM4TE"
1339 # Test the ENV AUTOHEADER if it exists, if not we add one and add --install
1340 if [[ -z "$ACLOCAL" ]]; then
1341 ACLOCAL
="aclocal --install"
1343 run
"$ACLOCAL" '--help' &> /dev
/null || die
"Failed to run ACLOCAL:$ACLOCAL"
1345 if [[ -z "$AUTORECONF" ]]; then
1346 AUTORECONF
="$(type -p autoreconf)"
1348 if [[ -z "$AUTORECONF" ]]; then
1349 die
"Couldn't find autoreconf"
1352 if [[ -n "$GNU_BUILD_FLAGS" ]]; then
1353 AUTORECONF_ARGS
="$GNU_BUILD_FLAGS"
1357 run
"$AUTORECONF" '--help' &> /dev
/null || die
"Failed to run AUTORECONF:$AUTORECONF"
1362 local saved_debug_status
=$debug
1367 echo '----------------------------------------------'
1368 echo 'BOOTSTRAP ENV'
1369 echo "AUTORECONF=$AUTORECONF"
1370 echo "HOST_OS=$HOST_OS"
1371 echo "VENDOR=$VENDOR"
1372 echo "VENDOR_DISTRIBUTION=$VENDOR_DISTRIBUTION"
1373 echo "VENDOR_RELEASE=$VENDOR_RELEASE"
1376 if $AUTORECONF_OPTION; then
1380 if $CLEAN_OPTION; then
1384 if $CONFIGURE_OPTION; then
1392 if $print_setup_opt; then
1396 if $TARGET_OPTION; then
1397 echo "--target=$TARGET_OPTION_ARG"
1400 if $opt_verbose; then
1404 if [[ -n "$MAKE" ]]; then
1408 if [[ -n "$BOOTSTRAP_TARGET" ]]; then
1409 echo "BOOTSTRAP_TARGET=$BOOTSTRAP_TARGET"
1412 if [[ -n "$PREFIX" ]]; then
1413 echo "PREFIX=$PREFIX"
1416 if [[ -n "$LOG_COMPILER" ]]; then
1417 echo "LOG_COMPILER=$LOG_COMPILER"
1420 if [[ -n "$VCS_CHECKOUT" ]]; then
1421 echo "VCS_CHECKOUT=$VCS_CHECKOUT"
1428 if [[ -n "$WARNINGS" ]]; then
1429 echo "WARNINGS=$WARNINGS"
1432 if $saved_debug_status; then
1436 echo '----------------------------------------------'
1438 if $saved_debug_status; then
1443 make_clean_option
()
1445 run_configure_if_required
1447 make_maintainer_clean
1449 if [[ "$VCS_CHECKOUT" == 'git' ]]; then
1450 run
"$VCS_CHECKOUT" status
--ignored
1451 elif [[ -n "$VCS_CHECKOUT" ]]; then
1452 run
"$VCS_CHECKOUT" status
1456 make_for_autoreconf
()
1458 if [ -f 'Makefile' ]; then
1459 make_maintainer_clean
1464 assert_no_file
'Makefile'
1522 echo "Matched default"
1532 # We should always have a target by this point
1533 assert BOOTSTRAP_TARGET
1535 determine_target_platform
1539 # Set up whatever we need to do to use autoreconf later
1542 if ! autoreconf_setup
; then
1546 if $print_setup_opt -o $debug; then
1551 # Exit if all we were looking for were the currently used options
1552 if $print_setup_opt; then
1557 # Use OLD_LOG_COMPILER for tracking the state of the variable
1558 local OLD_LOG_COMPILER
=
1560 # Set ENV PREFIX in order to set --prefix for ./configure
1561 if [[ -n "$PREFIX" ]]; then
1562 PREFIX_ARG
="--prefix=$PREFIX"
1565 if $CLEAN_OPTION; then
1566 make_maintainer_clean
1569 local BOOTSTRAP_TARGET_ARRAY
1570 BOOTSTRAP_TARGET_ARRAY
=( $BOOTSTRAP_TARGET )
1572 for target
in "${BOOTSTRAP_TARGET_ARRAY[@]}"
1574 # If we are running inside of Jenkins, we want to only run some of the possible tests
1575 if $jenkins_build_environment; then
1576 check_make_target
$target
1578 if [ $ret -ne 0 ]; then
1579 warn
"Unknown BOOTSTRAP_TARGET option: $target"
1584 if $jenkins_build_environment; then
1588 local snapshot_run
=false
1589 local valgrind_run
=false
1618 if ! check_clang
; then
1619 die
"clang was not found"
1622 if ! make_for_clang
; then
1623 die
"Failed to build clang: $?"
1628 if ! check_clang_analyzer
; then
1629 die
"clang-analyzer was not found"
1631 if ! check_clang
; then
1632 die
"clang was not found"
1635 if ! make_for_clang_analyzer
; then
1636 die
"Failed to build clang-analyzer: $?"
1641 if ! make_for_mingw
; then
1642 die
"Failed to build mingw: $?"
1663 make_for_continuus_integration
1666 run_configure_if_required
1667 make_target
"$target"
1675 # Are we running inside of Jenkins?
1676 if [[ -n "$JENKINS_HOME" ]]; then
1677 declare -r jenkins_build_environment
=true
1679 declare -r jenkins_build_environment
=false
1682 # Variables we export
1683 declare -x VCS_CHECKOUT
=
1685 # Variables we control globally
1686 local -a BOOTSTRAP_TARGET
=
1688 local use_libtool
=false
1692 local opt_debug
=false
1693 local opt_verbose
=false
1695 if [[ -n "$VERBOSE" ]]; then
1699 # Options for getopt
1700 local AUTORECONF_OPTION
=false
1701 local CLEAN_OPTION
=false
1702 local CONFIGURE_OPTION
=false
1703 local print_setup_opt
=false
1704 local TARGET_OPTION
=false
1705 local TARGET_OPTION_ARG
=
1707 local OLD_CONFIGURE
=
1708 local OLD_CONFIGURE_ARG
=
1711 local OLD_LOG_COMPILER
=
1713 # If we call autoreconf on the platform or not
1714 local AUTORECONF_REBUILD_HOST
=false
1715 local AUTORECONF_REBUILD
=false
1717 local -r top_srcdir
="$(pwd)"
1720 if [ -z "$CONFIGURE" ]; then
1721 CONFIGURE
="$top_srcdir/configure"
1725 # Variables for determine_target_platform () and rebuild_host_os ()
1726 # UNAME_MACHINE_ARCH= uname -m
1727 # VENDOR= apple, redhat, centos, canonical
1729 # RHEL{rhel,Tikanga,Santiago}
1730 # Ubuntu{ubuntu,Lucid,Maverick,Natty,Oneiric,Precise,Quantal}
1731 # Fedora{fedora,Verne,Beefy}
1732 # OSX{osx,lion,snow,mountain}
1733 # VENDOR_DISTRIBUTION= darwin,fedora,rhel,ubuntu
1734 # UNAME_KERNEL= Linux, Darwin,...
1735 # UNAME_KERNEL_RELEASE= Linux, Darwin,...
1736 local UNAME_MACHINE_ARCH
=unknown
1737 local VENDOR
=unknown
1738 local VENDOR_RELEASE
=unknown
1739 local VENDOR_DISTRIBUTION
=unknown
1740 local UNAME_KERNEL
=unknown
1741 local UNAME_KERNEL_RELEASE
=unknown
1744 rebuild_host_os no_output
1747 parse_command_line_options
"$@"
1749 nassert BOOTSTRAP_TARGET
1751 if [ -n "$OPT_TARGET" ]; then
1752 BOOTSTRAP_TARGET
="$OPT_TARGET"
1755 if [ -z "$BOOTSTRAP_TARGET" ]; then
1756 BOOTSTRAP_TARGET
="make_default"
1759 # We should always have a target by this point
1760 assert BOOTSTRAP_TARGET
1773 if [ -z "$BRANCH" ]; then
1774 if [ -z "$CI_PROJECT_TEAM" ]; then
1775 die
"Variable CI_PROJECT_TEAM has not been set"
1777 if [ -z "$PROJECT" ]; then
1778 die
"Variable PROJECT has not been set"
1780 if [ -z "$BUILD_TAG" ]; then
1781 die
"Variable BUILD_TAG has not been set"
1784 BRANCH
="lp:~$CI_PROJECT_TEAM/$PROJECT/$BUILD_TAG"
1788 if [ -z "$BRANCH" ]; then
1789 die
"Missing values required to build BRANCH variable."
1795 if [ -z "$VCS_CHECKOUT" ]; then
1796 die
"Merges require VCS_CHECKOUT."
1801 if [[ "$VCS_CHECKOUT" == 'bzr' ]]; then
1802 if test -n "$BRANCH_TO_MERGE"; then
1803 bzr merge
$BRANCH_TO_MERGE
1804 bzr commit
--message="Merge $BRANCH_TO_MERGE Build: $BUILD_TAG" --unchanged
1808 elif [[ -n "$VCS_CHECKOUT" ]]; then
1809 die
"Merge attempt occured, current VCS setup does not support this"
1816 local caller_loc
="$(caller)"
1817 if [[ -n "$1" ]]; then
1818 echo "$caller_loc Enabling debug: $1"
1820 echo "$caller_loc Enabling debug"
1830 Usage: $program_name [OPTION]..
1832 Bootstrap this package from the checked-out sources, and optionally walk through CI run.
1847 if [ -x '/usr/local/bin/shellcheck' ]; then
1848 /usr
/local
/bin
/shellcheck
"$1"
1851 if [ "$ret" -ne 0 ]; then
1852 die
"$1 failed shellcheck"
1859 check_shell
'bootstrap.sh'
1860 local env_debug_enabled
=false
1869 export CONFIGURE_ARG
1871 export GNU_BUILD_FLAGS
1873 export LIBTOOLIZE_OPTIONS
1882 export MallocGuardEdges
1883 export MallocErrorAbort
1884 export MallocScribble
1888 # We check for DEBUG twice, once before we source the config file, and once afterward
1889 if [[ -n "$DEBUG" ]]; then
1890 env_debug_enabled
=true
1893 # Variables which only can be set by .bootstrap
1894 BOOTSTRAP_SNAPSHOT
=false
1895 BOOTSTRAP_SNAPSHOT_CHECK
=
1897 if [ -f '.bootstrap' ]; then
1901 # 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
1902 if $env_debug_enabled; then
1904 elif [[ -n "$DEBUG" ]]; then
1905 enable_debug
"Enabling DEBUG from '.bootstrap'"
1908 if $env_debug_enabled; then
1916 # Script begins here
1917 declare -r program_name
="$0"