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