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"
6 # Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 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
24 if [ "$1" = "--help" ] ; then
26 $0 [--ftp] [--without-autotools|--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.
34 trap 'echo "Bootstrap failed"' EXIT
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).
47 if [ -z "$SHA1SUM_TOOL" ] ; then
49 '${SHA1SUM-sha1sum} 2>/dev/null|cut -d\ -f1' \
50 '${SHASUM-shasum} 2>/dev/null|cut -d\ -f1' \
51 '$(OPENSSL-openssl} sha1 2>/dev/null|sed "s/.* //"' \
53 if [ -z "$SHA1SUM_TOOL" ] ; then
55 Need sha1sum or shasum or openssl installed to check SHA1 checksums.
56 Set environment variable SHA1SUM, SHASUM or OPENSSL if the tool isn't on
61 r
=`:|eval "$SHA1SUM_TOOL"`
62 [ X
"$r" != Xda39a3ee5e6b4b0d3255bfef95601890afd80709
] ||
break
65 r
=`< $tarball eval "$SHA1SUM_TOOL"`
66 if [ X
"$r" != X
"$checksum" ] ; then
67 echo "$tarball: computed SHA1 checksum did NOT match"
68 echo "computed: $r with $SHA1SUM_TOOL"
69 echo "expected: $checksum"
72 mv "$tarball" "$tarball.$r"
73 echo "Renamed $tarball to $tarball.$r"
83 if [ "$always_install" = no
] && [ -n $binary ] ; then
84 # Check if a new enough version is already installed.
85 version_installed
=`"$binary" --version 2>/dev/null|sed '1,1 s/.* //p;d'`
86 if [ -n "$version_installed" ] ; then
87 # Fast track equality.
88 if [ "$version_installed" = "$version" ] ; then
89 echo "$binary $version_installed installed, exactly what's needed"
94 set x
$version_installed
97 for v
in $version ; do
99 if [ "$1" != "$v" ] ; then
100 if [ "$1" -lt "$v" ] ; then
107 if [ "$ok" = yes ] ; then
108 echo "$binary $version_installed installed >= $version required"
114 basename=$package-$version
118 if [ "$ext" = "tar.xz" ] ; then
119 if [ -z "$xz_ok" ] ; then
120 if ${XZ-xz} --version > /dev
/null
2>&1 ; then
126 if [ "$xz_ok" = 0 ] ; then
132 if [ "$ext" = "tar.bz2" ] ; then
133 if [ -z "$bz2_ok" ] ; then
134 # bzip2 --version doesn't exit with code 0 in upstream version (though
135 # Debian at least patch this bug), so use --help to check it.
136 if bzip2 --help > /dev
/null
2>&1 ; then
142 if [ "$bz2_ok" = 0 ] ; then
148 tarball
=$basename.
$ext
150 *[24680][a-z
]) basename=`echo "$basename"|sed 's/[a-z]$//'` ;;
153 # Create the stamp file in INST so that rerunning bootstrap after
154 # "rm -rf INST" recovers nicely.
155 stamp
=..
/INST
/$package.stamp
157 # Download the tarball if required.
158 if [ ! -f "$tarball" ] ; then
159 if [ -z "$FETCH_URL_TOOL" ] ; then
160 if ${WGET-wget} --version > /dev
/null
2>&1 ; then
161 FETCH_URL_TOOL
="${WGET-wget} -O-"
162 elif ${CURL-curl} --version > /dev
/null
2>&1 ||
[ "$?" = 2 ] ; then
163 # curl --version exits with code 2.
164 # -L is needed to follow HTTP redirects.
165 FETCH_URL_TOOL
="${CURL-curl} -L"
166 elif ${LWP_REQUEST-lwp-request} -v > /dev
/null
2>&1 ||
[ "$?" = 9 -o "$?" = 255 ] ; then
167 # lwp-request -v exits with code 9 (5.810) or 255 (6.03)
168 FETCH_URL_TOOL
="${LWP_REQUEST-lwp-request} -mGET"
171 Neither wget nor curl nor lwp-request found - install one of them or if already
172 installed, set WGET, CURL or LWP_REQUEST to the full path. Alternatively,
175 then rerun this script.
182 if [ "$use_ftp" = yes ] ; then
183 url
="ftp://ftp.astron.com/pub/file/$tarball"
185 url
="http://fossies.org/unix/misc/$tarball"
189 if [ "$use_ftp" = yes ] ; then
190 url
="ftp://alpha.gnu.org/gnu/$package/$tarball"
192 url
="http://alpha.gnu.org/gnu/$package/$tarball"
195 if [ "$use_ftp" = yes ] ; then
196 url
="ftp://ftp.gnu.org/gnu/$package/$tarball"
198 url
="http://ftpmirror.gnu.org/$package/$tarball"
202 echo "Downloading <$url>"
203 $FETCH_URL_TOOL "$url" > download.tmp
&& mv download.tmp
"$tarball"
206 if [ -f "$stamp" ] ; then
207 find_stdout
=`find "$tarball" ../patches/"$package"/* -newer "$stamp" -print 2> /dev/null||true`
212 if [ -n "$find_stdout" ] ; then
213 # Verify the tarball's checksum before building it.
214 check_sha1sum
"$checksum" "$tarball"
216 # Remove tarballs of other versions.
217 for f
in "$package"-* ; do
218 [ "$f" = "$tarball" ] ||
rm -rf "$f"
223 ${XZ-xz} -dc "$tarball"|
tar xf
- ;;
225 bzip2 -dc "$tarball"|
tar xf
- ;;
227 gzip -dc "$tarball"|
tar xf
- ;;
232 if [ ! -f "../../patches/$package/series" ] ; then
234 No patch series file 'patches/$package/series' - if there are no patches,
235 this should just be an empty file.
239 echo "Applying patches from $package/series"
240 sed -n 's/[ ]*\(#.*\)\?$//;/./p' "../../patches/$package/series" | \
242 echo "Applying patch $package/$p"
243 patch -p1 < "../../patches/$package/$p"
246 if test -n "$AUTOCONF" ; then
247 .
/configure
--prefix "$instdir" AUTOCONF
="$AUTOCONF"
249 .
/configure
--prefix "$instdir"
261 handle_git_external
() {
263 if [ ! -f "$path/.nobootstrap" ] ; then
266 if [ ! -d "$path" ] ; then
267 git clone
--no-checkout -- "$url" "$path"
268 elif (cd "$path" && git reflog
"$rev" -- 2>/dev
/null
) ; then
269 : # Already have that revision locally
271 (cd "$path" && git fetch
)
273 (cd "$path" && git checkout
"$rev")
280 ts_from
=`perl -ne '/^timestamp=(\W?)([-\d]+)$1/ and do {$_=$2;y/-//d;print;exit}' "$from"`
281 ts_to
=`perl -ne '/^timestamp=(\W?)([-\d]+)$1/ and do {$_=$2;y/-//d;print;exit}' "$to"`
282 if [ "$ts_from" -gt "$ts_to" ] ; then
283 echo "Updating $to ($ts_to) with $from ($ts_from)"
284 # rm first in case the existing file is a symlink.
292 # cd to srcdir if we aren't already there.
293 srcdir
=`echo "$0"|sed 's!/*[^/]*$!!'`
301 # Commit hash to pass to handle_git_external for swig.
302 swig_git_commit_hash
=d21bb11153bd46c9eae124c13322add3e0df9cee
304 # Commit hashes to use for common in omega and letor respectively:
305 omega_common_commit_hash
=bddcf54435286b0363efff94f22529093e85fc89
306 letor_common_commit_hash
=bddcf54435286b0363efff94f22529093e85fc89
308 if [ ! -d .git
] ; then
309 echo "$0: No '.git' directory found - this script should be run from a"
310 echo "git repo cloned from git://git.xapian.org/xapian or a mirror of it"
314 for emptydir
in xapian-applications
/omega
/m4 xapian-bindings
/m4 xapian-letor
/m4 ; do
315 if test -d "$emptydir" ; then
318 parent
=`echo "$emptydir"|sed 's,/[^/]*$,,'`
319 if test -d "$parent" ; then
325 if [ -f .git
/info
/exclude
] ; then
326 sed '/^\(swig\|xapian-applications\/omega\/common$\)/d' .git
/info
/exclude
> .git
/info
/exclude~
328 [ -d .git
/info
] || mkdir .git
/info
330 cat <<END >> .git/info/exclude~
332 xapian-applications/omega/common
335 if [ -f .git
/info
/exclude
] &&
336 cmp -s .git
/info
/exclude~ .git
/info
/exclude
; then
337 rm .git
/info
/exclude~
339 mv .git
/info
/exclude~ .git
/info
/exclude
342 # If this tree is checked out from the github mirror, use the same access
343 # method for other things checked out from github (e.g. swig) so we avoid
344 # firewall issues. If there's no default remote, the git config command
345 # will exit with status 1, so ignore that failure.
346 origin_url
=`git config remote.origin.url||:`
348 *[@
/]github.com
[:/]*)
349 github_base_url
=`echo "X$origin_url"|sed 's/^X//;s!\([@/]github.com[:/]\).*!\1!'` ;;
351 github_base_url
=https
://github.com
/ ;;
353 swig_origin_url
=${github_base_url}swig
/swig.git
355 if [ -z "$XAPIAN_COMMON_CLONE_URL" ] ; then
356 xapian_common_clone_url
=.
358 xapian_common_clone_url
=$XAPIAN_COMMON_CLONE_URL
361 # Set to 'yes' to use ftp URLs where available.
363 # By default we prefer http downloads as they are more likely to work through
367 # Set to 'yes' to always use a locally installed copy of the autotools.
369 # By default we check for locally installed versions and use them if they are
370 # new enough versions. But e.g. for building releases we want to use a known
374 while [ "$#" -gt 0 ] ; do
395 echo "Ignoring '$1' - installed versions will be used if new enough"
406 echo "Unknown option '$1'" 1>&2
416 [ -d INST
] || mkdir INST
419 [ -d BUILD
] || mkdir BUILD
422 # The last field is the SHA1 checksum of the tarball.
423 if lazy_build autoconf autoconf
2.69 \
424 tar.xz e891c3193029775e83e0534ac0ee0c4c711f6d23 \
425 tar.gz
562471cbcb0dd0fa42a76665acf0dbb68479b78a \
427 AUTOCONF
=$instdir/bin
/autoconf
429 AUTORECONF
=$instdir/bin
/autoreconf
431 AUTOHEADER
=$instdir/bin
/autoheader
433 AUTOM4TE
=$instdir/bin
/autom4te
436 if lazy_build automake automake
1.15 \
437 tar.xz c279b35ca6c410809dac8ade143b805fb48b7655 \
438 tar.gz b5a840c7ec4321e78fdc9472e476263fa6614ca1 \
440 ACLOCAL
=$instdir/bin
/aclocal
442 AUTOMAKE
=$instdir/bin
/automake
445 if lazy_build libtool libtool
2.4.6 \
446 tar.xz
3e7504b832eb2dd23170c91b6af72e15b56eb94e \
447 tar.gz
25b6931265230a06f0fc2146df64c04e5ae6ec33 \
449 LIBTOOLIZE
=$instdir/bin
/libtoolize
452 if [ "$1" = "--deps=libmagic" ] ; then
454 lazy_build
file '' 5.25 \
455 tar.gz fea78106dd0b7a09a61714cdbe545135563e84bd
460 case `${LIBTOOLIZE-libtoolize} --version` in
462 echo "${LIBTOOLIZE-libtoolize} not found"
464 "libtoolize (GNU libtool) 1.4.*")
465 echo "${LIBTOOLIZE-libtoolize} is from libtool 1.4 which is too old - libtool 2.2 is required."
466 echo "If you have both installed, set LIBTOOLIZE to point to the correct version."
468 "libtoolize (GNU libtool) 1.5.*")
469 echo "${LIBTOOLIZE-libtoolize} is from libtool 1.5 which is too old - libtool 2.2 is required."
470 echo "If you have both installed, set LIBTOOLIZE to point to the correct version."
474 ACLOCAL
="${ACLOCAL-aclocal} -I `pwd`/xapian-core/m4-macros"
479 for module
in ${@:-xapian-core xapian-applications/omega swig xapian-bindings} ; do
481 if [ "$d" = swig
] ; then
482 if [ -f "xapian-bindings/.nobootstrap" ] ; then
483 # No point bootstrapping SWIG if we aren't going to use it.
484 echo "Skipping '$d' due to presence of 'xapian-bindings/.nobootstrap'."
487 handle_git_external swig
"$swig_git_commit_hash" "$swig_origin_url"
489 if [ -f "$d/configure.ac" -o -f "$d/configure.in" ] ; then
492 # Skip any directories we can't bootstrap.
495 if [ -f "$d/.nobootstrap" ] ; then
496 # Report why to save head scratching when someone forgets they created
497 # a .nobootstrap file.
498 echo "Skipping '$module' due to presence of '$d/.nobootstrap'."
502 xapian-applications
/omega|xapian-letor
)
503 # If someone's created a directory for common, leave it be.
504 if [ -h "$d/common" ] ||
[ ! -d "$d/common" ] ; then
505 # Pick omega_common_commit_hash or letor_common_commit_hash:
506 var
=`echo "$d"|sed 's!.*[-/]!!g'`_common_commit_hash
507 hash=`eval echo \\\$"$var"`
508 handle_git_external
"$d/.common.git" "$hash" "$xapian_common_clone_url"
509 ln -sf .common.git
/xapian-core
/common
"$d/common"
514 echo "Bootstrapping \`$module'"
515 [ -f "$d/preautoreconf" ] && "$d/preautoreconf"
517 # If we have a custom INSTALL file, preserve it since autoreconf insists on
518 # replacing INSTALL with "generic installation instructions" when --force
519 # is used. Be careful to replace it if autoreconf fails.
520 if [ -f "$d/INSTALL" ] ; then
521 if grep 'generic installation instructions' "$d/INSTALL" >/dev
/null
2>&1 ; then
524 mv -f "$d/INSTALL" "$d/INSTALL.preserved-by-bootstrap"
529 if [ swig
= "$module" ] ; then
530 # SWIG provides its own bootstrapping script.
533 .
/autogen.sh || autoreconf_rc
=$?
535 # Use the uninstalled wrapper for the in-tree copy of SWIG.
538 # Use --install as debian's autoconf wrapper uses 2.5X if it sees it
539 # (but it doesn't check for -i).
541 # Use --force so that we update files if autoconf, automake, or libtool
543 ${AUTORECONF-autoreconf} --install --force "$d" || autoreconf_rc
=$?
545 if [ -f "$d/INSTALL.preserved-by-bootstrap" ] ; then
546 mv -f "$d/INSTALL.preserved-by-bootstrap" "$d/INSTALL"
548 if [ -n "$autoreconf_rc" ] ; then
551 for f
in config.guess config.sub
; do
552 if [ -f "$d/$f" ] ; then
553 update_config
"config/$f" "$d/$f"
556 modules
="$modules $module"
559 # Produce an absolute path to srcdir.
562 # Generate the top-level configure script.
564 cat <<TOP_OF_CONFIGURE > configure.tmp
566 # configure each submodule in a xapian source tree
567 # Generated by Xapian top-level bootstrap script.
569 trap 'echo "configure failed"' EXIT
577 cat <<'MIDDLE_OF_CONFIGURE' >> configure.tmp
578 # Produced escaped version of command suitable for pasting back into sh
582 *[^-A-Za-z0-9_+=:@/.,]*)
583 esc_a=`echo "$a"|sed 's!\([^-A-Za-z0-9_+=:@/.,]\)!\\\\\\1!g'`
594 if [ yes = "$intree_swig" ] ; then
595 # We want the path to SWIG to point into srcdir, which isn't known until
596 # configure-time, so we need to expand $here in configure.
597 vars
=' SWIG=$here/swig/preinst-swig'
598 elif [ -n "$SWIG" ] ; then
599 # User specified SWIG in environment, e.g. with:
600 # SWIG=/opt/swig/bin/swig ./bootstrap
601 vars
=" SWIG='"`echo "$val"|sed 's/\(['"\\'"']\)/\\\1/g'`"'"
603 for tool
in $autotools ; do
605 if [ -n "$val" ] ; then
606 echo ': ${'"$tool='$val'"'}' >> configure.tmp
607 echo "export $tool" >> configure.tmp
608 vars
="$vars $tool='"`echo "$val"|sed 's/\(['"\\'"']\)/\\\1/g'`"'"
611 if [ -n "$vars" ] ; then
612 # $vars will always have a leading space.
613 echo "set$vars "'"$@"' >> configure.tmp
616 cat <<'END_OF_CONFIGURE' >> configure.tmp
619 XAPIAN_CONFIG=$here/xapian-core/xapian-config
620 for d in $modules ; do
621 if [ "$here" = "$srcdir" ] ; then
622 configure=./configure
623 configure_from_here=$d/configure
625 configure=$srcdir/$d/configure
626 configure_from_here=$configure
628 if [ -f "$configure_from_here" ] ; then
629 if [ -d "$d" ] ; then : ; else
631 xapian-applications/*) [ -d xapian-applications ] || mkdir xapian-applications ;;
635 echo "Configuring \`$d'"
636 # Use a shared config.cache for speed and to save a bit of diskspace, but
637 # don't share it with SWIG just in case it manages to probe and cache
638 # different answers (e.g. because it uses a C compiler).
642 *--host=*|*--host" "*)
643 # We're cross-building, but SWIG needs to be built natively.
647 if [ -n "$skip" ] ; then
660 # Drop CC=xxx or CXX=xxx
662 CC_FOR_BUILD=*|CXX_FOR_BUILD=*)
663 # CC_FOR_BUILD=xxx -> CC=xxx; CXX_FOR_BUILD=xxx -> CXX=xxx
664 arg=`echo "$arg"|sed 's/_FOR_BUILD//'`
667 # Drop SWIG=xxx - not useful and could cause problems.
670 swig_configure_args="$swig_configure_args "\'`echo "x$arg"|sed "s/^x//;s/'/'\\\\\\\\''/g"`\'
672 # Also handle compilers specified in environment variables. We can
673 # just reassign them unconditionally as CC and CXX are ignored if
675 cd "$d" && CC=$CC_FOR_BUILD CXX=$CXX_FOR_BUILD "$configure" `eval echo $swig_configure_args`
678 cd "$d" && "$configure" ${1+"$@"}
683 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking --cache-file="$here/config.cache" ${1+"$@"}
685 xapian-applications/omega)
686 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking XAPIAN_CONFIG="$XAPIAN_CONFIG" CPPFLAGS="-I$srcdir/INST/include" LDFLAGS="-L$srcdir/INST/lib" ${1+"$@"}
689 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking --cache-file="$here/config.cache" XAPIAN_CONFIG="$XAPIAN_CONFIG" ${1+"$@"}
694 revdirs="$d $revdirs"
699 *" --help "*|*" --version "*)
700 # Don't generate Makefile if --help or --version specified.
707 cat <<EOF > Makefile.tmp
708 # Makefile generated by:
709 CONFIGURE_COMMAND := $cmd
711 if [ "$srcdir" != . ] ; then
712 cat <<EOF >> Makefile.tmp
717 targets='all install uninstall install-strip clean distclean mostlyclean maintainer-clean dist check distcheck'
718 for target in $targets ; do
723 # When uninstalling or cleaning, process directories in reverse order, so
724 # that we process a directory after any directories which might use it.
731 swig,install*|swig,uninstall)
732 # Nothing to do with swig when installing/uninstalling.
734 swig,dist|swig,check|swig,distcheck|swig,all)
735 # Need to ensure swig is built before "make dist", "make check", etc.
736 echo " cd $d && \$(MAKE)" ;;
738 echo " cd $d && \$(MAKE) clean" ;;
739 xapian-bindings,distcheck)
740 # FIXME: distcheck doesn't currently work for xapian-bindings because
741 # xapian-core isn't installed.
742 echo " cd $d && \$(MAKE) check && \$(MAKE) dist" ;;
744 echo " cd $d && \$(MAKE) $target" ;;
748 distclean|maintainer-clean) echo " rm -f Makefile config.cache" ;;
751 cat <<EOF >> Makefile.tmp
754 \$(CONFIGURE_COMMAND)
756 Makefile: $srcdir/configure
757 \$(CONFIGURE_COMMAND)
759 $srcdir/configure: \\
764 # We want to rerun bootstrap if a series file changes (patch added or removed)
765 # or an existing patch changes. Since we always have an series file (even if
766 # it is empty), this also handles us adding the first patch for something.
768 for d
in patches
/* ; do
770 echo "$series:" >> configure.tmp2
774 sed -n 's/[ ]*\(#.*\)\?$//;/./p' "$series" |\
780 # Because there's a pipeline, this is a subshell, so use a temporary file
781 # rather than a variable to compile a list of patches to use below.
782 echo "$patch:" >> configure.tmp2
784 done >> configure.tmp
786 cat <<'END_OF_CONFIGURE' >> configure.tmp
790 .PHONY: $targets recheck
792 # Dummy dependencies to allow removing patches we no longer need.
795 cat configure.tmp2
>> configure.tmp
797 cat <<'END_OF_CONFIGURE' >> configure.tmp
799 mv -f Makefile.tmp Makefile
801 echo "Configured successfully - now run \"${MAKE-make}\""
806 chmod +x configure.tmp
807 mv -f configure.tmp configure
809 # git defaults to showing 7 character abbreviated hashes if that's enough to be
810 # unique for a particular commit. But you can't paste these into trac as it
811 # needs at least 8 hex digits to recognise a hex string as a commit hash. You
812 # need 9 characters to be unique across all of Xapian at the time of writing,
813 # and 12 for the Linux kernel currently (a much larger number of objects than
814 # Xapian). 12 is a manageable length and decently future-proof, so let's use
816 core_abbrev_recommended
=12
817 core_abbrev
=`git config --get core.abbrev||:`
818 if [ -z "$core_abbrev" ] ; then
819 echo "*** Setting core.abbrev=$core_abbrev_recommended in repo config"
820 git config
--local core.abbrev
"$core_abbrev_recommended"
821 elif [ "$core_abbrev" -lt "$core_abbrev_recommended" ] ; then
822 if [ -z "`git config --local core.abbrev`" ] ; then
823 # Set globally to < $core_abbrev_recommended, override in this repo.
824 echo "*** Setting core.abbrev=$core_abbrev_recommended in repo config to override global core.abbrev=$core_abbrev"
825 git config
--local core.abbrev
"$core_abbrev_recommended"
828 echo "warning: core.abbrev=$core_abbrev set on this repo, at least $core_abbrev_recommended is recommended"
833 echo "Bootstrapped successfully - now run \"$srcdir/configure\" and \"${MAKE-make}\""