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 (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Olly Betts
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License as
9 # published by the Free Software Foundation; either version 2 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22 if [ "$1" = "--help" ] ; then
24 $0 [--ftp] [--without-autotools|--clean] [MODULE...]
26 The default is to bootstrap all known modules. Any modules which have a
27 file called ".nobootstrap" in their top-level will be skipped.
32 trap 'echo "Bootstrap failed"' EXIT
35 # The variables which specify the autotools to use.
36 autotools
="AUTORECONF AUTOCONF AUTOHEADER AUTOM4TE AUTOMAKE ACLOCAL LIBTOOLIZE"
38 # Tool for downloading a file from a URL (currently wget or curl).
45 if [ -z "$SHA1SUM_TOOL" ] ; then
47 '${SHA1SUM-sha1sum} 2>/dev/null|cut -d\ -f1' \
48 '${SHASUM-shasum} 2>/dev/null|cut -d\ -f1' \
49 '$(OPENSSL-openssl} sha1 2>/dev/null|sed "s/.* //"' \
51 if [ -z "$SHA1SUM_TOOL" ] ; then
53 Need sha1sum or shasum or openssl installed to check SHA1 checksums.
54 Set environment variable SHA1SUM, SHASUM or OPENSSL if the tool isn't on
59 r
=`:|eval "$SHA1SUM_TOOL"`
60 [ X
"$r" != Xda39a3ee5e6b4b0d3255bfef95601890afd80709
] ||
break
63 r
=`< $tarball eval "$SHA1SUM_TOOL"`
64 if [ X
"$r" != X
"$checksum" ] ; then
65 echo "$tarball: computed SHA1 checksum did NOT match"
66 echo "computed: $r with $SHA1SUM_TOOL"
67 echo "expected: $checksum"
70 mv "$tarball" "$tarball.$r"
71 echo "Renamed $tarball to $tarball.$r"
81 if [ "$ext" = "tar.xz" ] ; then
82 if [ -z "$xz_ok" ] ; then
83 if ${XZ-xz} --version > /dev
/null
2>&1 ; then
89 if [ "$xz_ok" = 0 ] ; then
95 if [ "$ext" = "tar.bz2" ] ; then
96 if [ -z "$bz2_ok" ] ; then
97 # bzip2 --version doesn't exit with code 0 in upstream version (though
98 # Debian at least patch this bug), so use --help to check it.
99 if bzip2 --help > /dev
/null
2>&1 ; then
105 if [ "$bz2_ok" = 0 ] ; then
111 tarball
=$basename.
$ext
113 *[24680][a-z
]) basename=`echo "$basename"|sed 's/[a-z]$//'` ;;
116 # Create the stamp file in INST so that rerunning bootstrap after
117 # "rm -rf INST" recovers nicely.
118 stamp
=..
/INST
/$package.stamp
120 # Download the tarball if required.
121 if [ ! -f "$tarball" ] ; then
122 if [ -z "$FETCH_URL_TOOL" ] ; then
123 if ${WGET-wget} --version > /dev
/null
2>&1 ; then
124 FETCH_URL_TOOL
="${WGET-wget} -O-"
125 elif ${CURL-curl} --version > /dev
/null
2>&1 ||
[ "$?" = 2 ] ; then
126 # curl --version exits with code 2.
127 # -L is needed to follow HTTP redirects.
128 FETCH_URL_TOOL
="${CURL-curl} -L"
129 elif ${LWP_REQUEST-lwp-request} -v > /dev
/null
2>&1 ||
[ "$?" = 9 -o "$?" = 255 ] ; then
130 # lwp-request -v exits with code 9 (5.810) or 255 (6.03)
131 FETCH_URL_TOOL
="${LWP_REQUEST-lwp-request} -mGET"
134 Neither wget nor curl nor lwp-request found - install one of them or if already
135 installed, set WGET, CURL or LWP_REQUEST to the full path. Alternatively,
138 then rerun this script.
145 if [ "$use_ftp" = yes ] ; then
146 url
="ftp://ftp.astron.com/pub/file/$tarball"
148 url
="http://fossies.org/unix/misc/$tarball"
152 if [ "$use_ftp" = yes ] ; then
153 url
="ftp://alpha.gnu.org/gnu/$package/$tarball"
155 url
="http://alpha.gnu.org/gnu/$package/$tarball"
158 if [ "$use_ftp" = yes ] ; then
159 url
="ftp://ftp.gnu.org/gnu/$package/$tarball"
161 url
="http://ftpmirror.gnu.org/$package/$tarball"
165 echo "Downloading <$url>"
166 $FETCH_URL_TOOL "$url" > download.tmp
&& mv download.tmp
"$tarball"
169 if [ -f "$stamp" ] ; then
170 find_stdout
=`find "$tarball" ../patches/"$package"/* -newer "$stamp" -print 2> /dev/null||true`
175 if [ -n "$find_stdout" ] ; then
176 # Verify the tarball's checksum before building it.
177 check_sha1sum
"$checksum" "$tarball"
179 # Remove tarballs of other versions.
180 for f
in "$package"-* ; do
181 [ "$f" = "$tarball" ] ||
rm -rf "$f"
186 ${XZ-xz} -dc "$tarball"|
tar xf
- ;;
188 bzip2 -dc "$tarball"|
tar xf
- ;;
190 gzip -dc "$tarball"|
tar xf
- ;;
195 if [ ! -f "../../patches/$package/series" ] ; then
197 No patch series file 'patches/$package/series' - if there are no patches,
198 this should just be an empty file.
202 echo "Applying patches from $package/series"
203 sed -n 's/[ ]*\(#.*\)\?$//;/./p' "../../patches/$package/series" | \
205 echo "Applying patch $package/$p"
206 patch -p1 < "../../patches/$package/$p"
209 if test -n "$AUTOCONF" ; then
210 .
/configure
--prefix "$instdir" AUTOCONF
="$AUTOCONF"
212 .
/configure
--prefix "$instdir"
223 handle_git_external
() {
225 if [ ! -f "$path/.nobootstrap" ] ; then
228 if [ ! -d "$path" ] ; then
229 git clone
--no-checkout -- "$url" "$path"
230 elif (cd "$path" && git reflog
"$rev" -- 2>/dev
/null
) ; then
231 : # Already have that revision locally
233 (cd "$path" && git fetch
)
235 (cd "$path" && git checkout
"$rev")
242 ts_from
=`perl -ne '/^timestamp=(\W?)([-\d]+)$1/ and do {$_=$2;y/-//d;print;exit}' "$from"`
243 ts_to
=`perl -ne '/^timestamp=(\W?)([-\d]+)$1/ and do {$_=$2;y/-//d;print;exit}' "$to"`
244 if [ "$ts_from" -gt "$ts_to" ] ; then
245 echo "Updating $to ($ts_to) with $from ($ts_from)"
246 # rm first in case the existing file is a symlink.
254 # cd to srcdir if we aren't already there.
255 srcdir
=`echo "$0"|sed 's!/*[^/]*$!!'`
263 # Commit hash to pass to handle_git_external for swig.
264 swig_git_commit_hash
=bab51398053188a136effd155d7ed8f5d441908e
266 if [ ! -d .git
] ; then
267 echo "$0: No '.git' directory found - this script should be run from a"
268 echo "git repo cloned from git://git.xapian.org/xapian or a mirror of it"
272 for emptydir
in xapian-applications
/omega
/m4 xapian-bindings
/m4 xapian-letor
/m4 ; do
273 if test -d "$emptydir" ; then
276 parent
=`echo "$emptydir"|sed 's,/[^/]*$,,'`
277 if test -d "$parent" ; then
283 if [ -f .git
/info
/exclude
] ; then
284 sed '/^\(swig\|xapian-applications\/omega\/common$\)/d' .git
/info
/exclude
> .git
/info
/exclude~
286 [ -d .git
/info
] || mkdir .git
/info
288 cat <<END >> .git/info/exclude~
290 xapian-applications/omega/common
293 if [ -f .git
/info
/exclude
] &&
294 cmp -s .git
/info
/exclude~ .git
/info
/exclude
; then
295 rm .git
/info
/exclude~
297 mv .git
/info
/exclude~ .git
/info
/exclude
300 # If this tree is checked out from the github mirror, use the same access
301 # method for other things checked out from github (e.g. swig) so we avoid
302 # firewall issues. If there's no default remote, the git config command
303 # will exit with status 1, so ignore that failure.
304 origin_url
=`git config remote.origin.url||:`
306 *[@
/]github.com
[:/]*)
307 github_base_url
=`echo "X$origin_url"|sed 's/^X//;s!\([@/]github.com[:/]\).*!\1!'` ;;
309 github_base_url
=https
://github.com
/ ;;
311 swig_origin_url
=${github_base_url}swig
/swig.git
312 handle_git_external swig
"$swig_git_commit_hash" "$swig_origin_url"
314 if [ -z "$XAPIAN_COMMON_CLONE_URL" ] ; then
315 xapian_common_clone_url
=.
317 xapian_common_clone_url
=$XAPIAN_COMMON_CLONE_URL
320 # If someone's created a directory for common, leave it be.
321 if [ -h xapian-applications
/omega
/common
] || \
322 [ ! -d xapian-applications
/omega
/common
] ; then
323 handle_git_external xapian-applications
/omega
/.common.git bddcf54435286b0363efff94f22529093e85fc89
"$xapian_common_clone_url"
324 ln -sf .common.git
/xapian-core
/common xapian-applications
/omega
/common
327 # If someone's created a directory for common, leave it be.
328 if [ -h xapian-letor
/common
] ||
[ ! -d xapian-letor
/common
] ; then
329 handle_git_external xapian-letor
/.common.git bddcf54435286b0363efff94f22529093e85fc89
"$xapian_common_clone_url"
330 ln -sf .common.git
/xapian-core
/common xapian-letor
/common
333 # Prefer http downloads as they are more likely to work through firewalls.
335 if [ "$1" = "--ftp" ] ; then
340 if [ "$1" = "--without-autotools" ] ; then
343 if [ "$1" = "--clean" ] ; then
348 [ -d INST
] || mkdir INST
351 [ -d BUILD
] || mkdir BUILD
354 # The last field is the SHA1 checksum of the tarball.
355 lazy_build autoconf
2.69 \
356 tar.xz e891c3193029775e83e0534ac0ee0c4c711f6d23 \
357 tar.gz
562471cbcb0dd0fa42a76665acf0dbb68479b78a
358 AUTOCONF
=$instdir/bin
/autoconf \
359 lazy_build automake
1.15 \
360 tar.xz c279b35ca6c410809dac8ade143b805fb48b7655 \
361 tar.gz b5a840c7ec4321e78fdc9472e476263fa6614ca1
362 lazy_build libtool
2.4.6 \
363 tar.xz
3e7504b832eb2dd23170c91b6af72e15b56eb94e \
364 tar.gz
25b6931265230a06f0fc2146df64c04e5ae6ec33
365 if [ "$1" = "--deps=libmagic" ] ; then
367 lazy_build
file 5.25 \
368 tar.gz fea78106dd0b7a09a61714cdbe545135563e84bd
371 for v
in $autotools ; do
372 tool
=`echo "$v"|tr A-Z a-z`
373 eval "$v=\"\$instdir\"/bin/$tool;export $v"
379 case `${LIBTOOLIZE-libtoolize} --version` in
381 echo "${LIBTOOLIZE-libtoolize} not found"
383 "libtoolize (GNU libtool) 1.4.*")
384 echo "${LIBTOOLIZE-libtoolize} is from libtool 1.4 which is too old - libtool 2.2 is required."
385 echo "If you have both installed, set LIBTOOLIZE to point to the correct version."
387 "libtoolize (GNU libtool) 1.5.*")
388 echo "${LIBTOOLIZE-libtoolize} is from libtool 1.5 which is too old - libtool 2.2 is required."
389 echo "If you have both installed, set LIBTOOLIZE to point to the correct version."
393 ACLOCAL
="${ACLOCAL-aclocal} -I `pwd`/xapian-core/m4-macros"
398 for module
in ${@:-xapian-core xapian-applications/omega swig xapian-bindings xapian-letor} ; do
400 if [ -f "$d/configure.ac" -o -f "$d/configure.in" ] ; then
403 # Skip any directories we can't bootstrap.
406 if [ -f "$d/.nobootstrap" ] ; then
407 # Report why to save head scratching when someone forgets they created
408 # a .nobootstrap file.
409 echo "Skipping '$module' due to presence of '$d/.nobootstrap'."
412 if [ "$d" = swig
] && [ -f "xapian-bindings/.nobootstrap" ] ; then
413 # No point bootstrapping SWIG if we aren't going to use it.
414 echo "Skipping '$d' due to presence of 'xapian-bindings/.nobootstrap'."
417 echo "Bootstrapping \`$module'"
418 [ -f "$d/preautoreconf" ] && "$d/preautoreconf"
420 # If we have a custom INSTALL file, preserve it since autoreconf insists on
421 # replacing INSTALL with "generic installation instructions" when --force
422 # is used. Be careful to replace it if autoreconf fails.
423 if [ -f "$d/INSTALL" ] ; then
424 if grep 'generic installation instructions' "$d/INSTALL" >/dev
/null
2>&1 ; then
427 mv -f "$d/INSTALL" "$d/INSTALL.preserved-by-bootstrap"
432 if [ swig
= "$module" ] ; then
433 # SWIG provides its own bootstrapping script.
436 .
/autogen.sh || autoreconf_rc
=$?
438 # Use the uninstalled wrapper for the in-tree copy of SWIG.
441 # Use --install as debian's autoconf wrapper uses 2.5X if it sees it
442 # (but it doesn't check for -i).
444 # Use --force so that we update files if autoconf, automake, or libtool
446 ${AUTORECONF-autoreconf} --install --force "$d" || autoreconf_rc
=$?
448 if [ -f "$d/INSTALL.preserved-by-bootstrap" ] ; then
449 mv -f "$d/INSTALL.preserved-by-bootstrap" "$d/INSTALL"
451 if [ -n "$autoreconf_rc" ] ; then
454 for f
in config.guess config.sub
; do
455 if [ -f "$d/$f" ] ; then
456 update_config
"config/$f" "$d/$f"
459 modules
="$modules $module"
462 # Generate the top-level configure script.
464 cat <<'TOP_OF_CONFIGURE' > configure.tmp
466 # configure each submodule in a xapian source tree
467 # Generated by Xapian top-level bootstrap script.
469 # Copyright (C) 2003,2004,2007,2008 Olly Betts
471 # This program is free software; you can redistribute it and/or
472 # modify it under the terms of the GNU General Public License as
473 # published by the Free Software Foundation; either version 2 of the
474 # License, or (at your option) any later version.
476 # This program is distributed in the hope that it will be useful,
477 # but WITHOUT ANY WARRANTY; without even the implied warranty of
478 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
479 # GNU General Public License for more details.
481 # You should have received a copy of the GNU General Public License
482 # along with this program; if not, write to the Free Software
483 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
486 trap 'echo "configure failed"' EXIT
489 # Produced escaped version of command suitable for pasting back into sh
493 *[^-A-Za-z0-9_+=:@/.,]*)
494 esc_a=`echo "$a"|sed 's!\([^-A-Za-z0-9_+=:@/.,]\)!\\\\\\1!g'`
504 # Produce an absolute path to srcdir.
506 # This section is unquoted so we can substitute variables.
507 cat <<MIDDLE_OF_CONFIGURE >> configure.tmp
513 if [ yes = "$intree_swig" ] ; then
514 # We want the path to SWIG to point into srcdir, which isn't known until
515 # configure-time, so we need to expand $here in configure. We can't just set
516 # SWIG here and let the case below handle it as that would escape the value
517 # such that $here didn't get expanded at all.
518 echo ': ${SWIG="$here/swig/preinst-swig"}' >> configure.tmp
519 echo "export SWIG" >> configure.tmp
520 vars
=' SWIG=$here/swig/preinst-swig'
521 # Kill any existing setting of SWIG so that we don't try to handle it again
525 for tool
in SWIG
$autotools ; do
527 if [ -n "$val" ] ; then
528 echo ': ${'"$tool='$val'"'}' >> configure.tmp
529 echo "export $tool" >> configure.tmp
530 vars
="$vars $tool='"`echo "$val"|sed 's/\(['"\\'"']\)/\\\1/g'`"'"
533 if [ -n "$vars" ] ; then
534 # $vars will always have a leading space.
535 echo "set$vars "'"$@"' >> configure.tmp
538 cat <<'END_OF_CONFIGURE' >> configure.tmp
541 XAPIAN_CONFIG=$here/xapian-core/xapian-config
542 for d in $modules ; do
543 if [ "$here" = "$srcdir" ] ; then
544 configure=./configure
545 configure_from_here=$d/configure
547 configure=$srcdir/$d/configure
548 configure_from_here=$configure
550 if [ -f "$configure_from_here" ] ; then
551 if [ -d "$d" ] ; then : ; else
553 xapian-applications/*) [ -d xapian-applications ] || mkdir xapian-applications ;;
557 echo "Configuring \`$d'"
558 # Use a shared config.cache for speed and to save a bit of diskspace, but
559 # don't share it with SWIG just in case it manages to probe and cache
560 # different answers (e.g. because it uses a C compiler).
563 cd "$d" && "$configure" ${1+"$@"}
566 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking --cache-file="$here/config.cache" ${1+"$@"}
568 xapian-applications/omega)
569 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking XAPIAN_CONFIG="$XAPIAN_CONFIG" CPPFLAGS="-I$srcdir/INST/include" LDFLAGS="-L$srcdir/INST/lib" ${1+"$@"}
572 cd "$d" && "$configure" --enable-maintainer-mode --disable-option-checking --cache-file="$here/config.cache" XAPIAN_CONFIG="$XAPIAN_CONFIG" ${1+"$@"}
577 revdirs="$d $revdirs"
582 *" --help "*|*" --version "*)
583 # Don't generate Makefile if --help or --version specified.
590 cat <<EOF > Makefile.tmp
591 # Makefile generated by:
592 CONFIGURE_COMMAND := $cmd
594 if [ "$srcdir" != . ] ; then
595 cat <<EOF >> Makefile.tmp
600 targets='all install uninstall install-strip clean distclean mostlyclean maintainer-clean dist check distcheck'
601 for target in $targets ; do
606 # When uninstalling or cleaning, process directories in reverse order, so
607 # that we process a directory after any directories which might use it.
614 swig,install*|swig,uninstall)
615 # Nothing to do with swig when installing/uninstalling.
617 swig,dist|swig,check|swig,distcheck|swig,all)
618 # Need to ensure swig is built before "make dist", "make check", etc.
619 echo " cd $d && \$(MAKE)" ;;
621 echo " cd $d && \$(MAKE) clean" ;;
622 xapian-bindings,distcheck)
623 # FIXME: distcheck doesn't currently work for xapian-bindings because
624 # xapian-core isn't installed.
625 echo " cd $d && \$(MAKE) check && \$(MAKE) dist" ;;
627 echo " cd $d && \$(MAKE) $target" ;;
631 distclean|maintainer-clean) echo " rm -f Makefile config.cache" ;;
634 cat <<EOF >> Makefile.tmp
637 \$(CONFIGURE_COMMAND)
639 Makefile: $srcdir/configure
640 \$(CONFIGURE_COMMAND)
642 $srcdir/configure: \\
647 # We want to rerun bootstrap if a series file changes (patch added or removed)
648 # or an existing patch changes. Since we always have an series file (even if
649 # it is empty), this also handles us adding the first patch for something.
651 for d
in patches
/* ; do
653 echo "$series:" >> configure.tmp2
657 sed -n 's/[ ]*\(#.*\)\?$//;/./p' "$series" |\
663 # Because there's a pipeline, this is a subshell, so use a temporary file
664 # rather than a variable to compile a list of patches to use below.
665 echo "$patch:" >> configure.tmp2
667 done >> configure.tmp
669 cat <<'END_OF_CONFIGURE' >> configure.tmp
673 .PHONY: $targets recheck
675 # Dummy dependencies to allow removing patches we no longer need.
678 cat configure.tmp2
>> configure.tmp
680 cat <<'END_OF_CONFIGURE' >> configure.tmp
682 mv -f Makefile.tmp Makefile
684 echo "Configured successfully - now run \"${MAKE-make}\""
689 chmod +x configure.tmp
690 mv -f configure.tmp configure
693 echo "Bootstrapped successfully - now run \"$srcdir/configure\" and \"${MAKE-make}\""