Merge latest lemon.c and template from upstream
[xapian.git] / bootstrap
blobc36264c66aa6d75d4ecb9294c4cd08dff6508291
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)] [--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 or curl).
41 FETCH_URL_TOOL=
43 check_checksum() {
44 # This function is expected to be used in 'if' so we can't rely on set -e
45 # being in effect here.
46 checksum=$1
47 tarball=$2
49 if [ -z "$SHA256SUM_TOOL" ] ; then
50 for SHA256SUM_TOOL in \
51 '${SHA256SUM-sha256sum} 2>/dev/null|cut -d\ -f1' \
52 '${SHASUM-shasum} -a256 2>/dev/null|cut -d\ -f1' \
53 '${OPENSSL-openssl} sha256 2>/dev/null|sed "s/.* //"' \
54 '' ; do
55 if [ -z "$SHA256SUM_TOOL" ] ; then
56 echo <<'END'
57 Need sha256sum or shasum or openssl installed to check SHA256 checksums.
58 Set environment variable SHA256SUM, SHASUM or OPENSSL if the tool isn't on
59 your PATH.
60 END
61 exit 1
63 # Sanity check by hashing empty input.
64 r=`:|eval "$SHA256SUM_TOOL"`
65 [ X"$r" != Xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 ] || break
66 done
68 r=`< $tarball eval "$SHA256SUM_TOOL"`
69 if [ X"$r" != X"$checksum" ] ; then
70 echo "$tarball: computed SHA256 checksum did NOT match"
71 echo "computed: $r with $SHA256SUM_TOOL"
72 echo "expected: $checksum"
73 ls -l $tarball
74 file $tarball || true
75 mv "$tarball" "$tarball.$r"
76 echo "Renamed $tarball to $tarball.$r"
77 exit 1
81 check_at_least() {
82 # This function is expected to be used in 'if' so we can't rely on set -e
83 # being in effect here.
84 v1=$1
85 v2=$2
86 save_IFS=$IFS
87 IFS=.
88 set x $v1
89 for v in $v2 ; do
90 shift
91 if [ "$1" != "$v" ] ; then
92 if [ -z "$1" ] || [ "$1" -lt "$v" ] ; then
93 IFS=$save_IFS
94 return 1
96 break
98 done
99 IFS=$save_IFS
100 return 0
103 lazy_build() {
104 # This function is expected to be used in 'if' so we can't rely on set -e
105 # being in effect here.
106 package=$1
107 binary=$2
108 version=$3
110 case $download_tools in
111 always) ;;
112 never)
113 return 1
116 if [ -n $binary ] ; then
117 if [ -s "../patches/$package/series" ] ; then
118 echo "There are patches to apply to $package so it has to be built"
119 else
120 # Check if a new enough version is already installed.
121 version_installed=`"$binary" --version 2>/dev/null|sed '1,1 s/.* //p;d'`
122 if [ -n "$version_installed" ] ; then
123 # Fast track equality.
124 if [ "$version_installed" = "$version" ] ; then
125 echo "$binary $version_installed installed, exactly what's needed"
126 return 1
128 if check_at_least "$version_installed" "$version" ; then
129 echo "$binary $version_installed installed >= $version required"
130 return 1
136 esac
138 basename=$package-$version
139 ext=$4
140 checksum=$5
142 if [ "$ext" = "tar.xz" ] ; then
143 if [ -z "$xz_ok" ] ; then
144 if ${XZ-xz} --version > /dev/null 2>&1 ; then
145 xz_ok=1
146 else
147 xz_ok=0
150 if [ "$xz_ok" = 0 ] ; then
151 shift 2
152 ext=$4
153 checksum=$5
156 if [ "$ext" = "tar.bz2" ] ; then
157 if [ -z "$bz2_ok" ] ; then
158 # bzip2 --version doesn't exit with code 0 in upstream version (though
159 # Debian at least patch this bug), so use --help to check it.
160 if bzip2 --help > /dev/null 2>&1 ; then
161 bz2_ok=1
162 else
163 bz2_ok=0
166 if [ "$bz2_ok" = 0 ] ; then
167 shift 2
168 ext=$4
169 checksum=$5
172 tarball=$basename.$ext
173 case $basename in
174 *[24680][a-z]) basename=`echo "$basename"|sed 's/[a-z]$//'` ;;
175 esac
177 # Create the stamp file in INST so that rerunning bootstrap after
178 # "rm -rf INST" recovers nicely.
179 stamp=../INST/$package.stamp
181 # Download the tarball if required.
182 if [ ! -f "$tarball" ] ; then
183 if [ -z "$FETCH_URL_TOOL" ] ; then
184 if ${WGET-wget} --version > /dev/null 2>&1 ; then
185 FETCH_URL_TOOL="${WGET-wget} -O-"
186 elif ${CURL-curl} --version > /dev/null 2>&1 || [ "$?" = 2 ] ; then
187 # curl --version exits with code 2.
188 # -L is needed to follow HTTP redirects.
189 FETCH_URL_TOOL="${CURL-curl} -L"
190 elif ${LWP_REQUEST-lwp-request} -v > /dev/null 2>&1 || [ "$?" = 9 -o "$?" = 255 ] ; then
191 # lwp-request -v exits with code 9 (5.810) or 255 (6.03)
192 FETCH_URL_TOOL="${LWP_REQUEST-lwp-request} -mGET"
193 else
194 cat <<END >&2
195 Neither wget nor curl nor lwp-request found - install one of them or if already
196 installed, set WGET, CURL or LWP_REQUEST to the full path. Alternatively,
197 download $url
198 to directory `pwd`
199 then rerun this script.
201 exit 1
204 url="https://github.com/xapian/xapian-dev-deps/releases/download/current/$tarball"
205 case $basename in
206 file-*)
207 case $download_protocol in
208 ftp) url="ftp://ftp.astron.com/pub/file/$tarball" ;;
209 # We used to use http://fossies.org/ but that now redirects to https.
210 esac ;;
211 *[13579][a-z])
212 # GNU alpha release
213 case $download_protocol in
214 ftp) url="ftp://alpha.gnu.org/gnu/$package/$tarball" ;;
215 http) url="http://alpha.gnu.org/gnu/$package/$tarball" ;;
216 esac ;;
218 case $download_protocol in
219 ftp) url="ftp://ftp.gnu.org/gnu/$package/$tarball" ;;
220 http) url="http://ftpmirror.gnu.org/$package/$tarball" ;;
221 esac ;;
222 esac
223 case $download_protocol,$url in
224 http,https:*)
225 echo "warning: No http: link for $tarball available, using https:"
227 esac
228 rm -f download.tmp
229 echo "Downloading <$url>"
230 $FETCH_URL_TOOL "$url" > download.tmp || exit $?
231 mv download.tmp "$tarball"
234 if [ -f "$stamp" ] ; then
235 find_stdout=`find "$tarball" ../patches/"$package"/* -newer "$stamp" -print 2> /dev/null||true`
236 else
237 find_stdout=force
240 if [ -n "$find_stdout" ] ; then
241 # Verify the tarball's checksum before building it.
242 check_checksum "$checksum" "$tarball"
244 # Remove tarballs of other versions.
245 for f in "$package"-* ; do
246 [ "$f" = "$tarball" ] || rm -rf "$f"
247 done
249 case $ext in
250 tar.xz)
251 ${XZ-xz} -dc "$tarball"| tar xf - || exit $? ;;
252 tar.bz2)
253 bzip2 -dc "$tarball"| tar xf - || exit $? ;;
255 gzip -dc "$tarball"| tar xf - || exit $? ;;
256 esac
258 cd "$basename" || exit $?
260 series="../../patches/$package/series"
261 if [ ! -f "$series" ] ; then
262 cat <<END >&2
263 No patch series file 'patches/$package/series' - if there are no patches,
264 this should just be an empty file.
266 exit 1
268 if [ -s "$series" ] ; then
269 echo "Applying patches from $package/series"
270 sed -n 's/[ ]*\(#.*\)\?$//;/./p' "$series" | \
271 while read p ; do
272 echo "Applying patch $package/$p"
273 patch -p1 < "../../patches/$package/$p" || exit $?
274 done
277 echo "Configuring $package"
278 if test -n "$AUTOCONF" ; then
279 ./configure --prefix "$instdir" AUTOCONF="$AUTOCONF" || exit $?
280 else
281 ./configure --prefix "$instdir" || exit $?
283 echo "Building $package"
284 make || exit $?
285 echo "Installing $package"
286 make install || exit $?
287 echo "Done installing $package"
288 cd .. || exit $?
289 rm -rf "$basename" || exit $?
291 touch "$stamp" || exit $?
293 return 0
296 handle_git_external() {
297 path=$1
298 if [ ! -f "$path/.nobootstrap" ] ; then
299 rev=$2
300 url=$3
301 if [ ! -d "$path" ] ; then
302 git clone --no-checkout -- "$url" "$path"
303 elif (cd "$path" && git reflog "$rev" -- 2>/dev/null) ; then
304 : # Already have that revision locally
305 else
306 (cd "$path" && git fetch)
308 (cd "$path" && git checkout "$rev")
312 update_config() {
313 from=$1
314 to=$2
315 ts_from=`perl -ne '/^timestamp=(\W?)([-\d]+)$1/ and do {$_=$2;y/-//d;print;exit}' "$from"`
316 ts_to=`perl -ne '/^timestamp=(\W?)([-\d]+)$1/ and do {$_=$2;y/-//d;print;exit}' "$to"`
317 if [ "$ts_from" -gt "$ts_to" ] ; then
318 echo "Updating $to ($ts_to) with $from ($ts_from)"
319 # rm first in case the existing file is a symlink.
320 rm -f "$to"
321 cp "$from" "$to"
325 curdir=`pwd`
327 # cd to srcdir if we aren't already there.
328 srcdir=`echo "$0"|sed 's!/*[^/]*$!!'`
329 case $srcdir in
330 ""|.)
331 srcdir=. ;;
333 cd "$srcdir" ;;
334 esac
336 # Commit hash to pass to handle_git_external for swig.
337 swig_git_commit_hash=2c910e47ae788412b95e356c99cef5862808bf9a
339 # Commit hashes to use for common in omega and letor respectively:
340 omega_common_commit_hash=b310f9988f63cdc15b48323f9ac42f6b08c3a36c
341 letor_common_commit_hash=b310f9988f63cdc15b48323f9ac42f6b08c3a36c
343 if [ ! -d .git ] ; then
344 echo "$0: No '.git' directory found - this script should be run from a"
345 echo "git repo cloned from git://git.xapian.org/xapian or a mirror of it"
346 exit 1
349 for emptydir in xapian-applications/omega/m4 xapian-bindings/m4 xapian-letor/m4 ; do
350 if test -d "$emptydir" ; then
352 else
353 parent=`echo "$emptydir"|sed 's,/[^/]*$,,'`
354 if test -d "$parent" ; then
355 mkdir "$emptydir"
358 done
360 if [ -f .git/info/exclude ] ; then
361 sed '/^\(swig\|xapian-applications\/omega\/common$\)/d' .git/info/exclude > .git/info/exclude~
362 else
363 [ -d .git/info ] || mkdir .git/info
365 cat <<END >> .git/info/exclude~
366 swig
367 xapian-applications/omega/common
368 xapian-letor/common
370 if [ -f .git/info/exclude ] &&
371 cmp -s .git/info/exclude~ .git/info/exclude ; then
372 rm .git/info/exclude~
373 else
374 mv .git/info/exclude~ .git/info/exclude
377 # If this tree is checked out from the github mirror, use the same access
378 # method for other things checked out from github (e.g. swig) so we avoid
379 # firewall issues. If there's no default remote, the git config command
380 # will exit with status 1, so ignore that failure.
381 origin_url=`git config remote.origin.url||:`
382 case $origin_url in
383 *[@/]github.com[:/]*)
384 github_base_url=`echo "X$origin_url"|sed 's/^X//;s!\([@/]github.com[:/]\).*!\1!'` ;;
386 github_base_url=https://github.com/ ;;
387 esac
388 swig_origin_url=${github_base_url}swig/swig.git
390 if [ -z "$XAPIAN_COMMON_CLONE_URL" ] ; then
391 xapian_common_clone_url=.
392 else
393 xapian_common_clone_url=$XAPIAN_COMMON_CLONE_URL
396 # Set to 'ftp' to use ftp URLs where available and 'http' to use unencrypted
397 # 'http'. By default we prefer https downloads as they are more likely to work
398 # through firewalls and better preserve user privacy.
399 download_protocol=
401 # Set to 'always' to always use a locally installed copy of the autotools
402 # or 'never' to never download.
404 # By default we check for locally installed versions and use them if they are
405 # new enough versions. But e.g. for building releases we want to use a known
406 # set of versions.
407 download_tools=ifneeded
409 # Save options which should be sticky for when "make" needs to rerun bootstrap.
410 # This should be empty or start with a space. FIXME: We don't even try to
411 # shell-escape options here - this isn't a security concern, and currently
412 # none of the options should be affected, but it would be good to sort out.
413 bootstrap_sticky_opts=
415 while [ "$#" -gt 0 ] ; do
416 case $1 in
417 --download-tools=*)
418 bootstrap_sticky_opts="$bootstrap_sticky_opts $1"
419 download_tools=`echo "x$1"|sed 's/x--download-tools=//'`
420 shift
421 continue
424 --download-tools)
425 bootstrap_sticky_opts="$bootstrap_sticky_opts $1 $2"
426 download_tools=$2
427 shift 2
428 continue
431 --ftp)
432 bootstrap_sticky_opts="$bootstrap_sticky_opts $1"
433 download_protocol=ftp
434 shift
435 continue
438 --http)
439 bootstrap_sticky_opts="$bootstrap_sticky_opts $1"
440 download_protocol=http
441 shift
442 continue
445 --clean)
446 # This probably shouldn't be sticky.
447 rm -rf INST
448 shift
449 continue
452 --without-autotools)
453 # This shouldn't be sticky.
454 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"
455 shift
456 continue
460 bootstrap_sticky_opts="$bootstrap_sticky_opts $1"
461 shift
462 break
466 echo "Unknown option '$1'" 1>&2
467 exit 1
471 break
473 esac
474 done
476 if [ "$#" -gt 0 ] ; then
477 bootstrap_sticky_opts="$bootstrap_sticky_opts $*"
480 case $download_tools in
481 always|ifneeded) ;;
482 never)
483 echo "warning: If stuff breaks with '--download-tools=never', you get to keep the pieces"
486 echo "Invalid --download-tools value '$download_tools'"
487 exit 1
489 esac
491 [ -d INST ] || mkdir INST
492 instdir=`pwd`/INST
494 [ -d BUILD ] || mkdir BUILD
495 cd BUILD
497 # The hex strings are SHA256 checksums for the preceding extension.
498 if lazy_build autoconf autoconf 2.69 \
499 tar.xz 64ebcec9f8ac5b2487125a86a7760d2591ac9e1d3dbd59489633f9de62a57684 \
500 tar.gz 954bd69b391edc12d6a4a51a2dd1476543da5c6bbf05a95b59dc0dd6fd4c2969 \
501 ; then
502 AUTOCONF=$instdir/bin/autoconf
503 export AUTOCONF
504 AUTORECONF=$instdir/bin/autoreconf
505 export AUTORECONF
506 AUTOHEADER=$instdir/bin/autoheader
507 export AUTOHEADER
508 AUTOM4TE=$instdir/bin/autom4te
509 export AUTOM4TE
511 if lazy_build automake automake 1.16.1 \
512 tar.xz 5d05bb38a23fd3312b10aea93840feec685bdf4a41146e78882848165d3ae921 \
513 tar.gz 608a97523f97db32f1f5d5615c98ca69326ced2054c9f82e65bade7fc4c9dea8 \
514 ; then
515 ACLOCAL=$instdir/bin/aclocal
516 export ACLOCAL
517 AUTOMAKE=$instdir/bin/automake
518 export AUTOMAKE
520 if lazy_build libtool libtool 2.4.6 \
521 tar.xz 7c87a8c2c8c0fc9cd5019e402bed4292462d00a718a7cd5f11218153bf28b26f \
522 tar.gz e3bd4d5d3d025a36c21dd6af7ea818a2afcd4dfc1ea5a17b39d7854bcd0c06e3 \
523 ; then
524 LIBTOOLIZE=$instdir/bin/libtoolize
525 export LIBTOOLIZE
526 libtool_aclocal=$instdir/share/aclocal
527 else
528 libtool_aclocal=`which libtool|sed 's!/bin/[^/]*$!/share/aclocal!'`
530 # If the aclocal we're using is in a different prefix to the libtool we're
531 # using, we probably need to tell aclocal where to look for our libtool's
532 # macros. Our directory may already by specified by other means, but it's
533 # fairly harmless to specify an explicit -I for a directory which is searched
534 # anyway - at worst it changes the search order.
535 if [ "`${ACLOCAL-aclocal} --print-ac-dir`" != "$libtool_aclocal" ] ; then
536 ACLOCAL="${ACLOCAL-aclocal} -I $libtool_aclocal"
537 export ACLOCAL
540 if [ "$1" = "--deps=libmagic" ] ; then
541 shift
542 lazy_build file '' 5.32 \
543 tar.gz 8639dc4d1b21e232285cd483604afc4a6ee810710e00e579dbe9591681722b50
546 cd ..
548 case `${LIBTOOLIZE-libtoolize} --version` in
550 echo "${LIBTOOLIZE-libtoolize} not found"
551 exit 1 ;;
552 "libtoolize (GNU libtool) 1.4.*")
553 echo "${LIBTOOLIZE-libtoolize} is from libtool 1.4 which is too old - libtool 2.2 is required."
554 echo "If you have both installed, set LIBTOOLIZE to point to the correct version."
555 exit 1 ;;
556 "libtoolize (GNU libtool) 1.5.*")
557 echo "${LIBTOOLIZE-libtoolize} is from libtool 1.5 which is too old - libtool 2.2 is required."
558 echo "If you have both installed, set LIBTOOLIZE to point to the correct version."
559 exit 1 ;;
560 esac
562 ACLOCAL="${ACLOCAL-aclocal} -I `pwd`/xapian-core/m4-macros"
563 export ACLOCAL
565 intree_swig=no
566 modules=
567 for module in ${@:-xapian-core xapian-applications/omega swig xapian-bindings} ; do
568 d=$module
569 if [ "$d" = swig ] ; then
570 if [ -f "xapian-bindings/.nobootstrap" ] ; then
571 # No point bootstrapping SWIG if we aren't going to use it.
572 echo "Skipping '$d' due to presence of 'xapian-bindings/.nobootstrap'."
573 continue
575 handle_git_external swig "$swig_git_commit_hash" "$swig_origin_url"
577 if [ -f "$d/configure.ac" -o -f "$d/configure.in" ] ; then
579 else
580 # Skip any directories we can't bootstrap.
581 continue
583 if [ -f "$d/.nobootstrap" ] ; then
584 # Report why to save head scratching when someone forgets they created
585 # a .nobootstrap file.
586 echo "Skipping '$module' due to presence of '$d/.nobootstrap'."
587 continue
589 case $d in
590 xapian-applications/omega|xapian-letor)
591 # If someone's created a directory for common, leave it be.
592 if [ -h "$d/common" ] || [ ! -d "$d/common" ] ; then
593 # Pick omega_common_commit_hash or letor_common_commit_hash:
594 var=`echo "$d"|sed 's!.*[-/]!!g'`_common_commit_hash
595 hash=`eval echo \\\$"$var"`
596 handle_git_external "$d/.common.git" "$hash" "$xapian_common_clone_url"
597 ln -sf .common.git/xapian-core/common "$d/common"
600 esac
602 echo "Bootstrapping \`$module'"
603 [ -f "$d/preautoreconf" ] && "$d/preautoreconf"
605 # If we have a custom INSTALL file, preserve it since autoreconf insists on
606 # replacing INSTALL with "generic installation instructions" when --force
607 # is used. Be careful to replace it if autoreconf fails.
608 if [ -f "$d/INSTALL" ] ; then
609 if grep 'generic installation instructions' "$d/INSTALL" >/dev/null 2>&1 ; then
611 else
612 mv -f "$d/INSTALL" "$d/INSTALL.preserved-by-bootstrap"
616 autoreconf_rc=
617 if [ swig = "$module" ] ; then
618 # SWIG provides its own bootstrapping script.
619 curdir=`pwd`
620 cd "$d"
621 ./autogen.sh || autoreconf_rc=$?
622 cd "$curdir"
623 # Use the uninstalled wrapper for the in-tree copy of SWIG.
624 intree_swig=yes
625 else
626 # Use --install as debian's autoconf wrapper uses 2.5X if it sees it
627 # (but it doesn't check for -i).
629 # Use --force so that we update files if autoconf, automake, or libtool
630 # has been upgraded.
631 ${AUTORECONF-autoreconf} --install --force "$d" || autoreconf_rc=$?
633 if [ -f "$d/INSTALL.preserved-by-bootstrap" ] ; then
634 mv -f "$d/INSTALL.preserved-by-bootstrap" "$d/INSTALL"
636 if [ -n "$autoreconf_rc" ] ; then
637 exit $autoreconf_rc
639 for f in config.guess config.sub ; do
640 if [ -f "$d/$f" ] ; then
641 update_config "config/$f" "$d/$f"
643 done
644 modules="$modules $module"
645 done
647 # Produce an absolute path to srcdir.
648 srcdir_abs=`pwd`
650 # Generate the top-level configure script.
651 rm -f configure.tmp
652 cat <<TOP_OF_CONFIGURE > configure.tmp
653 #!/bin/sh
654 # configure each submodule in a xapian source tree
655 # Generated by Xapian top-level bootstrap script.
656 #$copyright
657 trap 'echo "configure failed"' EXIT
658 set -e
660 srcdir="$srcdir_abs"
661 modules="$modules"
663 TOP_OF_CONFIGURE
665 cat <<'MIDDLE_OF_CONFIGURE' >> configure.tmp
666 # Produced escaped version of command suitable for pasting back into sh
667 cmd=$0
668 for a ; do
669 case $a in
670 *[^-A-Za-z0-9_+=:@/.,]*)
671 esc_a=`echo "$a"|sed 's!\([^-A-Za-z0-9_+=:@/.,]\)!\\\\\\1!g'`
672 cmd="$cmd $esc_a" ;;
674 cmd="$cmd $a" ;;
675 esac
676 done
678 here=`pwd`
679 MIDDLE_OF_CONFIGURE
681 vars=
682 if [ yes = "$intree_swig" ] ; then
683 # We want the path to SWIG to point into srcdir, which isn't known until
684 # configure-time, so we need to expand $here in configure.
685 vars=' SWIG=$here/swig/preinst-swig'
686 elif [ -n "$SWIG" ] ; then
687 # User specified SWIG in environment, e.g. with:
688 # SWIG=/opt/swig/bin/swig ./bootstrap
689 vars=" SWIG='"`echo "$val"|sed 's/\(['"\\'"']\)/\\\1/g'`"'"
691 for tool in $autotools ; do
692 eval "val=\$$tool"
693 if [ -n "$val" ] ; then
694 echo ': ${'"$tool='$val'"'}' >> configure.tmp
695 echo "export $tool" >> configure.tmp
696 vars="$vars $tool='"`echo "$val"|sed 's/\(['"\\'"']\)/\\\1/g'`"'"
698 done
699 if [ -n "$vars" ] ; then
700 # $vars will always have a leading space.
701 echo "set$vars "'"$@"' >> configure.tmp
704 cat <<'END_OF_CONFIGURE' >> configure.tmp
705 dirs=
706 revdirs=
707 XAPIAN_CONFIG=$here/xapian-core/xapian-config
708 for d in $modules ; do
709 if [ "$here" = "$srcdir" ] ; then
710 configure=./configure
711 configure_from_here=$d/configure
712 else
713 configure=$srcdir/$d/configure
714 configure_from_here=$configure
716 if [ -f "$configure_from_here" ] ; then
717 if [ -d "$d" ] ; then : ; else
718 case $d in
719 xapian-applications/*) [ -d xapian-applications ] || mkdir xapian-applications ;;
720 esac
721 mkdir "$d"
723 echo "Configuring \`$d'"
724 # Use a shared config.cache for speed and to save a bit of diskspace, but
725 # don't share it with SWIG just in case it manages to probe and cache
726 # different answers (e.g. because it uses a C compiler).
727 case $d in
728 swig)
729 case "$*" in
730 *--host=*|*--host" "*)
731 # We're cross-building, but SWIG needs to be built natively.
732 swig_configure_args=
733 skip=
734 for arg in "$@" ; do
735 if [ -n "$skip" ] ; then
736 skip=
737 continue
739 case $arg in
740 --host=*)
741 # Drop --host=xxx
742 continue ;;
743 --host)
744 # Drop --host xxx
745 skip=1
746 continue ;;
747 CC=*|CXX=*)
748 # Drop CC=xxx or CXX=xxx
749 continue ;;
750 CC_FOR_BUILD=*|CXX_FOR_BUILD=*)
751 # CC_FOR_BUILD=xxx -> CC=xxx; CXX_FOR_BUILD=xxx -> CXX=xxx
752 arg=`echo "$arg"|sed 's/_FOR_BUILD//'`
754 SWIG=*)
755 # Drop SWIG=xxx - not useful and could cause problems.
756 continue ;;
757 esac
758 swig_configure_args="$swig_configure_args "\'`echo "x$arg"|sed "s/^x//;s/'/'\\\\\\\\''/g"`\'
759 done
760 # Also handle compilers specified in environment variables. We can
761 # just reassign them unconditionally as CC and CXX are ignored if
762 # empty.
763 cd "$d" && CC=$CC_FOR_BUILD CXX=$CXX_FOR_BUILD "$configure" `eval echo $swig_configure_args`
766 cd "$d" && "$configure" ${1+"$@"}
768 esac
770 xapian-core)
771 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking --cache-file="$here/config.cache" ${1+"$@"}
773 xapian-applications/omega)
774 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking XAPIAN_CONFIG="$XAPIAN_CONFIG" CPPFLAGS="-I$srcdir/INST/include" LDFLAGS="-L$srcdir/INST/lib" ${1+"$@"}
777 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking --cache-file="$here/config.cache" XAPIAN_CONFIG="$XAPIAN_CONFIG" ${1+"$@"}
779 esac
780 cd "$here"
781 dirs="$dirs $d"
782 revdirs="$d $revdirs"
784 done
786 case " $* " in
787 *" --help "*|*" --version "*)
788 # Don't generate Makefile if --help or --version specified.
789 trap - EXIT
790 exit 0
792 esac
794 rm -f Makefile.tmp
795 cat <<EOF > Makefile.tmp
796 # Makefile generated by:
797 CONFIGURE_COMMAND := $cmd
799 if [ "$srcdir" != . ] ; then
800 cat <<EOF >> Makefile.tmp
802 VPATH = $srcdir
805 targets='all install uninstall install-strip clean distclean mostlyclean maintainer-clean dist check distcheck'
806 for target in $targets ; do
807 echo
808 echo "$target:"
809 case $target in
810 uninstall|*clean)
811 # When uninstalling or cleaning, process directories in reverse order, so
812 # that we process a directory after any directories which might use it.
813 list=$revdirs ;;
815 list=$dirs ;;
816 esac
817 for d in $list ; do
818 case $d,$target in
819 swig,install*|swig,uninstall)
820 # Nothing to do with swig when installing/uninstalling.
822 swig,dist|swig,check|swig,distcheck|swig,all)
823 # Need to ensure swig is built before "make dist", "make check", etc.
824 echo " cd $d && \$(MAKE)" ;;
825 swig,mostlyclean)
826 echo " cd $d && \$(MAKE) clean" ;;
827 xapian-bindings,distcheck)
828 # FIXME: distcheck doesn't currently work for xapian-bindings because
829 # xapian-core isn't installed.
830 echo " cd $d && \$(MAKE) check && \$(MAKE) dist" ;;
832 echo " cd $d && \$(MAKE) $target" ;;
833 esac
834 done
835 case $target in
836 distclean|maintainer-clean) echo " rm -f Makefile config.cache" ;;
837 esac
838 done >> Makefile.tmp
839 cat <<EOF >> Makefile.tmp
841 recheck:
842 \$(CONFIGURE_COMMAND)
844 Makefile: $srcdir/configure
845 \$(CONFIGURE_COMMAND)
847 $srcdir/configure: \\
848 END_OF_CONFIGURE
850 : > configure.tmp2
852 # We want to rerun bootstrap if a series file changes (patch added or removed)
853 # or an existing patch changes. Since we always have an series file (even if
854 # it is empty), this also handles us adding the first patch for something.
855 patches=
856 for d in patches/* ; do
857 series=$d/series
858 echo "$series:" >> configure.tmp2
859 cat << END
860 $series\\\\
862 sed -n 's/[ ]*\(#.*\)\?$//;/./p' "$series" |\
863 while read p ; do
864 patch=$d/$p
865 cat << END
866 $patch\\\\
868 # Because there's a pipeline, this is a subshell, so use a temporary file
869 # rather than a variable to compile a list of patches to use below.
870 echo "$patch:" >> configure.tmp2
871 done
872 done >> configure.tmp
874 cat <<'END_OF_CONFIGURE' >> configure.tmp
875 $srcdir/bootstrap
876 END_OF_CONFIGURE
877 echo " \$srcdir/bootstrap$bootstrap_sticky_opts" >> configure.tmp
878 cat <<'END_OF_CONFIGURE' >> configure.tmp
880 .PHONY: $targets recheck
882 # Dummy dependencies to allow removing patches we no longer need.
883 END_OF_CONFIGURE
885 cat configure.tmp2 >> configure.tmp
887 cat <<'END_OF_CONFIGURE' >> configure.tmp
889 mv -f Makefile.tmp Makefile
890 trap - EXIT
891 echo "Configured successfully - now run \"${MAKE-make}\""
892 END_OF_CONFIGURE
894 rm -f configure.tmp2
896 chmod +x configure.tmp
897 mv -f configure.tmp configure
899 # git defaults to showing 7 character abbreviated hashes if that's enough to be
900 # unique for a particular commit. But you can't paste these into trac as it
901 # needs at least 8 hex digits to recognise a hex string as a commit hash. You
902 # need 9 characters to be unique across all of Xapian at the time of writing,
903 # and 12 for the Linux kernel currently (a much larger number of objects than
904 # Xapian). 12 is a manageable length and decently future-proof, so let's use
905 # that.
906 core_abbrev_recommended=12
907 core_abbrev=`git config --get core.abbrev||:`
908 if [ -z "$core_abbrev" ] ; then
909 echo "*** Setting core.abbrev=$core_abbrev_recommended in repo config"
910 git config --local core.abbrev "$core_abbrev_recommended"
911 elif [ "$core_abbrev" -lt "$core_abbrev_recommended" ] ; then
912 if [ -z "`git config --local core.abbrev`" ] ; then
913 # Set globally to < $core_abbrev_recommended, override in this repo.
914 echo "*** Setting core.abbrev=$core_abbrev_recommended in repo config to override global core.abbrev=$core_abbrev"
915 git config --local core.abbrev "$core_abbrev_recommended"
916 else
917 # Just warn.
918 echo "warning: core.abbrev=$core_abbrev set on this repo, at least $core_abbrev_recommended is recommended"
922 trap - EXIT
923 echo "Bootstrapped successfully - now run \"$srcdir/configure\" and \"${MAKE-make}\""