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