Improve date handling in .eml files
[xapian.git] / bootstrap
blob5464e5dd9e2442c53ccaa70b9b4aa142fb9a00e1
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 # Canonicalise main_worktree_dir before comparing with pwd.
189 main_worktree_dir=`cd "$main_worktree_dir" && pwd`
190 if [ "$main_worktree_dir/BUILD" != "`pwd`" ] ; then
191 # If main_tarball is set non-empty, then we're a linked worktree.
192 main_tarball=$main_worktree_dir/BUILD/$tarball
195 if [ -n "$main_tarball" ] && [ -f "$main_tarball" ] ; then
196 # Don't re-download the tarball if the main worktree already has it.
197 tarball=$main_tarball
198 else
199 if [ -z "$FETCH_URL_TOOL" ] ; then
200 if ${WGET-wget} --version > /dev/null 2>&1 ; then
201 FETCH_URL_TOOL="${WGET-wget} -O-"
202 elif ${CURL-curl} --version > /dev/null 2>&1 || [ "$?" = 2 ] ; then
203 # curl --version exits with code 2 (~7.18.2) or 0 (7.35.0).
204 # -L is needed to follow HTTP redirects.
205 FETCH_URL_TOOL="${CURL-curl} -L"
206 elif ${LWP_REQUEST-lwp-request} -v > /dev/null 2>&1 || [ "$?" = 9 -o "$?" = 255 ] ; then
207 # lwp-request -v exits with code 9 (5.810) or 255 (6.03)
208 FETCH_URL_TOOL="${LWP_REQUEST-lwp-request} -mGET"
209 else
210 cat <<END >&2
211 Neither wget nor curl nor lwp-request found - install one of them or if already
212 installed, set WGET, CURL or LWP_REQUEST to the full path. Alternatively,
213 download $url
214 to directory `pwd`
215 then rerun this script.
217 exit 1
220 url="https://github.com/xapian/xapian-dev-deps/releases/download/current/$tarball"
221 case $basename in
222 file-*)
223 case $download_protocol in
224 ftp) url="ftp://ftp.astron.com/pub/file/$tarball" ;;
225 # We used to use http://fossies.org/ but that now redirects to https.
226 esac ;;
227 *[13579][a-z])
228 # GNU alpha release
229 case $download_protocol in
230 ftp) url="ftp://alpha.gnu.org/gnu/$package/$tarball" ;;
231 http) url="http://alpha.gnu.org/gnu/$package/$tarball" ;;
232 esac ;;
234 case $download_protocol in
235 ftp) url="ftp://ftp.gnu.org/gnu/$package/$tarball" ;;
236 http) url="http://ftpmirror.gnu.org/$package/$tarball" ;;
237 esac ;;
238 esac
239 case $download_protocol,$url in
240 http,https:*)
241 echo "warning: No http: link for $tarball available, using https:"
243 esac
245 # Keep the tarball under a quarantined name until we've verified its
246 # checksum. Once verified, if this is a linked git worktree we save
247 # the tarball in the main worktree's BUILD directory so that it can
248 # be shared with other worktrees.
249 if [ -n "$main_tarball" ] ; then
250 tarball=$main_tarball
252 quarantined_tarball=$tarball-quarantine.$$
253 rm -f "$quarantined_tarball"
254 echo "Downloading <$url>"
255 $FETCH_URL_TOOL "$url" > "$quarantined_tarball" || exit $?
256 check_checksum "$checksum" "$quarantined_tarball"
257 mv "$quarantined_tarball" "$tarball"
259 # Force a build.
260 out_of_date=force
264 if [ -z "$out_of_date" ] ; then
265 if [ -f "$stamp" ] ; then
266 # Check if the tarball or the patches we're applying have changed since
267 # the existing build.
268 out_of_date=`find "$tarball" ../patches/"$package"/* -newer "$stamp" -print 2> /dev/null||true`
269 else
270 out_of_date=force
274 if [ -n "$out_of_date" ] ; then
275 # Verify the tarball's checksum before building it. We now check at
276 # download time, but older versions of bootstrap didn't, and this also
277 # protects a user who manually downloads a tarball (which we suggest as an
278 # option if wget, curl, etc aren't found).
279 check_checksum "$checksum" "$tarball"
281 case $tarball in
282 */*) ;; # Only expire tarballs from the main worktree.
284 case `git worktree list --porcelain|grep -c '^worktree '` in
285 1|0)
286 # Remove tarballs of other versions if there's only one worktree, or if
287 # using git < 2.5 (before worktrees were added).
288 for f in "$package"-* ; do
289 [ "$f" = "$tarball" ] || rm -rf "$f"
290 done
292 esac
294 esac
296 case $ext in
297 tar.xz)
298 ${XZ-xz} -dc "$tarball"| tar xf - || exit $? ;;
299 tar.bz2)
300 bzip2 -dc "$tarball"| tar xf - || exit $? ;;
302 gzip -dc "$tarball"| tar xf - || exit $? ;;
303 esac
305 cd "$basename" || exit $?
307 series="../../patches/$package/series"
308 if [ ! -f "$series" ] ; then
309 cat <<END >&2
310 No patch series file 'patches/$package/series' - if there are no patches,
311 this should just be an empty file.
313 exit 1
315 if [ -s "$series" ] ; then
316 echo "Applying patches from $package/series"
317 sed -n 's/[ ]*\(#.*\)\?$//;/./p' "$series" | \
318 while read p ; do
319 echo "Applying patch $package/$p"
320 patch -p1 < "../../patches/$package/$p" || exit $?
321 done
324 echo "Configuring $package"
325 if test -n "$AUTOCONF" ; then
326 ./configure --prefix "$instdir" AUTOCONF="$AUTOCONF" || exit $?
327 else
328 ./configure --prefix "$instdir" || exit $?
330 echo "Building $package"
331 make || exit $?
332 echo "Installing $package"
333 make install || exit $?
334 echo "Done installing $package"
335 cd .. || exit $?
336 rm -rf "$basename" || exit $?
338 touch "$stamp" || exit $?
340 return 0
343 handle_git_external() {
344 path=$1
345 if [ ! -f "$path/.nobootstrap" ] ; then
346 rev=$2
347 url=$3
348 if [ ! -d "$path" ] ; then
349 git clone --no-checkout -- "$url" "$path"
350 elif (cd "$path" && git reflog "$rev" -- 2>/dev/null) ; then
351 : # Already have that revision locally
352 else
353 (cd "$path" && git fetch)
355 (cd "$path" && git checkout "$rev")
359 update_config() {
360 from=$1
361 to=$2
362 ts_from=`perl -ne '/^timestamp=(\W?)([-\d]+)$1/ and do {$_=$2;y/-//d;print;exit}' "$from"`
363 ts_to=`perl -ne '/^timestamp=(\W?)([-\d]+)$1/ and do {$_=$2;y/-//d;print;exit}' "$to"`
364 if [ "$ts_from" -gt "$ts_to" ] ; then
365 echo "Updating $to ($ts_to) with $from ($ts_from)"
366 # rm first in case the existing file is a symlink.
367 rm -f "$to"
368 cp "$from" "$to"
372 update_bootstrap_sticky_opts() {
373 arg=$1
374 case $arg in
375 *[^-A-Za-z0-9_+=:@/.,]*)
376 # Quote for the shell and escape $ to $$ for make.
377 bootstrap_sticky_opts="$bootstrap_sticky_opts '"`echo "$arg"|sed "s/'/'\\\\\\''/g;"'s/[$]/\\\\$\\\\$/g'`"'"
380 bootstrap_sticky_opts="$bootstrap_sticky_opts $arg"
382 esac
385 curdir=`pwd`
387 # cd to srcdir if we aren't already there.
388 srcdir=`echo "$0"|sed 's!/*[^/]*$!!'`
389 case $srcdir in
390 ""|.)
391 srcdir=. ;;
393 cd "$srcdir" ;;
394 esac
396 # Commit hash to pass to handle_git_external for swig.
397 swig_git_commit_hash=2c910e47ae788412b95e356c99cef5862808bf9a
399 # Commit hashes to use for common in omega and letor respectively:
400 omega_common_commit_hash=bddcf54435286b0363efff94f22529093e85fc89
401 letor_common_commit_hash=bddcf54435286b0363efff94f22529093e85fc89
403 if [ ! -r .git ] ; then
404 echo "$0: '.git' not found - this script should be run from a git repo cloned"
405 echo "from git://git.xapian.org/xapian or a mirror of it"
406 exit 1
409 for emptydir in xapian-applications/omega/m4 xapian-bindings/m4 xapian-letor/m4 ; do
410 if test -d "$emptydir" ; then
412 else
413 parent=`echo "$emptydir"|sed 's,/[^/]*$,,'`
414 if test -d "$parent" ; then
415 mkdir "$emptydir"
418 done
420 if [ -f .git ] ; then
421 : # Looks like we're in a git worktree.
422 else
423 if [ -f .git/info/exclude ] ; then
424 sed '/^\(swig\|xapian-applications\/omega\/common$\)/d' .git/info/exclude > .git/info/exclude~
425 else
426 [ -d .git/info ] || mkdir .git/info
428 cat <<END >> .git/info/exclude~
429 swig
430 xapian-applications/omega/common
431 xapian-letor/common
433 if [ -f .git/info/exclude ] &&
434 cmp -s .git/info/exclude~ .git/info/exclude ; then
435 rm .git/info/exclude~
436 else
437 mv .git/info/exclude~ .git/info/exclude
441 # If this tree is checked out from the github mirror, use the same access
442 # method for other things checked out from github (e.g. swig) so we avoid
443 # firewall issues. If there's no default remote, the git config command
444 # will exit with status 1, so ignore that failure.
445 origin_url=`git config remote.origin.url||:`
446 case $origin_url in
447 *[@/]github.com[:/]*)
448 github_base_url=`echo "X$origin_url"|sed 's/^X//;s!\([@/]github.com[:/]\).*!\1!'` ;;
450 github_base_url=https://github.com/ ;;
451 esac
452 swig_origin_url=${github_base_url}swig/swig.git
454 if [ -z "$XAPIAN_COMMON_CLONE_URL" ] ; then
455 xapian_common_clone_url=.
456 else
457 xapian_common_clone_url=$XAPIAN_COMMON_CLONE_URL
460 # Set to 'ftp' to use ftp URLs where available and 'http' to use unencrypted
461 # 'http'. By default we prefer https downloads as they are more likely to work
462 # through firewalls and better preserve user privacy.
463 download_protocol=
465 # Set to 'always' to always use a locally installed copy of the autotools
466 # or 'never' to never download.
468 # By default we check for locally installed versions and use them if they are
469 # new enough versions. But e.g. for building releases we want to use a known
470 # set of versions.
471 download_tools=ifneeded
473 # Save options which should be sticky for when "make" needs to rerun bootstrap.
474 # This should be empty or start with a space.
475 bootstrap_sticky_opts=
477 while [ "$#" -gt 0 ] ; do
478 case $1 in
479 --download-tools=*)
480 update_bootstrap_sticky_opts "$1"
481 download_tools=`echo "x$1"|sed 's/^x--download-tools=//'`
482 shift
483 continue
486 --download-tools)
487 update_bootstrap_sticky_opts "$1=$2"
488 download_tools=$2
489 shift 2
490 continue
493 --ftp)
494 bootstrap_sticky_opts="$bootstrap_sticky_opts $1"
495 download_protocol=ftp
496 shift
497 continue
500 --http)
501 bootstrap_sticky_opts="$bootstrap_sticky_opts $1"
502 download_protocol=http
503 shift
504 continue
507 --fetch-url-command=*)
508 update_bootstrap_sticky_opts "$1"
509 FETCH_URL_TOOL=`echo "x$1"|sed 's/^x--fetch-url-command=//'`
510 shift
511 continue
514 --fetch-url-command)
515 update_bootstrap_sticky_opts "$1=$2"
516 FETCH_URL_TOOL=$2
517 shift 2
518 continue
521 --clean)
522 # This probably shouldn't be sticky.
523 rm -rf INST
524 shift
525 continue
528 --without-autotools)
529 # This shouldn't be sticky.
530 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"
531 shift
532 continue
536 bootstrap_sticky_opts="$bootstrap_sticky_opts $1"
537 shift
538 break
542 echo "Unknown option '$1'" 1>&2
543 exit 1
547 break
549 esac
550 done
552 if [ "$#" -gt 0 ] ; then
553 for a in "$@" ; do
554 update_bootstrap_sticky_opts "$a"
555 done
558 case $download_tools in
559 always|ifneeded) ;;
560 never)
561 echo "warning: If stuff breaks with '--download-tools=never', you get to keep the pieces"
564 echo "Invalid --download-tools value '$download_tools'"
565 exit 1
567 esac
569 [ -d INST ] || mkdir INST
570 instdir=`pwd`/INST
572 [ -d BUILD ] || mkdir BUILD
573 cd BUILD
575 # The hex strings are SHA256 checksums for the preceding extension.
576 if lazy_build autoconf autoconf 2.69 \
577 tar.xz 64ebcec9f8ac5b2487125a86a7760d2591ac9e1d3dbd59489633f9de62a57684 \
578 tar.gz 954bd69b391edc12d6a4a51a2dd1476543da5c6bbf05a95b59dc0dd6fd4c2969 \
579 ; then
580 AUTOCONF=$instdir/bin/autoconf
581 export AUTOCONF
582 AUTORECONF=$instdir/bin/autoreconf
583 export AUTORECONF
584 AUTOHEADER=$instdir/bin/autoheader
585 export AUTOHEADER
586 AUTOM4TE=$instdir/bin/autom4te
587 export AUTOM4TE
589 if lazy_build automake automake 1.15.1 \
590 tar.xz af6ba39142220687c500f79b4aa2f181d9b24e4f8d8ec497cea4ba26c64bedaf \
591 tar.gz 988e32527abe052307d21c8ca000aa238b914df363a617e38f4fb89f5abf6260 \
592 ; then
593 ACLOCAL=$instdir/bin/aclocal
594 export ACLOCAL
595 AUTOMAKE=$instdir/bin/automake
596 export AUTOMAKE
598 if lazy_build libtool libtool 2.4.6 \
599 tar.xz 7c87a8c2c8c0fc9cd5019e402bed4292462d00a718a7cd5f11218153bf28b26f \
600 tar.gz e3bd4d5d3d025a36c21dd6af7ea818a2afcd4dfc1ea5a17b39d7854bcd0c06e3 \
601 ; then
602 LIBTOOLIZE=$instdir/bin/libtoolize
603 export LIBTOOLIZE
604 libtool_aclocal=$instdir/share/aclocal
605 else
606 libtool_aclocal=`which libtool|sed 's!/bin/[^/]*$!/share/aclocal!'`
608 # If the aclocal we're using is in a different prefix to the libtool we're
609 # using, we probably need to tell aclocal where to look for our libtool's
610 # macros. Our directory may already by specified by other means, but it's
611 # fairly harmless to specify an explicit -I for a directory which is searched
612 # anyway - at worst it changes the search order.
613 if [ "`${ACLOCAL-aclocal} --print-ac-dir`" != "$libtool_aclocal" ] ; then
614 ACLOCAL="${ACLOCAL-aclocal} -I $libtool_aclocal"
615 export ACLOCAL
618 if [ "$1" = "--deps=libmagic" ] ; then
619 shift
620 lazy_build file '' 5.32 \
621 tar.gz 8639dc4d1b21e232285cd483604afc4a6ee810710e00e579dbe9591681722b50
624 cd ..
626 case `${LIBTOOLIZE-libtoolize} --version` in
628 echo "${LIBTOOLIZE-libtoolize} not found"
629 exit 1 ;;
630 "libtoolize (GNU libtool) 1.4.*")
631 echo "${LIBTOOLIZE-libtoolize} is from libtool 1.4 which is too old - libtool 2.2 is required."
632 echo "If you have both installed, set LIBTOOLIZE to point to the correct version."
633 exit 1 ;;
634 "libtoolize (GNU libtool) 1.5.*")
635 echo "${LIBTOOLIZE-libtoolize} is from libtool 1.5 which is too old - libtool 2.2 is required."
636 echo "If you have both installed, set LIBTOOLIZE to point to the correct version."
637 exit 1 ;;
638 esac
640 ACLOCAL="${ACLOCAL-aclocal} -I `pwd`/xapian-core/m4-macros"
641 export ACLOCAL
643 intree_swig=no
644 modules=
645 for module in ${@:-xapian-core xapian-applications/omega swig xapian-bindings xapian-letor} ; do
646 d=$module
647 if [ "$d" = swig ] ; then
648 if [ -f "xapian-bindings/.nobootstrap" ] ; then
649 # No point bootstrapping SWIG if we aren't going to use it.
650 echo "Skipping '$d' due to presence of 'xapian-bindings/.nobootstrap'."
651 continue
653 handle_git_external swig "$swig_git_commit_hash" "$swig_origin_url"
655 if [ -f "$d/configure.ac" -o -f "$d/configure.in" ] ; then
657 else
658 # Skip any directories we can't bootstrap.
659 continue
661 if [ -f "$d/.nobootstrap" ] ; then
662 # Report why to save head scratching when someone forgets they created
663 # a .nobootstrap file.
664 echo "Skipping '$module' due to presence of '$d/.nobootstrap'."
665 continue
667 case $d in
668 xapian-applications/omega|xapian-letor)
669 # If someone's created a directory for common, leave it be.
670 if [ -h "$d/common" ] || [ ! -d "$d/common" ] ; then
671 # Pick omega_common_commit_hash or letor_common_commit_hash:
672 var=`echo "$d"|sed 's!.*[-/]!!g'`_common_commit_hash
673 hash=`eval echo \\\$"$var"`
674 handle_git_external "$d/.common.git" "$hash" "$xapian_common_clone_url"
675 ln -sf .common.git/xapian-core/common "$d/common"
678 esac
680 echo "Bootstrapping \`$module'"
681 [ -f "$d/preautoreconf" ] && "$d/preautoreconf"
683 # If we have a custom INSTALL file, preserve it since autoreconf insists on
684 # replacing INSTALL with "generic installation instructions" when --force
685 # is used. Be careful to replace it if autoreconf fails.
686 if [ -f "$d/INSTALL" ] ; then
687 if grep 'generic installation instructions' "$d/INSTALL" >/dev/null 2>&1 ; then
689 else
690 mv -f "$d/INSTALL" "$d/INSTALL.preserved-by-bootstrap"
694 autoreconf_rc=
695 if [ swig = "$module" ] ; then
696 # SWIG provides its own bootstrapping script.
697 curdir=`pwd`
698 cd "$d"
699 ./autogen.sh || autoreconf_rc=$?
700 cd "$curdir"
701 # Use the uninstalled wrapper for the in-tree copy of SWIG.
702 intree_swig=yes
703 else
704 # Use --install as debian's autoconf wrapper uses 2.5X if it sees it
705 # (but it doesn't check for -i).
707 # Use --force so that we update files if autoconf, automake, or libtool
708 # has been upgraded.
709 ${AUTORECONF-autoreconf} --install --force "$d" || autoreconf_rc=$?
711 if [ -f "$d/INSTALL.preserved-by-bootstrap" ] ; then
712 mv -f "$d/INSTALL.preserved-by-bootstrap" "$d/INSTALL"
714 if [ -n "$autoreconf_rc" ] ; then
715 exit $autoreconf_rc
717 for f in config.guess config.sub ; do
718 if [ -f "$d/$f" ] ; then
719 update_config "config/$f" "$d/$f"
721 done
722 modules="$modules $module"
723 done
725 # Produce an absolute path to srcdir.
726 srcdir_abs=`pwd`
728 # Generate the top-level configure script.
729 rm -f configure.tmp
730 cat <<TOP_OF_CONFIGURE > configure.tmp
731 #!/bin/sh
732 # configure each submodule in a xapian source tree
733 # Generated by Xapian top-level bootstrap script.
734 #$copyright
735 trap 'echo "configure failed"' EXIT
736 set -e
738 srcdir="$srcdir_abs"
739 modules="$modules"
741 TOP_OF_CONFIGURE
743 cat <<'MIDDLE_OF_CONFIGURE' >> configure.tmp
744 # Produced escaped version of command suitable for pasting back into sh
745 cmd=$0
746 for a ; do
747 case $a in
748 *[^-A-Za-z0-9_+=:@/.,]*)
749 esc_a=`echo "$a"|sed 's!\([^-A-Za-z0-9_+=:@/.,]\)!\\\\\\1!g'`
750 cmd="$cmd $esc_a" ;;
752 cmd="$cmd $a" ;;
753 esac
754 done
756 here=`pwd`
757 MIDDLE_OF_CONFIGURE
759 vars=
760 if [ yes = "$intree_swig" ] ; then
761 # We want the path to SWIG to point into srcdir, which isn't known until
762 # configure-time, so we need to expand $here in configure.
763 vars=' SWIG=$here/swig/preinst-swig'
764 elif [ -n "$SWIG" ] ; then
765 # User specified SWIG in environment, e.g. with:
766 # SWIG=/opt/swig/bin/swig ./bootstrap
767 vars=" SWIG='"`echo "$val"|sed 's/\(['"\\'"']\)/\\\1/g'`"'"
769 for tool in $autotools ; do
770 eval "val=\$$tool"
771 if [ -n "$val" ] ; then
772 echo ': ${'"$tool='$val'"'}' >> configure.tmp
773 echo "export $tool" >> configure.tmp
774 vars="$vars $tool='"`echo "$val"|sed 's/\(['"\\'"']\)/\\\1/g'`"'"
776 done
777 if [ -n "$vars" ] ; then
778 # $vars will always have a leading space.
779 echo "set$vars "'"$@"' >> configure.tmp
782 cat <<'END_OF_CONFIGURE' >> configure.tmp
783 dirs=
784 revdirs=
785 XAPIAN_CONFIG=$here/xapian-core/xapian-config
786 for d in $modules ; do
787 if [ "$here" = "$srcdir" ] ; then
788 configure=./configure
789 configure_from_here=$d/configure
790 else
791 configure=$srcdir/$d/configure
792 configure_from_here=$configure
794 if [ -f "$configure_from_here" ] ; then
795 if [ -d "$d" ] ; then : ; else
796 case $d in
797 xapian-applications/*) [ -d xapian-applications ] || mkdir xapian-applications ;;
798 esac
799 mkdir "$d"
801 echo "Configuring \`$d'"
802 # Use a shared config.cache for speed and to save a bit of diskspace, but
803 # don't share it with SWIG just in case it manages to probe and cache
804 # different answers (e.g. because it uses a C compiler).
805 case $d in
806 swig)
807 case "$*" in
808 *--host=*|*--host" "*)
809 # We're cross-building, but SWIG needs to be built natively.
810 swig_configure_args=
811 skip=
812 for arg in "$@" ; do
813 if [ -n "$skip" ] ; then
814 skip=
815 continue
817 case $arg in
818 --host=*)
819 # Drop --host=xxx
820 continue ;;
821 --host)
822 # Drop --host xxx
823 skip=1
824 continue ;;
825 CC=*|CXX=*)
826 # Drop CC=xxx or CXX=xxx
827 continue ;;
828 CC_FOR_BUILD=*|CXX_FOR_BUILD=*)
829 # CC_FOR_BUILD=xxx -> CC=xxx; CXX_FOR_BUILD=xxx -> CXX=xxx
830 arg=`echo "$arg"|sed 's/_FOR_BUILD//'`
832 SWIG=*)
833 # Drop SWIG=xxx - not useful and could cause problems.
834 continue ;;
835 esac
836 swig_configure_args="$swig_configure_args "\'`echo "x$arg"|sed "s/^x//;s/'/'\\\\\\\\''/g"`\'
837 done
838 # Also handle compilers specified in environment variables. We can
839 # just reassign them unconditionally as CC and CXX are ignored if
840 # empty.
841 cd "$d" && CC=$CC_FOR_BUILD CXX=$CXX_FOR_BUILD "$configure" `eval echo $swig_configure_args`
844 cd "$d" && "$configure" ${1+"$@"}
846 esac
848 xapian-core)
849 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking --cache-file="$here/config.cache" ${1+"$@"}
851 xapian-applications/omega)
852 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking XAPIAN_CONFIG="$XAPIAN_CONFIG" CPPFLAGS="-I$srcdir/INST/include" LDFLAGS="-L$srcdir/INST/lib" ${1+"$@"}
855 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking --cache-file="$here/config.cache" XAPIAN_CONFIG="$XAPIAN_CONFIG" ${1+"$@"}
857 esac
858 cd "$here"
859 dirs="$dirs $d"
860 revdirs="$d $revdirs"
862 done
864 case " $* " in
865 *" --help "*|*" --version "*)
866 # Don't generate Makefile if --help or --version specified.
867 trap - EXIT
868 exit 0
870 esac
872 rm -f Makefile.tmp
873 cat <<EOF > Makefile.tmp
874 # Makefile generated by:
875 CONFIGURE_COMMAND := $cmd
877 if [ "$srcdir" != . ] ; then
878 cat <<EOF >> Makefile.tmp
880 VPATH = $srcdir
883 targets='all install uninstall install-strip clean distclean mostlyclean maintainer-clean dist check distcheck'
884 for target in $targets ; do
885 echo
886 echo "$target:"
887 case $target in
888 uninstall|*clean)
889 # When uninstalling or cleaning, process directories in reverse order, so
890 # that we process a directory after any directories which might use it.
891 list=$revdirs ;;
893 list=$dirs ;;
894 esac
895 for d in $list ; do
896 case $d,$target in
897 swig,install*|swig,uninstall)
898 # Nothing to do with swig when installing/uninstalling.
900 swig,dist|swig,check|swig,distcheck|swig,all)
901 # Need to ensure swig is built before "make dist", "make check", etc.
902 echo " cd $d && \$(MAKE)" ;;
903 swig,mostlyclean)
904 echo " cd $d && \$(MAKE) clean" ;;
905 xapian-bindings,distcheck)
906 # FIXME: distcheck doesn't currently work for xapian-bindings because
907 # xapian-core isn't installed.
908 echo " cd $d && \$(MAKE) check && \$(MAKE) dist" ;;
910 echo " cd $d && \$(MAKE) $target" ;;
911 esac
912 done
913 case $target in
914 distclean|maintainer-clean) echo " rm -f Makefile config.cache" ;;
915 esac
916 done >> Makefile.tmp
917 cat <<EOF >> Makefile.tmp
919 recheck:
920 \$(CONFIGURE_COMMAND)
922 Makefile: $srcdir/configure
923 \$(CONFIGURE_COMMAND)
925 $srcdir/configure: \\
926 END_OF_CONFIGURE
928 : > configure.tmp2
930 # We want to rerun bootstrap if a series file changes (patch added or removed)
931 # or an existing patch changes. Since we always have an series file (even if
932 # it is empty), this also handles us adding the first patch for something.
933 patches=
934 for d in patches/* ; do
935 series=$d/series
936 echo "$series:" >> configure.tmp2
937 cat << END
938 $series\\\\
940 sed -n 's/[ ]*\(#.*\)\?$//;/./p' "$series" |\
941 while read p ; do
942 patch=$d/$p
943 cat << END
944 $patch\\\\
946 # Because there's a pipeline, this is a subshell, so use a temporary file
947 # rather than a variable to compile a list of patches to use below.
948 echo "$patch:" >> configure.tmp2
949 done
950 done >> configure.tmp
952 cat <<'END_OF_CONFIGURE' >> configure.tmp
953 $srcdir/bootstrap
954 END_OF_CONFIGURE
955 echo " \$srcdir/bootstrap$bootstrap_sticky_opts" >> configure.tmp
956 cat <<'END_OF_CONFIGURE' >> configure.tmp
958 .PHONY: $targets recheck
960 # Dummy dependencies to allow removing patches we no longer need.
961 END_OF_CONFIGURE
963 cat configure.tmp2 >> configure.tmp
965 cat <<'END_OF_CONFIGURE' >> configure.tmp
967 mv -f Makefile.tmp Makefile
968 trap - EXIT
969 echo "Configured successfully - now run \"${MAKE-make}\""
970 END_OF_CONFIGURE
972 rm -f configure.tmp2
974 chmod +x configure.tmp
975 mv -f configure.tmp configure
977 # git defaults to showing 7 character abbreviated hashes if that's enough to be
978 # unique for a particular commit. But you can't paste these into trac as it
979 # needs at least 8 hex digits to recognise a hex string as a commit hash. You
980 # need 9 characters to be unique across all of Xapian at the time of writing,
981 # and 12 for the Linux kernel currently (a much larger number of objects than
982 # Xapian). 12 is a manageable length and decently future-proof, so let's use
983 # that.
984 core_abbrev_recommended=12
985 core_abbrev=`git config --get core.abbrev||:`
986 if [ -z "$core_abbrev" ] ; then
987 echo "*** Setting core.abbrev=$core_abbrev_recommended in repo config"
988 git config --local core.abbrev "$core_abbrev_recommended"
989 elif [ "$core_abbrev" -lt "$core_abbrev_recommended" ] ; then
990 if [ -z "`git config --local core.abbrev`" ] ; then
991 # Set globally to < $core_abbrev_recommended, override in this repo.
992 echo "*** Setting core.abbrev=$core_abbrev_recommended in repo config to override global core.abbrev=$core_abbrev"
993 git config --local core.abbrev "$core_abbrev_recommended"
994 else
995 # Just warn.
996 echo "warning: core.abbrev=$core_abbrev set on this repo, at least $core_abbrev_recommended is recommended"
1000 trap - EXIT
1001 echo "Bootstrapped successfully - now run \"$srcdir/configure\" and \"${MAKE-make}\""