Update where we do full build
[awesomized/libmemcached] / bootstrap.sh
1 #!/bin/bash
2 #
3 # Copyright (C) 2012-2013 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 # 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
301 if $DEBUG; then
302 BUILD_CONFIGURE_ARG+=' --enable-debug --enable-assert'
303 elif [[ -n "$VCS_CHECKOUT" ]]; then
304 BUILD_CONFIGURE_ARG+=' --enable-assert'
305 fi
306
307 if [[ -n "$CONFIGURE_ARG" ]]; then
308 BUILD_CONFIGURE_ARG+=" $CONFIGURE_ARG"
309 fi
310
311 if [[ -n "$PREFIX_ARG" ]]; then
312 BUILD_CONFIGURE_ARG+=" $PREFIX_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"
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 || die "Cannot execute CC=gcc44 CXX=gcc44 configure $BUILD_CONFIGURE_ARG"
325 ret=$?
326 ;;
327 *)
328 $CONFIGURE $BUILD_CONFIGURE_ARG
329 ret=$?
330 ;;
331 esac
332
333 if [ $ret -ne 0 ]; then
334 die "Could not execute $CONFIGURE $BUILD_CONFIGURE_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_PREFIX" ]]; then
371 die "OLD_PREFIX($OLD_PREFIX) was set on push, programmer error!"
372 fi
373
374 if [[ -n "$OLD_MAKE" ]]; then
375 die "OLD_MAKE($OLD_MAKE) was set on push, programmer error!"
376 fi
377
378 if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
379 die "OLD_TESTS_ENVIRONMENT($OLD_TESTS_ENVIRONMENT) was set on push, programmer error!"
380 fi
381
382 if [[ -n "$CONFIGURE" ]]; then
383 OLD_CONFIGURE=$CONFIGURE
384 fi
385
386 if [[ -n "$CONFIGURE_ARG" ]]; then
387 OLD_CONFIGURE_ARG=$CONFIGURE_ARG
388 fi
389
390 if [[ -n "$MAKE" ]]; then
391 OLD_MAKE=$MAKE
392 fi
393
394 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
395 OLD_TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT
396 fi
397 }
398
399 function restore_BUILD ()
400 {
401 if [[ -n "$OLD_CONFIGURE" ]]; then
402 CONFIGURE=$OLD_CONFIGURE
403 fi
404
405 if [[ -n "$OLD_CONFIGURE_ARG" ]]; then
406 CONFIGURE_ARG=$OLD_CONFIGURE_ARG
407 fi
408
409 if [[ -n "$OLD_PREFIX" ]]; then
410 PREFIX_ARG=$OLD_PREFIX
411 fi
412
413 if [[ -n "$OLD_MAKE" ]]; then
414 MAKE=$OLD_MAKE
415 fi
416
417 if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
418 TESTS_ENVIRONMENT=$OLD_TESTS_ENVIRONMENT
419 fi
420
421 OLD_CONFIGURE=
422 OLD_CONFIGURE_ARG=
423 OLD_PREFIX=
424 OLD_MAKE=
425 OLD_TESTS_ENVIRONMENT=
426
427 export -n CC CXX
428 }
429
430 function safe_pushd ()
431 {
432 pushd $1 &> /dev/null ;
433
434 if [ -n "$BUILD_DIR" ]; then
435 if $VERBOSE; then
436 echo "BUILD_DIR=$BUILD_DIR"
437 fi
438 fi
439 }
440
441 function safe_popd ()
442 {
443 local directory_to_delete=`pwd`
444 popd &> /dev/null ;
445 if [ $? -eq 0 ]; then
446 if [[ "$top_srcdir" == "$directory_to_delete" ]]; then
447 die "We almost deleted top_srcdir($top_srcdir), programmer error"
448 fi
449
450 rm -r -f "$directory_to_delete"
451 fi
452 }
453
454 function make_valgrind ()
455 {
456 if [[ "$VENDOR_DISTRIBUTION" == 'darwin' ]]; then
457 make_darwin_malloc
458 return
459 fi
460
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
467 fi
468 else
469 valgrind_was_set=true
470 fi
471
472 # If valgrind_was_set is set to no we bail
473 if ! $valgrind_was_set; then
474 echo 'valgrind was not present'
475 return 1
476 fi
477
478 save_BUILD
479
480 # If we are required to run configure, do so now
481 run_configure_if_required
482
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"
487 else
488 TESTS_ENVIRONMENT="$VALGRIND_COMMAND"
489 fi
490
491 make_target 'check' || return 1
492
493 restore_BUILD
494 }
495
496 function make_install_system ()
497 {
498 local INSTALL_LOCATION=$(mktemp -d /tmp/XXXXXXXXXX)
499
500 save_BUILD
501 PREFIX_ARG="--prefix=$INSTALL_LOCATION"
502
503 if [ ! -d $INSTALL_LOCATION ] ; then
504 die "ASSERT temp directory not found '$INSTALL_LOCATION'"
505 fi
506
507 run_configure #install_buid_dir
508
509 make_target 'install'
510
511 make_target 'installcheck'
512
513 make_target 'uninstall'
514
515 rm -r -f $INSTALL_LOCATION
516 make 'distclean'
517
518 if [ -f 'Makefile' ]; then
519 die "ASSERT Makefile should not exist"
520 fi
521
522 restore_BUILD
523 safe_popd
524 }
525
526 function make_darwin_malloc ()
527 {
528 run_configure_if_required
529
530 old_MallocGuardEdges=$MallocGuardEdges
531 MallocGuardEdges=1
532 old_MallocErrorAbort=$MallocErrorAbort
533 MallocErrorAbort=1
534 old_MallocScribble=$MallocScribble
535 MallocScribble=1
536
537 make_check
538
539 MallocGuardEdges=$old_MallocGuardEdges
540 MallocErrorAbort=$old_MallocErrorAbort
541 MallocScribble=$old_MallocScribble
542 }
543
544 function snapshot_check ()
545 {
546 if [ ! -f "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then
547 make_for_snapshot
548 fi
549
550 if [ -n "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then
551 assert_file "$BOOTSTRAP_SNAPSHOT_CHECK" 'snapshot check failed'
552 fi
553 }
554
555 # This will reset our environment, and make sure built files are available.
556 function make_for_snapshot ()
557 {
558 # Make sure it is clean
559 make_maintainer_clean
560
561 run_configure
562 make_target 'dist'
563 make_target 'distclean'
564
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'
568
569 snapshot_check
570 }
571
572 function check_mingw ()
573 {
574 command_exists 'mingw64-configure'
575 ret=$?
576 if [ "$ret" -ne 0 ]; then
577 return 1
578 fi
579
580 command_exists 'mingw64-make'
581 ret=$?
582 if [ "$ret" -ne 0 ]; then
583 return 1
584 fi
585
586 return 0
587 }
588
589 function check_clang ()
590 {
591 command_exists 'clang'
592 ret=$?
593 if [ "$ret" -ne 0 ]; then
594 return 1
595 fi
596
597 return 0
598 }
599
600 function check_clang_analyzer ()
601 {
602 command_exists 'scan-build'
603 ret=$?
604 if [ "$ret" -ne 0 ]; then
605 return 1
606 fi
607
608 return 0
609 }
610
611 function make_skeleton ()
612 {
613 run_configure
614 ret=$?
615
616 if [ $ret -eq 0 ]; then
617 assert_file 'Makefile'
618
619 make_target 'all' 'warn'
620 ret=$?
621 if [ $ret -ne 0 ]; then
622 warn "$MAKE failed"
623 else
624 if [[ -n "$DISPLAY" ]]; then
625 if command_exists 'wine'; then
626 TESTS_ENVIRONMENT='wine'
627 fi
628 fi
629
630 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
631 make_target 'check' 'warn' || warn "$MAKE check failed"
632 ret=$?
633 fi
634 fi
635
636 if $jenkins_build_environment; then
637 make_target 'clean' 'warn'
638 fi
639 fi
640
641 return $ret
642 }
643
644 function make_for_mingw ()
645 {
646 if ! check_mingw; then
647 return 1
648 fi
649
650 # Make sure it is clean
651 if [ -f Makefile -o -f configure ]; then
652 make_maintainer_clean
653 fi
654
655 run_autoreconf
656
657 save_BUILD
658
659 CONFIGURE='mingw64-configure'
660 MAKE='mingw64-make'
661 CONFIGURE_ARGS='--enable-static --disable-shared'
662
663 make_skeleton
664 ret=$?
665
666 restore_BUILD
667
668 return $ret
669 }
670
671 function make_for_clang ()
672 {
673 if ! check_clang; then
674 return 1
675 fi
676
677 # Make sure it is clean
678 if [ -f Makefile -o -f configure ]; then
679 make_maintainer_clean
680 fi
681
682 run_autoreconf
683
684 save_BUILD
685
686 CC=clang CXX=clang++
687 export CC CXX
688
689 make_skeleton
690 ret=$?
691
692 make_target 'check'
693
694 restore_BUILD
695
696 return $ret
697 }
698
699 function make_for_clang_analyzer ()
700 {
701 if ! check_clang; then
702 return 1
703 fi
704
705 if ! check_clang_analyzer; then
706 die 'clang-analyzer was not found'
707 fi
708
709 # Make sure it is clean
710 if [ -f Makefile -o -f configure ]; then
711 make_maintainer_clean
712 fi
713
714 run_autoreconf
715
716 save_BUILD
717
718 CC=clang CXX=clang++
719 export CC CXX
720 CONFIGURE_ARGS='--enable-debug'
721
722 make_skeleton
723 ret=$?
724
725 make_target 'clean' 'warn'
726
727 scan-build -o clang-html make -j4 -k
728
729 restore_BUILD
730
731 return $ret
732 }
733
734 # If we are locally testing, we should make sure the environment is setup correctly
735 function check_for_jenkins ()
736 {
737 if ! $jenkins_build_environment; then
738 echo "Not inside of jenkins"
739
740 if [ -f 'configure' ]; then
741 make_maintainer_clean
742 fi
743
744 if $BOOTSTRAP_SNAPSHOT; then
745 make_for_snapshot
746 fi
747 fi
748 }
749
750 function make_universe ()
751 {
752 make_for_snapshot
753 make_valgrind
754 make_gdb
755 make_rpm
756 make_for_clang
757 make_for_clang_analyzer
758
759 if [ check_mingw -eq 0 ]; then
760 make_for_mingw
761 fi
762
763 make_distcheck
764 make_install_system
765 }
766
767 function make_for_continuus_integration ()
768 {
769 # Setup the environment if we are local
770 check_for_jenkins
771
772 # No matter then evironment, we should not have a Makefile at this point
773 assert_no_file 'Makefile'
774
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
778 snapshot_check
779 else
780 # If we didn't require a snapshot, then we should not have a configure
781 assert_no_file 'configure'
782
783 run_autoreconf
784 fi
785
786 assert_no_file 'Makefile' 'Programmer error, Makefile existed where build state should have been clean'
787
788 case $HOST_OS in
789 *-fedora-*)
790 run_configure
791
792 assert_exec_file 'configure'
793 assert_file 'Makefile'
794
795 make_target 'all'
796
797 # make rpm includes "make distcheck"
798 if [[ -f rpm.am ]]; then
799 make_rpm
800 elif [[ -d rpm ]]; then
801 make_rpm
802 else
803 make_distcheck
804 fi
805
806 assert_exec_file 'configure'
807 assert_file 'Makefile'
808
809 make_install_system
810 ;;
811 *-ubuntu-quantal-*)
812 run_configure
813
814 assert_exec_file 'configure'
815 assert_file 'Makefile'
816
817 make_target 'all'
818
819 make_distcheck
820
821 assert_exec_file 'configure'
822 assert_file 'Makefile'
823
824 make_valgrind
825
826 assert_exec_file 'configure'
827 assert_file 'Makefile'
828
829 make_install_system
830 ;;
831 *)
832 make_jenkins_default
833 ;;
834 esac
835
836 make_maintainer_clean
837
838 safe_popd
839 }
840
841 # The point to this test is to test bootstrap.sh itself
842 function self_test ()
843 {
844 # We start off with a clean env
845 make_maintainer_clean
846
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'"
851 }
852
853 function make_install_html ()
854 {
855 run_configure_if_required
856 assert_file 'configure'
857
858 make_target 'install-html'
859 }
860
861 function make_gdb ()
862 {
863 save_BUILD
864
865 if command_exists 'gdb'; then
866 run_configure_if_required
867
868 # Set ENV GDB_COMMAND
869 if [[ -z "$GDB_COMMAND" ]]; then
870 setup_gdb_command
871 fi
872
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"
877 else
878 TESTS_ENVIRONMENT="$GDB_COMMAND"
879 fi
880
881 make_target 'check'
882
883 if [ -f 'gdb.txt' ]; then
884 rm 'gdb.txt'
885 fi
886
887 if [ -f '.gdb_history' ]; then
888 rm '.gdb_history'
889 fi
890
891 if $jenkins_build_environment; then
892 make_target 'clean'
893 fi
894 else
895 echo 'gdb was not present'
896 return 1
897 fi
898
899 restore_BUILD
900 }
901
902 # $1 target to compile
903 # $2 to die, or not to die, based on contents
904 function make_target ()
905 {
906 if [ -z "$1" ]; then
907 die "Programmer error, no target provided for make"
908 fi
909
910 if [ ! -f 'Makefile' ]; then
911 die "Programmer error, make was called before configure"
912 run_configure
913 fi
914
915 if [ -n "$TESTS_ENVIRONMENT" ]; then
916 if $VERBOSE; then
917 echo "TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT"
918 fi
919 fi
920
921 if [ -z "$MAKE" ]; then
922 die "MAKE was not set"
923 fi
924
925 # $2 represents error or warn
926 run $MAKE $1
927 ret=$?
928
929 if [ $ret -ne 0 ]; then
930 if [ -n "$2" ]; then
931 warn "Failed to execute $MAKE $1: $ret"
932 else
933 die "Failed to execute $MAKE $1: $ret"
934 fi
935 fi
936
937 return $ret
938 }
939
940 function make_distcheck ()
941 {
942 make_target 'distcheck'
943 }
944
945 function make_rpm ()
946 {
947 if command_exists 'rpmbuild'; then
948 if [ -f 'rpm.am' -o -d 'rpm' ]; then
949 run_configure_if_required
950 make_target 'rpm'
951
952 if $jenkins_build_environment; then
953 make_target 'clean'
954 fi
955
956 fi
957 fi
958 }
959
960 function make_maintainer_clean ()
961 {
962 run_configure_if_required
963 make_target 'maintainer-clean' 'no_error'
964
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'
969 }
970
971 function make_check ()
972 {
973 make_target 'check'
974 }
975
976 function make_jenkins_default ()
977 {
978 run_configure
979 make_target 'all'
980 }
981
982 function make_default ()
983 {
984 run_configure_if_required
985 make_target 'all'
986 }
987
988 function run_configure_if_required ()
989 {
990 run_autoreconf_if_required
991
992 if [ ! -f 'Makefile' ]; then
993 run_configure
994 fi
995
996 assert_file 'Makefile' 'configure did not produce a Makefile'
997 }
998
999 function run_autoreconf_if_required ()
1000 {
1001 if [ ! -x 'configure' ]; then
1002 run_autoreconf
1003 fi
1004
1005 assert_exec_file 'configure'
1006 }
1007
1008 function run_autoreconf ()
1009 {
1010 if [[ -z "$AUTORECONF" ]]; then
1011 die "Programmer error, tried to call run_autoreconf () but AUTORECONF was not set"
1012 fi
1013
1014 if test $use_libtool = 1; then
1015 assert $BOOTSTRAP_LIBTOOLIZE
1016 run $BOOTSTRAP_LIBTOOLIZE '--copy' '--install' '--force' || die "Cannot execute $BOOTSTRAP_LIBTOOLIZE"
1017 fi
1018
1019 run $AUTORECONF || die "Cannot execute $AUTORECONF"
1020
1021 eval 'bash -n configure' || die "autoreconf generated a malformed configure"
1022 }
1023
1024 function run ()
1025 {
1026 if $VERBOSE; then
1027 echo "\`$@' $ARGS"
1028 fi
1029
1030 if [ -z "$1" ]; then
1031 return 127;
1032 fi
1033
1034 eval $@ $ARGS
1035 }
1036
1037 function parse_command_line_options ()
1038 {
1039 local SHORTOPTS=':apcmt:dvh'
1040
1041 nassert MAKE_TARGET
1042
1043 while getopts "$SHORTOPTS" opt; do
1044 case $opt in
1045 a) #--autoreconf
1046 AUTORECONF_OPTION=true
1047 MAKE_TARGET='autoreconf'
1048 ;;
1049 p) #--print-env
1050 PRINT_SETUP_OPTION=true
1051 ;;
1052 c) # --configure
1053 CONFIGURE_OPTION=true
1054 MAKE_TARGET='configure'
1055 ;;
1056 m) # maintainer-clean
1057 CLEAN_OPTION=true
1058 MAKE_TARGET='clean_op'
1059 ;;
1060 t) # target
1061 TARGET_OPTION=true
1062 TARGET_OPTION_ARG="$OPTARG"
1063 MAKE_TARGET="$OPTARG"
1064 ;;
1065 d) # debug
1066 DEBUG_OPTION=true
1067 enable_debug
1068 ;;
1069 h) # help
1070 echo "bootstrap.sh [options] optional_target ..."
1071 exit
1072 ;;
1073 v) # verbose
1074 VERBOSE_OPTION=true
1075 VERBOSE=true
1076 ;;
1077 :)
1078 echo "Option -$OPTARG requires an argument." >&2
1079 exit 1
1080 ;;
1081 *)
1082 echo "$0: error - unrecognized option $1" 1>&2
1083 exit 1
1084 ;;
1085 esac
1086 done
1087
1088 shift $((OPTIND-1))
1089
1090 if [ -n "$1" ]; then
1091 MAKE_TARGET="$@"
1092 fi
1093 }
1094
1095 function determine_vcs ()
1096 {
1097 if [[ -d '.git' ]]; then
1098 VCS_CHECKOUT=git
1099 elif [[ -d '.bzr' ]]; then
1100 VCS_CHECKOUT=bzr
1101 elif [[ -d '.svn' ]]; then
1102 VCS_CHECKOUT=svn
1103 elif [[ -d '.hg' ]]; then
1104 VCS_CHECKOUT=hg
1105 else
1106 VCS_CHECKOUT=
1107 fi
1108
1109 if [[ -n "$VCS_CHECKOUT" ]]; then
1110 VERBOSE=true
1111 fi
1112 }
1113
1114 function require_libtoolise ()
1115 {
1116 use_libtool=0
1117 grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \
1118 && use_libtool=1
1119 grep '^[ ]*LT_INIT' configure.ac >/dev/null \
1120 && use_libtool=1
1121 }
1122
1123 function autoreconf_setup ()
1124 {
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`
1129 else
1130 if command_exists 'make'; then
1131 MAKE=`type -p make`
1132 fi
1133 fi
1134
1135 if [ "$VCS_CHECKOUT" ]; then
1136 if $DEBUG; then
1137 MAKE="$MAKE --warn-undefined-variables"
1138 fi
1139 fi
1140
1141 if $DEBUG; then
1142 MAKE="$MAKE -d"
1143 fi
1144 fi
1145
1146 if [[ -z "$GNU_BUILD_FLAGS" ]]; then
1147 GNU_BUILD_FLAGS="--install --force"
1148 fi
1149
1150 if $VERBOSE; then
1151 GNU_BUILD_FLAGS="$GNU_BUILD_FLAGS --verbose"
1152 fi
1153
1154 if [ -z "$ACLOCAL_PATH" ]; then
1155 ACLOCAL_PATH="/usr/local/share/aclocal $ACLOCAL_PATH"
1156 fi
1157
1158 if [[ -z "$WARNINGS" ]]; then
1159 if [[ -n "$VCS_CHECKOUT" ]]; then
1160 WARNINGS="all,error"
1161 else
1162 WARNINGS="all"
1163 fi
1164 fi
1165
1166 if test $use_libtool = 1; then
1167 if [[ -n "$LIBTOOLIZE" ]]; then
1168 BOOTSTRAP_LIBTOOLIZE=`type -p $LIBTOOLIZE`
1169
1170 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1171 echo "Couldn't find user supplied libtoolize, it is required"
1172 fi
1173 else
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`
1177
1178 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1179 echo "Couldn't find glibtoolize, it is required on OSX"
1180 fi
1181 else
1182 BOOTSTRAP_LIBTOOLIZE=`type -p libtoolize`
1183
1184 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1185 echo "Couldn't find libtoolize, it is required"
1186 fi
1187 fi
1188 fi
1189 if $VERBOSE; then
1190 LIBTOOLIZE_OPTIONS="--verbose $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
1191 fi
1192 if $DEBUG; then
1193 LIBTOOLIZE_OPTIONS="--debug $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
1194 fi
1195 LIBTOOLIZE=true
1196 fi
1197
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"
1201 fi
1202
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"
1206 fi
1207
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"
1211 fi
1212
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"
1216 fi
1217
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"
1221 fi
1222 run $ACLOCAL '--help' &> /dev/null || die "Failed to run ACLOCAL:$ACLOCAL"
1223
1224 if [[ -z "$AUTORECONF" ]]; then
1225 AUTORECONF=`type -p autoreconf`
1226
1227 if [[ -z "$AUTORECONF" ]]; then
1228 die "Couldn't find autoreconf"
1229 fi
1230
1231 if [[ -n "$GNU_BUILD_FLAGS" ]]; then
1232 AUTORECONF="$AUTORECONF $GNU_BUILD_FLAGS"
1233 fi
1234 fi
1235
1236 run $AUTORECONF '--help' &> /dev/null || die "Failed to run AUTORECONF:$AUTORECONF"
1237 }
1238
1239 function print_setup ()
1240 {
1241 saved_debug_status=$DEBUG
1242 if $DEBUG; then
1243 disable_debug
1244 fi
1245
1246 echo '----------------------------------------------'
1247 echo 'BOOTSTRAP ENV'
1248 echo "AUTORECONF=$AUTORECONF"
1249 echo "HOST_OS=$HOST_OS"
1250
1251 echo "getopt()"
1252 if $AUTORECONF_OPTION; then
1253 echo "--autoreconf"
1254 fi
1255
1256 if $CLEAN_OPTION; then
1257 echo "--clean"
1258 fi
1259
1260 if $CONFIGURE_OPTION; then
1261 echo "--configure"
1262 fi
1263
1264 if $DEBUG_OPTION; then
1265 echo "--debug"
1266 fi
1267
1268 if $PRINT_SETUP_OPTION; then
1269 echo "--print-env"
1270 fi
1271
1272 if $TARGET_OPTION; then
1273 echo "--target=$TARGET_OPTION_ARG"
1274 fi
1275
1276 if $VERBOSE_OPTION; then
1277 echo "--verbose"
1278 fi
1279
1280 if [[ -n "$MAKE" ]]; then
1281 echo "MAKE=$MAKE"
1282 fi
1283
1284 if [[ -n "$MAKE_TARGET" ]]; then
1285 echo "MAKE_TARGET=$MAKE_TARGET"
1286 fi
1287
1288 if [[ -n "$PREFIX" ]]; then
1289 echo "PREFIX=$PREFIX"
1290 fi
1291
1292 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
1293 echo "TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT"
1294 fi
1295
1296 if [[ -n "$VCS_CHECKOUT" ]]; then
1297 echo "VCS_CHECKOUT=$VCS_CHECKOUT"
1298 fi
1299
1300 if $VERBOSE; then
1301 echo "VERBOSE=true"
1302 fi
1303
1304 if $DEBUG; then
1305 echo "DEBUG=true"
1306 fi
1307
1308 if [[ -n "$WARNINGS" ]]; then
1309 echo "WARNINGS=$WARNINGS"
1310 fi
1311 echo '----------------------------------------------'
1312
1313 if $saved_debug_status; then
1314 enable_debug
1315 fi
1316 }
1317
1318 function make_clean_option ()
1319 {
1320 run_configure_if_required
1321
1322 make_maintainer_clean
1323
1324 if [[ "$VCS_CHECKOUT" == 'git' ]]; then
1325 run "$VCS_CHECKOUT" status --ignored
1326 elif [[ -n "$VCS_CHECKOUT" ]]; then
1327 run "$VCS_CHECKOUT" status
1328 fi
1329 }
1330
1331 function make_for_autoreconf ()
1332 {
1333 if [ -f 'Makefile' ]; then
1334 make_maintainer_clean
1335 fi
1336
1337 run_autoreconf
1338
1339 assert_no_file 'Makefile'
1340 }
1341
1342 function check_make_target()
1343 {
1344 case $1 in
1345 'self')
1346 ;;
1347 'rpm')
1348 ;;
1349 'gdb')
1350 ;;
1351 'clean_op')
1352 ;;
1353 'autoreconf')
1354 ;;
1355 'install-system')
1356 ;;
1357 'configure')
1358 ;;
1359 'distcheck')
1360 ;;
1361 'check')
1362 ;;
1363 'snapshot')
1364 ;;
1365 'mingw')
1366 ;;
1367 'universe')
1368 ;;
1369 'valgrind')
1370 ;;
1371 'jenkins')
1372 ;;
1373 'distclean')
1374 ;;
1375 'maintainer-clean')
1376 ;;
1377 'install')
1378 ;;
1379 'all')
1380 ;;
1381 'make_default')
1382 ;;
1383 'clang')
1384 ;;
1385 'clang-analyzer')
1386 ;;
1387 'test-*')
1388 ;;
1389 'valgrind-*')
1390 ;;
1391 'gdb-*')
1392 ;;
1393 'dist')
1394 ;;
1395 *)
1396 die "Unknown MAKE_TARGET option: $1"
1397 ;;
1398 esac
1399 }
1400
1401 function bootstrap ()
1402 {
1403 determine_target_platform
1404
1405 determine_vcs
1406
1407 # Set up whatever we need to do to use autoreconf later
1408 require_libtoolise
1409 autoreconf_setup
1410
1411 if [ -z "$MAKE_TARGET" ]; then
1412 MAKE_TARGET="make_default"
1413 fi
1414
1415 if $PRINT_SETUP_OPTION -o $DEBUG; then
1416 echo
1417 print_setup
1418 echo
1419
1420 # Exit if all we were looking for were the currently used options
1421 if $PRINT_SETUP_OPTION; then
1422 exit
1423 fi
1424 fi
1425
1426 # Use OLD_TESTS_ENVIRONMENT for tracking the state of the variable
1427 local OLD_TESTS_ENVIRONMENT=
1428
1429 # Set ENV PREFIX in order to set --prefix for ./configure
1430 if [[ -n "$PREFIX" ]]; then
1431 PREFIX_ARG="--prefix=$PREFIX"
1432 fi
1433
1434 # We should always have a target by this point
1435 assert MAKE_TARGET
1436
1437 local MAKE_TARGET_ARRAY=($MAKE_TARGET)
1438
1439 for target in "${MAKE_TARGET_ARRAY[@]}"
1440 do
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
1444 fi
1445
1446 case $target in
1447 'self')
1448 self_test
1449 ;;
1450 'gdb')
1451 make_gdb
1452 ;;
1453 'install-html')
1454 make_install_html
1455 ;;
1456 'clean_op')
1457 make_clean_option
1458 ;;
1459 'autoreconf')
1460 make_for_autoreconf
1461 ;;
1462 'install-system')
1463 make_install_system
1464 ;;
1465 'configure')
1466 run_configure
1467 ;;
1468 'make_default')
1469 make_default
1470 ;;
1471 'clang')
1472 if ! check_clang; then
1473 die "clang was not found"
1474 fi
1475
1476 if ! make_for_clang; then
1477 die "Failed to build clang: $?"
1478 fi
1479 ;;
1480 'clang-analyzer')
1481 if ! check_clang_analyzer; then
1482 die "clang-analyzer was not found"
1483 fi
1484 if ! check_clang; then
1485 die "clang was not found"
1486 fi
1487
1488 if ! make_for_clang_analyzer; then
1489 die "Failed to build clang-analyzer: $?"
1490 fi
1491 ;;
1492 'mingw')
1493 if ! check_mingw; then
1494 die "mingw was not found"
1495 fi
1496
1497 if ! make_for_mingw; then
1498 die "Failed to build mingw: $?"
1499 fi
1500 ;;
1501 'snapshot')
1502 make_for_snapshot
1503 ;;
1504 'rpm')
1505 make_rpm
1506 ;;
1507 'valgrind')
1508 make_valgrind
1509 ;;
1510 'universe')
1511 make_universe
1512 ;;
1513 'jenkins')
1514 make_for_continuus_integration
1515 ;;
1516 *)
1517 run_configure_if_required
1518 make_target "$target"
1519 ;;
1520 esac
1521 done
1522 }
1523
1524 function main ()
1525 {
1526 # Variables we export
1527 declare -x VCS_CHECKOUT=
1528
1529 # Variables we control globally
1530 local MAKE_TARGET=
1531 local CONFIGURE=
1532
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
1542
1543 local OLD_CONFIGURE=
1544 local OLD_CONFIGURE_ARG=
1545 local OLD_PREFIX=
1546 local OLD_MAKE=
1547 local OLD_TESTS_ENVIRONMENT=
1548
1549 # If we call autoreconf on the platform or not
1550 local AUTORECONF_REBUILD_HOST=false
1551 local AUTORECONF_REBUILD=false
1552
1553 local -r top_srcdir=`pwd`
1554
1555 # Default configure
1556 if [ -z "$CONFIGURE" ]; then
1557 CONFIGURE="$top_srcdir/configure"
1558 fi
1559
1560
1561 # Variables for determine_target_platform () and rebuild_host_os ()
1562 # UNAME_MACHINE_ARCH= uname -m
1563 # VENDOR= apple, redhat, centos, canonical
1564 # VENDOR_RELEASE=
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
1578 local HOST_OS=
1579
1580 rebuild_host_os no_output
1581
1582 parse_command_line_options $@
1583
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'
1590 fi
1591 fi
1592
1593 bootstrap
1594
1595 jobs -l
1596 wait
1597
1598 exit 0
1599 }
1600
1601 function set_branch ()
1602 {
1603 if [ -z "$BRANCH" ]; then
1604 if [ -z "$CI_PROJECT_TEAM" ]; then
1605 die "Variable CI_PROJECT_TEAM has not been set"
1606 fi
1607 if [ -z "$PROJECT" ]; then
1608 die "Variable PROJECT has not been set"
1609 fi
1610 if [ -z "$BUILD_TAG" ]; then
1611 die "Variable BUILD_TAG has not been set"
1612 fi
1613
1614 BRANCH="lp:~$CI_PROJECT_TEAM/$PROJECT/$BUILD_TAG"
1615 export BRANCH
1616 fi
1617
1618 if [ -z "$BRANCH" ]; then
1619 die "Missing values required to build BRANCH variable."
1620 fi
1621 }
1622
1623 function merge ()
1624 {
1625 if [ -z "$VCS_CHECKOUT" ]; then
1626 die "Merges require VCS_CHECKOUT."
1627 fi
1628
1629 set_branch
1630
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
1635 fi
1636
1637 bzr push "$BRANCH"
1638 elif [[ -n "$VCS_CHECKOUT" ]]; then
1639 die "Merge attempt occured, current VCS setup does not support this"
1640 fi
1641 }
1642
1643 function enable_debug ()
1644 {
1645 if ! $DEBUG; then
1646 local caller_loc=`caller`
1647 if [ -n $1 ]; then
1648 echo "$caller_loc Enabling debug: $1"
1649 else
1650 echo "$caller_loc Enabling debug"
1651 fi
1652 set -x
1653 DEBUG=true
1654 fi
1655 }
1656
1657 function usage ()
1658 {
1659 cat << EOF
1660 Usage: $program_name [OPTION]..
1661
1662 Bootstrap this package from the checked-out sources, and optionally walk through CI run.
1663
1664 Options:
1665
1666 EOF
1667 }
1668
1669 function disable_debug ()
1670 {
1671 set +x
1672 DEBUG=true
1673 }
1674
1675 # Script begins here
1676
1677 program_name=$0
1678
1679 env_debug_enabled=false
1680 if [[ -n "$JENKINS_HOME" ]]; then
1681 declare -r jenkins_build_environment=true
1682 else
1683 declare -r jenkins_build_environment=false
1684 fi
1685
1686 export ACLOCAL
1687 export AUTOCONF
1688 export AUTOHEADER
1689 export AUTOM4TE
1690 export AUTOMAKE
1691 export AUTORECONF
1692 export CONFIGURE_ARG
1693 export DEBUG
1694 export GNU_BUILD_FLAGS
1695 export LIBTOOLIZE
1696 export LIBTOOLIZE_OPTIONS
1697 export MAKE
1698 export PREFIX_ARG
1699 export TESTS_ENVIRONMENT
1700 export VERBOSE
1701 export WARNINGS
1702
1703 case $OSTYPE in
1704 darwin*)
1705 export MallocGuardEdges
1706 export MallocErrorAbort
1707 export MallocScribble
1708 ;;
1709 esac
1710
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
1715 enable_debug
1716 print_setup
1717 fi
1718
1719 # Variables which only can be set by .bootstrap
1720 BOOTSTRAP_SNAPSHOT=false
1721 BOOTSTRAP_SNAPSHOT_CHECK=
1722
1723 if [ -f '.bootstrap' ]; then
1724 source '.bootstrap'
1725 fi
1726
1727 if $env_debug_enabled; then
1728 enable_debug
1729 else
1730 if [[ -n "$DEBUG" ]]; then
1731 enable_debug "Enabling DEBUG from '.bootstrap'"
1732 print_setup
1733 fi
1734 fi
1735
1736 # We do this in order to protect the case where DEBUG
1737 if ! $env_debug_enabled; then
1738 DEBUG=false
1739 fi
1740
1741 main $@