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 # Valid values are: darwin,fedora,rhel,ubuntu
155 function set_VENDOR_DISTRIBUTION
()
157 local dist
=`echo "$1" | tr '[A-Z]' '[a-z]'`
160 VENDOR_DISTRIBUTION
='darwin'
163 VENDOR_DISTRIBUTION
='fedora'
166 VENDOR_DISTRIBUTION
='rhel'
169 VENDOR_DISTRIBUTION
='ubuntu'
172 VENDOR_DISTRIBUTION
='opensuse'
175 die
"attempt to set an invalid VENDOR_DISTRIBUTION=$dist"
180 function set_VENDOR_RELEASE
()
182 local release
=`echo "$1" | tr '[A-Z]' '[a-z]'`
183 case "$VENDOR_DISTRIBUTION" in
185 VENDOR_RELEASE
='mountain'
188 VENDOR_RELEASE
="$release"
191 VENDOR_RELEASE
="$release"
194 VENDOR_RELEASE
="$release"
197 VENDOR_RELEASE
="$release"
200 die
"attempt to set VENDOR_RELEASE without setting VENDOR_DISTRIBUTION"
203 die
"attempt to set with an invalid VENDOR_DISTRIBUTION=$VENDOR_DISTRIBUTION"
209 # Valid values are: apple, redhat, centos, canonical
210 function set_VENDOR
()
212 local vendor
=`echo "$1" | tr '[A-Z]' '[a-z]'`
231 die
"An attempt was made to set an invalid VENDOR=$_vendor"
235 set_VENDOR_DISTRIBUTION
$2
236 set_VENDOR_RELEASE
$3
239 function determine_target_platform
()
241 UNAME_MACHINE_ARCH
=`(uname -m) 2>/dev/null` || UNAME_MACHINE_ARCH
=unknown
242 UNAME_KERNEL
=`(uname -s) 2>/dev/null` || UNAME_SYSTEM
=unknown
243 UNAME_KERNEL_RELEASE
=`(uname -r) 2>/dev/null` || UNAME_KERNEL_RELEASE
=unknown
245 if [[ $
(uname
) == 'Darwin' ]]; then
246 set_VENDOR
'apple' 'darwin' 'mountain'
247 elif [[ -f '/etc/fedora-release' ]]; then
248 local fedora_version
=`cat /etc/fedora-release | awk ' { print $3 } '`
249 set_VENDOR
'redhat' 'fedora' $fedora_version
250 if [[ "x$VENDOR_RELEASE" == 'x17' ]]; then
251 AUTORECONF_REBUILD_HOST
=true
253 elif [[ -f '/etc/centos-release' ]]; then
254 local centos_version
=`cat /etc/centos-release | awk ' { print $7 } '`
255 set_VENDOR
'centos' 'rhel' $centos_version
256 elif [[ -f '/etc/SuSE-release' ]]; then
257 local suse_distribution
=`head -1 /etc/SuSE-release | awk ' { print $1 } '`
258 local suse_version
=`head -1 /etc/SuSE-release | awk ' { print $2 } '`
259 set_VENDOR
'suse' $suse_distribution $suse_version
260 elif [[ -f '/etc/redhat-release' ]]; then
261 local rhel_version
=`cat /etc/redhat-release | awk ' { print $7 } '`
262 set_VENDOR
'redhat' 'rhel' $rhel_version
263 elif [[ -f '/etc/lsb-release' ]]; then
264 local debian_DISTRIB_ID
=`cat /etc/lsb-release | grep DISTRIB_ID | awk -F= ' { print $2 } '`
265 local debian_version
=`cat /etc/lsb-release | grep DISTRIB_CODENAME | awk -F= ' { print $2 } '`
266 set_VENDOR
'canonical' $debian_DISTRIB_ID $debian_version
267 if [[ "x$VENDOR_RELEASE" == 'xprecise' ]]; then
268 AUTORECONF_REBUILD_HOST
=true
275 function run_configure
()
277 # We will run autoreconf if we are required
278 run_autoreconf_if_required
280 # We always begin at the root of our build
282 die
"Programmer error, we entered run_configure with a stacked directory"
285 if ! command_exists
"$CONFIGURE"; then
286 die
"$CONFIGURE does not exist"
290 if [[ -n "$BUILD_DIR" ]]; then
293 safe_pushd
$BUILD_DIR
296 # Arguments for configure
297 local BUILD_CONFIGURE_ARG
=
299 # 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
300 # Set ENV ASSERT in order to enable assert
302 BUILD_CONFIGURE_ARG
+=' --enable-debug --enable-assert'
303 elif [[ -n "$VCS_CHECKOUT" ]]; then
304 BUILD_CONFIGURE_ARG
+=' --enable-assert'
307 if [[ -n "$CONFIGURE_ARG" ]]; then
308 BUILD_CONFIGURE_ARG
+=" $CONFIGURE_ARG"
311 if [[ -n "$PREFIX_ARG" ]]; then
312 BUILD_CONFIGURE_ARG
+=" $PREFIX_ARG"
316 # If we are executing on OSX use CLANG, otherwise only use it if we find it in the ENV
319 CC
=clang CXX
=clang
++ $top_srcdir/configure
$BUILD_CONFIGURE_ARG || die
"Cannot execute CC=clang CXX=clang++ configure $BUILD_CONFIGURE_ARG"
323 command_exists
'gcc44' || die
"Could not locate gcc44"
324 CC
=gcc44 CXX
=gcc44
$top_srcdir/configure
$BUILD_CONFIGURE_ARG || die
"Cannot execute CC=gcc44 CXX=gcc44 configure $BUILD_CONFIGURE_ARG"
328 $CONFIGURE $BUILD_CONFIGURE_ARG
333 if [ $ret -ne 0 ]; then
334 die
"Could not execute $CONFIGURE $BUILD_CONFIGURE_ARG"
337 if [ ! -f 'Makefile' ]; then
338 die
"Programmer error, configure was run but no Makefile existed after $CONFIGURE was run"
342 function setup_gdb_command
() {
343 GDB_TMPFILE
=$
(mktemp
/tmp
/gdb.XXXXXXXXXX
)
344 echo 'set logging overwrite on' > $GDB_TMPFILE
345 echo 'set logging on' >> $GDB_TMPFILE
346 echo 'set environment LIBTEST_IN_GDB=1' >> $GDB_TMPFILE
347 echo 'run' >> $GDB_TMPFILE
348 echo 'thread apply all bt' >> $GDB_TMPFILE
349 echo 'quit' >> $GDB_TMPFILE
350 GDB_COMMAND
="gdb -f -batch -x $GDB_TMPFILE"
353 function setup_valgrind_command
() {
354 VALGRIND_PROGRAM
=`type -p valgrind`
355 if [[ -n "$VALGRIND_PROGRAM" ]]; then
356 VALGRIND_COMMAND
="$VALGRIND_PROGRAM --error-exitcode=1 --leak-check=yes --show-reachable=yes --track-fds=yes --malloc-fill=A5 --free-fill=DE"
360 function save_BUILD
()
362 if [[ -n "$OLD_CONFIGURE" ]]; then
363 die
"OLD_CONFIGURE($OLD_CONFIGURE) was set on push, programmer error!"
366 if [[ -n "$OLD_CONFIGURE_ARG" ]]; then
367 die
"OLD_CONFIGURE_ARG($OLD_CONFIGURE_ARG) was set on push, programmer error!"
370 if [[ -n "$OLD_PREFIX" ]]; then
371 die
"OLD_PREFIX($OLD_PREFIX) was set on push, programmer error!"
374 if [[ -n "$OLD_MAKE" ]]; then
375 die
"OLD_MAKE($OLD_MAKE) was set on push, programmer error!"
378 if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
379 die
"OLD_TESTS_ENVIRONMENT($OLD_TESTS_ENVIRONMENT) was set on push, programmer error!"
382 if [[ -n "$CONFIGURE" ]]; then
383 OLD_CONFIGURE
=$CONFIGURE
386 if [[ -n "$CONFIGURE_ARG" ]]; then
387 OLD_CONFIGURE_ARG
=$CONFIGURE_ARG
390 if [[ -n "$MAKE" ]]; then
394 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
395 OLD_TESTS_ENVIRONMENT
=$TESTS_ENVIRONMENT
399 function restore_BUILD
()
401 if [[ -n "$OLD_CONFIGURE" ]]; then
402 CONFIGURE
=$OLD_CONFIGURE
405 if [[ -n "$OLD_CONFIGURE_ARG" ]]; then
406 CONFIGURE_ARG
=$OLD_CONFIGURE_ARG
409 if [[ -n "$OLD_PREFIX" ]]; then
410 PREFIX_ARG
=$OLD_PREFIX
413 if [[ -n "$OLD_MAKE" ]]; then
417 if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
418 TESTS_ENVIRONMENT
=$OLD_TESTS_ENVIRONMENT
425 OLD_TESTS_ENVIRONMENT
=
430 function safe_pushd
()
432 pushd $1 &> /dev
/null
;
434 if [ -n "$BUILD_DIR" ]; then
436 echo "BUILD_DIR=$BUILD_DIR"
441 function safe_popd
()
443 local directory_to_delete
=`pwd`
445 if [ $?
-eq 0 ]; then
446 if [[ "$top_srcdir" == "$directory_to_delete" ]]; then
447 die
"We almost deleted top_srcdir($top_srcdir), programmer error"
450 rm -r -f "$directory_to_delete"
454 function make_valgrind
()
456 if [[ "$VENDOR_DISTRIBUTION" == 'darwin' ]]; then
461 # If the env VALGRIND_COMMAND is set then we assume it is valid
462 local valgrind_was_set
=false
463 if [[ -z "$VALGRIND_COMMAND" ]]; then
464 setup_valgrind_command
465 if [[ -n "$VALGRIND_COMMAND" ]]; then
466 valgrind_was_set
=true
469 valgrind_was_set
=true
472 # If valgrind_was_set is set to no we bail
473 if ! $valgrind_was_set; then
474 echo 'valgrind was not present'
480 # If we are required to run configure, do so now
481 run_configure_if_required
483 # If we don't have a configure, then most likely we will be missing libtool
484 assert_file
'configure'
485 if [[ -f 'libtool' ]]; then
486 TESTS_ENVIRONMENT
="./libtool --mode=execute $VALGRIND_COMMAND"
488 TESTS_ENVIRONMENT
="$VALGRIND_COMMAND"
491 make_target
'check' ||
return 1
496 function make_install_system
()
498 local INSTALL_LOCATION
=$
(mktemp
-d /tmp
/XXXXXXXXXX
)
501 PREFIX_ARG
="--prefix=$INSTALL_LOCATION"
503 if [ ! -d $INSTALL_LOCATION ] ; then
504 die
"ASSERT temp directory not found '$INSTALL_LOCATION'"
507 run_configure
#install_buid_dir
509 make_target
'install'
511 make_target
'installcheck'
513 make_target
'uninstall'
515 rm -r -f $INSTALL_LOCATION
518 if [ -f 'Makefile' ]; then
519 die
"ASSERT Makefile should not exist"
526 function make_darwin_malloc
()
528 run_configure_if_required
530 old_MallocGuardEdges
=$MallocGuardEdges
532 old_MallocErrorAbort
=$MallocErrorAbort
534 old_MallocScribble
=$MallocScribble
539 MallocGuardEdges
=$old_MallocGuardEdges
540 MallocErrorAbort
=$old_MallocErrorAbort
541 MallocScribble
=$old_MallocScribble
544 function snapshot_check
()
546 if [ ! -f "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then
550 if [ -n "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then
551 assert_file
"$BOOTSTRAP_SNAPSHOT_CHECK" 'snapshot check failed'
555 # This will reset our environment, and make sure built files are available.
556 function make_for_snapshot
()
558 # Make sure it is clean
559 make_maintainer_clean
563 make_target
'distclean'
565 # We should have a configure, but no Makefile at the end of this exercise
566 assert_no_file
'Makefile'
567 assert_exec_file
'configure'
572 function check_mingw
()
574 command_exists
'mingw64-configure'
576 if [ "$ret" -ne 0 ]; then
580 command_exists
'mingw64-make'
582 if [ "$ret" -ne 0 ]; then
589 function check_clang
()
591 command_exists
'clang'
593 if [ "$ret" -ne 0 ]; then
600 function check_clang_analyzer
()
602 command_exists
'scan-build'
604 if [ "$ret" -ne 0 ]; then
611 function make_skeleton
()
616 if [ $ret -eq 0 ]; then
617 assert_file
'Makefile'
619 make_target
'all' 'warn'
621 if [ $ret -ne 0 ]; then
624 if [[ -n "$DISPLAY" ]]; then
625 if command_exists
'wine'; then
626 TESTS_ENVIRONMENT
='wine'
630 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
631 make_target
'check' 'warn' || warn
"$MAKE check failed"
636 if $jenkins_build_environment; then
637 make_target
'clean' 'warn'
644 function make_for_mingw
()
646 if ! check_mingw
; then
650 # Make sure it is clean
651 if [ -f Makefile
-o -f configure
]; then
652 make_maintainer_clean
659 CONFIGURE
='mingw64-configure'
661 CONFIGURE_ARGS
='--enable-static --disable-shared'
671 function make_for_clang
()
673 if ! check_clang
; then
677 # Make sure it is clean
678 if [ -f Makefile
-o -f configure
]; then
679 make_maintainer_clean
699 function make_for_clang_analyzer
()
701 if ! check_clang
; then
705 if ! check_clang_analyzer
; then
706 die
'clang-analyzer was not found'
709 # Make sure it is clean
710 if [ -f Makefile
-o -f configure
]; then
711 make_maintainer_clean
720 CONFIGURE_ARGS
='--enable-debug'
725 make_target
'clean' 'warn'
727 scan-build
-o clang-html
make -j4 -k
734 # If we are locally testing, we should make sure the environment is setup correctly
735 function check_for_jenkins
()
737 if ! $jenkins_build_environment; then
738 echo "Not inside of jenkins"
740 if [ -f 'configure' ]; then
741 make_maintainer_clean
744 if $BOOTSTRAP_SNAPSHOT; then
750 function make_universe
()
757 make_for_clang_analyzer
759 if [ check_mingw
-eq 0 ]; then
767 function make_for_continuus_integration
()
769 # Setup the environment if we are local
772 # No matter then evironment, we should not have a Makefile at this point
773 assert_no_file
'Makefile'
775 # Platforms which require bootstrap should have some setup done before we hit this stage.
776 # If we are building locally, skip this step, unless we are just testing locally.
777 if $BOOTSTRAP_SNAPSHOT; then
780 # If we didn't require a snapshot, then we should not have a configure
781 assert_no_file
'configure'
786 assert_no_file
'Makefile' 'Programmer error, Makefile existed where build state should have been clean'
792 assert_exec_file
'configure'
793 assert_file
'Makefile'
797 # make rpm includes "make distcheck"
798 if [[ -f rpm.am
]]; then
800 elif [[ -d rpm
]]; then
806 assert_exec_file
'configure'
807 assert_file
'Makefile'
814 assert_exec_file
'configure'
815 assert_file
'Makefile'
821 assert_exec_file
'configure'
822 assert_file
'Makefile'
826 assert_exec_file
'configure'
827 assert_file
'Makefile'
836 make_maintainer_clean
841 # The point to this test is to test bootstrap.sh itself
842 function self_test
()
844 # We start off with a clean env
845 make_maintainer_clean
847 eval "./bootstrap.sh jenkins" || die
"failed 'jenkins'"
848 eval "./bootstrap.sh all" || die
"failed 'all'"
849 eval "./bootstrap.sh gdb" || die
"failed 'gdb'"
850 eval "./bootstrap.sh maintainer-clean" || die
"failed 'maintainer-clean'"
853 function make_install_html
()
855 run_configure_if_required
856 assert_file
'configure'
858 make_target
'install-html'
865 if command_exists
'gdb'; then
866 run_configure_if_required
868 # Set ENV GDB_COMMAND
869 if [[ -z "$GDB_COMMAND" ]]; then
873 # If we don't have a configure, then most likely we will be missing libtool
874 assert_file
'configure'
875 if [[ -f 'libtool' ]]; then
876 TESTS_ENVIRONMENT
="./libtool --mode=execute $GDB_COMMAND"
878 TESTS_ENVIRONMENT
="$GDB_COMMAND"
883 if [ -f 'gdb.txt' ]; then
887 if [ -f '.gdb_history' ]; then
891 if $jenkins_build_environment; then
895 echo 'gdb was not present'
902 # $1 target to compile
903 # $2 to die, or not to die, based on contents
904 function make_target
()
907 die
"Programmer error, no target provided for make"
910 if [ ! -f 'Makefile' ]; then
911 die
"Programmer error, make was called before configure"
915 if [ -n "$TESTS_ENVIRONMENT" ]; then
917 echo "TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT"
921 if [ -z "$MAKE" ]; then
922 die
"MAKE was not set"
925 # $2 represents error or warn
929 if [ $ret -ne 0 ]; then
931 warn
"Failed to execute $MAKE $1: $ret"
933 die
"Failed to execute $MAKE $1: $ret"
940 function make_distcheck
()
942 make_target
'distcheck'
947 if command_exists
'rpmbuild'; then
948 if [ -f 'rpm.am' -o -d 'rpm' ]; then
949 run_configure_if_required
952 if $jenkins_build_environment; then
960 function make_maintainer_clean
()
962 run_configure_if_required
963 make_target
'maintainer-clean' 'no_error'
965 # Lets make sure we really cleaned up the environment
966 assert_no_file
'Makefile'
967 assert_no_file
'configure'
968 assert_no_directory
'autom4te.cache'
971 function make_check
()
976 function make_jenkins_default
()
982 function make_default
()
984 run_configure_if_required
988 function run_configure_if_required
()
990 run_autoreconf_if_required
992 if [ ! -f 'Makefile' ]; then
996 assert_file
'Makefile' 'configure did not produce a Makefile'
999 function run_autoreconf_if_required
()
1001 if [ ! -x 'configure' ]; then
1005 assert_exec_file
'configure'
1008 function run_autoreconf
()
1010 if [[ -z "$AUTORECONF" ]]; then
1011 die
"Programmer error, tried to call run_autoreconf () but AUTORECONF was not set"
1014 if test $use_libtool = 1; then
1015 assert
$BOOTSTRAP_LIBTOOLIZE
1016 run
$BOOTSTRAP_LIBTOOLIZE '--copy' '--install' '--force' || die
"Cannot execute $BOOTSTRAP_LIBTOOLIZE"
1019 run
$AUTORECONF || die
"Cannot execute $AUTORECONF"
1021 eval 'bash -n configure' || die
"autoreconf generated a malformed configure"
1030 if [ -z "$1" ]; then
1037 function parse_command_line_options
()
1039 local SHORTOPTS
=':apcmt:dvh'
1043 while getopts "$SHORTOPTS" opt
; do
1046 AUTORECONF_OPTION
=true
1047 MAKE_TARGET
='autoreconf'
1050 PRINT_SETUP_OPTION
=true
1053 CONFIGURE_OPTION
=true
1054 MAKE_TARGET
='configure'
1056 m
) # maintainer-clean
1058 MAKE_TARGET
='clean_op'
1062 TARGET_OPTION_ARG
="$OPTARG"
1063 MAKE_TARGET
="$OPTARG"
1070 echo "bootstrap.sh [options] optional_target ..."
1078 echo "Option -$OPTARG requires an argument." >&2
1082 echo "$0: error - unrecognized option $1" 1>&2
1090 if [ -n "$1" ]; then
1095 function determine_vcs
()
1097 if [[ -d '.git' ]]; then
1099 elif [[ -d '.bzr' ]]; then
1101 elif [[ -d '.svn' ]]; then
1103 elif [[ -d '.hg' ]]; then
1109 if [[ -n "$VCS_CHECKOUT" ]]; then
1114 function require_libtoolise
()
1117 grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac
>/dev
/null \
1119 grep '^[ ]*LT_INIT' configure.ac
>/dev
/null \
1123 function autoreconf_setup
()
1125 # Set ENV MAKE in order to override "make"
1126 if [[ -z "$MAKE" ]]; then
1127 if command_exists
'gmake'; then
1128 MAKE
=`type -p gmake`
1130 if command_exists
'make'; then
1135 if [ "$VCS_CHECKOUT" ]; then
1137 MAKE
="$MAKE --warn-undefined-variables"
1146 if [[ -z "$GNU_BUILD_FLAGS" ]]; then
1147 GNU_BUILD_FLAGS
="--install --force"
1151 GNU_BUILD_FLAGS
="$GNU_BUILD_FLAGS --verbose"
1154 if [ -z "$ACLOCAL_PATH" ]; then
1155 ACLOCAL_PATH
="/usr/local/share/aclocal $ACLOCAL_PATH"
1158 if [[ -z "$WARNINGS" ]]; then
1159 if [[ -n "$VCS_CHECKOUT" ]]; then
1160 WARNINGS
="all,error"
1166 if test $use_libtool = 1; then
1167 if [[ -n "$LIBTOOLIZE" ]]; then
1168 BOOTSTRAP_LIBTOOLIZE
=`type -p $LIBTOOLIZE`
1170 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1171 echo "Couldn't find user supplied libtoolize, it is required"
1174 # If we are using OSX, we first check to see glibtoolize is available
1175 if [[ "$VENDOR_DISTRIBUTION" == "darwin" ]]; then
1176 BOOTSTRAP_LIBTOOLIZE
=`type -p glibtoolize`
1178 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1179 echo "Couldn't find glibtoolize, it is required on OSX"
1182 BOOTSTRAP_LIBTOOLIZE
=`type -p libtoolize`
1184 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1185 echo "Couldn't find libtoolize, it is required"
1190 LIBTOOLIZE_OPTIONS
="--verbose $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
1193 LIBTOOLIZE_OPTIONS
="--debug $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
1198 # Test the ENV AUTOMAKE if it exists
1199 if [[ -n "$AUTOMAKE" ]]; then
1200 run
$AUTOMAKE '--help' &> /dev
/null || die
"Failed to run AUTOMAKE:$AUTOMAKE"
1203 # Test the ENV AUTOCONF if it exists
1204 if [[ -n "$AUTOCONF" ]]; then
1205 run
$AUTOCONF '--help' &> /dev
/null || die
"Failed to run AUTOCONF:$AUTOCONF"
1208 # Test the ENV AUTOHEADER if it exists
1209 if [[ -n "$AUTOHEADER" ]]; then
1210 run
$AUTOHEADER '--help' &> /dev
/null || die
"Failed to run AUTOHEADER:$AUTOHEADER"
1213 # Test the ENV AUTOM4TE if it exists
1214 if [[ -n "$AUTOM4TE" ]]; then
1215 run
$AUTOM4TE '--help' &> /dev
/null || die
"Failed to run AUTOM4TE:$AUTOM4TE"
1218 # Test the ENV AUTOHEADER if it exists, if not we add one and add --install
1219 if [[ -z "$ACLOCAL" ]]; then
1220 ACLOCAL
="aclocal --install"
1222 run
$ACLOCAL '--help' &> /dev
/null || die
"Failed to run ACLOCAL:$ACLOCAL"
1224 if [[ -z "$AUTORECONF" ]]; then
1225 AUTORECONF
=`type -p autoreconf`
1227 if [[ -z "$AUTORECONF" ]]; then
1228 die
"Couldn't find autoreconf"
1231 if [[ -n "$GNU_BUILD_FLAGS" ]]; then
1232 AUTORECONF
="$AUTORECONF $GNU_BUILD_FLAGS"
1236 run
$AUTORECONF '--help' &> /dev
/null || die
"Failed to run AUTORECONF:$AUTORECONF"
1239 function print_setup
()
1241 saved_debug_status
=$DEBUG
1246 echo '----------------------------------------------'
1247 echo 'BOOTSTRAP ENV'
1248 echo "AUTORECONF=$AUTORECONF"
1249 echo "HOST_OS=$HOST_OS"
1252 if $AUTORECONF_OPTION; then
1256 if $CLEAN_OPTION; then
1260 if $CONFIGURE_OPTION; then
1264 if $DEBUG_OPTION; then
1268 if $PRINT_SETUP_OPTION; then
1272 if $TARGET_OPTION; then
1273 echo "--target=$TARGET_OPTION_ARG"
1276 if $VERBOSE_OPTION; then
1280 if [[ -n "$MAKE" ]]; then
1284 if [[ -n "$MAKE_TARGET" ]]; then
1285 echo "MAKE_TARGET=$MAKE_TARGET"
1288 if [[ -n "$PREFIX" ]]; then
1289 echo "PREFIX=$PREFIX"
1292 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
1293 echo "TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT"
1296 if [[ -n "$VCS_CHECKOUT" ]]; then
1297 echo "VCS_CHECKOUT=$VCS_CHECKOUT"
1308 if [[ -n "$WARNINGS" ]]; then
1309 echo "WARNINGS=$WARNINGS"
1311 echo '----------------------------------------------'
1313 if $saved_debug_status; then
1318 function make_clean_option
()
1320 run_configure_if_required
1322 make_maintainer_clean
1324 if [[ "$VCS_CHECKOUT" == 'git' ]]; then
1325 run
"$VCS_CHECKOUT" status
--ignored
1326 elif [[ -n "$VCS_CHECKOUT" ]]; then
1327 run
"$VCS_CHECKOUT" status
1331 function make_for_autoreconf
()
1333 if [ -f 'Makefile' ]; then
1334 make_maintainer_clean
1339 assert_no_file
'Makefile'
1342 function check_make_target
()
1396 die
"Unknown MAKE_TARGET option: $1"
1401 function bootstrap
()
1403 determine_target_platform
1407 # Set up whatever we need to do to use autoreconf later
1411 if [ -z "$MAKE_TARGET" ]; then
1412 MAKE_TARGET
="make_default"
1415 if $PRINT_SETUP_OPTION -o $DEBUG; then
1420 # Exit if all we were looking for were the currently used options
1421 if $PRINT_SETUP_OPTION; then
1426 # Use OLD_TESTS_ENVIRONMENT for tracking the state of the variable
1427 local OLD_TESTS_ENVIRONMENT
=
1429 # Set ENV PREFIX in order to set --prefix for ./configure
1430 if [[ -n "$PREFIX" ]]; then
1431 PREFIX_ARG
="--prefix=$PREFIX"
1434 # We should always have a target by this point
1437 local MAKE_TARGET_ARRAY
=($MAKE_TARGET)
1439 for target
in "${MAKE_TARGET_ARRAY[@]}"
1441 # If we are running inside of Jenkins, we want to only run some of the possible tests
1442 if $jenkins_build_environment; then
1443 check_make_target
$target
1472 if ! check_clang
; then
1473 die
"clang was not found"
1476 if ! make_for_clang
; then
1477 die
"Failed to build clang: $?"
1481 if ! check_clang_analyzer
; then
1482 die
"clang-analyzer was not found"
1484 if ! check_clang
; then
1485 die
"clang was not found"
1488 if ! make_for_clang_analyzer
; then
1489 die
"Failed to build clang-analyzer: $?"
1493 if ! check_mingw
; then
1494 die
"mingw was not found"
1497 if ! make_for_mingw
; then
1498 die
"Failed to build mingw: $?"
1514 make_for_continuus_integration
1517 run_configure_if_required
1518 make_target
"$target"
1526 # Variables we export
1527 declare -x VCS_CHECKOUT
=
1529 # Variables we control globally
1533 # Options for getopt
1534 local AUTORECONF_OPTION
=false
1535 local CLEAN_OPTION
=false
1536 local CONFIGURE_OPTION
=false
1537 local DEBUG_OPTION
=false
1538 local PRINT_SETUP_OPTION
=false
1539 local TARGET_OPTION
=false
1540 local TARGET_OPTION_ARG
=
1541 local VERBOSE_OPTION
=false
1543 local OLD_CONFIGURE
=
1544 local OLD_CONFIGURE_ARG
=
1547 local OLD_TESTS_ENVIRONMENT
=
1549 # If we call autoreconf on the platform or not
1550 local AUTORECONF_REBUILD_HOST
=false
1551 local AUTORECONF_REBUILD
=false
1553 local -r top_srcdir
=`pwd`
1556 if [ -z "$CONFIGURE" ]; then
1557 CONFIGURE
="$top_srcdir/configure"
1561 # Variables for determine_target_platform () and rebuild_host_os ()
1562 # UNAME_MACHINE_ARCH= uname -m
1563 # VENDOR= apple, redhat, centos, canonical
1565 # RHEL{rhel,Tikanga,Santiago}
1566 # Ubuntu{ubuntu,Lucid,Maverick,Natty,Oneiric,Precise,Quantal}
1567 # Fedora{fedora,Verne,Beefy}
1568 # OSX{osx,lion,snow,mountain}
1569 # VENDOR_DISTRIBUTION= darwin,fedora,rhel,ubuntu
1570 # UNAME_KERNEL= Linux, Darwin,...
1571 # UNAME_KERNEL_RELEASE= Linux, Darwin,...
1572 local UNAME_MACHINE_ARCH
=unknown
1573 local VENDOR
=unknown
1574 local VENDOR_RELEASE
=unknown
1575 local VENDOR_DISTRIBUTION
=unknown
1576 local UNAME_KERNEL
=unknown
1577 local UNAME_KERNEL_RELEASE
=unknown
1580 rebuild_host_os no_output
1582 parse_command_line_options $@
1584 # If we are running under Jenkins we predetermine what tests we will run against
1585 # This MAKE_TARGET can be overridden by parse_command_line_options based MAKE_TARGET changes.
1586 # We don't want Jenkins overriding other variables, so we NULL them.
1587 if [ -z "$MAKE_TARGET" ]; then
1588 if $jenkins_build_environment; then
1589 MAKE_TARGET
='jenkins'
1601 function set_branch
()
1603 if [ -z "$BRANCH" ]; then
1604 if [ -z "$CI_PROJECT_TEAM" ]; then
1605 die
"Variable CI_PROJECT_TEAM has not been set"
1607 if [ -z "$PROJECT" ]; then
1608 die
"Variable PROJECT has not been set"
1610 if [ -z "$BUILD_TAG" ]; then
1611 die
"Variable BUILD_TAG has not been set"
1614 BRANCH
="lp:~$CI_PROJECT_TEAM/$PROJECT/$BUILD_TAG"
1618 if [ -z "$BRANCH" ]; then
1619 die
"Missing values required to build BRANCH variable."
1625 if [ -z "$VCS_CHECKOUT" ]; then
1626 die
"Merges require VCS_CHECKOUT."
1631 if [[ "$VCS_CHECKOUT" == 'bzr' ]]; then
1632 if test -n "$BRANCH_TO_MERGE"; then
1633 bzr merge
$BRANCH_TO_MERGE
1634 bzr commit
--message="Merge $BRANCH_TO_MERGE Build: $BUILD_TAG" --unchanged
1638 elif [[ -n "$VCS_CHECKOUT" ]]; then
1639 die
"Merge attempt occured, current VCS setup does not support this"
1643 function enable_debug
()
1646 local caller_loc
=`caller`
1648 echo "$caller_loc Enabling debug: $1"
1650 echo "$caller_loc Enabling debug"
1660 Usage: $program_name [OPTION]..
1662 Bootstrap this package from the checked-out sources, and optionally walk through CI run.
1669 function disable_debug
()
1675 # Script begins here
1679 env_debug_enabled
=false
1680 if [[ -n "$JENKINS_HOME" ]]; then
1681 declare -r jenkins_build_environment
=true
1683 declare -r jenkins_build_environment
=false
1692 export CONFIGURE_ARG
1694 export GNU_BUILD_FLAGS
1696 export LIBTOOLIZE_OPTIONS
1699 export TESTS_ENVIRONMENT
1705 export MallocGuardEdges
1706 export MallocErrorAbort
1707 export MallocScribble
1711 # We check for DEBUG twice, once before we source the config file, and once afterward
1712 env_debug_enabled
=false
1713 if [[ -n "$DEBUG" ]]; then
1714 env_debug_enabled
=true
1719 # Variables which only can be set by .bootstrap
1720 BOOTSTRAP_SNAPSHOT
=false
1721 BOOTSTRAP_SNAPSHOT_CHECK
=
1723 if [ -f '.bootstrap' ]; then
1727 if $env_debug_enabled; then
1730 if [[ -n "$DEBUG" ]]; then
1731 enable_debug
"Enabling DEBUG from '.bootstrap'"
1736 # We do this in order to protect the case where DEBUG
1737 if ! $env_debug_enabled; then