Abstraction (which will save us merge hell with 1.2).
[awesomized/libmemcached] / bootstrap.sh
1 #!/bin/bash
2 #
3 # Copyright (C) 2012 Brian Aker
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
8 # met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 #
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
16 # distribution.
17 #
18 # * The names of its contributors may not be used to endorse or
19 # promote products derived from this software without specific prior
20 # written permission.
21 #
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.
33
34
35 # Environment Variables that will influence the build:
36 # AUTOMAKE
37 # AUTORECONF
38 # LIBTOOLIZE
39 # MAKE
40 # PREFIX
41 # TESTS_ENVIRONMENT
42 # VERBOSE
43 # WARNINGS
44 #
45
46 command_not_found_handle ()
47 {
48 warn "$@: command not found"
49
50 #if $DEBUG; then
51 echo ""
52 echo "Stack trace:"
53 local frame=0
54 while caller $frame; do
55 ((frame++));
56 done
57 echo ""
58 #fi
59
60 return 127
61 }
62
63 function error ()
64 {
65 echo "$BASH_SOURCE:$BASH_LINENO: $@" >&2
66 }
67
68 function die ()
69 {
70 echo "$BASH_SOURCE:$BASH_LINENO: $@" >&2
71 exit 1;
72 }
73
74 function warn ()
75 {
76 echo "$BASH_SOURCE:$BASH_LINENO: $@"
77 #echo "$BASH_SOURCE:$BASH_LINENO: $@" >&1
78 }
79
80 function nassert ()
81 {
82 local param_name=\$"$1"
83 local param_value=`eval "expr \"$param_name\" "`
84
85 if [ -n "$param_value" ]; then
86 echo "$bash_source:$bash_lineno: assert($param_name) had value of "$param_value"" >&2
87 exit 1
88 fi
89 }
90
91 function assert ()
92 {
93 local param_name=\$"$1"
94 local param_value=`eval "expr \"$param_name\" "`
95
96 if [ -z "$param_value" ]; then
97 echo "$bash_source:$bash_lineno: assert($param_name)" >&2
98 exit 1
99 fi
100 }
101
102 function assert_file ()
103 {
104 if [ ! -f "$1" ]; then
105 echo "$BASH_SOURCE:$BASH_LINENO: assert($1) does not exist: $2" >&2
106 exit 1;
107 fi
108 }
109
110 function assert_no_file ()
111 {
112 if [ -f "$1" ]; then
113 echo "$BASH_SOURCE:$BASH_LINENO: assert($1) file exists: $2" >&2
114 exit 1;
115 fi
116 }
117
118 function assert_no_directory ()
119 {
120 if [ -d "$1" ]; then
121 echo "$BASH_SOURCE:$BASH_LINENO: assert($1) directory exists: $2" >&2
122 exit 1;
123 fi
124 }
125
126 function assert_exec_file ()
127 {
128 if [ ! -f "$1" ]; then
129 echo "$BASH_SOURCE:$BASH_LINENO: assert($1) does not exist: $2" >&2
130 exit 1;
131 fi
132
133 if [ ! -x "$1" ]; then
134 echo "$BASH_SOURCE:$BASH_LINENO: assert($1) exists but is not executable: $2" >&2
135 exit 1;
136 fi
137 }
138
139 function command_exists ()
140 {
141 type "$1" &> /dev/null ;
142 }
143
144 function rebuild_host_os ()
145 {
146 HOST_OS="${UNAME_MACHINE_ARCH}-${VENDOR}-${VENDOR_DISTRIBUTION}-${VENDOR_RELEASE}-${UNAME_KERNEL}-${UNAME_KERNEL_RELEASE}"
147 if [ -z "$1" ]; then
148 if $VERBOSE; then
149 echo "HOST_OS=$HOST_OS"
150 fi
151 fi
152 }
153
154 # Valid values are: darwin,fedora,rhel,ubuntu
155 function set_VENDOR_DISTRIBUTION ()
156 {
157 local dist=`echo "$1" | tr '[A-Z]' '[a-z]'`
158 case "$dist" in
159 darwin)
160 VENDOR_DISTRIBUTION='darwin'
161 ;;
162 fedora)
163 VENDOR_DISTRIBUTION='fedora'
164 ;;
165 rhel)
166 VENDOR_DISTRIBUTION='rhel'
167 ;;
168 ubuntu)
169 VENDOR_DISTRIBUTION='ubuntu'
170 ;;
171 opensuse)
172 VENDOR_DISTRIBUTION='opensuse'
173 ;;
174 *)
175 die "attempt to set an invalid VENDOR_DISTRIBUTION=$dist"
176 ;;
177 esac
178 }
179
180 function set_VENDOR_RELEASE ()
181 {
182 local release=`echo "$1" | tr '[A-Z]' '[a-z]'`
183 case "$VENDOR_DISTRIBUTION" in
184 darwin)
185 VENDOR_RELEASE='mountain'
186 ;;
187 fedora)
188 VENDOR_RELEASE="$release"
189 ;;
190 rhel)
191 VENDOR_RELEASE="$release"
192 ;;
193 ubuntu)
194 VENDOR_RELEASE="$release"
195 ;;
196 opensuse)
197 VENDOR_RELEASE="$release"
198 ;;
199 unknown)
200 die "attempt to set VENDOR_RELEASE without setting VENDOR_DISTRIBUTION"
201 ;;
202 *)
203 die "attempt to set with an invalid VENDOR_DISTRIBUTION=$VENDOR_DISTRIBUTION"
204 ;;
205 esac
206 }
207
208
209 # Valid values are: apple, redhat, centos, canonical
210 function set_VENDOR ()
211 {
212 local vendor=`echo "$1" | tr '[A-Z]' '[a-z]'`
213
214 case $vendor in
215 apple)
216 VENDOR='apple'
217 ;;
218 redhat)
219 VENDOR='redhat'
220 ;;
221 centos)
222 VENDOR='centos'
223 ;;
224 canonical)
225 VENDOR='canonical'
226 ;;
227 suse)
228 VENDOR='suse'
229 ;;
230 *)
231 die "An attempt was made to set an invalid VENDOR=$_vendor"
232 ;;
233 esac
234
235 set_VENDOR_DISTRIBUTION $2
236 set_VENDOR_RELEASE $3
237 }
238
239 function determine_target_platform ()
240 {
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
244
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
252 fi
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
269 fi
270 fi
271
272 rebuild_host_os
273 }
274
275 function run_configure ()
276 {
277 # We will run autoreconf if we are required
278 run_autoreconf_if_required
279
280 # We always begin at the root of our build
281 if [ ! popd ]; then
282 die "Programmer error, we entered run_configure with a stacked directory"
283 fi
284
285 if ! command_exists "$CONFIGURE"; then
286 die "$CONFIGURE does not exist"
287 fi
288
289 local BUILD_DIR="$1"
290 if [[ -n "$BUILD_DIR" ]]; then
291 rm -r -f $BUILD_DIR
292 mkdir -p $BUILD_DIR
293 safe_pushd $BUILD_DIR
294 fi
295
296 # Arguments for configure
297 local BUILD_CONFIGURE_ARG=
298
299 # Set ENV DEBUG in order to enable debugging
300 if $DEBUG; then
301 BUILD_CONFIGURE_ARG='--enable-debug'
302 fi
303
304 # Set ENV ASSERT in order to enable assert
305 if [[ -n "$ASSERT" ]]; then
306 local ASSERT_ARG=
307 ASSERT_ARG='--enable-assert'
308 BUILD_CONFIGURE_ARG="$ASSERT_ARG $BUILD_CONFIGURE_ARG"
309 fi
310
311 if [[ -n "$CONFIGURE_ARG" ]]; then
312 BUILD_CONFIGURE_ARG= "$BUILD_CONFIGURE_ARG $CONFIGURE_ARG"
313 fi
314
315 ret=1;
316 # If we are executing on OSX use CLANG, otherwise only use it if we find it in the ENV
317 case $HOST_OS in
318 *-darwin-*)
319 CC=clang CXX=clang++ $top_srcdir/configure $BUILD_CONFIGURE_ARG || die "Cannot execute CC=clang CXX=clang++ configure $BUILD_CONFIGURE_ARG $PREFIX_ARG"
320 ret=$?
321 ;;
322 rhel-5*)
323 command_exists 'gcc44' || die "Could not locate gcc44"
324 CC=gcc44 CXX=gcc44 $top_srcdir/configure $BUILD_CONFIGURE_ARG $PREFIX_ARG || die "Cannot execute CC=gcc44 CXX=gcc44 configure $BUILD_CONFIGURE_ARG $PREFIX_ARG"
325 ret=$?
326 ;;
327 *)
328 $CONFIGURE $BUILD_CONFIGURE_ARG $PREFIX_ARG
329 ret=$?
330 ;;
331 esac
332
333 if [ $ret -ne 0 ]; then
334 die "Could not execute $CONFIGURE $BUILD_CONFIGURE_ARG $PREFIX_ARG"
335 fi
336
337 if [ ! -f 'Makefile' ]; then
338 die "Programmer error, configure was run but no Makefile existed after $CONFIGURE was run"
339 fi
340 }
341
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"
351 }
352
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"
357 fi
358 }
359
360 function save_BUILD ()
361 {
362 if [[ -n "$OLD_CONFIGURE" ]]; then
363 die "OLD_CONFIGURE($OLD_CONFIGURE) was set on push, programmer error!"
364 fi
365
366 if [[ -n "$OLD_CONFIGURE_ARG" ]]; then
367 die "OLD_CONFIGURE_ARG($OLD_CONFIGURE_ARG) was set on push, programmer error!"
368 fi
369
370 if [[ -n "$OLD_MAKE" ]]; then
371 die "OLD_MAKE($OLD_MAKE) was set on push, programmer error!"
372 fi
373
374 if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
375 die "OLD_TESTS_ENVIRONMENT($OLD_TESTS_ENVIRONMENT) was set on push, programmer error!"
376 fi
377
378 if [[ -n "$CONFIGURE" ]]; then
379 OLD_CONFIGURE=$CONFIGURE
380 fi
381
382 if [[ -n "$CONFIGURE_ARG" ]]; then
383 OLD_CONFIGURE_ARG=$CONFIGURE_ARG
384 fi
385
386 if [[ -n "$MAKE" ]]; then
387 OLD_MAKE=$MAKE
388 fi
389
390 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
391 OLD_TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT
392 fi
393 }
394
395 function restore_BUILD ()
396 {
397 if [[ -n "$OLD_CONFIGURE" ]]; then
398 CONFIGURE=$OLD_CONFIGURE
399 fi
400
401 if [[ -n "$OLD_CONFIGURE_ARG" ]]; then
402 CONFIGURE_ARG=$OLD_CONFIGURE_ARG
403 fi
404
405 if [[ -n "$OLD_MAKE" ]]; then
406 MAKE=$OLD_MAKE
407 fi
408
409 if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
410 TESTS_ENVIRONMENT=$OLD_TESTS_ENVIRONMENT
411 fi
412
413 OLD_CONFIGURE=
414 OLD_CONFIGURE_ARG=
415 OLD_MAKE=
416 OLD_TESTS_ENVIRONMENT=
417 echo "reset happened"
418 }
419
420 function push_PREFIX_ARG ()
421 {
422 if [[ -n "$OLD_PREFIX_ARG" ]]; then
423 die "OLD_PREFIX_ARG was set on push, programmer error!"
424 fi
425
426 if [[ -n "$PREFIX_ARG" ]]; then
427 OLD_PREFIX_ARG=$PREFIX_ARG
428 PREFIX_ARG=
429 fi
430
431 if [[ -n "$1" ]]; then
432 PREFIX_ARG="--prefix=$1"
433 fi
434 }
435
436 function pop_PREFIX_ARG ()
437 {
438 if [[ -n "$OLD_PREFIX_ARG" ]]; then
439 PREFIX_ARG=$OLD_PREFIX_ARG
440 OLD_PREFIX_ARG=
441 else
442 PREFIX_ARG=
443 fi
444 }
445
446 function push_TESTS_ENVIRONMENT ()
447 {
448 if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
449 die "OLD_TESTS_ENVIRONMENT was set on push, programmer error!"
450 fi
451
452 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
453 OLD_TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT
454 TESTS_ENVIRONMENT=
455 fi
456 }
457
458 function pop_TESTS_ENVIRONMENT ()
459 {
460 TESTS_ENVIRONMENT=
461 if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
462 TESTS_ENVIRONMENT=$OLD_TESTS_ENVIRONMENT
463 OLD_TESTS_ENVIRONMENT=
464 fi
465 }
466
467 function safe_pushd ()
468 {
469 pushd $1 &> /dev/null ;
470
471 if [ -n "$BUILD_DIR" ]; then
472 if $VERBOSE; then
473 echo "BUILD_DIR=$BUILD_DIR"
474 fi
475 fi
476 }
477
478 function safe_popd ()
479 {
480 local directory_to_delete=`pwd`
481 popd &> /dev/null ;
482 if [ $? -eq 0 ]; then
483 if [[ "$top_srcdir" == "$directory_to_delete" ]]; then
484 die "We almost deleted top_srcdir($top_srcdir), programmer error"
485 fi
486
487 rm -r -f "$directory_to_delete"
488 fi
489 }
490
491 function make_valgrind ()
492 {
493 if [[ "$VENDOR_DISTRIBUTION" == 'darwin' ]]; then
494 make_darwin_malloc
495 return
496 fi
497
498 # If the env VALGRIND_COMMAND is set then we assume it is valid
499 local valgrind_was_set=false
500 if [[ -z "$VALGRIND_COMMAND" ]]; then
501 setup_valgrind_command
502 if [[ -n "$VALGRIND_COMMAND" ]]; then
503 valgrind_was_set=true
504 fi
505 else
506 valgrind_was_set=true
507 fi
508
509 # If valgrind_was_set is set to no we bail
510 if ! $valgrind_was_set; then
511 echo 'valgrind was not present'
512 return 1
513 fi
514
515 # If we are required to run configure, do so now
516 run_configure_if_required
517
518 push_TESTS_ENVIRONMENT
519
520 # If we don't have a configure, then most likely we will be missing libtool
521 assert_file 'configure'
522 if [[ -f 'libtool' ]]; then
523 TESTS_ENVIRONMENT="./libtool --mode=execute $VALGRIND_COMMAND"
524 else
525 TESTS_ENVIRONMENT="$VALGRIND_COMMAND"
526 fi
527
528 make_target 'check' || return 1
529
530 pop_TESTS_ENVIRONMENT
531 }
532
533 function make_install_system ()
534 {
535 local INSTALL_LOCATION=$(mktemp -d /tmp/XXXXXXXXXX)
536 push_PREFIX_ARG $INSTALL_LOCATION
537
538 if [ ! -d $INSTALL_LOCATION ] ; then
539 die "ASSERT temp directory not found '$INSTALL_LOCATION'"
540 fi
541
542 run_configure #install_buid_dir
543
544 push_TESTS_ENVIRONMENT
545
546 make_target 'install'
547
548 make_target 'installcheck'
549
550 make_target 'uninstall'
551
552 pop_TESTS_ENVIRONMENT
553 pop_PREFIX_ARG
554
555 rm -r -f $INSTALL_LOCATION
556 make 'distclean'
557
558 if [ -f 'Makefile' ]; then
559 die "ASSERT Makefile should not exist"
560 fi
561
562 safe_popd
563 }
564
565 function make_darwin_malloc ()
566 {
567 run_configure_if_required
568
569 old_MallocGuardEdges=$MallocGuardEdges
570 MallocGuardEdges=1
571 old_MallocErrorAbort=$MallocErrorAbort
572 MallocErrorAbort=1
573 old_MallocScribble=$MallocScribble
574 MallocScribble=1
575
576 make_check
577
578 MallocGuardEdges=$old_MallocGuardEdges
579 MallocErrorAbort=$old_MallocErrorAbort
580 MallocScribble=$old_MallocScribble
581 }
582
583 function snapshot_check ()
584 {
585 if [ ! -f "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then
586 make_for_snapshot
587 fi
588
589 if [ -n "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then
590 assert_file "$BOOTSTRAP_SNAPSHOT_CHECK" 'snapshot check failed'
591 fi
592 }
593
594 # This will reset our environment, and make sure built files are available.
595 function make_for_snapshot ()
596 {
597 # Make sure it is clean
598 make_maintainer_clean
599
600 run_configure
601 make_target 'dist'
602 make_target 'distclean'
603
604 # We should have a configure, but no Makefile at the end of this exercise
605 assert_no_file 'Makefile'
606 assert_exec_file 'configure'
607
608 snapshot_check
609 }
610
611 function check_mingw ()
612 {
613 command_exists 'mingw64-configure'
614 ret=$?
615 if [ "$ret" -ne 0 ]; then
616 return 1
617 fi
618
619 command_exists 'mingw64-make'
620 ret=$?
621 if [ "$ret" -ne 0 ]; then
622 return 1
623 fi
624
625 return 0
626 }
627
628 function make_skeleton_mingw ()
629 {
630 run_configure
631 ret=$?
632
633 if [ $ret -eq 0 ]; then
634 assert_file 'Makefile'
635
636 make_target 'all' 'warn'
637 ret=$?
638 if [ $ret -ne 0 ]; then
639 warn "$MAKE failed"
640 else
641 if [[ -n "$DISPLAY" ]]; then
642 if command_exists 'wine'; then
643 TESTS_ENVIRONMENT='wine'
644 fi
645 elif command_exists 'wineconsole'; then
646 TESTS_ENVIRONMENT='wineconsole --backend=curses'
647 fi
648
649 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
650 make_target 'check' 'warn' || warn "$MAKE check failed"
651 ret=$?
652 fi
653 fi
654
655 if $jenkins_build_environment; then
656 make_target 'clean' 'warn'
657 fi
658 fi
659
660 return $ret
661 }
662
663 function make_for_mingw ()
664 {
665 check_mingw
666 if ! check_mingw; then
667 die 'mingw64 tools were not found'
668 fi
669
670 # Make sure it is clean
671 if [ -f Makefile -o -f configure ]; then
672 make_maintainer_clean
673 fi
674
675 run_autoreconf
676
677 save_BUILD
678
679 CONFIGURE='mingw64-configure'
680 MAKE='mingw64-make'
681 CONFIGURE_ARGS='--enable-static'
682
683 make_skeleton_mingw
684 ret=$?
685
686 restore_BUILD
687
688 return $ret
689 }
690
691 # If we are locally testing, we should make sure the environment is setup correctly
692 function check_for_jenkins ()
693 {
694 if ! $jenkins_build_environment; then
695 echo "Not inside of jenkins"
696
697 if [ -f 'configure' ]; then
698 make_maintainer_clean
699 fi
700
701 if $BOOTSTRAP_SNAPSHOT; then
702 make_for_snapshot
703 fi
704 fi
705 }
706
707 function make_universe ()
708 {
709 make_for_snapshot
710 make_valgrind
711 make_gdb
712 make_rpm
713
714 if [ check_mingw -eq 0 ]; then
715 make_for_mingw
716 fi
717
718 make_distcheck
719 make_install_system
720 }
721
722 function make_for_continuus_integration ()
723 {
724 # Setup the environment if we are local
725 check_for_jenkins
726
727 # No matter then evironment, we should not have a Makefile at this point
728 assert_no_file 'Makefile'
729
730 # Platforms which require bootstrap should have some setup done before we hit this stage.
731 # If we are building locally, skip this step, unless we are just testing locally.
732 if $BOOTSTRAP_SNAPSHOT; then
733 snapshot_check
734 else
735 # If we didn't require a snapshot, then we should not have a configure
736 assert_no_file 'configure'
737
738 run_autoreconf
739 fi
740
741 assert_no_file 'Makefile' 'Programmer error, Makefile existed where build state should have been clean'
742
743 case $HOST_OS in
744 *-fedora-*)
745 run_configure
746
747 assert_exec_file 'configure'
748 assert_file 'Makefile'
749
750 make_target 'all'
751
752 # make rpm includes "make distcheck"
753 if [[ -f rpm.am ]]; then
754 make_rpm
755 elif [[ -d rpm ]]; then
756 make_rpm
757 else
758 make_distcheck
759 fi
760
761 assert_exec_file 'configure'
762 assert_file 'Makefile'
763
764 make_install_system
765 ;;
766 *-precise-*)
767 run_configure
768
769 assert_exec_file 'configure'
770 assert_file 'Makefile'
771
772 make_target 'all'
773
774 make_distcheck
775
776 assert_exec_file 'configure'
777 assert_file 'Makefile'
778
779 make_valgrind
780
781 assert_exec_file 'configure'
782 assert_file 'Makefile'
783
784 make_install_system
785 ;;
786 *)
787 make_jenkins_default
788 ;;
789 esac
790
791 make_maintainer_clean
792
793 safe_popd
794 }
795
796 # The point to this test is to test bootstrap.sh itself
797 function self_test ()
798 {
799 # We start off with a clean env
800 make_maintainer_clean
801
802 eval "./bootstrap.sh jenkins" || die "failed 'jenkins'"
803 eval "./bootstrap.sh all" || die "failed 'all'"
804 eval "./bootstrap.sh gdb" || die "failed 'gdb'"
805 eval "./bootstrap.sh maintainer-clean" || die "failed 'maintainer-clean'"
806 }
807
808 function make_install_html ()
809 {
810 run_configure_if_required
811 assert_file 'configure'
812
813 make_target 'install-html'
814 }
815
816 function make_gdb ()
817 {
818 if command_exists 'gdb'; then
819 run_configure_if_required
820
821 push_TESTS_ENVIRONMENT
822
823 # Set ENV GDB_COMMAND
824 if [[ -z "$GDB_COMMAND" ]]; then
825 setup_gdb_command
826 fi
827
828 # If we don't have a configure, then most likely we will be missing libtool
829 assert_file 'configure'
830 if [[ -f 'libtool' ]]; then
831 TESTS_ENVIRONMENT="./libtool --mode=execute $GDB_COMMAND"
832 else
833 TESTS_ENVIRONMENT="$GDB_COMMAND"
834 fi
835
836 make_target 'check'
837
838 if [ -f 'gdb.txt' ]; then
839 rm 'gdb.txt'
840 fi
841
842 pop_TESTS_ENVIRONMENT
843
844 if [ -f '.gdb_history' ]; then
845 rm '.gdb_history'
846 fi
847
848 if $jenkins_build_environment; then
849 make_target 'clean'
850 fi
851 else
852 echo 'gdb was not present'
853 return 1
854 fi
855 }
856
857 # $1 target to compile
858 # $2 to die, or not to die, based on contents
859 function make_target ()
860 {
861 if [ -z "$1" ]; then
862 die "Programmer error, no target provided for make"
863 fi
864
865 if [ ! -f 'Makefile' ]; then
866 die "Programmer error, make was called before configure"
867 run_configure
868 fi
869
870 if [ -n "$TESTS_ENVIRONMENT" ]; then
871 if $VERBOSE; then
872 echo "TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT"
873 fi
874 fi
875
876 if [ -z "$MAKE" ]; then
877 die "MAKE was not set"
878 fi
879
880 # $2 represents error or warn
881 run $MAKE $1
882 ret=$?
883
884 if [ $ret -ne 0 ]; then
885 if [ -n "$2" ]; then
886 warn "Cannot execute $MAKE $1: $ret"
887 else
888 die "Cannot execute $MAKE $1: $ret"
889 fi
890 fi
891
892 return $ret
893 }
894
895 function make_distcheck ()
896 {
897 make_target 'distcheck'
898 }
899
900 function make_rpm ()
901 {
902 if command_exists 'rpmbuild'; then
903 if [ -f 'rpm.am' -o -d 'rpm' ]; then
904 run_configure_if_required
905 make_target 'rpm'
906
907 if $jenkins_build_environment; then
908 make_target 'clean'
909 fi
910
911 fi
912 fi
913 }
914
915 function make_maintainer_clean ()
916 {
917 run_configure_if_required
918 make_target 'maintainer-clean' 'no_error'
919
920 # Lets make sure we really cleaned up the environment
921 assert_no_file 'Makefile'
922 assert_no_file 'configure'
923 assert_no_directory 'autom4te.cache'
924 }
925
926 function make_check ()
927 {
928 make_target 'check'
929 }
930
931 function make_jenkins_default ()
932 {
933 run_configure
934 make_target 'all'
935 }
936
937 function make_default ()
938 {
939 run_configure_if_required
940 make_target 'all'
941 }
942
943 function run_configure_if_required ()
944 {
945 run_autoreconf_if_required
946
947 if [ ! -f 'Makefile' ]; then
948 run_configure
949 fi
950
951 assert_file 'Makefile' 'configure did not produce a Makefile'
952 }
953
954 function run_autoreconf_if_required ()
955 {
956 if [ ! -x 'configure' ]; then
957 run_autoreconf
958 fi
959
960 assert_exec_file 'configure'
961 }
962
963 function run_autoreconf ()
964 {
965 if [[ -z "$AUTORECONF" ]]; then
966 die "Programmer error, tried to call run_autoreconf () but AUTORECONF was not set"
967 fi
968
969 if test $use_libtool = 1; then
970 assert $BOOTSTRAP_LIBTOOLIZE
971 run $BOOTSTRAP_LIBTOOLIZE '--copy' '--install' '--force' || die "Cannot execute $BOOTSTRAP_LIBTOOLIZE"
972 fi
973
974 run $AUTORECONF || die "Cannot execute $AUTORECONF"
975
976 eval 'bash -n configure' || die "autoreconf generated a malformed configure"
977 }
978
979 function run ()
980 {
981 if $VERBOSE; then
982 echo "\`$@' $ARGS"
983 fi
984
985 if [ -z "$1" ]; then
986 return 127;
987 fi
988
989 eval $@ $ARGS
990 }
991
992 function parse_command_line_options ()
993 {
994 local SHORTOPTS=':apcmt:dvh'
995
996 nassert MAKE_TARGET
997
998 while getopts "$SHORTOPTS" opt; do
999 case $opt in
1000 a) #--autoreconf
1001 AUTORECONF_OPTION=true
1002 MAKE_TARGET='autoreconf'
1003 ;;
1004 p) #--print-env
1005 PRINT_SETUP_OPTION=true
1006 ;;
1007 c) # --configure
1008 CONFIGURE_OPTION=true
1009 MAKE_TARGET='configure'
1010 ;;
1011 m) # maintainer-clean
1012 CLEAN_OPTION=true
1013 MAKE_TARGET='clean_op'
1014 ;;
1015 t) # target
1016 TARGET_OPTION=true
1017 TARGET_OPTION_ARG="$OPTARG"
1018 MAKE_TARGET="$OPTARG"
1019 ;;
1020 d) # debug
1021 DEBUG_OPTION=true
1022 enable_debug
1023 ;;
1024 h) # help
1025 echo "bootstrap.sh [options] optional_target ..."
1026 exit
1027 ;;
1028 v) # verbose
1029 VERBOSE_OPTION=true
1030 VERBOSE=true
1031 ;;
1032 :)
1033 echo "Option -$OPTARG requires an argument." >&2
1034 exit 1
1035 ;;
1036 *)
1037 echo "$0: error - unrecognized option $1" 1>&2
1038 exit 1
1039 ;;
1040 esac
1041 done
1042
1043 shift $((OPTIND-1))
1044
1045 if [ -n "$1" ]; then
1046 MAKE_TARGET="$@"
1047 fi
1048 }
1049
1050 function determine_vcs ()
1051 {
1052 if [[ -d '.git' ]]; then
1053 VCS_CHECKOUT=git
1054 elif [[ -d '.bzr' ]]; then
1055 VCS_CHECKOUT=bzr
1056 elif [[ -d '.svn' ]]; then
1057 VCS_CHECKOUT=svn
1058 elif [[ -d '.hg' ]]; then
1059 VCS_CHECKOUT=hg
1060 fi
1061
1062 if [[ -n "$VCS_CHECKOUT" ]]; then
1063 VERBOSE=true
1064 fi
1065 }
1066
1067 function require_libtoolise ()
1068 {
1069 use_libtool=0
1070 grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \
1071 && use_libtool=1
1072 grep '^[ ]*LT_INIT' configure.ac >/dev/null \
1073 && use_libtool=1
1074 }
1075
1076 function autoreconf_setup ()
1077 {
1078 # Set ENV MAKE in order to override "make"
1079 if [[ -z "$MAKE" ]]; then
1080 if command_exists 'gmake'; then
1081 MAKE=`type -p gmake`
1082 else
1083 if command_exists 'make'; then
1084 MAKE=`type -p make`
1085 fi
1086 fi
1087
1088 if [ "$VCS_CHECKOUT" ]; then
1089 if $DEBUG; then
1090 MAKE="$MAKE --warn-undefined-variables"
1091 fi
1092 fi
1093
1094 if $DEBUG; then
1095 MAKE="$MAKE -d"
1096 fi
1097 fi
1098
1099 if [[ -z "$GNU_BUILD_FLAGS" ]]; then
1100 GNU_BUILD_FLAGS="--install --force"
1101 fi
1102
1103 if $VERBOSE; then
1104 GNU_BUILD_FLAGS="$GNU_BUILD_FLAGS --verbose"
1105 fi
1106
1107 if [ -z "$ACLOCAL_PATH" ]; then
1108 ACLOCAL_PATH="/usr/local/share/aclocal $ACLOCAL_PATH"
1109 fi
1110
1111 if [[ -z "$WARNINGS" ]]; then
1112 if [[ -n "$VCS_CHECKOUT" ]]; then
1113 WARNINGS="all,error"
1114 else
1115 WARNINGS="all"
1116 fi
1117 fi
1118
1119 if test $use_libtool = 1; then
1120 if [[ -n "$LIBTOOLIZE" ]]; then
1121 BOOTSTRAP_LIBTOOLIZE=`type -p $LIBTOOLIZE`
1122
1123 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1124 echo "Couldn't find user supplied libtoolize, it is required"
1125 fi
1126 else
1127 # If we are using OSX, we first check to see glibtoolize is available
1128 if [[ "$VENDOR_DISTRIBUTION" == "darwin" ]]; then
1129 BOOTSTRAP_LIBTOOLIZE=`type -p glibtoolize`
1130
1131 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1132 echo "Couldn't find glibtoolize, it is required on OSX"
1133 fi
1134 else
1135 BOOTSTRAP_LIBTOOLIZE=`type -p libtoolize`
1136
1137 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1138 echo "Couldn't find libtoolize, it is required"
1139 fi
1140 fi
1141 fi
1142 if $VERBOSE; then
1143 LIBTOOLIZE_OPTIONS="--verbose $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
1144 fi
1145 if $DEBUG; then
1146 LIBTOOLIZE_OPTIONS="--debug $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
1147 fi
1148 LIBTOOLIZE=true
1149 fi
1150
1151 # Test the ENV AUTOMAKE if it exists
1152 if [[ -n "$AUTOMAKE" ]]; then
1153 run $AUTOMAKE '--help' &> /dev/null || die "Failed to run AUTOMAKE:$AUTOMAKE"
1154 fi
1155
1156 # Test the ENV AUTOCONF if it exists
1157 if [[ -n "$AUTOCONF" ]]; then
1158 run $AUTOCONF '--help' &> /dev/null || die "Failed to run AUTOCONF:$AUTOCONF"
1159 fi
1160
1161 # Test the ENV AUTOHEADER if it exists
1162 if [[ -n "$AUTOHEADER" ]]; then
1163 run $AUTOHEADER '--help' &> /dev/null || die "Failed to run AUTOHEADER:$AUTOHEADER"
1164 fi
1165
1166 # Test the ENV AUTOM4TE if it exists
1167 if [[ -n "$AUTOM4TE" ]]; then
1168 run $AUTOM4TE '--help' &> /dev/null || die "Failed to run AUTOM4TE:$AUTOM4TE"
1169 fi
1170
1171 # Test the ENV AUTOHEADER if it exists, if not we add one and add --install
1172 if [[ -z "$ACLOCAL" ]]; then
1173 ACLOCAL="aclocal --install"
1174 fi
1175 run $ACLOCAL '--help' &> /dev/null || die "Failed to run ACLOCAL:$ACLOCAL"
1176
1177 if [[ -z "$AUTORECONF" ]]; then
1178 AUTORECONF=`type -p autoreconf`
1179
1180 if [[ -z "$AUTORECONF" ]]; then
1181 die "Couldn't find autoreconf"
1182 fi
1183
1184 if [[ -n "$GNU_BUILD_FLAGS" ]]; then
1185 AUTORECONF="$AUTORECONF $GNU_BUILD_FLAGS"
1186 fi
1187 fi
1188
1189 run $AUTORECONF '--help' &> /dev/null || die "Failed to run AUTORECONF:$AUTORECONF"
1190 }
1191
1192 function print_setup ()
1193 {
1194 saved_debug_status=$DEBUG
1195 if $DEBUG; then
1196 disable_debug
1197 fi
1198
1199 echo '----------------------------------------------'
1200 echo 'BOOTSTRAP ENV'
1201 echo "AUTORECONF=$AUTORECONF"
1202 echo "HOST_OS=$HOST_OS"
1203
1204 echo "getopt()"
1205 if $AUTORECONF_OPTION; then
1206 echo "--autoreconf"
1207 fi
1208
1209 if $CLEAN_OPTION; then
1210 echo "--clean"
1211 fi
1212
1213 if $CONFIGURE_OPTION; then
1214 echo "--configure"
1215 fi
1216
1217 if $DEBUG_OPTION; then
1218 echo "--debug"
1219 fi
1220
1221 if $PRINT_SETUP_OPTION; then
1222 echo "--print-env"
1223 fi
1224
1225 if $TARGET_OPTION; then
1226 echo "--target=$TARGET_OPTION_ARG"
1227 fi
1228
1229 if $VERBOSE_OPTION; then
1230 echo "--verbose"
1231 fi
1232
1233 if [[ -n "$MAKE" ]]; then
1234 echo "MAKE=$MAKE"
1235 fi
1236
1237 if [[ -n "$MAKE_TARGET" ]]; then
1238 echo "MAKE_TARGET=$MAKE_TARGET"
1239 fi
1240
1241 if [[ -n "$PREFIX" ]]; then
1242 echo "PREFIX=$PREFIX"
1243 fi
1244
1245 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
1246 echo "TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT"
1247 fi
1248
1249 if [[ -n "$VCS_CHECKOUT" ]]; then
1250 echo "VCS_CHECKOUT=$VCS_CHECKOUT"
1251 fi
1252
1253 if $VERBOSE; then
1254 echo "VERBOSE=true"
1255 fi
1256
1257 if $DEBUG; then
1258 echo "DEBUG=true"
1259 fi
1260
1261 if [[ -n "$WARNINGS" ]]; then
1262 echo "WARNINGS=$WARNINGS"
1263 fi
1264 echo '----------------------------------------------'
1265
1266 if $saved_debug_status; then
1267 enable_debug
1268 fi
1269 }
1270
1271 function make_clean_option ()
1272 {
1273 run_configure_if_required
1274
1275 make_maintainer_clean
1276
1277 if [[ "$VCS_CHECKOUT" == 'git' ]]; then
1278 run "$VCS_CHECKOUT" status --ignored
1279 elif [[ -n "$VCS_CHECKOUT" ]]; then
1280 run "$VCS_CHECKOUT" status
1281 fi
1282 }
1283
1284 function make_for_autoreconf ()
1285 {
1286 if [ -f 'Makefile' ]; then
1287 make_maintainer_clean
1288 fi
1289
1290 run_autoreconf
1291
1292 assert_no_file 'Makefile'
1293 }
1294
1295 function check_make_target()
1296 {
1297 case $1 in
1298 'self')
1299 ;;
1300 'rpm')
1301 ;;
1302 'gdb')
1303 ;;
1304 'clean_op')
1305 ;;
1306 'autoreconf')
1307 ;;
1308 'install-system')
1309 ;;
1310 'configure')
1311 ;;
1312 'distcheck')
1313 ;;
1314 'check')
1315 ;;
1316 'snapshot')
1317 ;;
1318 'mingw')
1319 ;;
1320 'universe')
1321 ;;
1322 'valgrind')
1323 ;;
1324 'jenkins')
1325 ;;
1326 'distclean')
1327 ;;
1328 'maintainer-clean')
1329 ;;
1330 'install')
1331 ;;
1332 'all')
1333 ;;
1334 'make_default')
1335 ;;
1336 'test-*')
1337 ;;
1338 'valgrind-*')
1339 ;;
1340 'gdb-*')
1341 ;;
1342 'dist')
1343 ;;
1344 *)
1345 die "Unknown MAKE_TARGET option: $1"
1346 ;;
1347 esac
1348 }
1349
1350 function bootstrap ()
1351 {
1352 determine_target_platform
1353
1354 determine_vcs
1355
1356 # Set up whatever we need to do to use autoreconf later
1357 require_libtoolise
1358 autoreconf_setup
1359
1360 if [ -z "$MAKE_TARGET" ]; then
1361 MAKE_TARGET="make_default"
1362 fi
1363
1364 if $PRINT_SETUP_OPTION -o $DEBUG; then
1365 echo
1366 print_setup
1367 echo
1368
1369 # Exit if all we were looking for were the currently used options
1370 if $PRINT_SETUP_OPTION; then
1371 exit
1372 fi
1373 fi
1374
1375 # Use OLD_TESTS_ENVIRONMENT for tracking the state of the variable
1376 local OLD_TESTS_ENVIRONMENT=
1377
1378 # Set ENV PREFIX in order to set --prefix for ./configure
1379 if [[ -n "$PREFIX" ]]; then
1380 push_PREFIX_ARG $PREFIX
1381 fi
1382
1383 # We should always have a target by this point
1384 assert MAKE_TARGET
1385
1386 local MAKE_TARGET_ARRAY=($MAKE_TARGET)
1387
1388 for target in "${MAKE_TARGET_ARRAY[@]}"
1389 do
1390 # If we are running inside of Jenkins, we want to only run some of the possible tests
1391 if $jenkins_build_environment; then
1392 check_make_target $target
1393 fi
1394
1395 case $target in
1396 'self')
1397 self_test
1398 ;;
1399 'gdb')
1400 make_gdb
1401 ;;
1402 'install-html')
1403 make_install_html
1404 ;;
1405 'clean_op')
1406 make_clean_option
1407 ;;
1408 'autoreconf')
1409 make_for_autoreconf
1410 ;;
1411 'install-system')
1412 make_install_system
1413 ;;
1414 'configure')
1415 run_configure
1416 ;;
1417 'make_default')
1418 make_default
1419 ;;
1420 'mingw')
1421 check_mingw
1422 if ! check_mingw; then
1423 die "mingw was not found"
1424 fi
1425
1426 make_for_mingw
1427 check_ret=$?
1428
1429 if ! make_for_mingw; then
1430 die "Failed to build mingw: $?"
1431 fi
1432 ;;
1433 'snapshot')
1434 make_for_snapshot
1435 ;;
1436 'rpm')
1437 make_rpm
1438 ;;
1439 'valgrind')
1440 make_valgrind
1441 ;;
1442 'universe')
1443 make_universe
1444 ;;
1445 'jenkins')
1446 make_for_continuus_integration
1447 ;;
1448 *)
1449 run_configure_if_required
1450 make_target "$target"
1451 ;;
1452 esac
1453 done
1454 }
1455
1456 function main ()
1457 {
1458 # Variables we export
1459 declare -x VCS_CHECKOUT=
1460
1461 # Variables we control globally
1462 local MAKE_TARGET=
1463 local CONFIGURE=
1464
1465 # Options for getopt
1466 local AUTORECONF_OPTION=false
1467 local CLEAN_OPTION=false
1468 local CONFIGURE_OPTION=false
1469 local DEBUG_OPTION=false
1470 local PRINT_SETUP_OPTION=false
1471 local TARGET_OPTION=false
1472 local TARGET_OPTION_ARG=
1473 local VERBOSE_OPTION=false
1474
1475 local OLD_CONFIGURE=
1476 local OLD_CONFIGURE_ARG=
1477 local OLD_MAKE=
1478 local OLD_TESTS_ENVIRONMENT=
1479
1480 # If we call autoreconf on the platform or not
1481 local AUTORECONF_REBUILD_HOST=false
1482 local AUTORECONF_REBUILD=false
1483
1484 local -r top_srcdir=`pwd`
1485
1486 # Default configure
1487 if [ -z "$CONFIGURE" ]; then
1488 CONFIGURE="$top_srcdir/configure"
1489 fi
1490
1491
1492 # Variables for determine_target_platform () and rebuild_host_os ()
1493 # UNAME_MACHINE_ARCH= uname -m
1494 # VENDOR= apple, redhat, centos, canonical
1495 # VENDOR_RELEASE=
1496 # RHEL{rhel,Tikanga,Santiago}
1497 # Ubuntu{ubuntu,Lucid,Maverick,Natty,Oneiric,Precise,Quantal}
1498 # Fedora{fedora,Verne,Beefy}
1499 # OSX{osx,lion,snow,mountain}
1500 # VENDOR_DISTRIBUTION= darwin,fedora,rhel,ubuntu
1501 # UNAME_KERNEL= Linux, Darwin,...
1502 # UNAME_KERNEL_RELEASE= Linux, Darwin,...
1503 local UNAME_MACHINE_ARCH=unknown
1504 local VENDOR=unknown
1505 local VENDOR_RELEASE=unknown
1506 local VENDOR_DISTRIBUTION=unknown
1507 local UNAME_KERNEL=unknown
1508 local UNAME_KERNEL_RELEASE=unknown
1509 local HOST_OS=
1510
1511 rebuild_host_os no_output
1512
1513 parse_command_line_options $@
1514
1515 # If we are running under Jenkins we predetermine what tests we will run against
1516 # This MAKE_TARGET can be overridden by parse_command_line_options based MAKE_TARGET changes.
1517 # We don't want Jenkins overriding other variables, so we NULL them.
1518 if [ -z "$MAKE_TARGET" ]; then
1519 if $jenkins_build_environment; then
1520 MAKE_TARGET='jenkins'
1521 fi
1522 fi
1523
1524 bootstrap
1525
1526 jobs -l
1527 wait
1528
1529 exit 0
1530 }
1531
1532 function set_branch ()
1533 {
1534 if [ -z "$BRANCH" ]; then
1535 if [ -z "$CI_PROJECT_TEAM" ]; then
1536 die "Variable CI_PROJECT_TEAM has not been set"
1537 fi
1538 if [ -z "$PROJECT" ]; then
1539 die "Variable PROJECT has not been set"
1540 fi
1541 if [ -z "$BUILD_TAG" ]; then
1542 die "Variable BUILD_TAG has not been set"
1543 fi
1544
1545 BRANCH="lp:~$CI_PROJECT_TEAM/$PROJECT/$BUILD_TAG"
1546 export BRANCH
1547 fi
1548
1549 if [ -z "$BRANCH" ]; then
1550 die "Missing values required to build BRANCH variable."
1551 fi
1552 }
1553
1554 function merge ()
1555 {
1556 if [ -z "$VCS_CHECKOUT" ]; then
1557 die "Merges require VCS_CHECKOUT."
1558 fi
1559
1560 set_branch
1561
1562 if [[ "$VCS_CHECKOUT" == 'bzr' ]]; then
1563 if test -n "$BRANCH_TO_MERGE"; then
1564 bzr merge $BRANCH_TO_MERGE
1565 bzr commit --message="Merge $BRANCH_TO_MERGE Build: $BUILD_TAG" --unchanged
1566 fi
1567
1568 bzr push "$BRANCH"
1569 elif [[ -n "$VCS_CHECKOUT" ]]; then
1570 die "Merge attempt occured, current VCS setup does not support this"
1571 fi
1572 }
1573
1574 function enable_debug ()
1575 {
1576 if ! $DEBUG; then
1577 local caller_loc=`caller`
1578 if [ -n $1 ]; then
1579 echo "$caller_loc Enabling debug: $1"
1580 else
1581 echo "$caller_loc Enabling debug"
1582 fi
1583 set -x
1584 DEBUG=true
1585 fi
1586 }
1587
1588 function usage ()
1589 {
1590 cat << EOF
1591 Usage: $program_name [OPTION]..
1592
1593 Bootstrap this package from the checked-out sources, and optionally walk through CI run.
1594
1595 Options:
1596
1597 EOF
1598 }
1599
1600 function disable_debug ()
1601 {
1602 set +x
1603 DEBUG=true
1604 }
1605
1606 # Script begins here
1607
1608 program_name=$0
1609
1610 env_debug_enabled=false
1611 if [[ -n "$JENKINS_HOME" ]]; then
1612 declare -r jenkins_build_environment=true
1613 else
1614 declare -r jenkins_build_environment=false
1615 fi
1616
1617 export ACLOCAL
1618 export AUTOCONF
1619 export AUTOHEADER
1620 export AUTOM4TE
1621 export AUTOMAKE
1622 export AUTORECONF
1623 export DEBUG
1624 export GNU_BUILD_FLAGS
1625 export LIBTOOLIZE
1626 export LIBTOOLIZE_OPTIONS
1627 export MAKE
1628 export TESTS_ENVIRONMENT
1629 export VERBOSE
1630 export WARNINGS
1631
1632 case $OSTYPE in
1633 darwin*)
1634 export MallocGuardEdges
1635 export MallocErrorAbort
1636 export MallocScribble
1637 ;;
1638 esac
1639
1640 # We check for DEBUG twice, once before we source the config file, and once afterward
1641 env_debug_enabled=false
1642 if [[ -n "$DEBUG" ]]; then
1643 env_debug_enabled=true
1644 enable_debug
1645 print_setup
1646 fi
1647
1648 # Variables which only can be set by .bootstrap
1649 BOOTSTRAP_SNAPSHOT=false
1650 BOOTSTRAP_SNAPSHOT_CHECK=
1651
1652 if [ -f '.bootstrap' ]; then
1653 source '.bootstrap'
1654 fi
1655
1656 if $env_debug_enabled; then
1657 enable_debug
1658 else
1659 if [[ -n "$DEBUG" ]]; then
1660 enable_debug "Enabling DEBUG from '.bootstrap'"
1661 print_setup
1662 fi
1663 fi
1664
1665 # We do this in order to protect the case where DEBUG
1666 if ! $env_debug_enabled; then
1667 DEBUG=false
1668 fi
1669
1670 main $@