Eliminate "byte" type for C++17 compatibility
[xapian.git] / bootstrap
blobc2d225488a6fd0636db277af91a539f9b0a42195
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 # Older git versions don't support "git worktree", so discard stderr and
187 # then we'll skip the worktree handling because main_worktree_dir will
188 # be empty.
189 main_worktree_dir=`git worktree list --porcelain 2>/dev/null|sed 's/^worktree //;q'`
190 if [ -n "$main_worktree_dir" ] ; then
191 # Canonicalise main_worktree_dir before comparing with pwd.
192 main_worktree_dir=`cd "$main_worktree_dir" && pwd`
193 if [ "$main_worktree_dir/BUILD" != "`pwd`" ] ; then
194 # If main_tarball is set non-empty, then we're a linked worktree.
195 main_tarball=$main_worktree_dir/BUILD/$tarball
198 if [ -n "$main_tarball" ] && [ -f "$main_tarball" ] ; then
199 # Don't re-download the tarball if the main worktree already has it.
200 tarball=$main_tarball
201 else
202 if [ -z "$FETCH_URL_TOOL" ] ; then
203 if ${WGET-wget} --version > /dev/null 2>&1 ; then
204 FETCH_URL_TOOL="${WGET-wget} -O-"
205 elif ${CURL-curl} --version > /dev/null 2>&1 || [ "$?" = 2 ] ; then
206 # curl --version exits with code 2 (~7.18.2) or 0 (7.35.0).
207 # -L is needed to follow HTTP redirects.
208 FETCH_URL_TOOL="${CURL-curl} -L"
209 elif ${LWP_REQUEST-lwp-request} -v > /dev/null 2>&1 || [ "$?" = 9 -o "$?" = 255 ] ; then
210 # lwp-request -v exits with code 9 (5.810) or 255 (6.03)
211 FETCH_URL_TOOL="${LWP_REQUEST-lwp-request} -mGET"
212 else
213 cat <<END >&2
214 Neither wget nor curl nor lwp-request found - install one of them or if already
215 installed, set WGET, CURL or LWP_REQUEST to the full path. Alternatively,
216 download $url
217 to directory `pwd`
218 then rerun this script.
220 exit 1
223 url="https://github.com/xapian/xapian-dev-deps/releases/download/current/$tarball"
224 case $basename in
225 file-*)
226 case $download_protocol in
227 ftp) url="ftp://ftp.astron.com/pub/file/$tarball" ;;
228 # We used to use http://fossies.org/ but that now redirects to https.
229 esac ;;
230 *[13579][a-z])
231 # GNU alpha release
232 case $download_protocol in
233 ftp) url="ftp://alpha.gnu.org/gnu/$package/$tarball" ;;
234 http) url="http://alpha.gnu.org/gnu/$package/$tarball" ;;
235 esac ;;
237 case $download_protocol in
238 ftp) url="ftp://ftp.gnu.org/gnu/$package/$tarball" ;;
239 http) url="http://ftpmirror.gnu.org/$package/$tarball" ;;
240 esac ;;
241 esac
242 case $download_protocol,$url in
243 http,https:*)
244 echo "warning: No http: link for $tarball available, using https:"
246 esac
248 # Keep the tarball under a quarantined name until we've verified its
249 # checksum. Once verified, if this is a linked git worktree we save
250 # the tarball in the main worktree's BUILD directory so that it can
251 # be shared with other worktrees.
252 if [ -n "$main_tarball" ] ; then
253 tarball=$main_tarball
255 quarantined_tarball=$tarball-quarantine.$$
256 rm -f "$quarantined_tarball"
257 echo "Downloading <$url>"
258 $FETCH_URL_TOOL "$url" > "$quarantined_tarball" || exit $?
259 check_checksum "$checksum" "$quarantined_tarball"
260 mv "$quarantined_tarball" "$tarball"
262 # Force a build.
263 out_of_date=force
267 if [ -z "$out_of_date" ] ; then
268 if [ -f "$stamp" ] ; then
269 # Check if the tarball or the patches we're applying have changed since
270 # the existing build.
271 out_of_date=`find "$tarball" ../patches/"$package"/* -newer "$stamp" -print 2> /dev/null||true`
272 else
273 out_of_date=force
277 if [ -n "$out_of_date" ] ; then
278 # Verify the tarball's checksum before building it. We now check at
279 # download time, but older versions of bootstrap didn't, and this also
280 # protects a user who manually downloads a tarball (which we suggest as an
281 # option if wget, curl, etc aren't found).
282 check_checksum "$checksum" "$tarball"
284 case $tarball in
285 */*) ;; # Only expire tarballs from the main worktree.
287 case `git worktree list --porcelain|grep -c '^worktree '` in
288 1|0)
289 # Remove tarballs of other versions if there's only one worktree, or if
290 # using git < 2.5 (before worktrees were added).
291 for f in "$package"-* ; do
292 [ "$f" = "$tarball" ] || rm -rf "$f"
293 done
295 esac
297 esac
299 case $ext in
300 tar.xz)
301 ${XZ-xz} -dc "$tarball"| tar xf - || exit $? ;;
302 tar.bz2)
303 bzip2 -dc "$tarball"| tar xf - || exit $? ;;
305 gzip -dc "$tarball"| tar xf - || exit $? ;;
306 esac
308 cd "$basename" || exit $?
310 series="../../patches/$package/series"
311 if [ ! -f "$series" ] ; then
312 cat <<END >&2
313 No patch series file 'patches/$package/series' - if there are no patches,
314 this should just be an empty file.
316 exit 1
318 if [ -s "$series" ] ; then
319 echo "Applying patches from $package/series"
320 sed -n 's/[ ]*\(#.*\)\?$//;/./p' "$series" | \
321 while read p ; do
322 echo "Applying patch $package/$p"
323 patch -p1 < "../../patches/$package/$p" || exit $?
324 done
327 echo "Configuring $package"
328 if test -n "$AUTOCONF" ; then
329 ./configure --prefix "$instdir" AUTOCONF="$AUTOCONF" || exit $?
330 else
331 ./configure --prefix "$instdir" || exit $?
333 echo "Building $package"
334 make || exit $?
335 echo "Installing $package"
336 make install || exit $?
337 echo "Done installing $package"
338 cd .. || exit $?
339 rm -rf "$basename" || exit $?
341 touch "$stamp" || exit $?
343 return 0
346 handle_git_external() {
347 path=$1
348 if [ ! -f "$path/.nobootstrap" ] ; then
349 rev=$2
350 url=$3
351 if [ ! -d "$path" ] ; then
352 git clone --no-checkout -- "$url" "$path"
353 elif (cd "$path" && git reflog "$rev" -- 2>/dev/null) ; then
354 : # Already have that revision locally
355 else
356 (cd "$path" && git fetch)
358 (cd "$path" && git checkout "$rev")
362 update_config() {
363 from=$1
364 to=$2
365 ts_from=`perl -ne '/^timestamp=(\W?)([-\d]+)$1/ and do {$_=$2;y/-//d;print;exit}' "$from"`
366 ts_to=`perl -ne '/^timestamp=(\W?)([-\d]+)$1/ and do {$_=$2;y/-//d;print;exit}' "$to"`
367 if [ "$ts_from" -gt "$ts_to" ] ; then
368 echo "Updating $to ($ts_to) with $from ($ts_from)"
369 # rm first in case the existing file is a symlink.
370 rm -f "$to"
371 cp "$from" "$to"
375 update_bootstrap_sticky_opts() {
376 arg=$1
377 case $arg in
378 *[^-A-Za-z0-9_+=:@/.,]*)
379 # Quote for the shell and escape $ to $$ for make.
380 bootstrap_sticky_opts="$bootstrap_sticky_opts '"`echo "$arg"|sed "s/'/'\\\\\\''/g;"'s/[$]/\\\\$\\\\$/g'`"'"
383 bootstrap_sticky_opts="$bootstrap_sticky_opts $arg"
385 esac
388 curdir=`pwd`
390 # cd to srcdir if we aren't already there.
391 srcdir=`echo "$0"|sed 's!/*[^/]*$!!'`
392 case $srcdir in
393 ""|.)
394 srcdir=. ;;
396 cd "$srcdir" ;;
397 esac
399 # Commit hash to pass to handle_git_external for swig.
400 swig_git_commit_hash=2c910e47ae788412b95e356c99cef5862808bf9a
402 # Commit hashes to use for common in omega and letor respectively:
403 omega_common_commit_hash=b310f9988f63cdc15b48323f9ac42f6b08c3a36c
404 letor_common_commit_hash=b310f9988f63cdc15b48323f9ac42f6b08c3a36c
406 if [ ! -r .git ] ; then
407 echo "$0: '.git' not found - this script should be run from a git repo cloned"
408 echo "from git://git.xapian.org/xapian or a mirror of it"
409 exit 1
412 for emptydir in xapian-applications/omega/m4 xapian-bindings/m4 xapian-letor/m4 ; do
413 if test -d "$emptydir" ; then
415 else
416 parent=`echo "$emptydir"|sed 's,/[^/]*$,,'`
417 if test -d "$parent" ; then
418 mkdir "$emptydir"
421 done
423 if [ -f .git ] ; then
424 : # Looks like we're in a git worktree.
425 else
426 if [ -f .git/info/exclude ] ; then
427 sed '/^\(swig\|xapian-applications\/omega\/common$\)/d' .git/info/exclude > .git/info/exclude~
428 else
429 [ -d .git/info ] || mkdir .git/info
431 cat <<END >> .git/info/exclude~
432 swig
433 xapian-applications/omega/common
434 xapian-letor/common
436 if [ -f .git/info/exclude ] &&
437 cmp -s .git/info/exclude~ .git/info/exclude ; then
438 rm .git/info/exclude~
439 else
440 mv .git/info/exclude~ .git/info/exclude
444 # If this tree is checked out from the github mirror, use the same access
445 # method for other things checked out from github (e.g. swig) so we avoid
446 # firewall issues. If there's no default remote, the git config command
447 # will exit with status 1, so ignore that failure.
448 origin_url=`git config remote.origin.url||:`
449 case $origin_url in
450 *[@/]github.com[:/]*)
451 github_base_url=`echo "X$origin_url"|sed 's/^X//;s!\([@/]github.com[:/]\).*!\1!'` ;;
453 github_base_url=https://github.com/ ;;
454 esac
455 swig_origin_url=${github_base_url}swig/swig.git
457 if [ -z "$XAPIAN_COMMON_CLONE_URL" ] ; then
458 xapian_common_clone_url=.
459 else
460 xapian_common_clone_url=$XAPIAN_COMMON_CLONE_URL
463 # Set to 'ftp' to use ftp URLs where available and 'http' to use unencrypted
464 # 'http'. By default we prefer https downloads as they are more likely to work
465 # through firewalls and better preserve user privacy.
466 download_protocol=
468 # Set to 'always' to always use a locally installed copy of the autotools
469 # or 'never' to never download.
471 # By default we check for locally installed versions and use them if they are
472 # new enough versions. But e.g. for building releases we want to use a known
473 # set of versions.
474 download_tools=ifneeded
476 # Save options which should be sticky for when "make" needs to rerun bootstrap.
477 # This should be empty or start with a space.
478 bootstrap_sticky_opts=
480 while [ "$#" -gt 0 ] ; do
481 case $1 in
482 --download-tools=*)
483 update_bootstrap_sticky_opts "$1"
484 download_tools=`echo "x$1"|sed 's/^x--download-tools=//'`
485 shift
486 continue
489 --download-tools)
490 update_bootstrap_sticky_opts "$1=$2"
491 download_tools=$2
492 shift 2
493 continue
496 --ftp)
497 bootstrap_sticky_opts="$bootstrap_sticky_opts $1"
498 download_protocol=ftp
499 shift
500 continue
503 --http)
504 bootstrap_sticky_opts="$bootstrap_sticky_opts $1"
505 download_protocol=http
506 shift
507 continue
510 --fetch-url-command=*)
511 update_bootstrap_sticky_opts "$1"
512 FETCH_URL_TOOL=`echo "x$1"|sed 's/^x--fetch-url-command=//'`
513 shift
514 continue
517 --fetch-url-command)
518 update_bootstrap_sticky_opts "$1=$2"
519 FETCH_URL_TOOL=$2
520 shift 2
521 continue
524 --clean)
525 # This probably shouldn't be sticky.
526 rm -rf INST
527 shift
528 continue
531 --without-autotools)
532 # This shouldn't be sticky.
533 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"
534 shift
535 continue
539 bootstrap_sticky_opts="$bootstrap_sticky_opts $1"
540 shift
541 break
545 echo "Unknown option '$1'" 1>&2
546 exit 1
550 break
552 esac
553 done
555 if [ "$#" -gt 0 ] ; then
556 for a in "$@" ; do
557 update_bootstrap_sticky_opts "$a"
558 done
561 case $download_tools in
562 always|ifneeded) ;;
563 never)
564 echo "warning: If stuff breaks with '--download-tools=never', you get to keep the pieces"
567 echo "Invalid --download-tools value '$download_tools'"
568 exit 1
570 esac
572 [ -d INST ] || mkdir INST
573 instdir=`pwd`/INST
575 [ -d BUILD ] || mkdir BUILD
576 cd BUILD
578 # The hex strings are SHA256 checksums for the preceding extension.
579 if lazy_build autoconf autoconf 2.69 \
580 tar.xz 64ebcec9f8ac5b2487125a86a7760d2591ac9e1d3dbd59489633f9de62a57684 \
581 tar.gz 954bd69b391edc12d6a4a51a2dd1476543da5c6bbf05a95b59dc0dd6fd4c2969 \
582 ; then
583 AUTOCONF=$instdir/bin/autoconf
584 export AUTOCONF
585 AUTORECONF=$instdir/bin/autoreconf
586 export AUTORECONF
587 AUTOHEADER=$instdir/bin/autoheader
588 export AUTOHEADER
589 AUTOM4TE=$instdir/bin/autom4te
590 export AUTOM4TE
592 if lazy_build automake automake 1.16.1 \
593 tar.xz 5d05bb38a23fd3312b10aea93840feec685bdf4a41146e78882848165d3ae921 \
594 tar.gz 608a97523f97db32f1f5d5615c98ca69326ced2054c9f82e65bade7fc4c9dea8 \
595 ; then
596 ACLOCAL=$instdir/bin/aclocal
597 export ACLOCAL
598 AUTOMAKE=$instdir/bin/automake
599 export AUTOMAKE
601 if lazy_build libtool libtool 2.4.6 \
602 tar.xz 7c87a8c2c8c0fc9cd5019e402bed4292462d00a718a7cd5f11218153bf28b26f \
603 tar.gz e3bd4d5d3d025a36c21dd6af7ea818a2afcd4dfc1ea5a17b39d7854bcd0c06e3 \
604 ; then
605 LIBTOOLIZE=$instdir/bin/libtoolize
606 export LIBTOOLIZE
607 libtool_aclocal=$instdir/share/aclocal
608 else
609 libtool_aclocal=`which libtool|sed 's!/bin/[^/]*$!/share/aclocal!'`
611 # If the aclocal we're using is in a different prefix to the libtool we're
612 # using, we probably need to tell aclocal where to look for our libtool's
613 # macros. Our directory may already by specified by other means, but it's
614 # fairly harmless to specify an explicit -I for a directory which is searched
615 # anyway - at worst it changes the search order.
616 if [ "`${ACLOCAL-aclocal} --print-ac-dir`" != "$libtool_aclocal" ] ; then
617 ACLOCAL="${ACLOCAL-aclocal} -I $libtool_aclocal"
618 export ACLOCAL
621 if [ "$1" = "--deps=libmagic" ] ; then
622 shift
623 lazy_build file '' 5.32 \
624 tar.gz 8639dc4d1b21e232285cd483604afc4a6ee810710e00e579dbe9591681722b50
627 cd ..
629 case `${LIBTOOLIZE-libtoolize} --version` in
631 echo "${LIBTOOLIZE-libtoolize} not found"
632 exit 1 ;;
633 "libtoolize (GNU libtool) 1.4.*")
634 echo "${LIBTOOLIZE-libtoolize} is from libtool 1.4 which is too old - libtool 2.2 is required."
635 echo "If you have both installed, set LIBTOOLIZE to point to the correct version."
636 exit 1 ;;
637 "libtoolize (GNU libtool) 1.5.*")
638 echo "${LIBTOOLIZE-libtoolize} is from libtool 1.5 which is too old - libtool 2.2 is required."
639 echo "If you have both installed, set LIBTOOLIZE to point to the correct version."
640 exit 1 ;;
641 esac
643 ACLOCAL="${ACLOCAL-aclocal} -I `pwd`/xapian-core/m4-macros"
644 export ACLOCAL
646 intree_swig=no
647 modules=
648 for module in ${@:-xapian-core xapian-applications/omega swig xapian-bindings} ; do
649 d=$module
650 if [ "$d" = swig ] ; then
651 if [ -f "xapian-bindings/.nobootstrap" ] ; then
652 # No point bootstrapping SWIG if we aren't going to use it.
653 echo "Skipping '$d' due to presence of 'xapian-bindings/.nobootstrap'."
654 continue
656 handle_git_external swig "$swig_git_commit_hash" "$swig_origin_url"
658 if [ -f "$d/configure.ac" -o -f "$d/configure.in" ] ; then
660 else
661 # Skip any directories we can't bootstrap.
662 continue
664 if [ -f "$d/.nobootstrap" ] ; then
665 # Report why to save head scratching when someone forgets they created
666 # a .nobootstrap file.
667 echo "Skipping '$module' due to presence of '$d/.nobootstrap'."
668 continue
670 case $d in
671 xapian-applications/omega|xapian-letor)
672 # If someone's created a directory for common, leave it be.
673 if [ -h "$d/common" ] || [ ! -d "$d/common" ] ; then
674 # Pick omega_common_commit_hash or letor_common_commit_hash:
675 var=`echo "$d"|sed 's!.*[-/]!!g'`_common_commit_hash
676 hash=`eval echo \\\$"$var"`
677 handle_git_external "$d/.common.git" "$hash" "$xapian_common_clone_url"
678 ln -sf .common.git/xapian-core/common "$d/common"
681 esac
683 echo "Bootstrapping \`$module'"
684 [ -f "$d/preautoreconf" ] && perl "$d/preautoreconf"
686 # If we have a custom INSTALL file, preserve it since autoreconf insists on
687 # replacing INSTALL with "generic installation instructions" when --force
688 # is used. Be careful to replace it if autoreconf fails.
689 if [ -f "$d/INSTALL" ] ; then
690 if grep 'generic installation instructions' "$d/INSTALL" >/dev/null 2>&1 ; then
692 else
693 mv -f "$d/INSTALL" "$d/INSTALL.preserved-by-bootstrap"
697 autoreconf_rc=
698 if [ swig = "$module" ] ; then
699 # SWIG provides its own bootstrapping script.
700 curdir=`pwd`
701 cd "$d"
702 ./autogen.sh || autoreconf_rc=$?
703 cd "$curdir"
704 # Use the uninstalled wrapper for the in-tree copy of SWIG.
705 intree_swig=yes
706 else
707 # Use --install as debian's autoconf wrapper uses 2.5X if it sees it
708 # (but it doesn't check for -i).
710 # Use --force so that we update files if autoconf, automake, or libtool
711 # has been upgraded.
712 ${AUTORECONF-autoreconf} --install --force "$d" || autoreconf_rc=$?
714 if [ -f "$d/INSTALL.preserved-by-bootstrap" ] ; then
715 mv -f "$d/INSTALL.preserved-by-bootstrap" "$d/INSTALL"
717 if [ -n "$autoreconf_rc" ] ; then
718 exit $autoreconf_rc
720 for f in config.guess config.sub ; do
721 if [ -f "$d/$f" ] ; then
722 update_config "config/$f" "$d/$f"
724 done
725 modules="$modules $module"
726 done
728 # Produce an absolute path to srcdir.
729 srcdir_abs=`pwd`
731 # Generate the top-level configure script.
732 rm -f configure.tmp
733 cat <<TOP_OF_CONFIGURE > configure.tmp
734 #!/bin/sh
735 # configure each submodule in a xapian source tree
736 # Generated by Xapian top-level bootstrap script.
737 #$copyright
738 trap 'echo "configure failed"' EXIT
739 set -e
741 srcdir="$srcdir_abs"
742 modules="$modules"
744 TOP_OF_CONFIGURE
746 cat <<'MIDDLE_OF_CONFIGURE' >> configure.tmp
747 # Produced escaped version of command suitable for pasting back into sh
748 cmd=$0
749 for a ; do
750 case $a in
751 *[^-A-Za-z0-9_+=:@/.,]*)
752 esc_a=`echo "$a"|sed 's!\([^-A-Za-z0-9_+=:@/.,]\)!\\\\\\1!g'`
753 cmd="$cmd $esc_a" ;;
755 cmd="$cmd $a" ;;
756 esac
757 done
759 here=`pwd`
760 MIDDLE_OF_CONFIGURE
762 vars=
763 if [ yes = "$intree_swig" ] ; then
764 # We want the path to SWIG to point into srcdir, which isn't known until
765 # configure-time, so we need to expand $here in configure.
766 vars=' SWIG=$here/swig/preinst-swig'
767 elif [ -n "$SWIG" ] ; then
768 # User specified SWIG in environment, e.g. with:
769 # SWIG=/opt/swig/bin/swig ./bootstrap
770 vars=" SWIG='"`echo "$val"|sed 's/\(['"\\'"']\)/\\\1/g'`"'"
772 for tool in $autotools ; do
773 eval "val=\$$tool"
774 if [ -n "$val" ] ; then
775 echo ': ${'"$tool='$val'"'}' >> configure.tmp
776 echo "export $tool" >> configure.tmp
777 vars="$vars $tool='"`echo "$val"|sed 's/\(['"\\'"']\)/\\\1/g'`"'"
779 done
780 if [ -n "$vars" ] ; then
781 # $vars will always have a leading space.
782 echo "set$vars "'"$@"' >> configure.tmp
785 cat <<'END_OF_CONFIGURE' >> configure.tmp
786 dirs=
787 revdirs=
788 XAPIAN_CONFIG=$here/xapian-core/xapian-config
789 for d in $modules ; do
790 if [ "$here" = "$srcdir" ] ; then
791 configure=./configure
792 configure_from_here=$d/configure
793 else
794 configure=$srcdir/$d/configure
795 configure_from_here=$configure
797 if [ -f "$configure_from_here" ] ; then
798 if [ -d "$d" ] ; then : ; else
799 case $d in
800 xapian-applications/*) [ -d xapian-applications ] || mkdir xapian-applications ;;
801 esac
802 mkdir "$d"
804 echo "Configuring \`$d'"
805 # Use a shared config.cache for speed and to save a bit of diskspace, but
806 # don't share it with SWIG just in case it manages to probe and cache
807 # different answers (e.g. because it uses a C compiler).
808 case $d in
809 swig)
810 case "$*" in
811 *--host=*|*--host" "*)
812 # We're cross-building, but SWIG needs to be built natively.
813 swig_configure_args=
814 skip=
815 for arg in "$@" ; do
816 if [ -n "$skip" ] ; then
817 skip=
818 continue
820 case $arg in
821 --host=*)
822 # Drop --host=xxx
823 continue ;;
824 --host)
825 # Drop --host xxx
826 skip=1
827 continue ;;
828 CC=*|CXX=*)
829 # Drop CC=xxx or CXX=xxx
830 continue ;;
831 CC_FOR_BUILD=*|CXX_FOR_BUILD=*)
832 # CC_FOR_BUILD=xxx -> CC=xxx; CXX_FOR_BUILD=xxx -> CXX=xxx
833 arg=`echo "$arg"|sed 's/_FOR_BUILD//'`
835 SWIG=*)
836 # Drop SWIG=xxx - not useful and could cause problems.
837 continue ;;
838 esac
839 swig_configure_args="$swig_configure_args "\'`echo "x$arg"|sed "s/^x//;s/'/'\\\\\\\\''/g"`\'
840 done
841 # Also handle compilers specified in environment variables. We can
842 # just reassign them unconditionally as CC and CXX are ignored if
843 # empty.
844 cd "$d" && CC=$CC_FOR_BUILD CXX=$CXX_FOR_BUILD "$configure" `eval echo $swig_configure_args`
847 cd "$d" && "$configure" ${1+"$@"}
849 esac
851 xapian-core)
852 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking --cache-file="$here/config.cache" ${1+"$@"}
854 xapian-applications/omega)
855 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking XAPIAN_CONFIG="$XAPIAN_CONFIG" CPPFLAGS="-I$srcdir/INST/include" LDFLAGS="-L$srcdir/INST/lib" ${1+"$@"}
858 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking --cache-file="$here/config.cache" XAPIAN_CONFIG="$XAPIAN_CONFIG" ${1+"$@"}
860 esac
861 cd "$here"
862 dirs="$dirs $d"
863 revdirs="$d $revdirs"
865 done
867 case " $* " in
868 *" --help "*|*" --version "*)
869 # Don't generate Makefile if --help or --version specified.
870 trap - EXIT
871 exit 0
873 esac
875 rm -f Makefile.tmp
876 cat <<EOF > Makefile.tmp
877 # Makefile generated by:
878 CONFIGURE_COMMAND := $cmd
880 if [ "$srcdir" != . ] ; then
881 cat <<EOF >> Makefile.tmp
883 VPATH = $srcdir
886 targets='all install uninstall install-strip clean distclean mostlyclean maintainer-clean dist check distcheck'
887 for target in $targets ; do
888 echo
889 echo "$target:"
890 case $target in
891 uninstall|*clean)
892 # When uninstalling or cleaning, process directories in reverse order, so
893 # that we process a directory after any directories which might use it.
894 list=$revdirs ;;
896 list=$dirs ;;
897 esac
898 for d in $list ; do
899 case $d,$target in
900 swig,install*|swig,uninstall)
901 # Nothing to do with swig when installing/uninstalling.
903 swig,dist|swig,check|swig,distcheck|swig,all)
904 # Need to ensure swig is built before "make dist", "make check", etc.
905 echo " cd $d && \$(MAKE)" ;;
906 swig,mostlyclean)
907 echo " cd $d && \$(MAKE) clean" ;;
908 xapian-bindings,distcheck)
909 # FIXME: distcheck doesn't currently work for xapian-bindings because
910 # xapian-core isn't installed.
911 echo " cd $d && \$(MAKE) check && \$(MAKE) dist" ;;
913 echo " cd $d && \$(MAKE) $target" ;;
914 esac
915 done
916 case $target in
917 distclean|maintainer-clean) echo " rm -f Makefile config.cache" ;;
918 esac
919 done >> Makefile.tmp
920 cat <<EOF >> Makefile.tmp
922 recheck:
923 \$(CONFIGURE_COMMAND)
925 Makefile: $srcdir/configure
926 \$(CONFIGURE_COMMAND)
928 $srcdir/configure: \\
929 END_OF_CONFIGURE
931 : > configure.tmp2
933 # We want to rerun bootstrap if a series file changes (patch added or removed)
934 # or an existing patch changes. Since we always have an series file (even if
935 # it is empty), this also handles us adding the first patch for something.
936 patches=
937 for d in patches/* ; do
938 series=$d/series
939 echo "$series:" >> configure.tmp2
940 cat << END
941 $series\\\\
943 sed -n 's/[ ]*\(#.*\)\?$//;/./p' "$series" |\
944 while read p ; do
945 patch=$d/$p
946 cat << END
947 $patch\\\\
949 # Because there's a pipeline, this is a subshell, so use a temporary file
950 # rather than a variable to compile a list of patches to use below.
951 echo "$patch:" >> configure.tmp2
952 done
953 done >> configure.tmp
955 cat <<'END_OF_CONFIGURE' >> configure.tmp
956 $srcdir/bootstrap
957 END_OF_CONFIGURE
958 echo " \$srcdir/bootstrap$bootstrap_sticky_opts" >> configure.tmp
959 cat <<'END_OF_CONFIGURE' >> configure.tmp
961 .PHONY: $targets recheck
963 # Dummy dependencies to allow removing patches we no longer need.
964 END_OF_CONFIGURE
966 cat configure.tmp2 >> configure.tmp
968 cat <<'END_OF_CONFIGURE' >> configure.tmp
970 mv -f Makefile.tmp Makefile
971 trap - EXIT
972 echo "Configured successfully - now run \"${MAKE-make}\""
973 END_OF_CONFIGURE
975 rm -f configure.tmp2
977 chmod +x configure.tmp
978 mv -f configure.tmp configure
980 # git defaults to showing 7 character abbreviated hashes if that's enough to be
981 # unique for a particular commit. But you can't paste these into trac as it
982 # needs at least 8 hex digits to recognise a hex string as a commit hash. You
983 # need 9 characters to be unique across all of Xapian at the time of writing,
984 # and 12 for the Linux kernel currently (a much larger number of objects than
985 # Xapian). 12 is a manageable length and decently future-proof, so let's use
986 # that.
987 core_abbrev_recommended=12
988 core_abbrev=`git config --get core.abbrev||:`
989 if [ -z "$core_abbrev" ] ; then
990 echo "*** Setting core.abbrev=$core_abbrev_recommended in repo config"
991 git config --local core.abbrev "$core_abbrev_recommended"
992 elif [ "$core_abbrev" -lt "$core_abbrev_recommended" ] ; then
993 if [ -z "`git config --local core.abbrev`" ] ; then
994 # Set globally to < $core_abbrev_recommended, override in this repo.
995 echo "*** Setting core.abbrev=$core_abbrev_recommended in repo config to override global core.abbrev=$core_abbrev"
996 git config --local core.abbrev "$core_abbrev_recommended"
997 else
998 # Just warn.
999 echo "warning: core.abbrev=$core_abbrev set on this repo, at least $core_abbrev_recommended is recommended"
1003 trap - EXIT
1004 echo "Bootstrapped successfully - now run \"$srcdir/configure\" and \"${MAKE-make}\""