Update for 1.4.19
[xapian.git] / bootstrap
blob485cd04868e30ef1b0c48451078aa8263acfd61f
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 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 echo <<'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 it has to be built"
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 -o "$?" = 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.
403 swig_git_commit_hash=2c910e47ae788412b95e356c99cef5862808bf9a
405 # Commit hash to use for common in omega:
406 omega_common_commit_hash=77db5ce3c7c95e54c9e119f09421894de2bb697a
408 gitdir=`git rev-parse --git-dir`
410 if [ ! -d "$gitdir" ] ; then
411 echo "$0: No '.git' directory found - this script should be run from a"
412 echo "git repo cloned from git://git.xapian.org/xapian or a mirror of it"
413 exit 1
416 for emptydir in xapian-applications/omega/m4 xapian-bindings/m4 ; do
417 if test -d "$emptydir" ; then
419 else
420 parent=`echo "$emptydir"|sed 's,/[^/]*$,,'`
421 if test -d "$parent" ; then
422 mkdir "$emptydir"
425 done
427 if [ -f "$gitdir/info/exclude" ] ; then
428 sed '/^\(swig\|xapian-applications\/omega\/common$\)/d' "$gitdir/info/exclude" > "$gitdir/info/exclude~"
429 else
430 [ -d "$gitdir/info" ] || mkdir "$gitdir/info"
432 cat <<END >> "$gitdir/info/exclude~"
433 swig
434 xapian-applications/omega/common
436 if [ -f "$gitdir/info/exclude" ] &&
437 cmp -s "$gitdir/info/exclude~" "$gitdir/info/exclude" ; then
438 rm "$gitdir/info/exclude~"
439 else
440 mv "$gitdir/info/exclude~" "$gitdir/info/exclude"
443 # If this tree is checked out from the github mirror, use the same access
444 # method for other things checked out from github (e.g. swig) so we avoid
445 # firewall issues. If there's no default remote, the git config command
446 # will exit with status 1, so ignore that failure.
447 origin_url=`git config remote.origin.url||:`
448 case $origin_url in
449 *[@/]github.com[:/]*)
450 github_base_url=`echo "X$origin_url"|sed 's/^X//;s!\([@/]github.com[:/]\).*!\1!'` ;;
452 github_base_url=https://github.com/ ;;
453 esac
454 swig_origin_url=${github_base_url}swig/swig.git
456 if [ -z "$XAPIAN_COMMON_CLONE_URL" ] ; then
457 xapian_common_clone_url=.
458 else
459 xapian_common_clone_url=$XAPIAN_COMMON_CLONE_URL
462 # Set to 'ftp' to use ftp URLs where available and 'http' to use unencrypted
463 # 'http'. By default we prefer https downloads as they are more likely to work
464 # through firewalls and better preserve user privacy.
465 download_protocol=
467 # Set to 'always' to always use a locally installed copy of the autotools
468 # or 'never' to never download.
470 # By default we check for locally installed versions and use them if they are
471 # new enough versions. But e.g. for building releases we want to use a known
472 # set of versions.
473 download_tools=ifneeded
475 # Save options which should be sticky for when "make" needs to rerun bootstrap.
476 # This should be empty or start with a space.
477 bootstrap_sticky_opts=
479 while [ "$#" -gt 0 ] ; do
480 case $1 in
481 --download-tools=*)
482 update_bootstrap_sticky_opts "$1"
483 download_tools=`echo "x$1"|sed 's/^x--download-tools=//'`
484 shift
485 continue
488 --download-tools)
489 update_bootstrap_sticky_opts "$1=$2"
490 download_tools=$2
491 shift 2
492 continue
495 --ftp)
496 bootstrap_sticky_opts="$bootstrap_sticky_opts $1"
497 download_protocol=ftp
498 shift
499 continue
502 --http)
503 bootstrap_sticky_opts="$bootstrap_sticky_opts $1"
504 download_protocol=http
505 shift
506 continue
509 --fetch-url-command=*)
510 update_bootstrap_sticky_opts "$1"
511 FETCH_URL_TOOL=`echo "x$1"|sed 's/^x--fetch-url-command=//'`
512 shift
513 continue
516 --fetch-url-command)
517 update_bootstrap_sticky_opts "$1=$2"
518 FETCH_URL_TOOL=$2
519 shift 2
520 continue
523 --clean)
524 # This probably shouldn't be sticky.
525 rm -rf INST
526 shift
527 continue
530 --without-autotools)
531 # This shouldn't be sticky.
532 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"
533 shift
534 continue
538 bootstrap_sticky_opts="$bootstrap_sticky_opts $1"
539 shift
540 break
544 echo "Unknown option '$1'" 1>&2
545 exit 1
549 break
551 esac
552 done
554 if [ "$#" -gt 0 ] ; then
555 for a in "$@" ; do
556 update_bootstrap_sticky_opts "$a"
557 done
560 case $download_tools in
561 always|ifneeded) ;;
562 never)
563 echo "warning: If stuff breaks with '--download-tools=never', you get to keep the pieces"
566 echo "Invalid --download-tools value '$download_tools'"
567 exit 1
569 esac
571 [ -d INST ] || mkdir INST
572 instdir=`pwd`/INST
574 [ -d BUILD ] || mkdir BUILD
575 cd BUILD
577 # The hex strings are SHA256 checksums for the preceding extension.
578 args='autoconf 2.69'
579 if need_to_build $args autoconf ; then
580 lazy_build $args \
581 tar.xz 64ebcec9f8ac5b2487125a86a7760d2591ac9e1d3dbd59489633f9de62a57684 \
582 tar.gz 954bd69b391edc12d6a4a51a2dd1476543da5c6bbf05a95b59dc0dd6fd4c2969
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 args='automake 1.15.1'
593 if need_to_build $args automake ; then
594 lazy_build $args \
595 tar.xz af6ba39142220687c500f79b4aa2f181d9b24e4f8d8ec497cea4ba26c64bedaf \
596 tar.gz 988e32527abe052307d21c8ca000aa238b914df363a617e38f4fb89f5abf6260
597 ACLOCAL=$instdir/bin/aclocal
598 export ACLOCAL
599 AUTOMAKE=$instdir/bin/automake
600 export AUTOMAKE
602 args='libtool 2.4.6'
603 if need_to_build $args libtool ; then
604 lazy_build $args \
605 tar.xz 7c87a8c2c8c0fc9cd5019e402bed4292462d00a718a7cd5f11218153bf28b26f \
606 tar.gz e3bd4d5d3d025a36c21dd6af7ea818a2afcd4dfc1ea5a17b39d7854bcd0c06e3
607 LIBTOOLIZE=$instdir/bin/libtoolize
608 export LIBTOOLIZE
609 libtool_aclocal=$instdir/share/aclocal
610 else
611 libtool_aclocal=`which libtoolize|sed 's!/bin/[^/]*$!/share/aclocal!'`
612 if [ -z "$libtool_aclocal" ] ; then
613 echo "libtoolize not found"
614 exit 1
617 # If the aclocal we're using is in a different prefix to the libtool we're
618 # using, we probably need to tell aclocal where to look for our libtool's
619 # macros. Our directory may already by specified by other means, but it's
620 # fairly harmless to specify an explicit -I for a directory which is searched
621 # anyway - at worst it changes the search order.
622 if [ "`${ACLOCAL-aclocal} --print-ac-dir`" != "$libtool_aclocal" ] ; then
623 ACLOCAL="${ACLOCAL-aclocal} -I $libtool_aclocal"
624 export ACLOCAL
627 if [ "$1" = "--deps=libmagic" ] ; then
628 shift
629 lazy_build file 5.3.2 \
630 tar.gz 8639dc4d1b21e232285cd483604afc4a6ee810710e00e579dbe9591681722b50
633 # Save the unadorned aclocal for bootstrapping SWIG. In particular SWIG
634 # uses a modified old version of AX_CXX_COMPILE_STDCXX_11 which isn't
635 # compatible with the current version which might be in a system directory.
636 SWIG_ACLOCAL=${ACLOCAL-aclocal}
638 cd ..
640 case `${LIBTOOLIZE-libtoolize} --version` in
642 echo "${LIBTOOLIZE-libtoolize} not found"
643 exit 1 ;;
644 "libtoolize (GNU libtool) 1.4.*")
645 echo "${LIBTOOLIZE-libtoolize} is from libtool 1.4 which is too old - libtool 2.2 is required."
646 echo "If you have both installed, set LIBTOOLIZE to point to the correct version."
647 exit 1 ;;
648 "libtoolize (GNU libtool) 1.5.*")
649 echo "${LIBTOOLIZE-libtoolize} is from libtool 1.5 which is too old - libtool 2.2 is required."
650 echo "If you have both installed, set LIBTOOLIZE to point to the correct version."
651 exit 1 ;;
652 esac
654 ACLOCAL="${ACLOCAL-aclocal} -I `pwd`/xapian-core/m4-macros"
655 export ACLOCAL
657 intree_swig=no
658 modules=
659 for module in ${@:-xapian-core xapian-applications/omega swig xapian-bindings} ; do
660 d=$module
661 if [ "$d" = swig ] ; then
662 if [ -f "xapian-bindings/.nobootstrap" ] ; then
663 # No point bootstrapping SWIG if we aren't going to use it.
664 echo "Skipping '$d' due to presence of 'xapian-bindings/.nobootstrap'."
665 continue
667 handle_git_external swig "$swig_git_commit_hash" "$swig_origin_url"
669 if [ -f "$d/configure.ac" -o -f "$d/configure.in" ] ; then
671 else
672 # Skip any directories we can't bootstrap.
673 continue
675 if [ -f "$d/.nobootstrap" ] ; then
676 # Report why to save head scratching when someone forgets they created
677 # a .nobootstrap file.
678 echo "Skipping '$module' due to presence of '$d/.nobootstrap'."
679 continue
681 case $d in
682 xapian-applications/omega)
683 # If someone's created a directory for common, leave it be.
684 if [ -h "$d/common" ] || [ ! -d "$d/common" ] ; then
685 hash=$omega_common_commit_hash
686 if [ -f "$gitdir/shallow" ] ; then
687 if git reflog "$hash" -- 2> /dev/null ; then
688 : # Already have the desired commit.
689 else
690 git fetch --unshallow
693 handle_git_external "$d/.common.git" "$hash" "$xapian_common_clone_url"
694 ln -sf .common.git/xapian-core/common "$d/common"
697 esac
699 echo "Bootstrapping \`$module'"
700 [ -f "$d/preautoreconf" ] && perl "$d/preautoreconf"
702 # If we have a custom INSTALL file, preserve it since autoreconf insists on
703 # replacing INSTALL with "generic installation instructions" when --force
704 # is used. Be careful to replace it if autoreconf fails.
705 if [ -f "$d/INSTALL" ] ; then
706 if grep 'generic installation instructions' "$d/INSTALL" >/dev/null 2>&1 ; then
708 else
709 mv -f "$d/INSTALL" "$d/INSTALL.preserved-by-bootstrap"
713 autoreconf_rc=
714 if [ swig = "$module" ] ; then
715 # SWIG provides its own bootstrapping script.
716 curdir=`pwd`
717 cd "$d"
718 ACLOCAL=$SWIG_ACLOCAL ./autogen.sh || autoreconf_rc=$?
719 cd "$curdir"
720 # Use the uninstalled wrapper for the in-tree copy of SWIG.
721 intree_swig=yes
722 else
723 # Use --install as debian's autoconf wrapper uses 2.5X if it sees it
724 # (but it doesn't check for -i).
726 # Use --force so that we update files if autoconf, automake, or libtool
727 # has been upgraded.
728 ${AUTORECONF-autoreconf} --install --force "$d" || autoreconf_rc=$?
730 if [ -f "$d/INSTALL.preserved-by-bootstrap" ] ; then
731 mv -f "$d/INSTALL.preserved-by-bootstrap" "$d/INSTALL"
733 if [ -n "$autoreconf_rc" ] ; then
734 exit $autoreconf_rc
736 for f in config.guess config.sub ; do
737 if [ -f "$d/$f" ] ; then
738 update_config "config/$f" "$d/$f"
740 done
741 modules="$modules $module"
742 done
744 # Produce an absolute path to srcdir.
745 srcdir_abs=`pwd`
747 # Generate the top-level configure script.
748 rm -f configure.tmp
749 cat <<TOP_OF_CONFIGURE > configure.tmp
750 #!/bin/sh
751 # configure each submodule in a xapian source tree
752 # Generated by Xapian top-level bootstrap script.
753 #$copyright
754 trap 'echo "configure failed"' EXIT
755 set -e
757 srcdir="$srcdir_abs"
758 modules="$modules"
760 TOP_OF_CONFIGURE
762 cat <<'MIDDLE_OF_CONFIGURE' >> configure.tmp
763 # Produced escaped version of command suitable for pasting back into sh
764 cmd=$0
765 user_CPPFLAGS=$CPPFLAGS
766 user_LDFLAGS=$LDFLAGS
767 for a ; do
768 case $a in
769 *[^-A-Za-z0-9_+=:@/.,]*)
770 esc_a=`echo "$a"|sed 's!\([^-A-Za-z0-9_+=:@/.,]\)!\\\\\\1!g'`
771 cmd="$cmd $esc_a" ;;
773 cmd="$cmd $a" ;;
774 esac
775 # Capture any command-line settings of CPPFLAGS or LDFLAGS so we can override
776 # for omega. We follow the behaviour of autoconf-generated configure scripts
777 # in that command-line setting beats environment variable setting, and the
778 # last of multiple command-line settings is used.
779 case $a in
780 CPPFLAGS=*)
781 user_CPPFLAGS=`expr "x$a" : 'xCPPFLAGS=\(.*\)'` ;;
782 LDFLAGS=*)
783 user_LDFLAGS=`expr "x$a" : 'xLDFLAGS=\(.*\)'` ;;
784 esac
785 done
787 here=`pwd`
788 MIDDLE_OF_CONFIGURE
790 vars=
791 if [ yes = "$intree_swig" ] ; then
792 # We want the path to SWIG to point into srcdir, which isn't known until
793 # configure-time, so we need to expand $here in configure.
794 vars=' SWIG=$here/swig/preinst-swig'
795 elif [ -n "$SWIG" ] ; then
796 # User specified SWIG in environment, e.g. with:
797 # SWIG=/opt/swig/bin/swig ./bootstrap
798 vars=" SWIG='"`echo "$val"|sed 's/\(['"\\'"']\)/\\\1/g'`"'"
800 for tool in $autotools ; do
801 eval "val=\$$tool"
802 if [ -n "$val" ] ; then
803 echo ': ${'"$tool='$val'"'}' >> configure.tmp
804 echo "export $tool" >> configure.tmp
805 vars="$vars $tool='"`echo "$val"|sed 's/\(['"\\'"']\)/\\\1/g'`"'"
807 done
808 if [ -n "$vars" ] ; then
809 # $vars will always have a leading space.
810 echo "set$vars "'"$@"' >> configure.tmp
813 cat <<'END_OF_CONFIGURE' >> configure.tmp
814 dirs=
815 revdirs=
816 XAPIAN_CONFIG=$here/xapian-core/xapian-config
817 for d in $modules ; do
818 if [ "$here" = "$srcdir" ] ; then
819 configure=./configure
820 configure_from_here=$d/configure
821 else
822 configure=$srcdir/$d/configure
823 configure_from_here=$configure
825 if [ -f "$configure_from_here" ] ; then
826 if [ -d "$d" ] ; then : ; else
827 case $d in
828 xapian-applications/*) [ -d xapian-applications ] || mkdir xapian-applications ;;
829 esac
830 mkdir "$d"
832 echo "Configuring \`$d'"
833 # Use a shared config.cache for speed and to save a bit of diskspace, but
834 # don't share it with SWIG just in case it manages to probe and cache
835 # different answers (e.g. because it uses a C compiler).
836 case $d in
837 swig)
838 case "$*" in
839 *--host=*|*--host" "*)
840 # We're cross-building, but SWIG needs to be built natively.
841 swig_configure_args=
842 skip=
843 for arg in "$@" ; do
844 if [ -n "$skip" ] ; then
845 skip=
846 continue
848 case $arg in
849 --host=*)
850 # Drop --host=xxx
851 continue ;;
852 --host)
853 # Drop --host xxx
854 skip=1
855 continue ;;
856 CC=*|CXX=*)
857 # Drop CC=xxx or CXX=xxx
858 continue ;;
859 CC_FOR_BUILD=*|CXX_FOR_BUILD=*)
860 # CC_FOR_BUILD=xxx -> CC=xxx; CXX_FOR_BUILD=xxx -> CXX=xxx
861 arg=`echo "$arg"|sed 's/_FOR_BUILD//'`
863 SWIG=*)
864 # Drop SWIG=xxx - not useful and could cause problems.
865 continue ;;
866 esac
867 swig_configure_args="$swig_configure_args "\'`echo "x$arg"|sed "s/^x//;s/'/'\\\\\\\\''/g"`\'
868 done
869 # Also handle compilers specified in environment variables. We can
870 # just reassign them unconditionally as CC and CXX are ignored if
871 # empty.
872 cd "$d" && CC=$CC_FOR_BUILD CXX=$CXX_FOR_BUILD "$configure" `eval echo $swig_configure_args`
875 cd "$d" && "$configure" ${1+"$@"}
877 esac
879 xapian-core)
880 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking --cache-file="$here/config.cache" ${1+"$@"}
882 xapian-applications/omega)
883 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+"$@"}
886 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking --cache-file="$here/config.cache" XAPIAN_CONFIG="$XAPIAN_CONFIG" ${1+"$@"}
888 esac
889 cd "$here"
890 dirs="$dirs $d"
891 revdirs="$d $revdirs"
893 done
895 case " $* " in
896 *" --help "*|*" --version "*)
897 # Don't generate Makefile if --help or --version specified.
898 trap - EXIT
899 exit 0
901 esac
903 rm -f Makefile.tmp
904 cat <<EOF > Makefile.tmp
905 # Makefile generated by:
906 CONFIGURE_COMMAND := $cmd
908 if [ "$srcdir" != . ] ; then
909 cat <<EOF >> Makefile.tmp
911 VPATH = $srcdir
914 targets='all install uninstall install-strip clean distclean mostlyclean maintainer-clean dist check distcheck'
915 for target in $targets ; do
916 echo
917 echo "$target:"
918 case $target in
919 uninstall|*clean)
920 # When uninstalling or cleaning, process directories in reverse order, so
921 # that we process a directory after any directories which might use it.
922 list=$revdirs ;;
924 list=$dirs ;;
925 esac
926 for d in $list ; do
927 case $d,$target in
928 swig,install*|swig,uninstall)
929 # Nothing to do with swig when installing/uninstalling.
931 swig,dist|swig,check|swig,distcheck|swig,all)
932 # Need to ensure swig is built before "make dist", "make check", etc.
933 echo " cd $d && \$(MAKE)" ;;
934 swig,mostlyclean)
935 echo " cd $d && \$(MAKE) clean" ;;
936 xapian-bindings,distcheck)
937 # FIXME: distcheck doesn't currently work for xapian-bindings because
938 # xapian-core isn't installed.
939 echo " cd $d && \$(MAKE) check && \$(MAKE) dist" ;;
941 echo " cd $d && \$(MAKE) $target" ;;
942 esac
943 done
944 case $target in
945 distclean|maintainer-clean) echo " rm -f Makefile config.cache" ;;
946 esac
947 done >> Makefile.tmp
948 cat <<EOF >> Makefile.tmp
950 recheck:
951 \$(CONFIGURE_COMMAND)
953 Makefile: $srcdir/configure
954 \$(CONFIGURE_COMMAND)
956 $srcdir/configure: \\
957 END_OF_CONFIGURE
959 : > configure.tmp2
961 # We want to rerun bootstrap if a series file changes (patch added or removed)
962 # or an existing patch changes. Since we always have an series file (even if
963 # it is empty), this also handles us adding the first patch for something.
964 patches=
965 for d in patches/* ; do
966 series=$d/series
967 echo "$series:" >> configure.tmp2
968 cat << END
969 $series\\\\
971 sed -n 's/[ ]*\(#.*\)\?$//;/./p' "$series" |\
972 while read p ; do
973 patch=$d/$p
974 cat << END
975 $patch\\\\
977 # Because there's a pipeline, this is a subshell, so use a temporary file
978 # rather than a variable to compile a list of patches to use below.
979 echo "$patch:" >> configure.tmp2
980 done
981 done >> configure.tmp
983 cat <<'END_OF_CONFIGURE' >> configure.tmp
984 $srcdir/bootstrap
985 END_OF_CONFIGURE
986 echo " \$srcdir/bootstrap$bootstrap_sticky_opts" >> configure.tmp
987 cat <<'END_OF_CONFIGURE' >> configure.tmp
989 .PHONY: $targets recheck
991 # Dummy dependencies to allow removing patches we no longer need.
992 END_OF_CONFIGURE
994 cat configure.tmp2 >> configure.tmp
996 cat <<'END_OF_CONFIGURE' >> configure.tmp
998 mv -f Makefile.tmp Makefile
999 trap - EXIT
1000 echo "Configured successfully - now run \"${MAKE-make}\""
1001 END_OF_CONFIGURE
1003 rm -f configure.tmp2
1005 chmod +x configure.tmp
1006 mv -f configure.tmp configure
1008 # git defaults to showing 7 character abbreviated hashes if that's enough to be
1009 # unique for a particular commit. But you can't paste these into trac as it
1010 # needs at least 8 hex digits to recognise a hex string as a commit hash. You
1011 # need 9 characters to be unique across all of Xapian at the time of writing,
1012 # and 12 for the Linux kernel currently (a much larger number of objects than
1013 # Xapian). 12 is a manageable length and decently future-proof, so let's use
1014 # that.
1015 core_abbrev_recommended=12
1016 core_abbrev=`git config --get core.abbrev||:`
1017 if [ -z "$core_abbrev" ] ; then
1018 echo "*** Setting core.abbrev=$core_abbrev_recommended in repo config"
1019 git config --local core.abbrev "$core_abbrev_recommended"
1020 elif [ "$core_abbrev" -lt "$core_abbrev_recommended" ] ; then
1021 if [ -z "`git config --local core.abbrev`" ] ; then
1022 # Set globally to < $core_abbrev_recommended, override in this repo.
1023 echo "*** Setting core.abbrev=$core_abbrev_recommended in repo config to override global core.abbrev=$core_abbrev"
1024 git config --local core.abbrev "$core_abbrev_recommended"
1025 else
1026 # Just warn.
1027 echo "warning: core.abbrev=$core_abbrev set on this repo, at least $core_abbrev_recommended is recommended"
1031 trap - EXIT
1032 echo "Bootstrapped successfully - now run \"$srcdir/configure\" and \"${MAKE-make}\""