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