Update to latest config.guess and config.sub
[xapian.git] / bootstrap
blobe96f347ba0d11f88c92a4dfe328a57c5e01a95f7
1 #!/bin/sh
2 # bootstrap a xapian source tree obtained from git to produce a tree like
3 # you'd get from unpacking the results of "make dist"
5 copyright='
6 # Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018 Olly Betts
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; either version 2 of the
11 # License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
21 # USA
24 if [ "$1" = "--help" ] ; then
25 cat <<__END__
26 $0 [--ftp|--http] [--download-tools=(always|ifneeded|never)] [--fetch-url-command=CMD] [--clean] [MODULE...]
28 The default is to bootstrap all known modules. Any modules which have a
29 file called ".nobootstrap" in their top-level will be skipped.
30 __END__
31 exit 0
34 trap 'echo "Bootstrap failed"' EXIT
35 set -e
37 # The variables which specify the autotools to use.
38 autotools="AUTORECONF AUTOCONF AUTOHEADER AUTOM4TE AUTOMAKE ACLOCAL LIBTOOLIZE"
40 # Tool for downloading a file from a URL (currently wget, curl, and lwp-request
41 # are probed for in that order). Can be specified with --fetch-url-command.
42 FETCH_URL_TOOL=
44 check_checksum() {
45 # This function is expected to be used in 'if' so we can't rely on set -e
46 # being in effect here.
47 checksum_=$1
48 tarball_=$2
50 if [ -z "$SHA256SUM_TOOL" ] ; then
51 for SHA256SUM_TOOL in \
52 '${SHA256SUM-sha256sum} 2>/dev/null|cut -d\ -f1' \
53 '${SHASUM-shasum} -a256 2>/dev/null|cut -d\ -f1' \
54 '${OPENSSL-openssl} sha256 2>/dev/null|sed "s/.* //"' \
55 '' ; do
56 if [ -z "$SHA256SUM_TOOL" ] ; then
57 echo <<'END'
58 Need sha256sum or shasum or openssl installed to check SHA256 checksums.
59 Set environment variable SHA256SUM, SHASUM or OPENSSL if the tool isn't on
60 your PATH.
61 END
62 exit 1
64 # Sanity check by hashing empty input.
65 r=`:|eval "$SHA256SUM_TOOL"`
66 [ X"$r" != Xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 ] || break
67 done
69 r=`< $tarball_ eval "$SHA256SUM_TOOL"`
70 if [ X"$r" != X"$checksum_" ] ; then
71 echo "$tarball_: computed SHA256 checksum did NOT match"
72 echo "computed: $r with $SHA256SUM_TOOL"
73 echo "expected: $checksum_"
74 ls -l $tarball_
75 file $tarball_ || true
76 mv "$tarball_" "$tarball_.$r"
77 echo "Renamed $tarball_ to $tarball_.$r"
78 exit 1
82 check_at_least() {
83 # This function is expected to be used in 'if' so we can't rely on set -e
84 # being in effect here.
85 v1=$1
86 v2=$2
87 save_IFS=$IFS
88 IFS=.
89 set x $v1
90 for v in $v2 ; do
91 shift
92 if [ "$1" != "$v" ] ; then
93 if [ -z "$1" ] || [ "$1" -lt "$v" ] ; then
94 IFS=$save_IFS
95 return 1
97 break
99 done
100 IFS=$save_IFS
101 return 0
104 lazy_build() {
105 # This function is expected to be used in 'if' so we can't rely on set -e
106 # being in effect here.
107 package=$1
108 binary=$2
109 version=$3
111 case $download_tools in
112 always) ;;
113 never)
114 return 1
117 if [ -n $binary ] ; then
118 if [ -s "../patches/$package/series" ] ; then
119 echo "There are patches to apply to $package so it has to be built"
120 else
121 # Check if a new enough version is already installed.
122 version_installed=`"$binary" --version 2>/dev/null|sed '1,1 s/.* //p;d'`
123 if [ -n "$version_installed" ] ; then
124 # Fast track equality.
125 if [ "$version_installed" = "$version" ] ; then
126 echo "$binary $version_installed installed, exactly what's needed"
127 return 1
129 if check_at_least "$version_installed" "$version" ; then
130 echo "$binary $version_installed installed >= $version required"
131 return 1
137 esac
139 basename=$package-$version
140 ext=$4
141 checksum=$5
143 if [ "$ext" = "tar.xz" ] ; then
144 if [ -z "$xz_ok" ] ; then
145 if ${XZ-xz} --version > /dev/null 2>&1 ; then
146 xz_ok=1
147 else
148 xz_ok=0
151 if [ "$xz_ok" = 0 ] ; then
152 shift 2
153 ext=$4
154 checksum=$5
157 if [ "$ext" = "tar.bz2" ] ; then
158 if [ -z "$bz2_ok" ] ; then
159 # bzip2 --version doesn't exit with code 0 in upstream version (though
160 # Debian at least patch this bug), so use --help to check it.
161 if bzip2 --help > /dev/null 2>&1 ; then
162 bz2_ok=1
163 else
164 bz2_ok=0
167 if [ "$bz2_ok" = 0 ] ; then
168 shift 2
169 ext=$4
170 checksum=$5
173 tarball=$basename.$ext
174 case $basename in
175 *[24680][a-z]) basename=`echo "$basename"|sed 's/[a-z]$//'` ;;
176 esac
178 # Create the stamp file in INST so that rerunning bootstrap after
179 # "rm -rf INST" recovers nicely.
180 stamp=../INST/$package.stamp
181 out_of_date=
183 # Download the tarball if required.
184 if [ ! -f "$tarball" ] ; then
185 main_tarball=
186 main_worktree_dir=`git worktree list --porcelain|sed 's/^worktree //;q'`
187 if [ -n "$main_worktree_dir" ] ; then
188 main_tarball=$main_worktree_dir/BUILD/$tarball
190 if [ -n "$main_tarball" ] && [ -f "$main_tarball" ] ; then
191 # Don't re-download the tarball if the main worktree already has it.
192 tarball=$main_tarball
193 else
194 if [ -z "$FETCH_URL_TOOL" ] ; then
195 if ${WGET-wget} --version > /dev/null 2>&1 ; then
196 FETCH_URL_TOOL="${WGET-wget} -O-"
197 elif ${CURL-curl} --version > /dev/null 2>&1 || [ "$?" = 2 ] ; then
198 # curl --version exits with code 2 (~7.18.2) or 0 (7.35.0).
199 # -L is needed to follow HTTP redirects.
200 FETCH_URL_TOOL="${CURL-curl} -L"
201 elif ${LWP_REQUEST-lwp-request} -v > /dev/null 2>&1 || [ "$?" = 9 -o "$?" = 255 ] ; then
202 # lwp-request -v exits with code 9 (5.810) or 255 (6.03)
203 FETCH_URL_TOOL="${LWP_REQUEST-lwp-request} -mGET"
204 else
205 cat <<END >&2
206 Neither wget nor curl nor lwp-request found - install one of them or if already
207 installed, set WGET, CURL or LWP_REQUEST to the full path. Alternatively,
208 download $url
209 to directory `pwd`
210 then rerun this script.
212 exit 1
215 url="https://github.com/xapian/xapian-dev-deps/releases/download/current/$tarball"
216 case $basename in
217 file-*)
218 case $download_protocol in
219 ftp) url="ftp://ftp.astron.com/pub/file/$tarball" ;;
220 # We used to use http://fossies.org/ but that now redirects to https.
221 esac ;;
222 *[13579][a-z])
223 # GNU alpha release
224 case $download_protocol in
225 ftp) url="ftp://alpha.gnu.org/gnu/$package/$tarball" ;;
226 http) url="http://alpha.gnu.org/gnu/$package/$tarball" ;;
227 esac ;;
229 case $download_protocol in
230 ftp) url="ftp://ftp.gnu.org/gnu/$package/$tarball" ;;
231 http) url="http://ftpmirror.gnu.org/$package/$tarball" ;;
232 esac ;;
233 esac
234 case $download_protocol,$url in
235 http,https:*)
236 echo "warning: No http: link for $tarball available, using https:"
238 esac
240 # Keep the tarball under a quarantined name until we've verified its
241 # checksum. Once verified, if this is a linked git worktree we save
242 # the tarball in the main worktree's BUILD directory so that it can
243 # be shared with other worktrees.
244 if [ -n "$main_tarball" ] ; then
245 tarball=$main_tarball
247 quarantined_tarball=$tarball-quarantine.$$
248 rm -f "$quarantined_tarball"
249 echo "Downloading <$url>"
250 $FETCH_URL_TOOL "$url" > "$quarantined_tarball" || exit $?
251 check_checksum "$checksum" "$quarantined_tarball"
252 mv "$quarantined_tarball" "$tarball"
254 # Force a build.
255 out_of_date=force
259 if [ -z "$out_of_date" ] ; then
260 if [ -f "$stamp" ] ; then
261 # Check if the tarball or the patches we're applying have changed since
262 # the existing build.
263 out_of_date=`find "$tarball" ../patches/"$package"/* -newer "$stamp" -print 2> /dev/null||true`
264 else
265 out_of_date=force
269 if [ -n "$out_of_date" ] ; then
270 # Verify the tarball's checksum before building it. We now check at
271 # download time, but older versions of bootstrap didn't, and this also
272 # protects a user who manually downloads a tarball (which we suggest as an
273 # option if wget, curl, etc aren't found).
274 check_checksum "$checksum" "$tarball"
276 case `git worktree --list --porcelain|grep -c '^worktree '` in
277 1|"")
278 # Remove tarballs of other versions if there's only one worktree, or if
279 # using git < 2.5 (before worktrees were added).
280 for f in "$package"-* ; do
281 [ "$f" = "$tarball" ] || rm -rf "$f"
282 done
284 esac
286 case $ext in
287 tar.xz)
288 ${XZ-xz} -dc "$tarball"| tar xf - || exit $? ;;
289 tar.bz2)
290 bzip2 -dc "$tarball"| tar xf - || exit $? ;;
292 gzip -dc "$tarball"| tar xf - || exit $? ;;
293 esac
295 cd "$basename" || exit $?
297 series="../../patches/$package/series"
298 if [ ! -f "$series" ] ; then
299 cat <<END >&2
300 No patch series file 'patches/$package/series' - if there are no patches,
301 this should just be an empty file.
303 exit 1
305 if [ -s "$series" ] ; then
306 echo "Applying patches from $package/series"
307 sed -n 's/[ ]*\(#.*\)\?$//;/./p' "$series" | \
308 while read p ; do
309 echo "Applying patch $package/$p"
310 patch -p1 < "../../patches/$package/$p" || exit $?
311 done
314 echo "Configuring $package"
315 if test -n "$AUTOCONF" ; then
316 ./configure --prefix "$instdir" AUTOCONF="$AUTOCONF" || exit $?
317 else
318 ./configure --prefix "$instdir" || exit $?
320 echo "Building $package"
321 make || exit $?
322 echo "Installing $package"
323 make install || exit $?
324 echo "Done installing $package"
325 cd .. || exit $?
326 rm -rf "$basename" || exit $?
328 touch "$stamp" || exit $?
330 return 0
333 handle_git_external() {
334 path=$1
335 if [ ! -f "$path/.nobootstrap" ] ; then
336 rev=$2
337 url=$3
338 if [ ! -d "$path" ] ; then
339 git clone --no-checkout -- "$url" "$path"
340 elif (cd "$path" && git reflog "$rev" -- 2>/dev/null) ; then
341 : # Already have that revision locally
342 else
343 (cd "$path" && git fetch)
345 (cd "$path" && git checkout "$rev")
349 update_config() {
350 from=$1
351 to=$2
352 ts_from=`perl -ne '/^timestamp=(\W?)([-\d]+)$1/ and do {$_=$2;y/-//d;print;exit}' "$from"`
353 ts_to=`perl -ne '/^timestamp=(\W?)([-\d]+)$1/ and do {$_=$2;y/-//d;print;exit}' "$to"`
354 if [ "$ts_from" -gt "$ts_to" ] ; then
355 echo "Updating $to ($ts_to) with $from ($ts_from)"
356 # rm first in case the existing file is a symlink.
357 rm -f "$to"
358 cp "$from" "$to"
362 update_bootstrap_sticky_opts() {
363 arg=$1
364 case $arg in
365 *[^-A-Za-z0-9_+=:@/.,]*)
366 # Quote for the shell and escape $ to $$ for make.
367 bootstrap_sticky_opts="$bootstrap_sticky_opts '"`echo "$arg"|sed "s/'/'\\\\\\''/g;"'s/[$]/\\\\$\\\\$/g'`"'"
370 bootstrap_sticky_opts="$bootstrap_sticky_opts $arg"
372 esac
375 curdir=`pwd`
377 # cd to srcdir if we aren't already there.
378 srcdir=`echo "$0"|sed 's!/*[^/]*$!!'`
379 case $srcdir in
380 ""|.)
381 srcdir=. ;;
383 cd "$srcdir" ;;
384 esac
386 # Commit hash to pass to handle_git_external for swig.
387 swig_git_commit_hash=2c910e47ae788412b95e356c99cef5862808bf9a
389 # Commit hashes to use for common in omega and letor respectively:
390 omega_common_commit_hash=b310f9988f63cdc15b48323f9ac42f6b08c3a36c
391 letor_common_commit_hash=b310f9988f63cdc15b48323f9ac42f6b08c3a36c
393 if [ ! -r .git ] ; then
394 echo "$0: '.git' not found - this script should be run from a git repo cloned"
395 echo "from git://git.xapian.org/xapian or a mirror of it"
396 exit 1
399 for emptydir in xapian-applications/omega/m4 xapian-bindings/m4 xapian-letor/m4 ; do
400 if test -d "$emptydir" ; then
402 else
403 parent=`echo "$emptydir"|sed 's,/[^/]*$,,'`
404 if test -d "$parent" ; then
405 mkdir "$emptydir"
408 done
410 if [ -f .git ] ; then
411 : # Looks like we're in a git worktree.
412 else
413 if [ -f .git/info/exclude ] ; then
414 sed '/^\(swig\|xapian-applications\/omega\/common$\)/d' .git/info/exclude > .git/info/exclude~
415 else
416 [ -d .git/info ] || mkdir .git/info
418 cat <<END >> .git/info/exclude~
419 swig
420 xapian-applications/omega/common
421 xapian-letor/common
423 if [ -f .git/info/exclude ] &&
424 cmp -s .git/info/exclude~ .git/info/exclude ; then
425 rm .git/info/exclude~
426 else
427 mv .git/info/exclude~ .git/info/exclude
431 # If this tree is checked out from the github mirror, use the same access
432 # method for other things checked out from github (e.g. swig) so we avoid
433 # firewall issues. If there's no default remote, the git config command
434 # will exit with status 1, so ignore that failure.
435 origin_url=`git config remote.origin.url||:`
436 case $origin_url in
437 *[@/]github.com[:/]*)
438 github_base_url=`echo "X$origin_url"|sed 's/^X//;s!\([@/]github.com[:/]\).*!\1!'` ;;
440 github_base_url=https://github.com/ ;;
441 esac
442 swig_origin_url=${github_base_url}swig/swig.git
444 if [ -z "$XAPIAN_COMMON_CLONE_URL" ] ; then
445 xapian_common_clone_url=.
446 else
447 xapian_common_clone_url=$XAPIAN_COMMON_CLONE_URL
450 # Set to 'ftp' to use ftp URLs where available and 'http' to use unencrypted
451 # 'http'. By default we prefer https downloads as they are more likely to work
452 # through firewalls and better preserve user privacy.
453 download_protocol=
455 # Set to 'always' to always use a locally installed copy of the autotools
456 # or 'never' to never download.
458 # By default we check for locally installed versions and use them if they are
459 # new enough versions. But e.g. for building releases we want to use a known
460 # set of versions.
461 download_tools=ifneeded
463 # Save options which should be sticky for when "make" needs to rerun bootstrap.
464 # This should be empty or start with a space.
465 bootstrap_sticky_opts=
467 while [ "$#" -gt 0 ] ; do
468 case $1 in
469 --download-tools=*)
470 update_bootstrap_sticky_opts "$1"
471 download_tools=`echo "x$1"|sed 's/^x--download-tools=//'`
472 shift
473 continue
476 --download-tools)
477 update_bootstrap_sticky_opts "$1=$2"
478 download_tools=$2
479 shift 2
480 continue
483 --ftp)
484 bootstrap_sticky_opts="$bootstrap_sticky_opts $1"
485 download_protocol=ftp
486 shift
487 continue
490 --http)
491 bootstrap_sticky_opts="$bootstrap_sticky_opts $1"
492 download_protocol=http
493 shift
494 continue
497 --fetch-url-command=*)
498 update_bootstrap_sticky_opts "$1"
499 FETCH_URL_TOOL=`echo "x$1"|sed 's/^x--fetch-url-command=//'`
500 shift
501 continue
504 --fetch-url-command)
505 update_bootstrap_sticky_opts "$1=$2"
506 FETCH_URL_TOOL=$2
507 shift 2
508 continue
511 --clean)
512 # This probably shouldn't be sticky.
513 rm -rf INST
514 shift
515 continue
518 --without-autotools)
519 # This shouldn't be sticky.
520 echo "warning: Ignoring old option '$1' - new default is to use installed versions of tools if new enough. Use '--download-tools=never' to prevent ever downloading"
521 shift
522 continue
526 bootstrap_sticky_opts="$bootstrap_sticky_opts $1"
527 shift
528 break
532 echo "Unknown option '$1'" 1>&2
533 exit 1
537 break
539 esac
540 done
542 if [ "$#" -gt 0 ] ; then
543 for a in "$@" ; do
544 update_bootstrap_sticky_opts "$a"
545 done
548 case $download_tools in
549 always|ifneeded) ;;
550 never)
551 echo "warning: If stuff breaks with '--download-tools=never', you get to keep the pieces"
554 echo "Invalid --download-tools value '$download_tools'"
555 exit 1
557 esac
559 [ -d INST ] || mkdir INST
560 instdir=`pwd`/INST
562 [ -d BUILD ] || mkdir BUILD
563 cd BUILD
565 # The hex strings are SHA256 checksums for the preceding extension.
566 if lazy_build autoconf autoconf 2.69 \
567 tar.xz 64ebcec9f8ac5b2487125a86a7760d2591ac9e1d3dbd59489633f9de62a57684 \
568 tar.gz 954bd69b391edc12d6a4a51a2dd1476543da5c6bbf05a95b59dc0dd6fd4c2969 \
569 ; then
570 AUTOCONF=$instdir/bin/autoconf
571 export AUTOCONF
572 AUTORECONF=$instdir/bin/autoreconf
573 export AUTORECONF
574 AUTOHEADER=$instdir/bin/autoheader
575 export AUTOHEADER
576 AUTOM4TE=$instdir/bin/autom4te
577 export AUTOM4TE
579 if lazy_build automake automake 1.16.1 \
580 tar.xz 5d05bb38a23fd3312b10aea93840feec685bdf4a41146e78882848165d3ae921 \
581 tar.gz 608a97523f97db32f1f5d5615c98ca69326ced2054c9f82e65bade7fc4c9dea8 \
582 ; then
583 ACLOCAL=$instdir/bin/aclocal
584 export ACLOCAL
585 AUTOMAKE=$instdir/bin/automake
586 export AUTOMAKE
588 if lazy_build libtool libtool 2.4.6 \
589 tar.xz 7c87a8c2c8c0fc9cd5019e402bed4292462d00a718a7cd5f11218153bf28b26f \
590 tar.gz e3bd4d5d3d025a36c21dd6af7ea818a2afcd4dfc1ea5a17b39d7854bcd0c06e3 \
591 ; then
592 LIBTOOLIZE=$instdir/bin/libtoolize
593 export LIBTOOLIZE
594 libtool_aclocal=$instdir/share/aclocal
595 else
596 libtool_aclocal=`which libtool|sed 's!/bin/[^/]*$!/share/aclocal!'`
598 # If the aclocal we're using is in a different prefix to the libtool we're
599 # using, we probably need to tell aclocal where to look for our libtool's
600 # macros. Our directory may already by specified by other means, but it's
601 # fairly harmless to specify an explicit -I for a directory which is searched
602 # anyway - at worst it changes the search order.
603 if [ "`${ACLOCAL-aclocal} --print-ac-dir`" != "$libtool_aclocal" ] ; then
604 ACLOCAL="${ACLOCAL-aclocal} -I $libtool_aclocal"
605 export ACLOCAL
608 if [ "$1" = "--deps=libmagic" ] ; then
609 shift
610 lazy_build file '' 5.32 \
611 tar.gz 8639dc4d1b21e232285cd483604afc4a6ee810710e00e579dbe9591681722b50
614 cd ..
616 case `${LIBTOOLIZE-libtoolize} --version` in
618 echo "${LIBTOOLIZE-libtoolize} not found"
619 exit 1 ;;
620 "libtoolize (GNU libtool) 1.4.*")
621 echo "${LIBTOOLIZE-libtoolize} is from libtool 1.4 which is too old - libtool 2.2 is required."
622 echo "If you have both installed, set LIBTOOLIZE to point to the correct version."
623 exit 1 ;;
624 "libtoolize (GNU libtool) 1.5.*")
625 echo "${LIBTOOLIZE-libtoolize} is from libtool 1.5 which is too old - libtool 2.2 is required."
626 echo "If you have both installed, set LIBTOOLIZE to point to the correct version."
627 exit 1 ;;
628 esac
630 ACLOCAL="${ACLOCAL-aclocal} -I `pwd`/xapian-core/m4-macros"
631 export ACLOCAL
633 intree_swig=no
634 modules=
635 for module in ${@:-xapian-core xapian-applications/omega swig xapian-bindings} ; do
636 d=$module
637 if [ "$d" = swig ] ; then
638 if [ -f "xapian-bindings/.nobootstrap" ] ; then
639 # No point bootstrapping SWIG if we aren't going to use it.
640 echo "Skipping '$d' due to presence of 'xapian-bindings/.nobootstrap'."
641 continue
643 handle_git_external swig "$swig_git_commit_hash" "$swig_origin_url"
645 if [ -f "$d/configure.ac" -o -f "$d/configure.in" ] ; then
647 else
648 # Skip any directories we can't bootstrap.
649 continue
651 if [ -f "$d/.nobootstrap" ] ; then
652 # Report why to save head scratching when someone forgets they created
653 # a .nobootstrap file.
654 echo "Skipping '$module' due to presence of '$d/.nobootstrap'."
655 continue
657 case $d in
658 xapian-applications/omega|xapian-letor)
659 # If someone's created a directory for common, leave it be.
660 if [ -h "$d/common" ] || [ ! -d "$d/common" ] ; then
661 # Pick omega_common_commit_hash or letor_common_commit_hash:
662 var=`echo "$d"|sed 's!.*[-/]!!g'`_common_commit_hash
663 hash=`eval echo \\\$"$var"`
664 handle_git_external "$d/.common.git" "$hash" "$xapian_common_clone_url"
665 ln -sf .common.git/xapian-core/common "$d/common"
668 esac
670 echo "Bootstrapping \`$module'"
671 [ -f "$d/preautoreconf" ] && "$d/preautoreconf"
673 # If we have a custom INSTALL file, preserve it since autoreconf insists on
674 # replacing INSTALL with "generic installation instructions" when --force
675 # is used. Be careful to replace it if autoreconf fails.
676 if [ -f "$d/INSTALL" ] ; then
677 if grep 'generic installation instructions' "$d/INSTALL" >/dev/null 2>&1 ; then
679 else
680 mv -f "$d/INSTALL" "$d/INSTALL.preserved-by-bootstrap"
684 autoreconf_rc=
685 if [ swig = "$module" ] ; then
686 # SWIG provides its own bootstrapping script.
687 curdir=`pwd`
688 cd "$d"
689 ./autogen.sh || autoreconf_rc=$?
690 cd "$curdir"
691 # Use the uninstalled wrapper for the in-tree copy of SWIG.
692 intree_swig=yes
693 else
694 # Use --install as debian's autoconf wrapper uses 2.5X if it sees it
695 # (but it doesn't check for -i).
697 # Use --force so that we update files if autoconf, automake, or libtool
698 # has been upgraded.
699 ${AUTORECONF-autoreconf} --install --force "$d" || autoreconf_rc=$?
701 if [ -f "$d/INSTALL.preserved-by-bootstrap" ] ; then
702 mv -f "$d/INSTALL.preserved-by-bootstrap" "$d/INSTALL"
704 if [ -n "$autoreconf_rc" ] ; then
705 exit $autoreconf_rc
707 for f in config.guess config.sub ; do
708 if [ -f "$d/$f" ] ; then
709 update_config "config/$f" "$d/$f"
711 done
712 modules="$modules $module"
713 done
715 # Produce an absolute path to srcdir.
716 srcdir_abs=`pwd`
718 # Generate the top-level configure script.
719 rm -f configure.tmp
720 cat <<TOP_OF_CONFIGURE > configure.tmp
721 #!/bin/sh
722 # configure each submodule in a xapian source tree
723 # Generated by Xapian top-level bootstrap script.
724 #$copyright
725 trap 'echo "configure failed"' EXIT
726 set -e
728 srcdir="$srcdir_abs"
729 modules="$modules"
731 TOP_OF_CONFIGURE
733 cat <<'MIDDLE_OF_CONFIGURE' >> configure.tmp
734 # Produced escaped version of command suitable for pasting back into sh
735 cmd=$0
736 for a ; do
737 case $a in
738 *[^-A-Za-z0-9_+=:@/.,]*)
739 esc_a=`echo "$a"|sed 's!\([^-A-Za-z0-9_+=:@/.,]\)!\\\\\\1!g'`
740 cmd="$cmd $esc_a" ;;
742 cmd="$cmd $a" ;;
743 esac
744 done
746 here=`pwd`
747 MIDDLE_OF_CONFIGURE
749 vars=
750 if [ yes = "$intree_swig" ] ; then
751 # We want the path to SWIG to point into srcdir, which isn't known until
752 # configure-time, so we need to expand $here in configure.
753 vars=' SWIG=$here/swig/preinst-swig'
754 elif [ -n "$SWIG" ] ; then
755 # User specified SWIG in environment, e.g. with:
756 # SWIG=/opt/swig/bin/swig ./bootstrap
757 vars=" SWIG='"`echo "$val"|sed 's/\(['"\\'"']\)/\\\1/g'`"'"
759 for tool in $autotools ; do
760 eval "val=\$$tool"
761 if [ -n "$val" ] ; then
762 echo ': ${'"$tool='$val'"'}' >> configure.tmp
763 echo "export $tool" >> configure.tmp
764 vars="$vars $tool='"`echo "$val"|sed 's/\(['"\\'"']\)/\\\1/g'`"'"
766 done
767 if [ -n "$vars" ] ; then
768 # $vars will always have a leading space.
769 echo "set$vars "'"$@"' >> configure.tmp
772 cat <<'END_OF_CONFIGURE' >> configure.tmp
773 dirs=
774 revdirs=
775 XAPIAN_CONFIG=$here/xapian-core/xapian-config
776 for d in $modules ; do
777 if [ "$here" = "$srcdir" ] ; then
778 configure=./configure
779 configure_from_here=$d/configure
780 else
781 configure=$srcdir/$d/configure
782 configure_from_here=$configure
784 if [ -f "$configure_from_here" ] ; then
785 if [ -d "$d" ] ; then : ; else
786 case $d in
787 xapian-applications/*) [ -d xapian-applications ] || mkdir xapian-applications ;;
788 esac
789 mkdir "$d"
791 echo "Configuring \`$d'"
792 # Use a shared config.cache for speed and to save a bit of diskspace, but
793 # don't share it with SWIG just in case it manages to probe and cache
794 # different answers (e.g. because it uses a C compiler).
795 case $d in
796 swig)
797 case "$*" in
798 *--host=*|*--host" "*)
799 # We're cross-building, but SWIG needs to be built natively.
800 swig_configure_args=
801 skip=
802 for arg in "$@" ; do
803 if [ -n "$skip" ] ; then
804 skip=
805 continue
807 case $arg in
808 --host=*)
809 # Drop --host=xxx
810 continue ;;
811 --host)
812 # Drop --host xxx
813 skip=1
814 continue ;;
815 CC=*|CXX=*)
816 # Drop CC=xxx or CXX=xxx
817 continue ;;
818 CC_FOR_BUILD=*|CXX_FOR_BUILD=*)
819 # CC_FOR_BUILD=xxx -> CC=xxx; CXX_FOR_BUILD=xxx -> CXX=xxx
820 arg=`echo "$arg"|sed 's/_FOR_BUILD//'`
822 SWIG=*)
823 # Drop SWIG=xxx - not useful and could cause problems.
824 continue ;;
825 esac
826 swig_configure_args="$swig_configure_args "\'`echo "x$arg"|sed "s/^x//;s/'/'\\\\\\\\''/g"`\'
827 done
828 # Also handle compilers specified in environment variables. We can
829 # just reassign them unconditionally as CC and CXX are ignored if
830 # empty.
831 cd "$d" && CC=$CC_FOR_BUILD CXX=$CXX_FOR_BUILD "$configure" `eval echo $swig_configure_args`
834 cd "$d" && "$configure" ${1+"$@"}
836 esac
838 xapian-core)
839 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking --cache-file="$here/config.cache" ${1+"$@"}
841 xapian-applications/omega)
842 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking XAPIAN_CONFIG="$XAPIAN_CONFIG" CPPFLAGS="-I$srcdir/INST/include" LDFLAGS="-L$srcdir/INST/lib" ${1+"$@"}
845 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking --cache-file="$here/config.cache" XAPIAN_CONFIG="$XAPIAN_CONFIG" ${1+"$@"}
847 esac
848 cd "$here"
849 dirs="$dirs $d"
850 revdirs="$d $revdirs"
852 done
854 case " $* " in
855 *" --help "*|*" --version "*)
856 # Don't generate Makefile if --help or --version specified.
857 trap - EXIT
858 exit 0
860 esac
862 rm -f Makefile.tmp
863 cat <<EOF > Makefile.tmp
864 # Makefile generated by:
865 CONFIGURE_COMMAND := $cmd
867 if [ "$srcdir" != . ] ; then
868 cat <<EOF >> Makefile.tmp
870 VPATH = $srcdir
873 targets='all install uninstall install-strip clean distclean mostlyclean maintainer-clean dist check distcheck'
874 for target in $targets ; do
875 echo
876 echo "$target:"
877 case $target in
878 uninstall|*clean)
879 # When uninstalling or cleaning, process directories in reverse order, so
880 # that we process a directory after any directories which might use it.
881 list=$revdirs ;;
883 list=$dirs ;;
884 esac
885 for d in $list ; do
886 case $d,$target in
887 swig,install*|swig,uninstall)
888 # Nothing to do with swig when installing/uninstalling.
890 swig,dist|swig,check|swig,distcheck|swig,all)
891 # Need to ensure swig is built before "make dist", "make check", etc.
892 echo " cd $d && \$(MAKE)" ;;
893 swig,mostlyclean)
894 echo " cd $d && \$(MAKE) clean" ;;
895 xapian-bindings,distcheck)
896 # FIXME: distcheck doesn't currently work for xapian-bindings because
897 # xapian-core isn't installed.
898 echo " cd $d && \$(MAKE) check && \$(MAKE) dist" ;;
900 echo " cd $d && \$(MAKE) $target" ;;
901 esac
902 done
903 case $target in
904 distclean|maintainer-clean) echo " rm -f Makefile config.cache" ;;
905 esac
906 done >> Makefile.tmp
907 cat <<EOF >> Makefile.tmp
909 recheck:
910 \$(CONFIGURE_COMMAND)
912 Makefile: $srcdir/configure
913 \$(CONFIGURE_COMMAND)
915 $srcdir/configure: \\
916 END_OF_CONFIGURE
918 : > configure.tmp2
920 # We want to rerun bootstrap if a series file changes (patch added or removed)
921 # or an existing patch changes. Since we always have an series file (even if
922 # it is empty), this also handles us adding the first patch for something.
923 patches=
924 for d in patches/* ; do
925 series=$d/series
926 echo "$series:" >> configure.tmp2
927 cat << END
928 $series\\\\
930 sed -n 's/[ ]*\(#.*\)\?$//;/./p' "$series" |\
931 while read p ; do
932 patch=$d/$p
933 cat << END
934 $patch\\\\
936 # Because there's a pipeline, this is a subshell, so use a temporary file
937 # rather than a variable to compile a list of patches to use below.
938 echo "$patch:" >> configure.tmp2
939 done
940 done >> configure.tmp
942 cat <<'END_OF_CONFIGURE' >> configure.tmp
943 $srcdir/bootstrap
944 END_OF_CONFIGURE
945 echo " \$srcdir/bootstrap$bootstrap_sticky_opts" >> configure.tmp
946 cat <<'END_OF_CONFIGURE' >> configure.tmp
948 .PHONY: $targets recheck
950 # Dummy dependencies to allow removing patches we no longer need.
951 END_OF_CONFIGURE
953 cat configure.tmp2 >> configure.tmp
955 cat <<'END_OF_CONFIGURE' >> configure.tmp
957 mv -f Makefile.tmp Makefile
958 trap - EXIT
959 echo "Configured successfully - now run \"${MAKE-make}\""
960 END_OF_CONFIGURE
962 rm -f configure.tmp2
964 chmod +x configure.tmp
965 mv -f configure.tmp configure
967 # git defaults to showing 7 character abbreviated hashes if that's enough to be
968 # unique for a particular commit. But you can't paste these into trac as it
969 # needs at least 8 hex digits to recognise a hex string as a commit hash. You
970 # need 9 characters to be unique across all of Xapian at the time of writing,
971 # and 12 for the Linux kernel currently (a much larger number of objects than
972 # Xapian). 12 is a manageable length and decently future-proof, so let's use
973 # that.
974 core_abbrev_recommended=12
975 core_abbrev=`git config --get core.abbrev||:`
976 if [ -z "$core_abbrev" ] ; then
977 echo "*** Setting core.abbrev=$core_abbrev_recommended in repo config"
978 git config --local core.abbrev "$core_abbrev_recommended"
979 elif [ "$core_abbrev" -lt "$core_abbrev_recommended" ] ; then
980 if [ -z "`git config --local core.abbrev`" ] ; then
981 # Set globally to < $core_abbrev_recommended, override in this repo.
982 echo "*** Setting core.abbrev=$core_abbrev_recommended in repo config to override global core.abbrev=$core_abbrev"
983 git config --local core.abbrev "$core_abbrev_recommended"
984 else
985 # Just warn.
986 echo "warning: core.abbrev=$core_abbrev set on this repo, at least $core_abbrev_recommended is recommended"
990 trap - EXIT
991 echo "Bootstrapped successfully - now run \"$srcdir/configure\" and \"${MAKE-make}\""