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