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