Update to latest bootstrap
[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 # Validate the distribution name, or toss an erro
155 # values: darwin,fedora,rhel,ubuntu,debian,opensuse
156 function set_VENDOR_DISTRIBUTION ()
157 {
158 local dist=`echo "$1" | tr '[A-Z]' '[a-z]'`
159 case "$dist" in
160 darwin)
161 VENDOR_DISTRIBUTION='darwin'
162 ;;
163 fedora)
164 VENDOR_DISTRIBUTION='fedora'
165 ;;
166 rhel)
167 VENDOR_DISTRIBUTION='rhel'
168 ;;
169 debian)
170 VENDOR_DISTRIBUTION='debian'
171 ;;
172 ubuntu)
173 VENDOR_DISTRIBUTION='ubuntu'
174 ;;
175 suse)
176 VENDOR_DISTRIBUTION='opensuse'
177 ;;
178 opensuse)
179 VENDOR_DISTRIBUTION='opensuse'
180 ;;
181 *)
182 die "attempt to set an invalid VENDOR_DISTRIBUTION=$dist"
183 ;;
184 esac
185 }
186
187 # Validate a Vendor's release name/number
188 function set_VENDOR_RELEASE ()
189 {
190 local release=`echo "$1" | tr '[A-Z]' '[a-z]'`
191
192 if $DEBUG; then
193 echo "VENDOR_DISTRIBUTION:$VENDOR_DISTRIBUTION"
194 echo "VENDOR_RELEASE:$release"
195 fi
196
197 case $VENDOR_DISTRIBUTION in
198 darwin)
199 case $release in
200 10.6*)
201 VENDOR_RELEASE='snow_leopard'
202 ;;
203 10.7*)
204 VENDOR_RELEASE='mountain'
205 ;;
206 mountain)
207 VENDOR_RELEASE='mountain'
208 ;;
209 10.8.*)
210 echo "mountain_lion"
211 VENDOR_RELEASE='mountain_lion'
212 ;;
213 *)
214 echo $VENDOR_RELEASE
215 VENDOR_RELEASE='unknown'
216 ;;
217 esac
218 ;;
219 fedora)
220 VENDOR_RELEASE="$release"
221 if [[ "x$VENDOR_RELEASE" == '18' ]]; then
222 VENDOR_RELEASE='sphericalcow'
223 fi
224 ;;
225 rhel)
226 VENDOR_RELEASE="$release"
227 ;;
228 debian)
229 VENDOR_RELEASE="$release"
230 ;;
231 ubuntu)
232 VENDOR_RELEASE="$release"
233 if [[ "x$VENDOR_RELEASE" == 'x12.04' ]]; then
234 VENDOR_RELEASE="precise"
235 elif [[ "x$VENDOR_RELEASE" == 'x12.10' ]]; then
236 VENDOR_RELEASE="quantal"
237 elif [[ "x$VENDOR_RELEASE" == 'x13.04' ]]; then
238 VENDOR_RELEASE="raring"
239 fi
240 ;;
241 opensuse)
242 VENDOR_RELEASE="$release"
243 ;;
244 unknown)
245 die "attempt to set VENDOR_RELEASE without setting VENDOR_DISTRIBUTION"
246 ;;
247 *)
248 die "attempt to set with an invalid VENDOR_DISTRIBUTION=$VENDOR_DISTRIBUTION"
249 ;;
250 esac
251 }
252
253
254 # Valid values are: apple, redhat, centos, canonical, oracle, suse
255 function set_VENDOR ()
256 {
257 local vendor=`echo "$1" | tr '[A-Z]' '[a-z]'`
258
259 case $vendor in
260 apple)
261 VENDOR='apple'
262 ;;
263 redhat)
264 VENDOR='redhat'
265 ;;
266 fedora)
267 VENDOR='redhat'
268 ;;
269 redhat-release-server-*)
270 VENDOR='redhat'
271 ;;
272 enterprise-release-*)
273 VENDOR='oracle'
274 ;;
275 centos)
276 VENDOR='centos'
277 ;;
278 canonical)
279 VENDOR='canonical'
280 ;;
281 ubuntu)
282 VENDOR='canonical'
283 ;;
284 debian)
285 VENDOR='debian'
286 ;;
287 opensuse)
288 VENDOR='suse'
289 ;;
290 suse)
291 VENDOR='suse'
292 ;;
293 *)
294 die "An attempt was made to set an invalid VENDOR=$_vendor"
295 ;;
296 esac
297
298 set_VENDOR_DISTRIBUTION $2
299 set_VENDOR_RELEASE $3
300
301 # Set which vendor/versions we trust for autoreconf
302 case $VENDOR_DISTRIBUTION in
303 fedora)
304 if [[ "x$VENDOR_RELEASE" == 'x18' ]]; then
305 AUTORECONF_REBUILD_HOST=true
306 elif [[ "x$VENDOR_RELEASE" == 'xsphericalcow' ]]; then
307 AUTORECONF_REBUILD_HOST=true
308 elif [[ "x$VENDOR_RELEASE" == 'x19' ]]; then
309 AUTORECONF_REBUILD_HOST=true
310 fi
311 ;;
312 canonical)
313 if [[ "x$VENDOR_RELEASE" == 'xprecise' ]]; then
314 AUTORECONF_REBUILD_HOST=true
315 elif [[ "x$VENDOR_RELEASE" == 'xquantal' ]]; then
316 AUTORECONF_REBUILD_HOST=true
317 fi
318 ;;
319 esac
320
321 }
322
323 function determine_target_platform ()
324 {
325 UNAME_MACHINE_ARCH=`(uname -m) 2>/dev/null` || UNAME_MACHINE_ARCH=unknown
326 UNAME_KERNEL=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
327 UNAME_KERNEL_RELEASE=`(uname -r) 2>/dev/null` || UNAME_KERNEL_RELEASE=unknown
328
329 if [[ -x '/usr/bin/sw_vers' ]]; then
330 local _VERSION=`/usr/bin/sw_vers -productVersion`
331 set_VENDOR 'apple' 'darwin' $_VERSION
332 elif [[ $(uname) == 'Darwin' ]]; then
333 set_VENDOR 'apple' 'darwin' 'mountain'
334 elif [[ -f '/etc/fedora-release' ]]; then
335 local fedora_version=`cat /etc/fedora-release | awk ' { print $3 } '`
336 set_VENDOR 'redhat' 'fedora' $fedora_version
337 elif [[ -f '/etc/centos-release' ]]; then
338 local centos_version=`cat /etc/centos-release | awk ' { print $7 } '`
339 set_VENDOR 'centos' 'rhel' $centos_version
340 elif [[ -f '/etc/SuSE-release' ]]; then
341 local suse_distribution=`head -1 /etc/SuSE-release | awk ' { print $1 } '`
342 local suse_version=`head -1 /etc/SuSE-release | awk ' { print $2 } '`
343 set_VENDOR 'suse' $suse_distribution $suse_version
344 elif [[ -f '/etc/redhat-release' ]]; then
345 local rhel_version=`cat /etc/redhat-release | awk ' { print $7 } '`
346 local _vendor=`rpm -qf /etc/redhat-release`
347 set_VENDOR $_vendor 'rhel' $rhel_version
348 elif [[ -f '/etc/os-release' ]]; then
349 source '/etc/os-release'
350 set_VENDOR $ID $ID $VERSION_ID
351 elif [[ -x '/usr/bin/lsb_release' ]]; then
352 local _ID=`/usr/bin/lsb_release -s -i`
353 local _VERSION=`/usr/bin/lsb_release -s -r`
354 set_VENDOR $_ID $_ID $_VERSION_ID
355 elif [[ -f '/etc/lsb-release' ]]; then
356 source '/etc/lsb-release'
357 set_VENDOR 'canonical' $DISTRIB_ID $DISTRIB_CODENAME
358 fi
359
360 rebuild_host_os
361 }
362
363 function run_configure ()
364 {
365 # We will run autoreconf if we are required
366 run_autoreconf_if_required
367
368 # We always begin at the root of our build
369 if [ ! popd ]; then
370 die "Programmer error, we entered run_configure with a stacked directory"
371 fi
372
373 if ! command_exists "$CONFIGURE"; then
374 die "$CONFIGURE does not exist"
375 fi
376
377 local BUILD_DIR="$1"
378 if [[ -n "$BUILD_DIR" ]]; then
379 rm -r -f $BUILD_DIR
380 mkdir -p $BUILD_DIR
381 safe_pushd $BUILD_DIR
382 fi
383
384 # Arguments for configure
385 local BUILD_CONFIGURE_ARG=
386
387 # 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
388 # Set ENV ASSERT in order to enable assert.
389 # If we are doing a valgrind run, we always compile with assert disabled
390 if $valgrind_run; then
391 BUILD_CONFIGURE_ARG+= " CXXFLAGS=-DNDEBUG "
392 BUILD_CONFIGURE_ARG+= " CFLAGS=-DNDEBUG "
393 else
394 if $DEBUG; then
395 BUILD_CONFIGURE_ARG+=' --enable-debug --enable-assert'
396 elif [[ -n "$VCS_CHECKOUT" ]]; then
397 BUILD_CONFIGURE_ARG+=' --enable-assert'
398 fi
399 fi
400
401 if [[ -n "$CONFIGURE_ARG" ]]; then
402 BUILD_CONFIGURE_ARG+=" $CONFIGURE_ARG"
403 fi
404
405 if [[ -n "$PREFIX_ARG" ]]; then
406 BUILD_CONFIGURE_ARG+=" $PREFIX_ARG"
407 fi
408
409 ret=1;
410 # If we are executing on OSX use CLANG, otherwise only use it if we find it in the ENV
411 case $HOST_OS in
412 *-darwin-*)
413 CC=clang CXX=clang++ $top_srcdir/configure $BUILD_CONFIGURE_ARG || die "Cannot execute CC=clang CXX=clang++ configure $BUILD_CONFIGURE_ARG"
414 ret=$?
415 ;;
416 rhel-5*)
417 command_exists 'gcc44' || die "Could not locate gcc44"
418 CC=gcc44 CXX=gcc44 $top_srcdir/configure $BUILD_CONFIGURE_ARG || die "Cannot execute CC=gcc44 CXX=gcc44 configure $BUILD_CONFIGURE_ARG"
419 ret=$?
420 ;;
421 *)
422 $CONFIGURE $BUILD_CONFIGURE_ARG
423 ret=$?
424 ;;
425 esac
426
427 if [ $ret -ne 0 ]; then
428 die "Could not execute $CONFIGURE $BUILD_CONFIGURE_ARG"
429 fi
430
431 if [ ! -f 'Makefile' ]; then
432 die "Programmer error, configure was run but no Makefile existed after $CONFIGURE was run"
433 fi
434 }
435
436 function setup_gdb_command () {
437 GDB_TMPFILE=$(mktemp /tmp/gdb.XXXXXXXXXX)
438 echo 'set logging overwrite on' > $GDB_TMPFILE
439 echo 'set logging on' >> $GDB_TMPFILE
440 echo 'set environment LIBTEST_IN_GDB=1' >> $GDB_TMPFILE
441 echo 'run' >> $GDB_TMPFILE
442 echo 'thread apply all bt' >> $GDB_TMPFILE
443 echo 'quit' >> $GDB_TMPFILE
444 GDB_COMMAND="gdb -f -batch -x $GDB_TMPFILE"
445 }
446
447 function setup_valgrind_command () {
448 VALGRIND_PROGRAM=`type -p valgrind`
449 if [[ -n "$VALGRIND_PROGRAM" ]]; then
450 VALGRIND_COMMAND="$VALGRIND_PROGRAM --error-exitcode=1 --leak-check=yes --malloc-fill=A5 --free-fill=DE --xml=yes --xml-file=\"valgrind-%p.xml\""
451 fi
452 }
453
454 function save_BUILD ()
455 {
456 if [[ -n "$OLD_CONFIGURE" ]]; then
457 die "OLD_CONFIGURE($OLD_CONFIGURE) was set on push, programmer error!"
458 fi
459
460 if [[ -n "$OLD_CONFIGURE_ARG" ]]; then
461 die "OLD_CONFIGURE_ARG($OLD_CONFIGURE_ARG) was set on push, programmer error!"
462 fi
463
464 if [[ -n "$OLD_PREFIX" ]]; then
465 die "OLD_PREFIX($OLD_PREFIX) was set on push, programmer error!"
466 fi
467
468 if [[ -n "$OLD_MAKE" ]]; then
469 die "OLD_MAKE($OLD_MAKE) was set on push, programmer error!"
470 fi
471
472 if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
473 die "OLD_TESTS_ENVIRONMENT($OLD_TESTS_ENVIRONMENT) was set on push, programmer error!"
474 fi
475
476 if [[ -n "$CONFIGURE" ]]; then
477 OLD_CONFIGURE=$CONFIGURE
478 fi
479
480 if [[ -n "$CONFIGURE_ARG" ]]; then
481 OLD_CONFIGURE_ARG=$CONFIGURE_ARG
482 fi
483
484 if [[ -n "$MAKE" ]]; then
485 OLD_MAKE=$MAKE
486 fi
487
488 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
489 OLD_TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT
490 fi
491 }
492
493 function restore_BUILD ()
494 {
495 if [[ -n "$OLD_CONFIGURE" ]]; then
496 CONFIGURE=$OLD_CONFIGURE
497 fi
498
499 if [[ -n "$OLD_CONFIGURE_ARG" ]]; then
500 CONFIGURE_ARG=$OLD_CONFIGURE_ARG
501 fi
502
503 if [[ -n "$OLD_PREFIX" ]]; then
504 PREFIX_ARG=$OLD_PREFIX
505 fi
506
507 if [[ -n "$OLD_MAKE" ]]; then
508 MAKE=$OLD_MAKE
509 fi
510
511 if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
512 TESTS_ENVIRONMENT=$OLD_TESTS_ENVIRONMENT
513 fi
514
515 OLD_CONFIGURE=
516 OLD_CONFIGURE_ARG=
517 OLD_PREFIX=
518 OLD_MAKE=
519 OLD_TESTS_ENVIRONMENT=
520
521 export -n CC CXX
522 }
523
524 function safe_pushd ()
525 {
526 pushd $1 &> /dev/null ;
527
528 if [ -n "$BUILD_DIR" ]; then
529 if $VERBOSE; then
530 echo "BUILD_DIR=$BUILD_DIR"
531 fi
532 fi
533 }
534
535 function safe_popd ()
536 {
537 local directory_to_delete=`pwd`
538 popd &> /dev/null ;
539 if [ $? -eq 0 ]; then
540 if [[ "$top_srcdir" == "$directory_to_delete" ]]; then
541 die "We almost deleted top_srcdir($top_srcdir), programmer error"
542 fi
543
544 rm -r -f "$directory_to_delete"
545 fi
546 }
547
548 function make_valgrind ()
549 {
550 # If the env VALGRIND_COMMAND is set then we assume it is valid
551 local valgrind_was_set=false
552 if [[ -z "$VALGRIND_COMMAND" ]]; then
553 setup_valgrind_command
554 if [[ -n "$VALGRIND_COMMAND" ]]; then
555 valgrind_was_set=true
556 fi
557 else
558 valgrind_was_set=true
559 fi
560
561 # If valgrind_was_set is set to no we bail
562 if ! $valgrind_was_set; then
563 echo 'valgrind was not present'
564 return 1
565 fi
566
567 save_BUILD
568
569 valgrind_run=true
570
571 # If we are required to run configure, do so now
572 run_configure
573
574 # If we don't have a configure, then most likely we will be missing libtool
575 assert_file 'configure'
576 if [[ -f 'libtool' ]]; then
577 TESTS_ENVIRONMENT="./libtool --mode=execute $VALGRIND_COMMAND"
578 else
579 TESTS_ENVIRONMENT="$VALGRIND_COMMAND"
580 fi
581
582 make_target 'check'
583 ret=$?
584
585 # If we aren't going to error, we will clean up our environment
586 if [ "$ret" -eq 0 ]; then
587 make 'distclean'
588 fi
589
590 valgrind_run=false
591
592 restore_BUILD
593
594 if [ "$ret" -ne 0 ]; then
595 return 1
596 fi
597 }
598
599 function make_install_system ()
600 {
601 local INSTALL_LOCATION=$(mktemp -d /tmp/XXXXXXXXXX)
602
603 save_BUILD
604 PREFIX_ARG="--prefix=$INSTALL_LOCATION"
605
606 if [ ! -d $INSTALL_LOCATION ] ; then
607 die "ASSERT temp directory not found '$INSTALL_LOCATION'"
608 fi
609
610 run_configure #install_buid_dir
611
612 make_target 'install'
613
614 make_target 'installcheck'
615
616 make_target 'uninstall'
617
618 rm -r -f $INSTALL_LOCATION
619 make 'distclean'
620
621 if [ -f 'Makefile' ]; then
622 die "ASSERT Makefile should not exist"
623 fi
624
625 restore_BUILD
626 safe_popd
627 }
628
629 function make_darwin_malloc ()
630 {
631 run_configure_if_required
632
633 old_MallocGuardEdges=$MallocGuardEdges
634 MallocGuardEdges=1
635 old_MallocErrorAbort=$MallocErrorAbort
636 MallocErrorAbort=1
637 old_MallocScribble=$MallocScribble
638 MallocScribble=1
639
640 make_check
641
642 MallocGuardEdges=$old_MallocGuardEdges
643 MallocErrorAbort=$old_MallocErrorAbort
644 MallocScribble=$old_MallocScribble
645 }
646
647 function snapshot_check ()
648 {
649 if [ ! -f "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then
650 make_for_snapshot
651 fi
652
653 if [ -n "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then
654 assert_file "$BOOTSTRAP_SNAPSHOT_CHECK" 'snapshot check failed'
655 fi
656 }
657
658 # This will reset our environment, and make sure built files are available.
659 function make_for_snapshot ()
660 {
661 # Make sure it is clean
662 make_maintainer_clean
663
664 run_configure
665 make_target 'dist'
666 make_target 'distclean'
667
668 # We should have a configure, but no Makefile at the end of this exercise
669 assert_no_file 'Makefile'
670 assert_exec_file 'configure'
671
672 snapshot_check
673 }
674
675 function check_mingw ()
676 {
677 command_exists 'mingw64-configure'
678 ret=$?
679 if [ "$ret" -ne 0 ]; then
680 return 1
681 fi
682
683 command_exists 'mingw64-make'
684 ret=$?
685 if [ "$ret" -ne 0 ]; then
686 return 1
687 fi
688
689 return 0
690 }
691
692 function check_clang ()
693 {
694 command_exists 'clang'
695 ret=$?
696 if [ "$ret" -ne 0 ]; then
697 return 1
698 fi
699
700 return 0
701 }
702
703 function check_clang_analyzer ()
704 {
705 command_exists 'scan-build'
706 ret=$?
707 if [ "$ret" -ne 0 ]; then
708 return 1
709 fi
710
711 return 0
712 }
713
714 function make_skeleton ()
715 {
716 run_configure
717 ret=$?
718
719 if [ $ret -eq 0 ]; then
720 assert_file 'Makefile'
721
722 make_target 'all' 'warn'
723 ret=$?
724 if [ $ret -ne 0 ]; then
725 warn "$MAKE failed"
726 else
727 if [[ -n "$DISPLAY" ]]; then
728 if command_exists 'wine'; then
729 TESTS_ENVIRONMENT='wine'
730 fi
731 fi
732
733 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
734 make_target 'check' 'warn' || warn "$MAKE check failed"
735 ret=$?
736 fi
737 fi
738
739 if $jenkins_build_environment; then
740 make_target 'clean' 'warn'
741 fi
742 fi
743
744 return $ret
745 }
746
747 function make_for_mingw ()
748 {
749 if ! check_mingw; then
750 return 1
751 fi
752
753 # Make sure it is clean
754 if [ -f Makefile -o -f configure ]; then
755 make_maintainer_clean
756 fi
757
758 run_autoreconf
759
760 save_BUILD
761
762 CONFIGURE='mingw64-configure'
763 MAKE='mingw64-make'
764 CONFIGURE_ARGS='--enable-static --disable-shared'
765
766 make_skeleton
767 ret=$?
768
769 restore_BUILD
770
771 return $ret
772 }
773
774 function make_for_clang ()
775 {
776 if ! check_clang; then
777 return 1
778 fi
779
780 # Make sure it is clean
781 if [ -f Makefile -o -f configure ]; then
782 make_maintainer_clean
783 fi
784
785 run_autoreconf
786
787 save_BUILD
788
789 CC=clang CXX=clang++
790 export CC CXX
791
792 make_skeleton
793 ret=$?
794
795 make_target 'check'
796
797 restore_BUILD
798
799 return $ret
800 }
801
802 function make_for_clang_analyzer ()
803 {
804 if ! check_clang; then
805 return 1
806 fi
807
808 if ! check_clang_analyzer; then
809 die 'clang-analyzer was not found'
810 fi
811
812 # Make sure it is clean
813 if [ -f Makefile -o -f configure ]; then
814 make_maintainer_clean
815 fi
816
817 run_autoreconf
818
819 save_BUILD
820
821 CC=clang CXX=clang++
822 export CC CXX
823 CONFIGURE_ARGS='--enable-debug'
824
825 make_skeleton
826 ret=$?
827
828 make_target 'clean' 'warn'
829
830 scan-build -o clang-html make -j4 -k
831
832 restore_BUILD
833
834 return $ret
835 }
836
837 # If we are locally testing, we should make sure the environment is setup correctly
838 function check_for_jenkins ()
839 {
840 if ! $jenkins_build_environment; then
841 echo "Not inside of jenkins"
842
843 if [ -f 'configure' ]; then
844 make_maintainer_clean
845 fi
846
847 if $BOOTSTRAP_SNAPSHOT; then
848 make_for_snapshot
849 fi
850 fi
851 }
852
853 function make_universe ()
854 {
855 make_for_snapshot
856 make_valgrind
857 make_gdb
858 make_rpm
859 make_for_clang
860 make_for_clang_analyzer
861
862 if [ check_mingw -eq 0 ]; then
863 make_for_mingw
864 fi
865
866 make_distcheck
867 make_install_system
868 }
869
870 function make_for_continuus_integration ()
871 {
872 # Setup the environment if we are local
873 check_for_jenkins
874
875 # No matter then evironment, we should not have a Makefile at this point
876 assert_no_file 'Makefile'
877
878 # Platforms which require bootstrap should have some setup done before we hit this stage.
879 # If we are building locally, skip this step, unless we are just testing locally.
880 if $BOOTSTRAP_SNAPSHOT; then
881 snapshot_check
882 else
883 # If we didn't require a snapshot, then we should not have a configure
884 assert_no_file 'configure'
885
886 run_autoreconf
887 fi
888
889 assert_no_file 'Makefile' 'Programmer error, Makefile existed where build state should have been clean'
890
891 case $HOST_OS in
892 *-fedora-*)
893 run_configure
894
895 assert_exec_file 'configure'
896 assert_file 'Makefile'
897
898 # make rpm includes "make distcheck"
899 if [[ -f rpm.am ]]; then
900 make_target 'all'
901 make_rpm
902 elif [[ -d rpm ]]; then
903 make_target 'all'
904 make_rpm
905 else
906 make_distcheck
907 fi
908 ;;
909 *-precise-*)
910 run_configure
911
912 assert_exec_file 'configure'
913 assert_file 'Makefile'
914
915 make_distcheck
916 ;;
917 *-quantal-*)
918 run_configure
919
920 assert_exec_file 'configure'
921 assert_file 'Makefile'
922
923 make_distcheck
924 ;;
925 *-raring-*)
926 run_configure
927
928 assert_exec_file 'configure'
929 assert_file 'Makefile'
930
931 make_distcheck
932 ;;
933 *)
934 make_jenkins_default
935 ;;
936 esac
937
938 make_maintainer_clean
939
940 safe_popd
941 }
942
943 # The point to this test is to test bootstrap.sh itself
944 function self_test ()
945 {
946 # We start off with a clean env
947 make_maintainer_clean
948
949 eval "./bootstrap.sh jenkins" || die "failed 'jenkins'"
950 eval "./bootstrap.sh all" || die "failed 'all'"
951 eval "./bootstrap.sh gdb" || die "failed 'gdb'"
952 eval "./bootstrap.sh maintainer-clean" || die "failed 'maintainer-clean'"
953 }
954
955 function make_install_html ()
956 {
957 run_configure_if_required
958 assert_file 'configure'
959
960 make_target 'install-html'
961 }
962
963 function make_gdb ()
964 {
965 save_BUILD
966
967 if command_exists 'gdb'; then
968 run_configure_if_required
969
970 # Set ENV GDB_COMMAND
971 if [[ -z "$GDB_COMMAND" ]]; then
972 setup_gdb_command
973 fi
974
975 # If we don't have a configure, then most likely we will be missing libtool
976 assert_file 'configure'
977 if [[ -f 'libtool' ]]; then
978 TESTS_ENVIRONMENT="./libtool --mode=execute $GDB_COMMAND"
979 else
980 TESTS_ENVIRONMENT="$GDB_COMMAND"
981 fi
982
983 make_target 'check'
984
985 if [ -f 'gdb.txt' ]; then
986 rm 'gdb.txt'
987 fi
988
989 if [ -f '.gdb_history' ]; then
990 rm '.gdb_history'
991 fi
992
993 if $jenkins_build_environment; then
994 make_target 'clean'
995 fi
996 else
997 echo 'gdb was not present'
998 return 1
999 fi
1000
1001 restore_BUILD
1002 }
1003
1004 # $1 target to compile
1005 # $2 to die, or not to die, based on contents
1006 function make_target ()
1007 {
1008 if [ -z "$1" ]; then
1009 die "Programmer error, no target provided for make"
1010 fi
1011
1012 if [ ! -f 'Makefile' ]; then
1013 die "Programmer error, make was called before configure"
1014 run_configure
1015 fi
1016
1017 if [ -n "$TESTS_ENVIRONMENT" ]; then
1018 if $VERBOSE; then
1019 echo "TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT"
1020 fi
1021 fi
1022
1023 if [ -z "$MAKE" ]; then
1024 die "MAKE was not set"
1025 fi
1026
1027 # $2 represents error or warn
1028 run $MAKE $1
1029 ret=$?
1030
1031 if [ $ret -ne 0 ]; then
1032 if [ -n "$2" ]; then
1033 warn "Failed to execute $MAKE $1: $ret"
1034 else
1035 die "Failed to execute $MAKE $1: $ret"
1036 fi
1037 fi
1038
1039 return $ret
1040 }
1041
1042 function make_distcheck ()
1043 {
1044 make_target 'distcheck'
1045 }
1046
1047 function make_rpm ()
1048 {
1049 if command_exists 'rpmbuild'; then
1050 if [ -f 'rpm.am' -o -d 'rpm' ]; then
1051 run_configure_if_required
1052 make_target 'rpm'
1053
1054 if $jenkins_build_environment; then
1055 make_target 'clean'
1056 fi
1057
1058 fi
1059 fi
1060 }
1061
1062 function make_maintainer_clean ()
1063 {
1064 run_configure_if_required
1065 make_target 'maintainer-clean' 'no_error'
1066
1067 # Lets make sure we really cleaned up the environment
1068 assert_no_file 'Makefile'
1069 assert_no_file 'configure'
1070 assert_no_directory 'autom4te.cache'
1071 }
1072
1073 function make_check ()
1074 {
1075 make_target 'check'
1076 }
1077
1078 function make_jenkins_default ()
1079 {
1080 run_configure
1081 make_target 'all'
1082 }
1083
1084 function make_default ()
1085 {
1086 run_configure_if_required
1087 make_target 'all'
1088 }
1089
1090 function run_configure_if_required ()
1091 {
1092 run_autoreconf_if_required
1093
1094 if [ ! -f 'Makefile' ]; then
1095 run_configure
1096 fi
1097
1098 assert_file 'Makefile' 'configure did not produce a Makefile'
1099 }
1100
1101 function run_make_maintainer_clean_if_possible ()
1102 {
1103 if [ -f 'Makefile' ]; then
1104 make_maintainer_clean
1105 fi
1106 }
1107
1108 function run_autoreconf_if_required ()
1109 {
1110 if [ ! -x 'configure' ]; then
1111 run_autoreconf
1112 fi
1113
1114 assert_exec_file 'configure'
1115 bash -n configure
1116 }
1117
1118 function run_autoreconf ()
1119 {
1120 if [[ -z "$AUTORECONF" ]]; then
1121 die "Programmer error, tried to call run_autoreconf () but AUTORECONF was not set"
1122 fi
1123
1124 if test $use_libtool = 1; then
1125 assert $BOOTSTRAP_LIBTOOLIZE
1126 run $BOOTSTRAP_LIBTOOLIZE '--copy' '--install' '--force' || die "Cannot execute $BOOTSTRAP_LIBTOOLIZE"
1127 fi
1128
1129 run $AUTORECONF $AUTORECONF_ARGS || die "Cannot execute $AUTORECONF"
1130
1131 eval 'bash -n configure' || die "autoreconf generated a malformed configure"
1132 }
1133
1134 function run ()
1135 {
1136 if $VERBOSE; then
1137 echo "\`$@' $ARGS"
1138 fi
1139
1140 if [ -z "$1" ]; then
1141 return 127;
1142 fi
1143
1144 eval $@ $ARGS
1145 }
1146
1147 function parse_command_line_options ()
1148 {
1149 local SHORTOPTS=':apcmt:dvh'
1150
1151 nassert MAKE_TARGET
1152
1153 while getopts "$SHORTOPTS" opt; do
1154 case $opt in
1155 a) #--autoreconf
1156 AUTORECONF_OPTION=true
1157 MAKE_TARGET='autoreconf'
1158 ;;
1159 p) #--print-env
1160 PRINT_SETUP_OPTION=true
1161 ;;
1162 c) # --configure
1163 CONFIGURE_OPTION=true
1164 MAKE_TARGET='configure'
1165 ;;
1166 m) # maintainer-clean
1167 CLEAN_OPTION=true
1168 MAKE_TARGET='clean_op'
1169 ;;
1170 t) # target
1171 TARGET_OPTION=true
1172 TARGET_OPTION_ARG="$OPTARG"
1173 MAKE_TARGET="$OPTARG"
1174 ;;
1175 d) # debug
1176 DEBUG_OPTION=true
1177 enable_debug
1178 ;;
1179 h) # help
1180 echo "bootstrap.sh [options] optional_target ..."
1181 echo " -a # Just run autoreconf";
1182 echo " -p # Print ENV";
1183 echo " -c # Just run configure";
1184 echo " -m # Just run maintainer-clean";
1185 echo " -t # Make target";
1186 echo " -d # Enable debug";
1187 echo " -h # Show help";
1188 echo " -v # Be more verbose in output";
1189 exit
1190 ;;
1191 v) # verbose
1192 VERBOSE_OPTION=true
1193 VERBOSE=true
1194 ;;
1195 :)
1196 echo "Option -$OPTARG requires an argument." >&2
1197 exit 1
1198 ;;
1199 *)
1200 echo "$0: error - unrecognized option $1" 1>&2
1201 exit 1
1202 ;;
1203 esac
1204 done
1205
1206 shift $((OPTIND-1))
1207
1208 if [ -n "$1" ]; then
1209 MAKE_TARGET="$@"
1210 fi
1211 }
1212
1213 function determine_vcs ()
1214 {
1215 if [[ -d '.git' ]]; then
1216 VCS_CHECKOUT=git
1217 elif [[ -d '.bzr' ]]; then
1218 VCS_CHECKOUT=bzr
1219 elif [[ -d '.svn' ]]; then
1220 VCS_CHECKOUT=svn
1221 elif [[ -d '.hg' ]]; then
1222 VCS_CHECKOUT=hg
1223 else
1224 VCS_CHECKOUT=
1225 fi
1226
1227 if [[ -n "$VCS_CHECKOUT" ]]; then
1228 VERBOSE=true
1229 fi
1230 }
1231
1232 function require_libtoolise ()
1233 {
1234 use_libtool=0
1235 grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \
1236 && use_libtool=1
1237 grep '^[ ]*LT_INIT' configure.ac >/dev/null \
1238 && use_libtool=1
1239 }
1240
1241 function autoreconf_setup ()
1242 {
1243 # Set ENV MAKE in order to override "make"
1244 if [[ -z "$MAKE" ]]; then
1245 if command_exists 'gmake'; then
1246 MAKE=`type -p gmake`
1247 else
1248 if command_exists 'make'; then
1249 MAKE=`type -p make`
1250 fi
1251 fi
1252
1253 if [ "$VCS_CHECKOUT" ]; then
1254 if $DEBUG; then
1255 MAKE="$MAKE --warn-undefined-variables"
1256 fi
1257 fi
1258
1259 if $DEBUG; then
1260 MAKE="$MAKE -d"
1261 fi
1262 fi
1263
1264 if [[ -z "$GNU_BUILD_FLAGS" ]]; then
1265 GNU_BUILD_FLAGS="--install --force"
1266 fi
1267
1268 if $VERBOSE; then
1269 GNU_BUILD_FLAGS="$GNU_BUILD_FLAGS --verbose"
1270 fi
1271
1272 if [ -z "$ACLOCAL_PATH" ]; then
1273 ACLOCAL_PATH="/usr/local/share/aclocal $ACLOCAL_PATH"
1274 fi
1275
1276 if [[ -z "$WARNINGS" ]]; then
1277 if [[ -n "$VCS_CHECKOUT" ]]; then
1278 WARNINGS="all,error"
1279 else
1280 WARNINGS="all"
1281 fi
1282 fi
1283
1284 if test $use_libtool = 1; then
1285 if [[ -n "$LIBTOOLIZE" ]]; then
1286 BOOTSTRAP_LIBTOOLIZE=`type -p $LIBTOOLIZE`
1287
1288 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1289 echo "Couldn't find user supplied libtoolize, it is required"
1290 return 1
1291 fi
1292 else
1293 # If we are using OSX, we first check to see glibtoolize is available
1294 if [[ "$VENDOR_DISTRIBUTION" == "darwin" ]]; then
1295 BOOTSTRAP_LIBTOOLIZE=`type -p glibtoolize`
1296
1297 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1298 echo "Couldn't find glibtoolize, it is required on OSX"
1299 return 1
1300 fi
1301 else
1302 BOOTSTRAP_LIBTOOLIZE=`type -p libtoolize`
1303
1304 if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
1305 echo "Couldn't find libtoolize, it is required"
1306 return 1
1307 fi
1308 fi
1309 fi
1310
1311 if $VERBOSE; then
1312 LIBTOOLIZE_OPTIONS="--verbose $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
1313 fi
1314
1315 if $DEBUG; then
1316 LIBTOOLIZE_OPTIONS="--debug $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
1317 fi
1318
1319 # Here we set LIBTOOLIZE to true since we are going to invoke it via BOOTSTRAP_LIBTOOLIZE
1320 LIBTOOLIZE=true
1321 fi
1322
1323 # Test the ENV AUTOMAKE if it exists
1324 if [[ -n "$AUTOMAKE" ]]; then
1325 run $AUTOMAKE '--help' &> /dev/null || die "Failed to run AUTOMAKE:$AUTOMAKE"
1326 fi
1327
1328 # Test the ENV AUTOCONF if it exists
1329 if [[ -n "$AUTOCONF" ]]; then
1330 run $AUTOCONF '--help' &> /dev/null || die "Failed to run AUTOCONF:$AUTOCONF"
1331 fi
1332
1333 # Test the ENV AUTOHEADER if it exists
1334 if [[ -n "$AUTOHEADER" ]]; then
1335 run $AUTOHEADER '--help' &> /dev/null || die "Failed to run AUTOHEADER:$AUTOHEADER"
1336 fi
1337
1338 # Test the ENV AUTOM4TE if it exists
1339 if [[ -n "$AUTOM4TE" ]]; then
1340 run $AUTOM4TE '--help' &> /dev/null || die "Failed to run AUTOM4TE:$AUTOM4TE"
1341 fi
1342
1343 # Test the ENV AUTOHEADER if it exists, if not we add one and add --install
1344 if [[ -z "$ACLOCAL" ]]; then
1345 ACLOCAL="aclocal --install"
1346 fi
1347 run $ACLOCAL '--help' &> /dev/null || die "Failed to run ACLOCAL:$ACLOCAL"
1348
1349 if [[ -z "$AUTORECONF" ]]; then
1350 AUTORECONF=`type -p autoreconf`
1351
1352 if [[ -z "$AUTORECONF" ]]; then
1353 die "Couldn't find autoreconf"
1354 fi
1355
1356 if [[ -n "$GNU_BUILD_FLAGS" ]]; then
1357 AUTORECONF_ARGS="$GNU_BUILD_FLAGS"
1358 fi
1359 fi
1360
1361 run $AUTORECONF '--help' &> /dev/null || die "Failed to run AUTORECONF:$AUTORECONF"
1362 }
1363
1364 function print_setup ()
1365 {
1366 saved_debug_status=$DEBUG
1367 if $DEBUG; then
1368 disable_debug
1369 fi
1370
1371 echo '----------------------------------------------'
1372 echo 'BOOTSTRAP ENV'
1373 echo "AUTORECONF=$AUTORECONF"
1374 echo "HOST_OS=$HOST_OS"
1375 echo "VENDOR=$VENDOR"
1376 echo "VENDOR_DISTRIBUTION=$VENDOR_DISTRIBUTION"
1377 echo "VENDOR_RELEASE=$VENDOR_RELEASE"
1378
1379 echo "getopt()"
1380 if $AUTORECONF_OPTION; then
1381 echo "--autoreconf"
1382 fi
1383
1384 if $CLEAN_OPTION; then
1385 echo "--clean"
1386 fi
1387
1388 if $CONFIGURE_OPTION; then
1389 echo "--configure"
1390 fi
1391
1392 if $DEBUG_OPTION; then
1393 echo "--debug"
1394 fi
1395
1396 if $PRINT_SETUP_OPTION; then
1397 echo "--print-env"
1398 fi
1399
1400 if $TARGET_OPTION; then
1401 echo "--target=$TARGET_OPTION_ARG"
1402 fi
1403
1404 if $VERBOSE_OPTION; then
1405 echo "--verbose"
1406 fi
1407
1408 if [[ -n "$MAKE" ]]; then
1409 echo "MAKE=$MAKE"
1410 fi
1411
1412 if [[ -n "$MAKE_TARGET" ]]; then
1413 echo "MAKE_TARGET=$MAKE_TARGET"
1414 fi
1415
1416 if [[ -n "$PREFIX" ]]; then
1417 echo "PREFIX=$PREFIX"
1418 fi
1419
1420 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
1421 echo "TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT"
1422 fi
1423
1424 if [[ -n "$VCS_CHECKOUT" ]]; then
1425 echo "VCS_CHECKOUT=$VCS_CHECKOUT"
1426 fi
1427
1428 if $VERBOSE; then
1429 echo "VERBOSE=true"
1430 fi
1431
1432 if $DEBUG; then
1433 echo "DEBUG=true"
1434 fi
1435
1436 if [[ -n "$WARNINGS" ]]; then
1437 echo "WARNINGS=$WARNINGS"
1438 fi
1439 echo '----------------------------------------------'
1440
1441 if $saved_debug_status; then
1442 enable_debug
1443 fi
1444 }
1445
1446 function make_clean_option ()
1447 {
1448 run_configure_if_required
1449
1450 make_maintainer_clean
1451
1452 if [[ "$VCS_CHECKOUT" == 'git' ]]; then
1453 run "$VCS_CHECKOUT" status --ignored
1454 elif [[ -n "$VCS_CHECKOUT" ]]; then
1455 run "$VCS_CHECKOUT" status
1456 fi
1457 }
1458
1459 function make_for_autoreconf ()
1460 {
1461 if [ -f 'Makefile' ]; then
1462 make_maintainer_clean
1463 fi
1464
1465 run_autoreconf
1466
1467 assert_no_file 'Makefile'
1468 }
1469
1470 function check_make_target()
1471 {
1472 case $1 in
1473 'self')
1474 ;;
1475 'rpm')
1476 ;;
1477 'gdb')
1478 ;;
1479 'clean_op')
1480 ;;
1481 'autoreconf')
1482 ;;
1483 'install-system')
1484 ;;
1485 'configure')
1486 ;;
1487 'distcheck')
1488 ;;
1489 'check')
1490 ;;
1491 'snapshot')
1492 ;;
1493 'mingw')
1494 ;;
1495 'universe')
1496 ;;
1497 'valgrind')
1498 ;;
1499 'jenkins')
1500 ;;
1501 'distclean')
1502 ;;
1503 'maintainer-clean')
1504 ;;
1505 'install')
1506 ;;
1507 'all')
1508 ;;
1509 'make_default')
1510 ;;
1511 'clang')
1512 ;;
1513 'clang-analyzer')
1514 ;;
1515 test-*)
1516 ;;
1517 valgrind-*)
1518 ;;
1519 gdb-*)
1520 ;;
1521 'dist')
1522 ;;
1523 *)
1524 echo "Matched default"
1525 return 1
1526 ;;
1527 esac
1528
1529 return 0
1530 }
1531
1532 function bootstrap ()
1533 {
1534 determine_target_platform
1535
1536 determine_vcs
1537
1538 # Set up whatever we need to do to use autoreconf later
1539 require_libtoolise
1540 if ! autoreconf_setup; then
1541 return 1
1542 fi
1543
1544 if [ -z "$MAKE_TARGET" ]; then
1545 MAKE_TARGET="make_default"
1546 fi
1547
1548 if $PRINT_SETUP_OPTION -o $DEBUG; then
1549 echo
1550 print_setup
1551 echo
1552
1553 # Exit if all we were looking for were the currently used options
1554 if $PRINT_SETUP_OPTION; then
1555 exit
1556 fi
1557 fi
1558
1559 # Use OLD_TESTS_ENVIRONMENT for tracking the state of the variable
1560 local OLD_TESTS_ENVIRONMENT=
1561
1562 # Set ENV PREFIX in order to set --prefix for ./configure
1563 if [[ -n "$PREFIX" ]]; then
1564 PREFIX_ARG="--prefix=$PREFIX"
1565 fi
1566
1567 # We should always have a target by this point
1568 assert MAKE_TARGET
1569
1570 local MAKE_TARGET_ARRAY=($MAKE_TARGET)
1571
1572 for target in "${MAKE_TARGET_ARRAY[@]}"
1573 do
1574 # If we are running inside of Jenkins, we want to only run some of the possible tests
1575 if $jenkins_build_environment; then
1576 check_make_target $target
1577 ret=$?
1578 if [ $ret -ne 0 ]; then
1579 die "Unknown MAKE_TARGET option: $target"
1580 fi
1581 fi
1582
1583 local snapshot_run=false
1584 local valgrind_run=false
1585
1586 case $target in
1587 'self')
1588 self_test
1589 ;;
1590 'gdb')
1591 make_gdb
1592 ;;
1593 'install-html')
1594 make_install_html
1595 ;;
1596 'clean_op')
1597 make_clean_option
1598 ;;
1599 'autoreconf')
1600 make_for_autoreconf
1601 ;;
1602 'install-system')
1603 make_install_system
1604 ;;
1605 'configure')
1606 run_configure
1607 ;;
1608 'make_default')
1609 make_default
1610 ;;
1611 'clang')
1612 if ! check_clang; then
1613 die "clang was not found"
1614 fi
1615
1616 if ! make_for_clang; then
1617 die "Failed to build clang: $?"
1618 fi
1619 ;;
1620 'clang-analyzer')
1621 if ! check_clang_analyzer; then
1622 die "clang-analyzer was not found"
1623 fi
1624 if ! check_clang; then
1625 die "clang was not found"
1626 fi
1627
1628 if ! make_for_clang_analyzer; then
1629 die "Failed to build clang-analyzer: $?"
1630 fi
1631 ;;
1632 'mingw')
1633 if ! check_mingw; then
1634 die "mingw was not found"
1635 fi
1636
1637 if ! make_for_mingw; then
1638 die "Failed to build mingw: $?"
1639 fi
1640 ;;
1641 'snapshot')
1642 make_for_snapshot
1643 snapshot_run=true
1644 ;;
1645 'rpm')
1646 make_rpm
1647 ;;
1648 'darwin_malloc')
1649 make_darwin_malloc
1650 ;;
1651 'valgrind')
1652 make_maintainer_clean
1653 make_valgrind
1654 ;;
1655 'universe')
1656 make_universe
1657 ;;
1658 'jenkins')
1659 make_for_continuus_integration
1660 ;;
1661 *)
1662 run_configure_if_required
1663 make_target "$target"
1664 ;;
1665 esac
1666
1667 if $jenkins_build_environment; then
1668 if ! $snapshot_run; then
1669 run_make_maintainer_clean_if_possible
1670 fi
1671 fi
1672
1673 done
1674 }
1675
1676 function main ()
1677 {
1678 # Variables we export
1679 declare -x VCS_CHECKOUT=
1680
1681 # Variables we control globally
1682 local MAKE_TARGET=
1683 local CONFIGURE=
1684
1685 # Options for getopt
1686 local AUTORECONF_OPTION=false
1687 local CLEAN_OPTION=false
1688 local CONFIGURE_OPTION=false
1689 local DEBUG_OPTION=false
1690 local PRINT_SETUP_OPTION=false
1691 local TARGET_OPTION=false
1692 local TARGET_OPTION_ARG=
1693 local VERBOSE_OPTION=false
1694
1695 local OLD_CONFIGURE=
1696 local OLD_CONFIGURE_ARG=
1697 local OLD_PREFIX=
1698 local OLD_MAKE=
1699 local OLD_TESTS_ENVIRONMENT=
1700
1701 # If we call autoreconf on the platform or not
1702 local AUTORECONF_REBUILD_HOST=false
1703 local AUTORECONF_REBUILD=false
1704
1705 local -r top_srcdir=`pwd`
1706
1707 # Default configure
1708 if [ -z "$CONFIGURE" ]; then
1709 CONFIGURE="$top_srcdir/configure"
1710 fi
1711
1712
1713 # Variables for determine_target_platform () and rebuild_host_os ()
1714 # UNAME_MACHINE_ARCH= uname -m
1715 # VENDOR= apple, redhat, centos, canonical
1716 # VENDOR_RELEASE=
1717 # RHEL{rhel,Tikanga,Santiago}
1718 # Ubuntu{ubuntu,Lucid,Maverick,Natty,Oneiric,Precise,Quantal}
1719 # Fedora{fedora,Verne,Beefy}
1720 # OSX{osx,lion,snow,mountain}
1721 # VENDOR_DISTRIBUTION= darwin,fedora,rhel,ubuntu
1722 # UNAME_KERNEL= Linux, Darwin,...
1723 # UNAME_KERNEL_RELEASE= Linux, Darwin,...
1724 local UNAME_MACHINE_ARCH=unknown
1725 local VENDOR=unknown
1726 local VENDOR_RELEASE=unknown
1727 local VENDOR_DISTRIBUTION=unknown
1728 local UNAME_KERNEL=unknown
1729 local UNAME_KERNEL_RELEASE=unknown
1730 local HOST_OS=
1731
1732 rebuild_host_os no_output
1733
1734 parse_command_line_options $@
1735
1736 # If we are running under Jenkins we predetermine what tests we will run against
1737 # This MAKE_TARGET can be overridden by parse_command_line_options based MAKE_TARGET changes.
1738 # We don't want Jenkins overriding other variables, so we NULL them.
1739 if [ -z "$MAKE_TARGET" ]; then
1740 if $jenkins_build_environment; then
1741 if [[ -n "$label" ]]; then
1742 check_make_target $label
1743 if [ $? -eq 0 ]; then
1744 MAKE_TARGET="$label"
1745 fi
1746 fi
1747
1748 if [ -z "$MAKE_TARGET" ]; then
1749 MAKE_TARGET='jenkins'
1750 fi
1751 fi
1752 fi
1753
1754 bootstrap
1755
1756 jobs -l
1757 wait
1758
1759 exit 0
1760 }
1761
1762 function set_branch ()
1763 {
1764 if [ -z "$BRANCH" ]; then
1765 if [ -z "$CI_PROJECT_TEAM" ]; then
1766 die "Variable CI_PROJECT_TEAM has not been set"
1767 fi
1768 if [ -z "$PROJECT" ]; then
1769 die "Variable PROJECT has not been set"
1770 fi
1771 if [ -z "$BUILD_TAG" ]; then
1772 die "Variable BUILD_TAG has not been set"
1773 fi
1774
1775 BRANCH="lp:~$CI_PROJECT_TEAM/$PROJECT/$BUILD_TAG"
1776 export BRANCH
1777 fi
1778
1779 if [ -z "$BRANCH" ]; then
1780 die "Missing values required to build BRANCH variable."
1781 fi
1782 }
1783
1784 function merge ()
1785 {
1786 if [ -z "$VCS_CHECKOUT" ]; then
1787 die "Merges require VCS_CHECKOUT."
1788 fi
1789
1790 set_branch
1791
1792 if [[ "$VCS_CHECKOUT" == 'bzr' ]]; then
1793 if test -n "$BRANCH_TO_MERGE"; then
1794 bzr merge $BRANCH_TO_MERGE
1795 bzr commit --message="Merge $BRANCH_TO_MERGE Build: $BUILD_TAG" --unchanged
1796 fi
1797
1798 bzr push "$BRANCH"
1799 elif [[ -n "$VCS_CHECKOUT" ]]; then
1800 die "Merge attempt occured, current VCS setup does not support this"
1801 fi
1802 }
1803
1804 function enable_debug ()
1805 {
1806 if ! $DEBUG; then
1807 local caller_loc=`caller`
1808 if [ -n $1 ]; then
1809 echo "$caller_loc Enabling debug: $1"
1810 else
1811 echo "$caller_loc Enabling debug"
1812 fi
1813 set -x
1814 DEBUG=true
1815 fi
1816 }
1817
1818 function usage ()
1819 {
1820 cat << EOF
1821 Usage: $program_name [OPTION]..
1822
1823 Bootstrap this package from the checked-out sources, and optionally walk through CI run.
1824
1825 Options:
1826
1827 EOF
1828 }
1829
1830 function disable_debug ()
1831 {
1832 set +x
1833 DEBUG=true
1834 }
1835
1836 # Script begins here
1837
1838 program_name=$0
1839
1840 env_debug_enabled=false
1841 if [[ -n "$JENKINS_HOME" ]]; then
1842 declare -r jenkins_build_environment=true
1843 else
1844 declare -r jenkins_build_environment=false
1845 fi
1846
1847 export ACLOCAL
1848 export AUTOCONF
1849 export AUTOHEADER
1850 export AUTOM4TE
1851 export AUTOMAKE
1852 export AUTORECONF
1853 export CONFIGURE_ARG
1854 export DEBUG
1855 export GNU_BUILD_FLAGS
1856 export LIBTOOLIZE
1857 export LIBTOOLIZE_OPTIONS
1858 export MAKE
1859 export PREFIX_ARG
1860 export TESTS_ENVIRONMENT
1861 export VERBOSE
1862 export WARNINGS
1863
1864 case $OSTYPE in
1865 darwin*)
1866 export MallocGuardEdges
1867 export MallocErrorAbort
1868 export MallocScribble
1869 ;;
1870 esac
1871
1872 # We check for DEBUG twice, once before we source the config file, and once afterward
1873 env_debug_enabled=false
1874 if [[ -n "$DEBUG" ]]; then
1875 env_debug_enabled=true
1876 enable_debug
1877 print_setup
1878 fi
1879
1880 # Variables which only can be set by .bootstrap
1881 BOOTSTRAP_SNAPSHOT=false
1882 BOOTSTRAP_SNAPSHOT_CHECK=
1883
1884 if [ -f '.bootstrap' ]; then
1885 source '.bootstrap'
1886 fi
1887
1888 if $env_debug_enabled; then
1889 enable_debug
1890 else
1891 if [[ -n "$DEBUG" ]]; then
1892 enable_debug "Enabling DEBUG from '.bootstrap'"
1893 print_setup
1894 fi
1895 fi
1896
1897 # We do this in order to protect the case where DEBUG
1898 if ! $env_debug_enabled; then
1899 DEBUG=false
1900 fi
1901
1902 main $@