Use _exit() after fork()
[xapian.git] / bootstrap
blobdc1461731adede2420a70ea41dac4046d05c4b1c
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-2024 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 checksum_=$1
46 tarball_=$2
48 if [ -z "$SHA256SUM_TOOL" ] ; then
49 for SHA256SUM_TOOL in \
50 '${SHA256SUM-sha256sum} 2>/dev/null|cut -d\ -f1' \
51 '${SHASUM-shasum} -a256 2>/dev/null|cut -d\ -f1' \
52 '${OPENSSL-openssl} sha256 2>/dev/null|sed "s/.* //"' \
53 '' ; do
54 if [ -z "$SHA256SUM_TOOL" ] ; then
55 cat <<'END'
56 Need sha256sum or shasum or openssl installed to check SHA256 checksums.
57 Set environment variable SHA256SUM, SHASUM or OPENSSL if the tool isn't on
58 your PATH.
59 END
60 exit 1
62 # Sanity check by hashing empty input.
63 r=`:|eval "$SHA256SUM_TOOL"`
64 [ X"$r" != Xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 ] || break
65 done
67 r=`< "$tarball_" eval "$SHA256SUM_TOOL"`
68 if [ X"$r" != X"$checksum_" ] ; then
69 echo "$tarball_: computed SHA256 checksum did NOT match"
70 echo "computed: $r with $SHA256SUM_TOOL"
71 echo "expected: $checksum_"
72 ls -l "$tarball_"
73 file "$tarball_" || true
74 mv "$tarball_" "$tarball_.$r"
75 echo "Renamed $tarball_ to $tarball_.$r"
76 exit 1
80 check_at_least() {
81 # This function is expected to be used in 'if' so we can't rely on set -e
82 # being in effect here.
83 v1=$1
84 v2=$2
85 save_IFS=$IFS
86 IFS=.
87 set x $v1
88 for v in $v2 ; do
89 shift
90 if [ "$1" != "$v" ] ; then
91 if [ -z "$1" ] || [ "$1" -lt "$v" ] ; then
92 IFS=$save_IFS
93 return 1
95 break
97 done
98 IFS=$save_IFS
99 return 0
102 need_to_build() {
103 # This function is expected to be used in 'if' so we can't rely on set -e
104 # being in effect here.
105 package=$1
106 version=$2
107 binary=$3
109 case $download_tools in
110 always) ;;
111 never)
112 return 1
115 if [ -n "$binary" ] ; then
116 if [ -s "../patches/$package/series" ] ; then
117 echo "There are patches to apply to $package so using private build"
118 else
119 # Check if a new enough version is already installed.
120 version_installed=`"$binary" --version 2>/dev/null|sed '1,1 s/.* //p;d'`
121 if [ -n "$version_installed" ] ; then
122 # Fast track equality.
123 if [ "$version_installed" = "$version" ] ; then
124 echo "$binary $version_installed installed, exactly what's needed"
125 return 1
127 if check_at_least "$version_installed" "$version" ; then
128 echo "$binary $version_installed installed >= $version required"
129 return 1
135 esac
136 return 0
139 lazy_build() {
140 package=$1
141 version=$2
142 basename=$package-$version
143 ext=$3
144 checksum=$4
146 if [ "$ext" = "tar.xz" ] ; then
147 if [ -z "$xz_ok" ] ; then
148 if ${XZ-xz} --version > /dev/null 2>&1 ; then
149 xz_ok=1
150 else
151 xz_ok=0
154 if [ "$xz_ok" = 0 ] ; then
155 shift 2
156 ext=$3
157 checksum=$4
160 if [ "$ext" = "tar.bz2" ] ; then
161 if [ -z "$bz2_ok" ] ; then
162 # bzip2 --version doesn't exit with code 0 in upstream version (though
163 # Debian at least patch this bug), so use --help to check it.
164 if bzip2 --help > /dev/null 2>&1 ; then
165 bz2_ok=1
166 else
167 bz2_ok=0
170 if [ "$bz2_ok" = 0 ] ; then
171 shift 2
172 ext=$3
173 checksum=$4
176 tarball=$basename.$ext
177 case $basename in
178 *[24680][a-z]) basename=`echo "$basename"|sed 's/[a-z]$//'` ;;
179 esac
181 # Create the stamp file in INST so that rerunning bootstrap after
182 # "rm -rf INST" recovers nicely.
183 stamp=../INST/$package.stamp
184 out_of_date=
186 # Download the tarball if required.
187 if [ ! -f "$tarball" ] ; then
188 main_tarball=
189 # Older git versions don't support "git worktree", so discard stderr and
190 # then we'll skip the worktree handling because main_worktree_dir will
191 # be empty.
192 main_worktree_dir=`git worktree list --porcelain 2>/dev/null|sed 's/^worktree //;q'`
193 if [ -n "$main_worktree_dir" ] ; then
194 # Canonicalise main_worktree_dir before comparing with pwd.
195 main_worktree_dir=`cd "$main_worktree_dir" && pwd`
196 if [ "$main_worktree_dir/BUILD" != "`pwd`" ] ; then
197 # If main_tarball is set non-empty, then we're a linked worktree.
198 main_tarball=$main_worktree_dir/BUILD/$tarball
201 if [ -n "$main_tarball" ] && [ -f "$main_tarball" ] ; then
202 # Don't re-download the tarball if the main worktree already has it.
203 tarball=$main_tarball
204 else
205 if [ -z "$FETCH_URL_TOOL" ] ; then
206 if ${WGET-wget} --version > /dev/null 2>&1 ; then
207 FETCH_URL_TOOL="${WGET-wget} -O-"
208 elif ${CURL-curl} --version > /dev/null 2>&1 || [ "$?" = 2 ] ; then
209 # curl --version exits with code 2 (~7.18.2) or 0 (7.35.0).
210 # -L is needed to follow HTTP redirects.
211 FETCH_URL_TOOL="${CURL-curl} -L"
212 elif ${LWP_REQUEST-lwp-request} -v > /dev/null 2>&1 || [ "$?" = 9 ] || [ "$?" = 255 ] ; then
213 # lwp-request -v exits with code 9 (5.810) or 255 (6.03)
214 FETCH_URL_TOOL="${LWP_REQUEST-lwp-request} -mGET"
215 else
216 cat <<END >&2
217 Neither wget nor curl nor lwp-request found - install one of them or if already
218 installed, set WGET, CURL or LWP_REQUEST to the full path. Alternatively,
219 download $url
220 to directory `pwd`
221 then rerun this script.
223 exit 1
226 url="https://github.com/xapian/xapian-dev-deps/releases/download/current/$tarball"
227 case $basename in
228 file-*)
229 case $download_protocol in
230 ftp) url="ftp://ftp.astron.com/pub/file/$tarball" ;;
231 # We used to use http://fossies.org/ but that now redirects to https.
232 esac ;;
233 *[13579][a-z])
234 # GNU alpha release
235 case $download_protocol in
236 ftp) url="ftp://alpha.gnu.org/gnu/$package/$tarball" ;;
237 http) url="http://alpha.gnu.org/gnu/$package/$tarball" ;;
238 esac ;;
240 case $download_protocol in
241 ftp) url="ftp://ftp.gnu.org/gnu/$package/$tarball" ;;
242 http) url="http://ftpmirror.gnu.org/$package/$tarball" ;;
243 esac ;;
244 esac
245 case $download_protocol,$url in
246 http,https:*)
247 echo "warning: No http: link for $tarball available, using https:"
249 esac
251 # Keep the tarball under a quarantined name until we've verified its
252 # checksum. Once verified, if this is a linked git worktree we save
253 # the tarball in the main worktree's BUILD directory so that it can
254 # be shared with other worktrees.
255 if [ -n "$main_tarball" ] ; then
256 tarball=$main_tarball
258 quarantined_tarball=$tarball-quarantine.$$
259 rm -f "$quarantined_tarball"
260 echo "Downloading <$url>"
261 $FETCH_URL_TOOL "$url" > "$quarantined_tarball" || exit $?
262 check_checksum "$checksum" "$quarantined_tarball"
263 mv "$quarantined_tarball" "$tarball"
265 # Force a build.
266 out_of_date=force
270 if [ -z "$out_of_date" ] ; then
271 if [ -f "$stamp" ] ; then
272 # Check if the tarball or the patches we're applying have changed since
273 # the existing build.
274 out_of_date=`find "$tarball" ../patches/"$package"/* -newer "$stamp" -print 2> /dev/null||true`
275 else
276 out_of_date=force
280 if [ -n "$out_of_date" ] ; then
281 # Verify the tarball's checksum before building it. We now check at
282 # download time, but older versions of bootstrap didn't, and this also
283 # protects a user who manually downloads a tarball (which we suggest as an
284 # option if wget, curl, etc aren't found).
285 check_checksum "$checksum" "$tarball"
287 case $tarball in
288 */*) ;; # Only expire tarballs from the main worktree.
290 case `git worktree list --porcelain 2>/dev/null|grep -c '^worktree '` in
291 1|0)
292 # Remove tarballs of other versions if there's only one worktree, or if
293 # using git < 2.5 (before worktrees were added).
294 for f in "$package"-* ; do
295 [ "$f" = "$tarball" ] || rm -rf "$f"
296 done
298 esac
300 esac
302 case $ext in
303 tar.xz)
304 ${XZ-xz} -dc "$tarball"| tar xf - || exit $? ;;
305 tar.bz2)
306 bzip2 -dc "$tarball"| tar xf - || exit $? ;;
308 gzip -dc "$tarball"| tar xf - || exit $? ;;
309 esac
311 cd "$basename" || exit $?
313 series="../../patches/$package/series"
314 if [ ! -f "$series" ] ; then
315 cat <<END >&2
316 No patch series file 'patches/$package/series' - if there are no patches,
317 this should just be an empty file.
319 exit 1
321 if [ -s "$series" ] ; then
322 echo "Applying patches from $package/series"
323 sed -n 's/[ ]*\(#.*\)\?$//;/./p' "$series" | \
324 while read p ; do
325 echo "Applying patch $package/$p"
326 patch -p1 < "../../patches/$package/$p" || exit $?
327 done
330 echo "Configuring $package"
331 if test -n "$AUTOCONF" ; then
332 ./configure --prefix "$instdir" AUTOCONF="$AUTOCONF" || exit $?
333 else
334 ./configure --prefix "$instdir" || exit $?
336 echo "Building $package"
337 make || exit $?
338 echo "Installing $package"
339 make install || exit $?
340 echo "Done installing $package"
341 cd .. || exit $?
342 rm -rf "$basename" || exit $?
344 touch "$stamp" || exit $?
346 return 0
349 handle_git_external() {
350 path=$1
351 if [ ! -f "$path/.nobootstrap" ] ; then
352 rev=$2
353 url=$3
354 if [ ! -d "$path" ] ; then
355 git clone --no-checkout -- "$url" "$path"
356 elif (cd "$path" && git reflog "$rev" -- 2>/dev/null) ; then
357 : # Already have that revision locally
358 else
359 (cd "$path" && git fetch)
361 (cd "$path" && git checkout "$rev")
365 update_config() {
366 from=$1
367 to=$2
368 ts_from=`perl -ne '/^timestamp=(\W?)([-\d]+)$1/ and do {$_=$2;y/-//d;print;exit}' "$from"`
369 ts_to=`perl -ne '/^timestamp=(\W?)([-\d]+)$1/ and do {$_=$2;y/-//d;print;exit}' "$to"`
370 if [ "$ts_from" -gt "$ts_to" ] ; then
371 echo "Updating $to ($ts_to) with $from ($ts_from)"
372 # rm first in case the existing file is a symlink.
373 rm -f "$to"
374 cp "$from" "$to"
378 update_bootstrap_sticky_opts() {
379 arg=$1
380 case $arg in
381 *[!-A-Za-z0-9_+=:@/.,]*)
382 # Quote for the shell and escape $ to $$ for make.
383 bootstrap_sticky_opts="$bootstrap_sticky_opts '"`echo "$arg"|sed "s/'/'\\\\\\''/g;"'s/[$]/\\\\$\\\\$/g'`"'"
386 bootstrap_sticky_opts="$bootstrap_sticky_opts $arg"
388 esac
391 curdir=`pwd`
393 # cd to srcdir if we aren't already there.
394 srcdir=`echo "$0"|sed 's!/*[^/]*$!!'`
395 case $srcdir in
396 ""|.)
397 srcdir=. ;;
399 cd "$srcdir" ;;
400 esac
402 # Commit hash to pass to handle_git_external for swig. Equivalent to
403 # SWIG 4.2.1 plus 68 commits, in order to get typemaps for std::string_view
404 # including a fix for a regression in handling a function taking multiple
405 # std::string_view parameters.
406 swig_git_commit_hash=6226d58065005a31f3737530ae93eaa628ae4995
408 # Commit hashes to use for common in omega and letor respectively:
409 omega_common_commit_hash=501bddf177275d87a46f7a659aa3a0b0d85ee4c8
410 letor_common_commit_hash=501bddf177275d87a46f7a659aa3a0b0d85ee4c8
412 gitdir=`git rev-parse --git-dir`
414 if [ ! -d "$gitdir" ] ; then
415 echo "$0: No '.git' directory found - this script should be run from a"
416 echo "git repo cloned from git://git.xapian.org/xapian or a mirror of it"
417 exit 1
420 for emptydir in xapian-applications/omega/m4 xapian-bindings/m4 xapian-letor/m4 ; do
421 if test -d "$emptydir" ; then
423 else
424 parent=`echo "$emptydir"|sed 's,/[^/]*$,,'`
425 if test -d "$parent" ; then
426 mkdir "$emptydir"
429 done
431 if [ -f "$gitdir/info/exclude" ] ; then
432 sed '/^\(swig\|xapian-applications\/omega\/common$\)/d' "$gitdir/info/exclude" > "$gitdir/info/exclude~"
433 else
434 [ -d "$gitdir/info" ] || mkdir "$gitdir/info"
436 cat <<END >> "$gitdir/info/exclude~"
437 swig
438 xapian-applications/omega/common
439 xapian-letor/common
441 if [ -f "$gitdir/info/exclude" ] &&
442 cmp -s "$gitdir/info/exclude~" "$gitdir/info/exclude" ; then
443 rm "$gitdir/info/exclude~"
444 else
445 mv "$gitdir/info/exclude~" "$gitdir/info/exclude"
448 # If this tree is checked out from the github mirror, use the same access
449 # method for other things checked out from github (e.g. swig) so we avoid
450 # firewall issues. If there's no default remote, the git config command
451 # will exit with status 1, so ignore that failure.
452 origin_url=`git config remote.origin.url||:`
453 case $origin_url in
454 *[@/]github.com[:/]*)
455 github_base_url=`echo "X$origin_url"|sed 's/^X//;s!\([@/]github.com[:/]\).*!\1!'` ;;
457 github_base_url=https://github.com/ ;;
458 esac
459 swig_origin_url=${github_base_url}swig/swig.git
461 if [ -z "$XAPIAN_COMMON_CLONE_URL" ] ; then
462 xapian_common_clone_url=.
463 else
464 xapian_common_clone_url=$XAPIAN_COMMON_CLONE_URL
467 # Set to 'ftp' to use ftp URLs where available and 'http' to use unencrypted
468 # 'http'. By default we prefer https downloads as they are more likely to work
469 # through firewalls and better preserve user privacy.
470 download_protocol=
472 # Set to 'always' to always use a locally installed copy of the autotools
473 # or 'never' to never download.
475 # By default we check for locally installed versions and use them if they are
476 # new enough versions. But e.g. for building releases we want to use a known
477 # set of versions.
478 download_tools=ifneeded
480 # Save options which should be sticky for when "make" needs to rerun bootstrap.
481 # This should be empty or start with a space.
482 bootstrap_sticky_opts=
484 while [ "$#" -gt 0 ] ; do
485 case $1 in
486 --download-tools=*)
487 update_bootstrap_sticky_opts "$1"
488 download_tools=`echo "x$1"|sed 's/^x--download-tools=//'`
489 shift
490 continue
493 --download-tools)
494 update_bootstrap_sticky_opts "$1=$2"
495 download_tools=$2
496 shift 2
497 continue
500 --ftp)
501 bootstrap_sticky_opts="$bootstrap_sticky_opts $1"
502 download_protocol=ftp
503 shift
504 continue
507 --http)
508 bootstrap_sticky_opts="$bootstrap_sticky_opts $1"
509 download_protocol=http
510 shift
511 continue
514 --fetch-url-command=*)
515 update_bootstrap_sticky_opts "$1"
516 FETCH_URL_TOOL=`echo "x$1"|sed 's/^x--fetch-url-command=//'`
517 shift
518 continue
521 --fetch-url-command)
522 update_bootstrap_sticky_opts "$1=$2"
523 FETCH_URL_TOOL=$2
524 shift 2
525 continue
528 --clean)
529 # This probably shouldn't be sticky.
530 rm -rf INST
531 shift
532 continue
535 --without-autotools)
536 # This shouldn't be sticky.
537 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"
538 shift
539 continue
543 bootstrap_sticky_opts="$bootstrap_sticky_opts $1"
544 shift
545 break
549 echo "Unknown option '$1'" 1>&2
550 exit 1
554 break
556 esac
557 done
559 if [ "$#" -gt 0 ] ; then
560 for a in "$@" ; do
561 update_bootstrap_sticky_opts "$a"
562 done
565 case $download_tools in
566 always|ifneeded) ;;
567 never)
568 echo "warning: If stuff breaks with '--download-tools=never', you get to keep the pieces"
571 echo "Invalid --download-tools value '$download_tools'"
572 exit 1
574 esac
576 [ -d INST ] || mkdir INST
577 instdir=`pwd`/INST
579 [ -d BUILD ] || mkdir BUILD
580 cd BUILD
582 # The hex strings are SHA256 checksums for the preceding extension.
583 args='autoconf 2.71'
584 if need_to_build $args autoconf ; then
585 lazy_build $args \
586 tar.xz f14c83cfebcc9427f2c3cea7258bd90df972d92eb26752da4ddad81c87a0faa4 \
587 tar.gz 431075ad0bf529ef13cb41e9042c542381103e80015686222b8a9d4abef42a1c
588 AUTOCONF=$instdir/bin/autoconf
589 export AUTOCONF
590 AUTORECONF=$instdir/bin/autoreconf
591 export AUTORECONF
592 AUTOHEADER=$instdir/bin/autoheader
593 export AUTOHEADER
594 AUTOM4TE=$instdir/bin/autom4te
595 export AUTOM4TE
597 args='automake 1.16.5'
598 if need_to_build $args automake ; then
599 lazy_build $args \
600 tar.xz f01d58cd6d9d77fbdca9eb4bbd5ead1988228fdb73d6f7a201f5f8d6b118b469 \
601 tar.gz 07bd24ad08a64bc17250ce09ec56e921d6343903943e99ccf63bbf0705e34605
602 ACLOCAL=$instdir/bin/aclocal
603 export ACLOCAL
604 AUTOMAKE=$instdir/bin/automake
605 export AUTOMAKE
607 args='libtool 2.4.7'
608 if need_to_build $args libtool ; then
609 lazy_build $args \
610 tar.xz 4f7f217f057ce655ff22559ad221a0fd8ef84ad1fc5fcb6990cecc333aa1635d \
611 tar.gz 04e96c2404ea70c590c546eba4202a4e12722c640016c12b9b2f1ce3d481e9a8
612 LIBTOOLIZE=$instdir/bin/libtoolize
613 export LIBTOOLIZE
614 libtool_aclocal=$instdir/share/aclocal
615 else
616 libtool_aclocal=`which libtoolize|sed 's!/bin/[^/]*$!/share/aclocal!'`
617 if [ -z "$libtool_aclocal" ] ; then
618 echo "libtoolize not found"
619 exit 1
623 if [ "$1" = "--deps=libmagic" ] ; then
624 shift
625 lazy_build file 5.3.2 \
626 tar.gz 8639dc4d1b21e232285cd483604afc4a6ee810710e00e579dbe9591681722b50
629 # Save the unadorned aclocal for bootstrapping SWIG. In particular SWIG
630 # uses a modified old version of AX_CXX_COMPILE_STDCXX_11 which isn't
631 # compatible with the current version which might be in a system directory.
632 SWIG_ACLOCAL=${ACLOCAL-aclocal}
634 cd ..
636 # Add -I for in-tree macro directory first, so we use that xapian.m4 in
637 # preference to one in any directories which may be added below.
638 ACLOCAL="${ACLOCAL-aclocal} -I `pwd`/xapian-core/m4-macros -I `pwd`/xapian-letor/m4-macros"
639 export ACLOCAL
641 aclocal_ac_dir=`${ACLOCAL-aclocal} --print-ac-dir`
642 aclocal_system_needed=
643 if [ ! -r "$aclocal_ac_dir/pkg.m4" ] ; then
644 if [ -r /usr/share/aclocal/pkg.m4 ] ; then
645 aclocal_system_needed=/usr/share/aclocal
646 elif [ -r /usr/local/share/aclocal/pkg.m4 ] ; then
647 aclocal_system_needed=/usr/local/share/aclocal
648 elif [ -r /opt/local/share/aclocal/pkg.m4 ] ; then
649 aclocal_system_needed=/opt/local/share/aclocal
653 # If the aclocal we're using is in a different prefix to the libtool we're
654 # using, we probably need to tell aclocal where to look for our libtool's
655 # macros. We also need to do this if we add -I /usr/share/aclocal below
656 # since otherwise the system libtool's macros may be used in preference.
657 if [ "$aclocal_ac_dir" != "$libtool_aclocal" ] || [ -n "$aclocal_system_needed" ]; then
658 ACLOCAL="${ACLOCAL-aclocal} -I $libtool_aclocal"
659 export ACLOCAL
662 # If we're using a non-system automake, check if pkg.m4 is in the directory
663 # aclocal looks in by default. If not and there's a system pkg.m4, tell
664 # aclocal to also look in the system aclocal directory.
665 if [ -n "$aclocal_system_needed" ] ; then
666 ACLOCAL="${ACLOCAL-aclocal} -I $aclocal_system_needed"
667 export ACLOCAL
670 case `${LIBTOOLIZE-libtoolize} --version` in
672 echo "${LIBTOOLIZE-libtoolize} not found"
673 exit 1 ;;
674 "libtoolize (GNU libtool) 1.4.*")
675 echo "${LIBTOOLIZE-libtoolize} is from libtool 1.4 which is too old - libtool 2.2 is required."
676 echo "If you have both installed, set LIBTOOLIZE to point to the correct version."
677 exit 1 ;;
678 "libtoolize (GNU libtool) 1.5.*")
679 echo "${LIBTOOLIZE-libtoolize} is from libtool 1.5 which is too old - libtool 2.2 is required."
680 echo "If you have both installed, set LIBTOOLIZE to point to the correct version."
681 exit 1 ;;
682 esac
684 intree_swig=no
685 modules=
686 for module in ${@:-xapian-core xapian-applications/omega swig xapian-bindings} ; do
687 d=$module
688 if [ "$d" = swig ] ; then
689 if [ -f "xapian-bindings/.nobootstrap" ] ; then
690 # No point bootstrapping SWIG if we aren't going to use it.
691 echo "Skipping '$d' due to presence of 'xapian-bindings/.nobootstrap'."
692 continue
694 handle_git_external swig "$swig_git_commit_hash" "$swig_origin_url"
696 if [ -f "$d/configure.ac" ] || [ -f "$d/configure.in" ] ; then
698 else
699 # Skip any directories we can't bootstrap.
700 continue
702 if [ -f "$d/.nobootstrap" ] ; then
703 # Report why to save head scratching when someone forgets they created
704 # a .nobootstrap file.
705 echo "Skipping '$module' due to presence of '$d/.nobootstrap'."
706 continue
708 case $d in
709 xapian-applications/omega|xapian-letor)
710 # If someone's created a directory for common, leave it be.
711 if [ -h "$d/common" ] || [ ! -d "$d/common" ] ; then
712 # Pick omega_common_commit_hash or letor_common_commit_hash:
713 var=`echo "$d"|sed 's!.*[-/]!!g'`_common_commit_hash
714 hash=`eval echo \\\$"$var"`
715 if [ -f "$gitdir/shallow" ] ; then
716 if git reflog "$hash" -- 2> /dev/null ; then
717 : # Already have the desired commit.
718 else
719 git fetch --unshallow
722 handle_git_external "$d/.common.git" "$hash" "$xapian_common_clone_url"
723 ln -sf .common.git/xapian-core/common "$d/common"
726 esac
728 echo "Bootstrapping \`$module'"
729 [ -f "$d/preautoreconf" ] && perl "$d/preautoreconf"
731 # If we have a custom INSTALL file, preserve it since autoreconf insists on
732 # replacing INSTALL with "generic installation instructions" when --force
733 # is used. Be careful to replace it if autoreconf fails.
734 if [ -f "$d/INSTALL" ] ; then
735 if grep 'generic installation instructions' "$d/INSTALL" >/dev/null 2>&1 ; then
737 else
738 mv -f "$d/INSTALL" "$d/INSTALL.preserved-by-bootstrap"
742 autoreconf_rc=
743 if [ swig = "$module" ] ; then
744 # SWIG provides its own bootstrapping script.
745 curdir=`pwd`
746 cd "$d"
747 ACLOCAL=$SWIG_ACLOCAL ./autogen.sh || autoreconf_rc=$?
748 cd "$curdir"
749 # Use the uninstalled wrapper for the in-tree copy of SWIG.
750 intree_swig=yes
751 else
752 # Use --install as debian's autoconf wrapper uses 2.5X if it sees it
753 # (but it doesn't check for -i).
755 # Use --force so that we update files if autoconf, automake, or libtool
756 # has been upgraded.
757 ${AUTORECONF-autoreconf} --install --force "$d" || autoreconf_rc=$?
759 if [ -f "$d/INSTALL.preserved-by-bootstrap" ] ; then
760 mv -f "$d/INSTALL.preserved-by-bootstrap" "$d/INSTALL"
762 if [ -n "$autoreconf_rc" ] ; then
763 exit $autoreconf_rc
765 for f in config.guess config.sub ; do
766 if [ -f "$d/$f" ] ; then
767 update_config "config/$f" "$d/$f"
769 done
770 modules="$modules $module"
771 done
773 # Produce an absolute path to srcdir.
774 srcdir_abs=`pwd`
776 # Generate the top-level configure script.
777 rm -f configure.tmp
778 cat <<TOP_OF_CONFIGURE > configure.tmp
779 #!/bin/sh
780 # configure each submodule in a xapian source tree
781 # Generated by Xapian top-level bootstrap script.
782 #$copyright
783 trap 'echo "configure failed"' EXIT
784 set -e
786 srcdir="$srcdir_abs"
787 modules="$modules"
789 TOP_OF_CONFIGURE
791 cat <<'MIDDLE_OF_CONFIGURE' >> configure.tmp
792 # Produced escaped version of command suitable for pasting back into sh
793 cmd=$0
794 user_CPPFLAGS=$CPPFLAGS
795 user_LDFLAGS=$LDFLAGS
796 for a ; do
797 case $a in
798 *[^-A-Za-z0-9_+=:@/.,]*)
799 esc_a=`echo "$a"|sed 's!\([^-A-Za-z0-9_+=:@/.,]\)!\\\\\\1!g'`
800 cmd="$cmd $esc_a" ;;
802 cmd="$cmd $a" ;;
803 esac
804 # Capture any command-line settings of CPPFLAGS or LDFLAGS so we can override
805 # for omega. We follow the behaviour of autoconf-generated configure scripts
806 # in that command-line setting beats environment variable setting, and the
807 # last of multiple command-line settings is used.
808 case $a in
809 CPPFLAGS=*)
810 user_CPPFLAGS=`expr "x$a" : 'xCPPFLAGS=\(.*\)'` ;;
811 LDFLAGS=*)
812 user_LDFLAGS=`expr "x$a" : 'xLDFLAGS=\(.*\)'` ;;
813 esac
814 done
816 here=`pwd`
817 MIDDLE_OF_CONFIGURE
819 vars=
820 if [ yes = "$intree_swig" ] ; then
821 # We want the path to SWIG to point into srcdir, which isn't known until
822 # configure-time, so we need to expand $here in configure.
823 vars=' SWIG=$here/swig/preinst-swig'
824 elif [ -n "$SWIG" ] ; then
825 # User specified SWIG in environment, e.g. with:
826 # SWIG=/opt/swig/bin/swig ./bootstrap
827 vars=" SWIG='"`echo "$val"|sed 's/\(['"\\'"']\)/\\\1/g'`"'"
829 for tool in $autotools ; do
830 eval "val=\$$tool"
831 if [ -n "$val" ] ; then
832 echo ': ${'"$tool='$val'"'}' >> configure.tmp
833 echo "export $tool" >> configure.tmp
834 vars="$vars $tool='"`echo "$val"|sed 's/\(['"\\'"']\)/\\\1/g'`"'"
836 done
837 if [ -n "$vars" ] ; then
838 # $vars will always have a leading space.
839 echo "set$vars "'"$@"' >> configure.tmp
842 cat <<'END_OF_CONFIGURE' >> configure.tmp
843 dirs=
844 revdirs=
845 XAPIAN_CONFIG=$here/xapian-core/xapian-config
846 XAPIANLETOR_CONFIG=$here/xapian-letor/xapianletor-config
847 for d in $modules ; do
848 if [ "$here" = "$srcdir" ] ; then
849 configure=./configure
850 configure_from_here=$d/configure
851 else
852 configure=$srcdir/$d/configure
853 configure_from_here=$configure
855 if [ -f "$configure_from_here" ] ; then
856 if [ -d "$d" ] ; then : ; else
857 case $d in
858 xapian-applications/*) [ -d xapian-applications ] || mkdir xapian-applications ;;
859 esac
860 mkdir "$d"
862 echo "Configuring \`$d'"
863 # Replace EXIT trap with one which shows `config.log`.
864 trap 'if [ -f config.log ]; then echo "configure failed, config.log was:"; sed "s/^/| /" config.log; else echo "configure failed"; fi' EXIT
865 # Use a shared config.cache for speed and to save a bit of diskspace, but
866 # don't share it with SWIG just in case it manages to probe and cache
867 # different answers (e.g. because it uses a C compiler).
868 case $d in
869 swig)
870 case "$*" in
871 *--host=*|*--host" "*)
872 # We're cross-building, but SWIG needs to be built natively.
873 swig_configure_args=
874 skip=
875 for arg in "$@" ; do
876 if [ -n "$skip" ] ; then
877 skip=
878 continue
880 case $arg in
881 --host=*)
882 # Drop --host=xxx
883 continue ;;
884 --host)
885 # Drop --host xxx
886 skip=1
887 continue ;;
888 CC=*|CXX=*)
889 # Drop CC=xxx or CXX=xxx
890 continue ;;
891 CC_FOR_BUILD=*|CXX_FOR_BUILD=*)
892 # CC_FOR_BUILD=xxx -> CC=xxx; CXX_FOR_BUILD=xxx -> CXX=xxx
893 arg=`echo "$arg"|sed 's/_FOR_BUILD//'`
895 SWIG=*)
896 # Drop SWIG=xxx - not useful and could cause problems.
897 continue ;;
898 esac
899 swig_configure_args="$swig_configure_args "\'`printf '%s' "$arg"|sed "s/'/'\\\\\\\\''/g"`\'
900 done
901 # Also handle compilers specified in environment variables. We can
902 # just reassign them unconditionally as CC and CXX are ignored if
903 # empty.
905 CC=$CC_FOR_BUILD
906 CXX=$CC_FOR_BUILD
907 export CC
908 export CXX
909 cd "$d" && eval "$configure" $swig_configure_args
913 cd "$d" && "$configure" ${1+"$@"}
915 esac
917 xapian-core)
918 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking --cache-file="$here/config.cache" ${1+"$@"}
920 xapian-letor)
921 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking XAPIAN_CONFIG="$XAPIAN_CONFIG" --cache-file="$here/config.cache" ${1+"$@"}
923 xapian-applications/omega)
924 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking XAPIAN_CONFIG="$XAPIAN_CONFIG" CPPFLAGS="-I$srcdir/INST/include $user_CPPFLAGS" LDFLAGS="-L$srcdir/INST/lib $user_LDFLAGS" ${1+"$@"}
927 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking --cache-file="$here/config.cache" XAPIAN_CONFIG="$XAPIAN_CONFIG" XAPIANLETOR_CONFIG="$XAPIANLETOR_CONFIG" ${1+"$@"}
929 esac
930 # Restore EXIT trap.
931 trap 'echo "configure failed"' EXIT
932 cd "$here"
933 dirs="$dirs $d"
934 revdirs="$d $revdirs"
936 done
938 case " $* " in
939 *" --help "*|*" --version "*)
940 # Don't generate Makefile if --help or --version specified.
941 trap - EXIT
942 exit 0
944 esac
946 rm -f Makefile.tmp
947 cat <<EOF > Makefile.tmp
948 # Makefile generated by:
949 CONFIGURE_COMMAND := $cmd
951 if [ "$srcdir" != . ] ; then
952 cat <<EOF >> Makefile.tmp
954 VPATH = $srcdir
957 targets='all install uninstall install-strip clean distclean mostlyclean maintainer-clean dist check distcheck'
958 for target in $targets ; do
959 echo
960 echo "$target:"
961 case $target in
962 uninstall|*clean)
963 # When uninstalling or cleaning, process directories in reverse order, so
964 # that we process a directory after any directories which might use it.
965 list=$revdirs ;;
967 list=$dirs ;;
968 esac
969 for d in $list ; do
970 case $d,$target in
971 swig,install*|swig,uninstall)
972 # Nothing to do with swig when installing/uninstalling.
974 swig,dist|swig,check|swig,distcheck|swig,all)
975 # Need to ensure swig is built before "make dist", "make check", etc.
976 echo " cd $d && \$(MAKE)" ;;
977 swig,mostlyclean)
978 echo " cd $d && \$(MAKE) clean" ;;
979 xapian-bindings,distcheck)
980 # FIXME: distcheck doesn't currently work for xapian-bindings because
981 # xapian-core isn't installed.
982 echo " cd $d && \$(MAKE) check && \$(MAKE) dist" ;;
984 echo " cd $d && \$(MAKE) $target" ;;
985 esac
986 done
987 case $target in
988 distclean|maintainer-clean) echo " rm -f Makefile config.cache" ;;
989 esac
990 done >> Makefile.tmp
991 cat <<EOF >> Makefile.tmp
993 recheck:
994 \$(CONFIGURE_COMMAND)
996 Makefile: $srcdir/configure
997 \$(CONFIGURE_COMMAND)
999 $srcdir/configure: \\
1000 END_OF_CONFIGURE
1002 : > configure.tmp2
1004 # We want to rerun bootstrap if a series file changes (patch added or removed)
1005 # or an existing patch changes. Since we always have an series file (even if
1006 # it is empty), this also handles us adding the first patch for something.
1007 for d in patches/* ; do
1008 series=$d/series
1009 echo "$series:" >> configure.tmp2
1010 cat << END
1011 $series\\\\
1013 sed -n 's/[ ]*\(#.*\)\?$//;/./p' "$series" |\
1014 while read p ; do
1015 patch=$d/$p
1016 cat << END
1017 $patch\\\\
1019 # Because there's a pipeline, this is a subshell, so use a temporary file
1020 # rather than a variable to compile a list of patches to use below.
1021 echo "$patch:" >> configure.tmp2
1022 done
1023 done >> configure.tmp
1025 cat <<'END_OF_CONFIGURE' >> configure.tmp
1026 $srcdir/bootstrap
1027 END_OF_CONFIGURE
1028 echo " \$srcdir/bootstrap$bootstrap_sticky_opts" >> configure.tmp
1029 cat <<'END_OF_CONFIGURE' >> configure.tmp
1031 .PHONY: $targets recheck
1033 # Dummy dependencies to allow removing patches we no longer need.
1034 END_OF_CONFIGURE
1036 cat configure.tmp2 >> configure.tmp
1038 cat <<'END_OF_CONFIGURE' >> configure.tmp
1040 mv -f Makefile.tmp Makefile
1041 trap - EXIT
1042 echo "Configured successfully - now run \"${MAKE-make}\""
1043 END_OF_CONFIGURE
1045 rm -f configure.tmp2
1047 chmod +x configure.tmp
1048 mv -f configure.tmp configure
1050 # git defaults to showing 7 character abbreviated hashes if that's enough to be
1051 # unique for a particular commit. But you can't paste these into trac as it
1052 # needs at least 8 hex digits to recognise a hex string as a commit hash. You
1053 # need 9 characters to be unique across all of Xapian at the time of writing,
1054 # and 12 for the Linux kernel currently (a much larger number of objects than
1055 # Xapian). 12 is a manageable length and decently future-proof, so let's use
1056 # that.
1057 core_abbrev_recommended=12
1058 core_abbrev=`git config --get core.abbrev||:`
1059 if [ -z "$core_abbrev" ] ; then
1060 echo "*** Setting core.abbrev=$core_abbrev_recommended in repo config"
1061 git config --local core.abbrev "$core_abbrev_recommended"
1062 elif [ "$core_abbrev" -lt "$core_abbrev_recommended" ] ; then
1063 if [ -z "`git config --local core.abbrev`" ] ; then
1064 # Set globally to < $core_abbrev_recommended, override in this repo.
1065 echo "*** Setting core.abbrev=$core_abbrev_recommended in repo config to override global core.abbrev=$core_abbrev"
1066 git config --local core.abbrev "$core_abbrev_recommended"
1067 else
1068 # Just warn.
1069 echo "warning: core.abbrev=$core_abbrev set on this repo, at least $core_abbrev_recommended is recommended"
1073 trap - EXIT
1074 echo "Bootstrapped successfully - now run \"$srcdir/configure\" and \"${MAKE-make}\""