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