Fix for lp:1164442
[m6w6/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 *-precise-*)
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 echo " -a # Just run autoreconf";
1072 echo " -p # Print ENV";
1073 echo " -c # Just run configure";
1074 echo " -m # Just run maintainer-clean";
1075 echo " -t # Make target";
1076 echo " -d # Enable debug";
1077 echo " -h # Show help";
1078 echo " -v # Be more verbose in output";
1079 exit
1080 ;;
1081 v) # verbose
1082 VERBOSE_OPTION=true
1083 VERBOSE=true
1084 ;;
1085 :)
1086 echo "Option -$OPTARG requires an argument." >&2
1087 exit 1
1088 ;;
1089 *)
1090 echo "$0: error - unrecognized option $1" 1>&2
1091 exit 1
1092 ;;
1093 esac
1094 done
1095
1096 shift $((OPTIND-1))
1097
1098 if [ -n "$1" ]; then
1099 MAKE_TARGET="$@"
1100 fi
1101 }
1102
1103 function determine_vcs ()
1104 {
1105 if [[ -d '.git' ]]; then
1106 VCS_CHECKOUT=git
1107 elif [[ -d '.bzr' ]]; then
1108 VCS_CHECKOUT=bzr
1109 elif [[ -d '.svn' ]]; then
1110 VCS_CHECKOUT=svn
1111 elif [[ -d '.hg' ]]; then
1112 VCS_CHECKOUT=hg
1113 else
1114 VCS_CHECKOUT=
1115 fi
1116
1117 if [[ -n "$VCS_CHECKOUT" ]]; then
1118 VERBOSE=true
1119 fi
1120 }
1121
1122 function require_libtoolise ()
1123 {
1124 use_libtool=0
1125 grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \
1126 && use_libtool=1
1127 grep '^[ ]*LT_INIT' configure.ac >/dev/null \
1128 && use_libtool=1
1129 }
1130
1131 function autoreconf_setup ()
1132 {
1133 # Set ENV MAKE in order to override "make"
1134 if [[ -z "$MAKE" ]]; then
1135 if command_exists 'gmake'; then
1136 MAKE=`type -p gmake`
1137 else
1138 if command_exists 'make'; then
1139 MAKE=`type -p make`
1140 fi
1141 fi
1142
1143 if [ "$VCS_CHECKOUT" ]; then
1144 if $DEBUG; then
1145 MAKE="$MAKE --warn-undefined-variables"
1146 fi
1147 fi
1148
1149 if $DEBUG; then
1150 MAKE="$MAKE -d"
1151 fi
1152 fi
1153
1154 if [[ -z "$GNU_BUILD_FLAGS" ]]; then
1155 GNU_BUILD_FLAGS="--install --force"
1156 fi
1157
1158 if $VERBOSE; then
1159 GNU_BUILD_FLAGS="$GNU_BUILD_FLAGS --verbose"
1160 fi
1161
1162 if [ -z "$ACLOCAL_PATH" ]; then
1163 ACLOCAL_PATH="/usr/local/share/aclocal $ACLOCAL_PATH"
1164 fi
1165
1166 if [[ -z "$WARNINGS" ]]; then
1167 if [[ -n "$VCS_CHECKOUT" ]]; then
1168 WARNINGS="all,error"
1169 else
1170 WARNINGS="all"
1171 fi
1172 fi
1173
1174 if test $use_libtool = 1; then
1175 if [[ -n "$LIBTOOLIZE" ]]; then
1176 BOOTSTRAP_LIBTOOLIZE=`type -p $LIBTOOLIZE`
1177
1178 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1179 echo "Couldn't find user supplied libtoolize, it is required"
1180 return 1
1181 fi
1182 else
1183 # If we are using OSX, we first check to see glibtoolize is available
1184 if [[ "$VENDOR_DISTRIBUTION" == "darwin" ]]; then
1185 BOOTSTRAP_LIBTOOLIZE=`type -p glibtoolize`
1186
1187 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1188 echo "Couldn't find glibtoolize, it is required on OSX"
1189 return 1
1190 fi
1191 else
1192 BOOTSTRAP_LIBTOOLIZE=`type -p libtoolize`
1193
1194 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1195 echo "Couldn't find libtoolize, it is required"
1196 return 1
1197 fi
1198 fi
1199 fi
1200 if $VERBOSE; then
1201 LIBTOOLIZE_OPTIONS="--verbose $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
1202 fi
1203 if $DEBUG; then
1204 LIBTOOLIZE_OPTIONS="--debug $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
1205 fi
1206 LIBTOOLIZE=true
1207 fi
1208
1209 # Test the ENV AUTOMAKE if it exists
1210 if [[ -n "$AUTOMAKE" ]]; then
1211 run $AUTOMAKE '--help' &> /dev/null || die "Failed to run AUTOMAKE:$AUTOMAKE"
1212 fi
1213
1214 # Test the ENV AUTOCONF if it exists
1215 if [[ -n "$AUTOCONF" ]]; then
1216 run $AUTOCONF '--help' &> /dev/null || die "Failed to run AUTOCONF:$AUTOCONF"
1217 fi
1218
1219 # Test the ENV AUTOHEADER if it exists
1220 if [[ -n "$AUTOHEADER" ]]; then
1221 run $AUTOHEADER '--help' &> /dev/null || die "Failed to run AUTOHEADER:$AUTOHEADER"
1222 fi
1223
1224 # Test the ENV AUTOM4TE if it exists
1225 if [[ -n "$AUTOM4TE" ]]; then
1226 run $AUTOM4TE '--help' &> /dev/null || die "Failed to run AUTOM4TE:$AUTOM4TE"
1227 fi
1228
1229 # Test the ENV AUTOHEADER if it exists, if not we add one and add --install
1230 if [[ -z "$ACLOCAL" ]]; then
1231 ACLOCAL="aclocal --install"
1232 fi
1233 run $ACLOCAL '--help' &> /dev/null || die "Failed to run ACLOCAL:$ACLOCAL"
1234
1235 if [[ -z "$AUTORECONF" ]]; then
1236 AUTORECONF=`type -p autoreconf`
1237
1238 if [[ -z "$AUTORECONF" ]]; then
1239 die "Couldn't find autoreconf"
1240 fi
1241
1242 if [[ -n "$GNU_BUILD_FLAGS" ]]; then
1243 AUTORECONF="$AUTORECONF $GNU_BUILD_FLAGS"
1244 fi
1245 fi
1246
1247 run $AUTORECONF '--help' &> /dev/null || die "Failed to run AUTORECONF:$AUTORECONF"
1248 }
1249
1250 function print_setup ()
1251 {
1252 saved_debug_status=$DEBUG
1253 if $DEBUG; then
1254 disable_debug
1255 fi
1256
1257 echo '----------------------------------------------'
1258 echo 'BOOTSTRAP ENV'
1259 echo "AUTORECONF=$AUTORECONF"
1260 echo "HOST_OS=$HOST_OS"
1261 echo "VENDOR=$VENDOR"
1262 echo "VENDOR_DISTRIBUTION=$VENDOR_DISTRIBUTION"
1263 echo "VENDOR_RELEASE=$VENDOR_RELEASE"
1264
1265 echo "getopt()"
1266 if $AUTORECONF_OPTION; then
1267 echo "--autoreconf"
1268 fi
1269
1270 if $CLEAN_OPTION; then
1271 echo "--clean"
1272 fi
1273
1274 if $CONFIGURE_OPTION; then
1275 echo "--configure"
1276 fi
1277
1278 if $DEBUG_OPTION; then
1279 echo "--debug"
1280 fi
1281
1282 if $PRINT_SETUP_OPTION; then
1283 echo "--print-env"
1284 fi
1285
1286 if $TARGET_OPTION; then
1287 echo "--target=$TARGET_OPTION_ARG"
1288 fi
1289
1290 if $VERBOSE_OPTION; then
1291 echo "--verbose"
1292 fi
1293
1294 if [[ -n "$MAKE" ]]; then
1295 echo "MAKE=$MAKE"
1296 fi
1297
1298 if [[ -n "$MAKE_TARGET" ]]; then
1299 echo "MAKE_TARGET=$MAKE_TARGET"
1300 fi
1301
1302 if [[ -n "$PREFIX" ]]; then
1303 echo "PREFIX=$PREFIX"
1304 fi
1305
1306 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
1307 echo "TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT"
1308 fi
1309
1310 if [[ -n "$VCS_CHECKOUT" ]]; then
1311 echo "VCS_CHECKOUT=$VCS_CHECKOUT"
1312 fi
1313
1314 if $VERBOSE; then
1315 echo "VERBOSE=true"
1316 fi
1317
1318 if $DEBUG; then
1319 echo "DEBUG=true"
1320 fi
1321
1322 if [[ -n "$WARNINGS" ]]; then
1323 echo "WARNINGS=$WARNINGS"
1324 fi
1325 echo '----------------------------------------------'
1326
1327 if $saved_debug_status; then
1328 enable_debug
1329 fi
1330 }
1331
1332 function make_clean_option ()
1333 {
1334 run_configure_if_required
1335
1336 make_maintainer_clean
1337
1338 if [[ "$VCS_CHECKOUT" == 'git' ]]; then
1339 run "$VCS_CHECKOUT" status --ignored
1340 elif [[ -n "$VCS_CHECKOUT" ]]; then
1341 run "$VCS_CHECKOUT" status
1342 fi
1343 }
1344
1345 function make_for_autoreconf ()
1346 {
1347 if [ -f 'Makefile' ]; then
1348 make_maintainer_clean
1349 fi
1350
1351 run_autoreconf
1352
1353 assert_no_file 'Makefile'
1354 }
1355
1356 function check_make_target()
1357 {
1358 case $1 in
1359 'self')
1360 ;;
1361 'rpm')
1362 ;;
1363 'gdb')
1364 ;;
1365 'clean_op')
1366 ;;
1367 'autoreconf')
1368 ;;
1369 'install-system')
1370 ;;
1371 'configure')
1372 ;;
1373 'distcheck')
1374 ;;
1375 'check')
1376 ;;
1377 'snapshot')
1378 ;;
1379 'mingw')
1380 ;;
1381 'universe')
1382 ;;
1383 'valgrind')
1384 ;;
1385 'jenkins')
1386 ;;
1387 'distclean')
1388 ;;
1389 'maintainer-clean')
1390 ;;
1391 'install')
1392 ;;
1393 'all')
1394 ;;
1395 'make_default')
1396 ;;
1397 'clang')
1398 ;;
1399 'clang-analyzer')
1400 ;;
1401 'test-*')
1402 ;;
1403 'valgrind-*')
1404 ;;
1405 'gdb-*')
1406 ;;
1407 'dist')
1408 ;;
1409 *)
1410 die "Unknown MAKE_TARGET option: $1"
1411 ;;
1412 esac
1413 }
1414
1415 function bootstrap ()
1416 {
1417 determine_target_platform
1418
1419 determine_vcs
1420
1421 # Set up whatever we need to do to use autoreconf later
1422 require_libtoolise
1423 if ! autoreconf_setup; then
1424 return 1
1425 fi
1426
1427 if [ -z "$MAKE_TARGET" ]; then
1428 MAKE_TARGET="make_default"
1429 fi
1430
1431 if $PRINT_SETUP_OPTION -o $DEBUG; then
1432 echo
1433 print_setup
1434 echo
1435
1436 # Exit if all we were looking for were the currently used options
1437 if $PRINT_SETUP_OPTION; then
1438 exit
1439 fi
1440 fi
1441
1442 # Use OLD_TESTS_ENVIRONMENT for tracking the state of the variable
1443 local OLD_TESTS_ENVIRONMENT=
1444
1445 # Set ENV PREFIX in order to set --prefix for ./configure
1446 if [[ -n "$PREFIX" ]]; then
1447 PREFIX_ARG="--prefix=$PREFIX"
1448 fi
1449
1450 # We should always have a target by this point
1451 assert MAKE_TARGET
1452
1453 local MAKE_TARGET_ARRAY=($MAKE_TARGET)
1454
1455 for target in "${MAKE_TARGET_ARRAY[@]}"
1456 do
1457 # If we are running inside of Jenkins, we want to only run some of the possible tests
1458 if $jenkins_build_environment; then
1459 check_make_target $target
1460 fi
1461
1462 case $target in
1463 'self')
1464 self_test
1465 ;;
1466 'gdb')
1467 make_gdb
1468 ;;
1469 'install-html')
1470 make_install_html
1471 ;;
1472 'clean_op')
1473 make_clean_option
1474 ;;
1475 'autoreconf')
1476 make_for_autoreconf
1477 ;;
1478 'install-system')
1479 make_install_system
1480 ;;
1481 'configure')
1482 run_configure
1483 ;;
1484 'make_default')
1485 make_default
1486 ;;
1487 'clang')
1488 if ! check_clang; then
1489 die "clang was not found"
1490 fi
1491
1492 if ! make_for_clang; then
1493 die "Failed to build clang: $?"
1494 fi
1495 ;;
1496 'clang-analyzer')
1497 if ! check_clang_analyzer; then
1498 die "clang-analyzer was not found"
1499 fi
1500 if ! check_clang; then
1501 die "clang was not found"
1502 fi
1503
1504 if ! make_for_clang_analyzer; then
1505 die "Failed to build clang-analyzer: $?"
1506 fi
1507 ;;
1508 'mingw')
1509 if ! check_mingw; then
1510 die "mingw was not found"
1511 fi
1512
1513 if ! make_for_mingw; then
1514 die "Failed to build mingw: $?"
1515 fi
1516 ;;
1517 'snapshot')
1518 make_for_snapshot
1519 ;;
1520 'rpm')
1521 make_rpm
1522 ;;
1523 'valgrind')
1524 make_valgrind
1525 ;;
1526 'universe')
1527 make_universe
1528 ;;
1529 'jenkins')
1530 make_for_continuus_integration
1531 ;;
1532 *)
1533 run_configure_if_required
1534 make_target "$target"
1535 ;;
1536 esac
1537 done
1538 }
1539
1540 function main ()
1541 {
1542 # Variables we export
1543 declare -x VCS_CHECKOUT=
1544
1545 # Variables we control globally
1546 local MAKE_TARGET=
1547 local CONFIGURE=
1548
1549 # Options for getopt
1550 local AUTORECONF_OPTION=false
1551 local CLEAN_OPTION=false
1552 local CONFIGURE_OPTION=false
1553 local DEBUG_OPTION=false
1554 local PRINT_SETUP_OPTION=false
1555 local TARGET_OPTION=false
1556 local TARGET_OPTION_ARG=
1557 local VERBOSE_OPTION=false
1558
1559 local OLD_CONFIGURE=
1560 local OLD_CONFIGURE_ARG=
1561 local OLD_PREFIX=
1562 local OLD_MAKE=
1563 local OLD_TESTS_ENVIRONMENT=
1564
1565 # If we call autoreconf on the platform or not
1566 local AUTORECONF_REBUILD_HOST=false
1567 local AUTORECONF_REBUILD=false
1568
1569 local -r top_srcdir=`pwd`
1570
1571 # Default configure
1572 if [ -z "$CONFIGURE" ]; then
1573 CONFIGURE="$top_srcdir/configure"
1574 fi
1575
1576
1577 # Variables for determine_target_platform () and rebuild_host_os ()
1578 # UNAME_MACHINE_ARCH= uname -m
1579 # VENDOR= apple, redhat, centos, canonical
1580 # VENDOR_RELEASE=
1581 # RHEL{rhel,Tikanga,Santiago}
1582 # Ubuntu{ubuntu,Lucid,Maverick,Natty,Oneiric,Precise,Quantal}
1583 # Fedora{fedora,Verne,Beefy}
1584 # OSX{osx,lion,snow,mountain}
1585 # VENDOR_DISTRIBUTION= darwin,fedora,rhel,ubuntu
1586 # UNAME_KERNEL= Linux, Darwin,...
1587 # UNAME_KERNEL_RELEASE= Linux, Darwin,...
1588 local UNAME_MACHINE_ARCH=unknown
1589 local VENDOR=unknown
1590 local VENDOR_RELEASE=unknown
1591 local VENDOR_DISTRIBUTION=unknown
1592 local UNAME_KERNEL=unknown
1593 local UNAME_KERNEL_RELEASE=unknown
1594 local HOST_OS=
1595
1596 rebuild_host_os no_output
1597
1598 parse_command_line_options $@
1599
1600 # If we are running under Jenkins we predetermine what tests we will run against
1601 # This MAKE_TARGET can be overridden by parse_command_line_options based MAKE_TARGET changes.
1602 # We don't want Jenkins overriding other variables, so we NULL them.
1603 if [ -z "$MAKE_TARGET" ]; then
1604 if $jenkins_build_environment; then
1605 MAKE_TARGET='jenkins'
1606 fi
1607 fi
1608
1609 bootstrap
1610
1611 jobs -l
1612 wait
1613
1614 exit 0
1615 }
1616
1617 function set_branch ()
1618 {
1619 if [ -z "$BRANCH" ]; then
1620 if [ -z "$CI_PROJECT_TEAM" ]; then
1621 die "Variable CI_PROJECT_TEAM has not been set"
1622 fi
1623 if [ -z "$PROJECT" ]; then
1624 die "Variable PROJECT has not been set"
1625 fi
1626 if [ -z "$BUILD_TAG" ]; then
1627 die "Variable BUILD_TAG has not been set"
1628 fi
1629
1630 BRANCH="lp:~$CI_PROJECT_TEAM/$PROJECT/$BUILD_TAG"
1631 export BRANCH
1632 fi
1633
1634 if [ -z "$BRANCH" ]; then
1635 die "Missing values required to build BRANCH variable."
1636 fi
1637 }
1638
1639 function merge ()
1640 {
1641 if [ -z "$VCS_CHECKOUT" ]; then
1642 die "Merges require VCS_CHECKOUT."
1643 fi
1644
1645 set_branch
1646
1647 if [[ "$VCS_CHECKOUT" == 'bzr' ]]; then
1648 if test -n "$BRANCH_TO_MERGE"; then
1649 bzr merge $BRANCH_TO_MERGE
1650 bzr commit --message="Merge $BRANCH_TO_MERGE Build: $BUILD_TAG" --unchanged
1651 fi
1652
1653 bzr push "$BRANCH"
1654 elif [[ -n "$VCS_CHECKOUT" ]]; then
1655 die "Merge attempt occured, current VCS setup does not support this"
1656 fi
1657 }
1658
1659 function enable_debug ()
1660 {
1661 if ! $DEBUG; then
1662 local caller_loc=`caller`
1663 if [ -n $1 ]; then
1664 echo "$caller_loc Enabling debug: $1"
1665 else
1666 echo "$caller_loc Enabling debug"
1667 fi
1668 set -x
1669 DEBUG=true
1670 fi
1671 }
1672
1673 function usage ()
1674 {
1675 cat << EOF
1676 Usage: $program_name [OPTION]..
1677
1678 Bootstrap this package from the checked-out sources, and optionally walk through CI run.
1679
1680 Options:
1681
1682 EOF
1683 }
1684
1685 function disable_debug ()
1686 {
1687 set +x
1688 DEBUG=true
1689 }
1690
1691 # Script begins here
1692
1693 program_name=$0
1694
1695 env_debug_enabled=false
1696 if [[ -n "$JENKINS_HOME" ]]; then
1697 declare -r jenkins_build_environment=true
1698 else
1699 declare -r jenkins_build_environment=false
1700 fi
1701
1702 export ACLOCAL
1703 export AUTOCONF
1704 export AUTOHEADER
1705 export AUTOM4TE
1706 export AUTOMAKE
1707 export AUTORECONF
1708 export CONFIGURE_ARG
1709 export DEBUG
1710 export GNU_BUILD_FLAGS
1711 export LIBTOOLIZE
1712 export LIBTOOLIZE_OPTIONS
1713 export MAKE
1714 export PREFIX_ARG
1715 export TESTS_ENVIRONMENT
1716 export VERBOSE
1717 export WARNINGS
1718
1719 case $OSTYPE in
1720 darwin*)
1721 export MallocGuardEdges
1722 export MallocErrorAbort
1723 export MallocScribble
1724 ;;
1725 esac
1726
1727 # We check for DEBUG twice, once before we source the config file, and once afterward
1728 env_debug_enabled=false
1729 if [[ -n "$DEBUG" ]]; then
1730 env_debug_enabled=true
1731 enable_debug
1732 print_setup
1733 fi
1734
1735 # Variables which only can be set by .bootstrap
1736 BOOTSTRAP_SNAPSHOT=false
1737 BOOTSTRAP_SNAPSHOT_CHECK=
1738
1739 if [ -f '.bootstrap' ]; then
1740 source '.bootstrap'
1741 fi
1742
1743 if $env_debug_enabled; then
1744 enable_debug
1745 else
1746 if [[ -n "$DEBUG" ]]; then
1747 enable_debug "Enabling DEBUG from '.bootstrap'"
1748 print_setup
1749 fi
1750 fi
1751
1752 # We do this in order to protect the case where DEBUG
1753 if ! $env_debug_enabled; then
1754 DEBUG=false
1755 fi
1756
1757 main $@