Update for version 1.0.13
[awesomized/libmemcached] / bootstrap.sh
1 #!/bin/bash
2 #
3 # Copyright (C) 2012 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 echo "Command not found: '$@'"
49 exit 127
50 }
51
52 die ()
53 {
54 echo "$BASH_SOURCE:$BASH_LINENO: $@" >&2
55 exit 1;
56 }
57
58 function assert ()
59 {
60 local param_name=\$"$1"
61 local param_value=`eval "expr \"$param_name\" "`
62
63 if [ -z "$param_value" ]; then
64 echo "$BASH_SOURCE:$BASH_LINENO: assert($param_name)" >&2
65 exit 1
66 fi
67 }
68
69 assert_file ()
70 {
71 if [ ! -f "$1" ]; then
72 echo "$BASH_SOURCE:$BASH_LINENO: assert($1) does not exist: $2" >&2
73 exit 1;
74 fi
75 }
76
77 assert_no_file ()
78 {
79 if [ -f "$1" ]; then
80 echo "$BASH_SOURCE:$BASH_LINENO: assert($1) file exists: $2" >&2
81 exit 1;
82 fi
83 }
84
85 assert_exec_file ()
86 {
87 if [ ! -f "$1" ]; then
88 echo "$BASH_SOURCE:$BASH_LINENO: assert($1) does not exist: $2" >&2
89 exit 1;
90 fi
91
92 if [ ! -x "$1" ]; then
93 echo "$BASH_SOURCE:$BASH_LINENO: assert($1) exists but is not executable: $2" >&2
94 exit 1;
95 fi
96 }
97
98 command_exists ()
99 {
100 type "$1" &> /dev/null ;
101 }
102
103 rebuild_host_os ()
104 {
105 HOST_OS="${UNAME_MACHINE_ARCH}-${VENDOR}-${VENDOR_DISTRIBUTION}-${VENDOR_RELEASE}-${UNAME_KERNEL}-${UNAME_KERNEL_RELEASE}"
106 if [ -z "$1" ]; then
107 if $VERBOSE; then
108 echo "HOST_OS=$HOST_OS"
109 fi
110 fi
111 }
112
113 # Valid values are: darwin,fedora,rhel,ubuntu
114 set_VENDOR_DISTRIBUTION ()
115 {
116 local dist=`echo "$1" | tr '[A-Z]' '[a-z]'`
117 case "$dist" in
118 darwin)
119 VENDOR_DISTRIBUTION='darwin'
120 ;;
121 fedora)
122 VENDOR_DISTRIBUTION='fedora'
123 ;;
124 rhel)
125 VENDOR_DISTRIBUTION='rhel'
126 ;;
127 ubuntu)
128 VENDOR_DISTRIBUTION='ubuntu'
129 ;;
130 opensuse)
131 VENDOR_DISTRIBUTION='opensuse'
132 ;;
133 *)
134 die "attempt to set an invalid VENDOR_DISTRIBUTION=$dist"
135 ;;
136 esac
137 }
138
139 set_VENDOR_RELEASE ()
140 {
141 local release=`echo "$1" | tr '[A-Z]' '[a-z]'`
142 case "$VENDOR_DISTRIBUTION" in
143 darwin)
144 VENDOR_RELEASE='mountain'
145 ;;
146 fedora)
147 VENDOR_RELEASE="$release"
148 ;;
149 rhel)
150 VENDOR_RELEASE="$release"
151 ;;
152 ubuntu)
153 VENDOR_RELEASE="$release"
154 ;;
155 opensuse)
156 VENDOR_RELEASE="$release"
157 ;;
158 unknown)
159 die "attempt to set VENDOR_RELEASE without setting VENDOR_DISTRIBUTION"
160 ;;
161 *)
162 die "attempt to set with an invalid VENDOR_DISTRIBUTION=$VENDOR_DISTRIBUTION"
163 ;;
164 esac
165 }
166
167
168 # Valid values are: apple, redhat, centos, canonical
169 set_VENDOR ()
170 {
171 local vendor=`echo "$1" | tr '[A-Z]' '[a-z]'`
172
173 case $vendor in
174 apple)
175 VENDOR='apple'
176 ;;
177 redhat)
178 VENDOR='redhat'
179 ;;
180 centos)
181 VENDOR='centos'
182 ;;
183 canonical)
184 VENDOR='canonical'
185 ;;
186 suse)
187 VENDOR='suse'
188 ;;
189 *)
190 die "An attempt was made to set an invalid VENDOR=$_vendor"
191 ;;
192 esac
193
194 set_VENDOR_DISTRIBUTION $2
195 set_VENDOR_RELEASE $3
196 }
197
198 determine_target_platform ()
199 {
200 UNAME_MACHINE_ARCH=`(uname -m) 2>/dev/null` || UNAME_MACHINE_ARCH=unknown
201 UNAME_KERNEL=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
202 UNAME_KERNEL_RELEASE=`(uname -r) 2>/dev/null` || UNAME_KERNEL_RELEASE=unknown
203
204 if [[ $(uname) == 'Darwin' ]]; then
205 set_VENDOR 'apple' 'darwin' 'mountain'
206 elif [[ -f '/etc/fedora-release' ]]; then
207 local fedora_version=`cat /etc/fedora-release | awk ' { print $3 } '`
208 set_VENDOR 'redhat' 'fedora' $fedora_version
209 if [[ "x$VENDOR_RELEASE" == 'x17' ]]; then
210 AUTORECONF_REBUILD_HOST=true
211 fi
212 elif [[ -f '/etc/centos-release' ]]; then
213 local centos_version=`cat /etc/centos-release | awk ' { print $7 } '`
214 set_VENDOR 'centos' 'rhel' $centos_version
215 elif [[ -f '/etc/SuSE-release' ]]; then
216 local suse_distribution=`head -1 /etc/SuSE-release | awk ' { print $1 } '`
217 local suse_version=`head -1 /etc/SuSE-release | awk ' { print $2 } '`
218 set_VENDOR 'suse' $suse_distribution $suse_version
219 elif [[ -f '/etc/redhat-release' ]]; then
220 local rhel_version=`cat /etc/redhat-release | awk ' { print $7 } '`
221 set_VENDOR 'redhat' 'rhel' $rhel_version
222 elif [[ -f '/etc/lsb-release' ]]; then
223 local debian_DISTRIB_ID=`cat /etc/lsb-release | grep DISTRIB_ID | awk -F= ' { print $2 } '`
224 local debian_version=`cat /etc/lsb-release | grep DISTRIB_CODENAME | awk -F= ' { print $2 } '`
225 set_VENDOR 'canonical' $debian_DISTRIB_ID $debian_version
226 if [[ "x$VENDOR_RELEASE" == 'xprecise' ]]; then
227 AUTORECONF_REBUILD_HOST=true
228 fi
229 fi
230
231 rebuild_host_os
232 }
233
234 run_configure ()
235 {
236 # We will run autoreconf if we are required
237 run_autoreconf_if_required
238
239 # We always begin at the root of our build
240 if [ ! popd ]; then
241 die "Programmer error, we entered run_configure with a stacked directory"
242 fi
243
244 local BUILD_DIR="$1"
245 if [[ -n "$BUILD_DIR" ]]; then
246 rm -r -f $BUILD_DIR
247 mkdir -p $BUILD_DIR
248 safe_pushd $BUILD_DIR
249 fi
250
251 # Arguments for configure
252 local CONFIGURE_ARG=
253
254 # Set ENV DEBUG in order to enable debugging
255 if $DEBUG; then
256 CONFIGURE_ARG='--enable-debug'
257 fi
258
259 # Set ENV ASSERT in order to enable assert
260 if [[ -n "$ASSERT" ]]; then
261 local ASSERT_ARG=
262 ASSERT_ARG='--enable-assert'
263 CONFIGURE_ARG="$ASSERT_ARG $CONFIGURE_ARG"
264 fi
265
266 # If we are executing on OSX use CLANG, otherwise only use it if we find it in the ENV
267 case $HOST_OS in
268 *-darwin-*)
269 CC=clang CXX=clang++ $top_srcdir/configure $CONFIGURE_ARG || die "Cannot execute CC=clang CXX=clang++ configure $CONFIGURE_ARG $PREFIX_ARG"
270 ;;
271 rhel-5*)
272 command_exists gcc44 || die "Could not locate gcc44"
273 CC=gcc44 CXX=gcc44 $top_srcdir/configure $CONFIGURE_ARG $PREFIX_ARG || die "Cannot execute CC=gcc44 CXX=gcc44 configure $CONFIGURE_ARG $PREFIX_ARG"
274 ;;
275 *)
276 $top_srcdir/configure $CONFIGURE_ARG $PREFIX_ARG || die "Cannot execute configure $CONFIGURE_ARG $PREFIX_ARG"
277 ;;
278 esac
279
280 if [ ! -f 'Makefile' ]; then
281 die "Programmer error, configure was run but no Makefile existed afterward"
282 fi
283 }
284
285 setup_gdb_command () {
286 GDB_TMPFILE=$(mktemp /tmp/gdb.XXXXXXXXXX)
287 echo 'set logging overwrite on' > $GDB_TMPFILE
288 echo 'set logging on' >> $GDB_TMPFILE
289 echo 'set environment LIBTEST_IN_GDB=1' >> $GDB_TMPFILE
290 echo 'run' >> $GDB_TMPFILE
291 echo 'thread apply all bt' >> $GDB_TMPFILE
292 echo 'quit' >> $GDB_TMPFILE
293 GDB_COMMAND="gdb -f -batch -x $GDB_TMPFILE"
294 }
295
296 setup_valgrind_command () {
297 VALGRIND_PROGRAM=`type -p valgrind`
298 if [[ -n "$VALGRIND_PROGRAM" ]]; then
299 VALGRIND_COMMAND="$VALGRIND_PROGRAM --error-exitcode=1 --leak-check=yes --show-reachable=yes --track-fds=yes --malloc-fill=A5 --free-fill=DE"
300 fi
301 }
302
303 push_PREFIX_ARG ()
304 {
305 if [[ -n "$PREFIX_ARG" ]]; then
306 OLD_PREFIX_ARG=$PREFIX_ARG
307 PREFIX_ARG=
308 fi
309
310 if [[ -n "$1" ]]; then
311 PREFIX_ARG="--prefix=$1"
312 fi
313 }
314
315 pop_PREFIX_ARG ()
316 {
317 if [[ -n "$OLD_PREFIX_ARG" ]]; then
318 PREFIX_ARG=$OLD_TESTS_ENVIRONMENT
319 OLD_PREFIX_ARG=
320 else
321 PREFIX_ARG=
322 fi
323 }
324
325 push_TESTS_ENVIRONMENT ()
326 {
327 if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
328 die "OLD_TESTS_ENVIRONMENT was set on push, programmer error!"
329 fi
330
331 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
332 OLD_TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT
333 TESTS_ENVIRONMENT=
334 fi
335 }
336
337 pop_TESTS_ENVIRONMENT ()
338 {
339 TESTS_ENVIRONMENT=
340 if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
341 TESTS_ENVIRONMENT=$OLD_TESTS_ENVIRONMENT
342 OLD_TESTS_ENVIRONMENT=
343 fi
344 }
345
346 safe_pushd ()
347 {
348 pushd $1 &> /dev/null ;
349
350 if $VERBOSE -a test -n "$BUILD_DIR"; then
351 echo "BUILD_DIR=$BUILD_DIR"
352 fi
353 }
354
355 safe_popd ()
356 {
357 local directory_to_delete=`pwd`
358 popd &> /dev/null ;
359 if [ $? -eq 0 ]; then
360 if [[ "$top_srcdir" == "$directory_to_delete" ]]; then
361 die "We almost deleted top_srcdir($top_srcdir), programmer error"
362 fi
363
364 rm -r -f "$directory_to_delete"
365 fi
366 }
367
368 make_valgrind ()
369 {
370 if [[ "$VENDOR_DISTRIBUTION" == 'darwin' ]]; then
371 make_darwin_malloc
372 return
373 fi
374
375 # If the env VALGRIND_COMMAND is set then we assume it is valid
376 local valgrind_was_set=false
377 if [[ -z "$VALGRIND_COMMAND" ]]; then
378 setup_valgrind_command
379 if [[ -n "$VALGRIND_COMMAND" ]]; then
380 valgrind_was_set=true
381 fi
382 else
383 valgrind_was_set=true
384 fi
385
386 # If valgrind_was_set is set to no we bail
387 if ! $valgrind_was_set; then
388 echo 'valgrind was not present'
389 return 1
390 fi
391
392 # If we are required to run configure, do so now
393 run_configure_if_required
394
395 push_TESTS_ENVIRONMENT
396
397 if [[ -f 'libtool' ]]; then
398 TESTS_ENVIRONMENT="$LIBTOOL_COMMAND $VALGRIND_COMMAND"
399 else
400 TESTS_ENVIRONMENT="$VALGRIND_COMMAND"
401 fi
402
403 make_target 'check' || return 1
404
405 pop_TESTS_ENVIRONMENT
406 }
407
408 make_install_system ()
409 {
410 local INSTALL_LOCATION=$(mktemp -d /tmp/XXXXXXXXXX)
411 push_PREFIX_ARG $INSTALL_LOCATION
412
413 if [ ! -d $INSTALL_LOCATION ] ; then
414 die "ASSERT temp directory not found '$INSTALL_LOCATION'"
415 fi
416
417 run_configure #install_buid_dir
418
419 push_TESTS_ENVIRONMENT
420
421 make_target 'install'
422
423 make_target 'installcheck'
424
425 make_target 'uninstall'
426
427 pop_TESTS_ENVIRONMENT
428 pop_PREFIX_ARG
429
430 rm -r -f $INSTALL_LOCATION
431 make 'distclean'
432
433 if [ -f 'Makefile' ]; then
434 die "ASSERT Makefile should not exist"
435 fi
436
437 safe_popd
438 }
439
440 make_darwin_malloc ()
441 {
442 run_configure_if_required
443
444 old_MallocGuardEdges=$MallocGuardEdges
445 MallocGuardEdges=1
446 old_MallocErrorAbort=$MallocErrorAbort
447 MallocErrorAbort=1
448 old_MallocScribble=$MallocScribble
449 MallocScribble=1
450
451 make_check
452
453 MallocGuardEdges=$old_MallocGuardEdges
454 MallocErrorAbort=$old_MallocErrorAbort
455 MallocScribble=$old_MallocScribble
456 }
457
458 snapshot_check ()
459 {
460 if [ -n "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then
461 assert_file "$BOOTSTRAP_SNAPSHOT_CHECK" 'snapshot check failed'
462 fi
463 }
464
465 # This will reset our environment, and make sure built files are available.
466 make_for_snapshot ()
467 {
468 # Make sure it is clean
469 make_maintainer_clean
470
471 run_configure
472 make_target 'dist'
473 make_target 'distclean'
474
475 # We should have a configure, but no Makefile at the end of this exercise
476 assert_no_file 'Makefile'
477 assert_exec_file 'configure'
478
479 snapshot_check
480 }
481
482 # If we are locally testing, we should make sure the environment is setup correctly
483 check_for_jenkins ()
484 {
485 if ! $jenkins_build_environment; then
486 echo "Not inside of jenkins"
487
488 if [ -f 'configure' ]; then
489 make_maintainer_clean
490 fi
491
492 if $BOOTSTRAP_SNAPSHOT; then
493 make_for_snapshot
494 fi
495 fi
496 }
497
498 make_for_continuus_integration ()
499 {
500 # Setup the environment if we are local
501 check_for_jenkins
502
503 # No matter then evironment, we should not have a Makefile at this point
504 assert_no_file 'Makefile'
505
506 # Platforms which require bootstrap should have some setup done before we hit this stage.
507 # If we are building locally, skip this step, unless we are just testing locally.
508 if $BOOTSTRAP_SNAPSHOT; then
509 snapshot_check
510 else
511 # If we didn't require a snapshot, then we should not have a configure
512 assert_no_file 'configure'
513
514 run_autoreconf
515 fi
516
517 assert_no_file 'Makefile' 'Programmer error, Makefile existed where build state should have been clean'
518
519 case $HOST_OS in
520 *-fedora-*)
521 run_configure
522
523 assert_exec_file 'configure'
524 assert_file 'Makefile'
525
526 # make rpm includes "make distcheck"
527 if [[ -f rpm.am ]]; then
528 make_rpm
529 elif [[ -d rpm ]]; then
530 make_rpm
531 else
532 make_distcheck
533 fi
534
535 assert_exec_file 'configure'
536 assert_file 'Makefile'
537
538 make_install_system
539 ;;
540 *-precise-*)
541 run_configure
542
543 assert_exec_file 'configure'
544 assert_file 'Makefile'
545
546 make_distcheck
547
548 assert_exec_file 'configure'
549 assert_file 'Makefile'
550
551 make_valgrind
552
553 assert_exec_file 'configure'
554 assert_file 'Makefile'
555
556 make_install_system
557 ;;
558 *)
559 run_configure
560 make_all
561 ;;
562 esac
563
564 make_maintainer_clean
565
566 safe_popd
567 }
568
569 make_gdb ()
570 {
571 run_configure_if_required
572
573 if command_exists gdb; then
574
575 push_TESTS_ENVIRONMENT
576
577 # Set ENV GDB_COMMAND
578 if [[ -z "$GDB_COMMAND" ]]; then
579 setup_gdb_command
580 fi
581
582 if [ -f 'libtool' ]; then
583 TESTS_ENVIRONMENT="$LIBTOOL_COMMAND $GDB_COMMAND"
584 else
585 TESTS_ENVIRONMENT="$GDB_COMMAND"
586 fi
587
588 make_target check
589
590 if [ -f 'gdb.txt' ]; then
591 rm 'gdb.txt'
592 fi
593
594 pop_TESTS_ENVIRONMENT
595
596 if [ -f '.gdb_history' ]; then
597 rm '.gdb_history'
598 fi
599 else
600 echo 'gdb was not present'
601 return 1
602 fi
603 }
604
605 # $1 target to compile
606 # $2 to die, or not to die, based on contents
607 function make_target ()
608 {
609 if [[ -z "$1" ]]; then
610 die "Programmer error, no target provided for make"
611 fi
612
613 if [ ! -f 'Makefile' ]; then
614 die "Programmer error, make was called before configure"
615 run_configure
616 fi
617
618 if test -n "$TESTS_ENVIRONMENT" -a $VERBOSE; then
619 echo "TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT"
620 fi
621
622 if [[ -z "$MAKE" ]]; then
623 die "MAKE was not set"
624 fi
625
626 if [[ -n "$2" ]]; then
627 run $MAKE $1 || return 1
628 else
629 run $MAKE $1 || die "Cannot execute $MAKE $1"
630 fi
631 }
632
633 make_distcheck ()
634 {
635 make_target 'distcheck'
636 }
637
638 make_rpm ()
639 {
640 make_target 'rpm'
641 }
642
643 make_maintainer_clean ()
644 {
645 run_configure_if_required
646 make_target 'maintainer-clean' 'no_error'
647 }
648
649 make_check ()
650 {
651 make_target 'check'
652 }
653
654 make_all ()
655 {
656 make_target 'all'
657 }
658
659 run_configure_if_required ()
660 {
661 run_autoreconf_if_required
662
663 if [ ! -f 'Makefile' ]; then
664 run_configure
665 fi
666
667 assert_file 'Makefile' 'configure did not produce a Makefile'
668 }
669
670 run_autoreconf_if_required ()
671 {
672 if [ ! -x 'configure' ]; then
673 run_autoreconf
674 fi
675
676 assert_exec_file 'configure'
677 }
678
679 run_autoreconf ()
680 {
681 if [[ -z "$AUTORECONF" ]]; then
682 die "Programmer error, tried to call run_autoreconf () but AUTORECONF was not set"
683 fi
684
685 run $AUTORECONF || die "Cannot execute $AUTORECONF"
686
687 eval 'bash -n configure' || die "autoreconf generated a malformed configure"
688 }
689
690 function run ()
691 {
692 if $VERBOSE; then
693 echo "\`$@' $ARGS"
694 fi
695
696 $@ $ARGS
697 }
698
699 parse_command_line_options ()
700 {
701 local SHORTOPTS=':apcmt:dv'
702
703 while getopts "$SHORTOPTS" opt; do
704 case $opt in
705 a) #--autoreconf
706 AUTORECONF_OPTION=true
707 MAKE_TARGET='autoreconf'
708 ;;
709 p) #--print-env
710 PRINT_SETUP_OPTION=true
711 ;;
712 c) # --configure
713 CONFIGURE_OPTION=true
714 MAKE_TARGET='configure'
715 ;;
716 m) # maintainer-clean
717 CLEAN_OPTION=true
718 MAKE_TARGET='clean_op'
719 ;;
720 t) # target
721 TARGET_OPTION=true
722 TARGET_OPTION_ARG="$OPTARG"
723 MAKE_TARGET="$OPTARG"
724 ;;
725 d) # debug
726 DEBUG_OPTION=true
727 enable_debug
728 ;;
729 v) # verbose
730 VERBOSE_OPTION=true
731 VERBOSE=true
732 ;;
733 :)
734 echo "Option -$OPTARG requires an argument." >&2
735 exit 1
736 ;;
737 *)
738 echo "$0: error - unrecognized option $1" 1>&2
739 exit 1
740 ;;
741 esac
742 done
743
744 if [ -n "$1" ]; then
745 MAKE_TARGET="$1"
746 fi
747 }
748
749 determine_vcs ()
750 {
751 if [[ -d '.git' ]]; then
752 VCS_CHECKOUT=git
753 elif [[ -d '.bzr' ]]; then
754 VCS_CHECKOUT=bzr
755 elif [[ -d '.svn' ]]; then
756 VCS_CHECKOUT=svn
757 elif [[ -d '.hg' ]]; then
758 VCS_CHECKOUT=hg
759 fi
760
761 if [[ -n "$VCS_CHECKOUT" ]]; then
762 VERBOSE=true
763 fi
764 }
765
766 autoreconf_setup ()
767 {
768 # Set ENV MAKE in order to override "make"
769 if [[ -z "$MAKE" ]]; then
770 if command_exists gmake; then
771 MAKE=`type -p gmake`
772 fi
773
774 if command_exists make; then
775 MAKE=`type -p make`
776 fi
777 fi
778
779 if [[ -z "$GNU_BUILD_FLAGS" ]]; then
780 GNU_BUILD_FLAGS="--install --force"
781 fi
782
783 if $VERBOSE; then
784 GNU_BUILD_FLAGS="$GNU_BUILD_FLAGS --verbose"
785 fi
786
787 if [[ -z "$WARNINGS" ]]; then
788 if [[ -n "$VCS_CHECKOUT" ]]; then
789 WARNINGS="all,error"
790 else
791 WARNINGS="all"
792 fi
793 fi
794
795 if [[ -z "$LIBTOOLIZE" ]]; then
796 # If we are using OSX, we first check to see glibtoolize is available
797 if [[ "$VENDOR_DISTRIBUTION" == "darwin" ]]; then
798 LIBTOOLIZE=`type -p glibtoolize`
799
800 if [[ -z "$LIBTOOLIZE" ]]; then
801 echo "Couldn't find glibtoolize, it is required on OSX"
802 fi
803 fi
804 fi
805
806 # Test the ENV AUTOMAKE if it exists
807 if [[ -n "$AUTOMAKE" ]]; then
808 run $AUTOMAKE '--help' &> /dev/null || die "Failed to run AUTOMAKE:$AUTOMAKE"
809 fi
810
811 # Test the ENV AUTOCONF if it exists
812 if [[ -n "$AUTOCONF" ]]; then
813 run $AUTOCONF '--help' &> /dev/null || die "Failed to run AUTOCONF:$AUTOCONF"
814 fi
815
816 # Test the ENV AUTOHEADER if it exists
817 if [[ -n "$AUTOHEADER" ]]; then
818 run $AUTOHEADER '--help' &> /dev/null || die "Failed to run AUTOHEADER:$AUTOHEADER"
819 fi
820
821 # Test the ENV AUTOM4TE if it exists
822 if [[ -n "$AUTOM4TE" ]]; then
823 run $AUTOM4TE '--help' &> /dev/null || die "Failed to run AUTOM4TE:$AUTOM4TE"
824 fi
825
826 if [[ -z "$AUTORECONF" ]]; then
827 AUTORECONF=`type -p autoreconf`
828
829 if [[ -z "$AUTORECONF" ]]; then
830 die "Couldn't find autoreconf"
831 fi
832
833 if [[ -n "$GNU_BUILD_FLAGS" ]]; then
834 AUTORECONF="$AUTORECONF $GNU_BUILD_FLAGS"
835 fi
836 fi
837
838 run $AUTORECONF '--help' &> /dev/null || die "Failed to run AUTORECONF:$AUTORECONF"
839 }
840
841 print_setup ()
842 {
843 saved_debug_status=$DEBUG
844 if $DEBUG; then
845 disable_debug
846 fi
847
848 echo '----------------------------------------------'
849 echo 'BOOTSTRAP ENV'
850 echo "AUTORECONF=$AUTORECONF"
851 echo "HOST_OS=$HOST_OS"
852
853 echo "getopt()"
854 if $AUTORECONF_OPTION; then
855 echo "--autoreconf"
856 fi
857
858 if $CLEAN_OPTION; then
859 echo "--clean"
860 fi
861
862 if $CONFIGURE_OPTION; then
863 echo "--configure"
864 fi
865
866 if $DEBUG_OPTION; then
867 echo "--debug"
868 fi
869
870 if $PRINT_SETUP_OPTION; then
871 echo "--print-env"
872 fi
873
874 if $TARGET_OPTION; then
875 echo "--target=$TARGET_OPTION_ARG"
876 fi
877
878 if $VERBOSE_OPTION; then
879 echo "--verbose"
880 fi
881
882 if [[ -n "$MAKE" ]]; then
883 echo "MAKE=$MAKE"
884 fi
885
886 if [[ -n "$MAKE_TARGET" ]]; then
887 echo "MAKE_TARGET=$MAKE_TARGET"
888 fi
889
890 if [[ -n "$PREFIX" ]]; then
891 echo "PREFIX=$PREFIX"
892 fi
893
894 if [[ -n "$TESTS_ENVIRONMENT" ]]; then
895 echo "TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT"
896 fi
897
898 if [[ -n "$VCS_CHECKOUT" ]]; then
899 echo "VCS_CHECKOUT=$VCS_CHECKOUT"
900 fi
901
902 if $VERBOSE; then
903 echo "VERBOSE=true"
904 fi
905
906 if $DEBUG; then
907 echo "DEBUG=true"
908 fi
909
910 if [[ -n "$WARNINGS" ]]; then
911 echo "WARNINGS=$WARNINGS"
912 fi
913 echo '----------------------------------------------'
914
915 if $saved_debug_status; then
916 enable_debug
917 fi
918 }
919
920 make_clean_option ()
921 {
922 run_configure_if_required
923
924 make_maintainer_clean
925
926 if [[ "$VCS_CHECKOUT" == 'git' ]]; then
927 run "$VCS_CHECKOUT" status --ignored
928 elif [[ -n "$VCS_CHECKOUT" ]]; then
929 run "$VCS_CHECKOUT" status
930 fi
931 }
932
933 make_for_autoreconf ()
934 {
935 if [ -f 'Makefile' ]; then
936 make_maintainer_clean
937 fi
938
939 run_autoreconf
940
941 assert_no_file 'Makefile'
942 }
943
944 check_make_target()
945 {
946 case $1 in
947 'gdb')
948 ;;
949 'clean_op')
950 ;;
951 'autoreconf')
952 ;;
953 'install-system')
954 ;;
955 'configure')
956 ;;
957 'snapshot')
958 ;;
959 'valgrind')
960 ;;
961 'jenkins')
962 ;;
963 'distclean')
964 ;;
965 'maintainer-clean')
966 ;;
967 'install')
968 ;;
969 'all')
970 ;;
971 'dist')
972 ;;
973 *)
974 die "Unknown MAKE_TARGET option: $1"
975 ;;
976 esac
977 }
978
979 bootstrap ()
980 {
981 determine_target_platform
982
983 determine_vcs
984
985 # Set up whatever we need to do to use autoreconf later
986 autoreconf_setup
987
988 if $PRINT_SETUP_OPTION -o $DEBUG; then
989 echo
990 print_setup
991 echo
992
993 # Exit if all we were looking for were the currently used options
994 if $PRINT_SETUP_OPTION; then
995 exit
996 fi
997 fi
998
999 # Setup LIBTOOL_COMMAND if we need it
1000 if [ -f 'libtool' ]; then
1001 LIBTOOL_COMMAND='./libtool --mode=execute'
1002 fi
1003
1004 # Use OLD_TESTS_ENVIRONMENT for tracking the state of the variable
1005 local OLD_TESTS_ENVIRONMENT=
1006
1007 # Set ENV PREFIX in order to set --prefix for ./configure
1008 if [[ -n "$PREFIX" ]]; then
1009 push_PREFIX_ARG $PREFIX
1010 fi
1011
1012 # Either we run a known target (or error), or we default to "all"
1013 if [[ -n "$MAKE_TARGET" ]]; then
1014
1015 # If we are running inside of Jenkins, we want to only run some of the possible tests
1016 if $jenkins_build_environment; then
1017 check_make_target $MAKE_TARGET
1018 fi
1019
1020 case $MAKE_TARGET in
1021 'gdb')
1022 make_gdb
1023 ;;
1024 'clean_op')
1025 make_clean_option
1026 ;;
1027 'autoreconf')
1028 make_for_autoreconf
1029 ;;
1030 'install-system')
1031 make_install_system
1032 ;;
1033 'configure')
1034 run_configure
1035 ;;
1036 'snapshot')
1037 make_for_snapshot
1038 ;;
1039 'valgrind')
1040 make_valgrind
1041 ;;
1042 'jenkins')
1043 make_for_continuus_integration
1044 ;;
1045 *)
1046 run_configure_if_required
1047 make_target $MAKE_TARGET
1048 ;;
1049 esac
1050 else
1051 run_configure_if_required
1052 make_all
1053 fi
1054 }
1055
1056 main ()
1057 {
1058 # Variables we export
1059 declare -x VCS_CHECKOUT=
1060
1061 # Variables we control globally
1062 local MAKE_TARGET=
1063
1064 # Options for getopt
1065 local AUTORECONF_OPTION=false
1066 local CLEAN_OPTION=false
1067 local CONFIGURE_OPTION=false
1068 local DEBUG_OPTION=false
1069 local PRINT_SETUP_OPTION=false
1070 local TARGET_OPTION=false
1071 local TARGET_OPTION_ARG=
1072 local VERBOSE_OPTION=false
1073
1074 # If we call autoreconf on the platform or not
1075 local AUTORECONF_REBUILD_HOST=false
1076 local AUTORECONF_REBUILD=false
1077
1078 local -r top_srcdir=`pwd`
1079
1080 # Variables for determine_target_platform () and rebuild_host_os ()
1081 # UNAME_MACHINE_ARCH= uname -m
1082 # VENDOR= apple, redhat, centos, canonical
1083 # VENDOR_RELEASE=
1084 # RHEL{rhel,Tikanga,Santiago}
1085 # Ubuntu{ubuntu,Lucid,Maverick,Natty,Oneiric,Precise,Quantal}
1086 # Fedora{fedora,Verne,Beefy}
1087 # OSX{osx,lion,snow,mountain}
1088 # VENDOR_DISTRIBUTION= darwin,fedora,rhel,ubuntu
1089 # UNAME_KERNEL= Linux, Darwin,...
1090 # UNAME_KERNEL_RELEASE= Linux, Darwin,...
1091 local UNAME_MACHINE_ARCH=unknown
1092 local VENDOR=unknown
1093 local VENDOR_RELEASE=unknown
1094 local VENDOR_DISTRIBUTION=unknown
1095 local UNAME_KERNEL=unknown
1096 local UNAME_KERNEL_RELEASE=unknown
1097 local HOST_OS=
1098
1099 rebuild_host_os no_output
1100
1101 # If we are running under Jenkins we predetermine what tests we will run against
1102 # This MAKE_TARGET can be overridden by parse_command_line_options based MAKE_TARGET changes.
1103 # We don't want Jenkins overriding other variables, so we NULL them.
1104 if $jenkins_build_environment; then
1105 MAKE_TARGET='jenkins'
1106 fi
1107
1108 parse_command_line_options $@
1109
1110 bootstrap
1111
1112 jobs -l
1113 wait
1114
1115 exit 0
1116 }
1117
1118 enable_debug ()
1119 {
1120 if ! $DEBUG; then
1121 local caller_loc=`caller`
1122 if [ -n $1 ]; then
1123 echo "$caller_loc Enabling debug: $1"
1124 else
1125 echo "$caller_loc Enabling debug"
1126 fi
1127 set -x
1128 DEBUG=true
1129 fi
1130 }
1131
1132 disable_debug ()
1133 {
1134 set +x
1135 DEBUG=true
1136 }
1137
1138 # Script begins here
1139
1140 env_debug_enabled=false
1141 if [[ -n "$JENKINS_HOME" ]]; then
1142 declare -r jenkins_build_environment=true
1143 else
1144 declare -r jenkins_build_environment=false
1145 fi
1146
1147 export AUTOCONF
1148 export AUTOHEADER
1149 export AUTOM4TE
1150 export AUTOMAKE
1151 export AUTORECONF
1152 export DEBUG
1153 export GNU_BUILD_FLAGS
1154 export MAKE
1155 export TESTS_ENVIRONMENT
1156 export VERBOSE
1157 export WARNINGS
1158
1159 case $OSTYPE in
1160 darwin*)
1161 export MallocGuardEdges
1162 export MallocErrorAbort
1163 export MallocScribble
1164 ;;
1165 esac
1166
1167 # We check for DEBUG twice, once before we source the config file, and once afterward
1168 env_debug_enabled=false
1169 if [[ -n "$DEBUG" ]]; then
1170 env_debug_enabled=true
1171 enable_debug
1172 print_setup
1173 fi
1174
1175 # Variables which only can be set by .bootstrap
1176 BOOTSTRAP_SNAPSHOT=false
1177 BOOTSTRAP_SNAPSHOT_CHECK=
1178
1179 if [ -f '.bootstrap' ]; then
1180 source '.bootstrap'
1181 fi
1182
1183 if $env_debug_enabled; then
1184 enable_debug
1185 else
1186 if [[ -n "$DEBUG" ]]; then
1187 enable_debug "Enabling DEBUG from '.bootstrap'"
1188 print_setup
1189 fi
1190 fi
1191
1192 # We do this in order to protect the case where DEBUG
1193 if ! $env_debug_enabled; then
1194 DEBUG=false
1195 fi
1196
1197 main $@