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