17fa8417cSAndreas Gruenbacher#! /bin/sh
27fa8417cSAndreas Gruenbacher# Print a version string.
309939400SAndreas Gruenbacherscriptversion=2020-04-13.15; # UTC
47fa8417cSAndreas Gruenbacher
57fa8417cSAndreas Gruenbacher# Bootstrap this package from checked-out sources.
67fa8417cSAndreas Gruenbacher
709939400SAndreas Gruenbacher# Copyright (C) 2003-2020 Free Software Foundation, Inc.
87fa8417cSAndreas Gruenbacher
97fa8417cSAndreas Gruenbacher# This program is free software: you can redistribute it and/or modify
107fa8417cSAndreas Gruenbacher# it under the terms of the GNU General Public License as published by
117fa8417cSAndreas Gruenbacher# the Free Software Foundation, either version 3 of the License, or
127fa8417cSAndreas Gruenbacher# (at your option) any later version.
137fa8417cSAndreas Gruenbacher
147fa8417cSAndreas Gruenbacher# This program is distributed in the hope that it will be useful,
157fa8417cSAndreas Gruenbacher# but WITHOUT ANY WARRANTY; without even the implied warranty of
177fa8417cSAndreas Gruenbacher# GNU General Public License for more details.
187fa8417cSAndreas Gruenbacher
197fa8417cSAndreas Gruenbacher# You should have received a copy of the GNU General Public License
209ab866d5SAndreas Gruenbacher# along with this program.  If not, see <https://www.gnu.org/licenses/>.
217fa8417cSAndreas Gruenbacher
227fa8417cSAndreas Gruenbacher# Originally written by Paul Eggert.  The canonical version of this
237fa8417cSAndreas Gruenbacher# script is maintained as build-aux/bootstrap in gnulib, however, to
247fa8417cSAndreas Gruenbacher# be useful to your project, you should place a copy of it under
257fa8417cSAndreas Gruenbacher# version control in the top-level directory of your project.  The
267fa8417cSAndreas Gruenbacher# intent is that all customization can be done with a bootstrap.conf
277fa8417cSAndreas Gruenbacher# file also maintained in your version control; gnulib comes with a
287fa8417cSAndreas Gruenbacher# template build-aux/bootstrap.conf to get you started.
297fa8417cSAndreas Gruenbacher
307fa8417cSAndreas Gruenbacher# Please report bugs or propose patches to bug-gnulib@gnu.org.
317fa8417cSAndreas Gruenbacher
327fa8417cSAndreas Gruenbachernl='
337fa8417cSAndreas Gruenbacher'
347fa8417cSAndreas Gruenbacher
357fa8417cSAndreas Gruenbacher# Ensure file names are sorted consistently across platforms.
367fa8417cSAndreas GruenbacherLC_ALL=C
377fa8417cSAndreas Gruenbacherexport LC_ALL
387fa8417cSAndreas Gruenbacher
39386ae15bSAndreas Gruenbacher# Ensure that CDPATH is not set.  Otherwise, the output from cd
40386ae15bSAndreas Gruenbacher# would cause trouble in at least one use below.
41386ae15bSAndreas Gruenbacher(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
42386ae15bSAndreas Gruenbacher
437fa8417cSAndreas Gruenbacherlocal_gl_dir=gl
447fa8417cSAndreas Gruenbacher
459ab866d5SAndreas Gruenbacher# Honor $PERL, but work even if there is none.
469ab866d5SAndreas GruenbacherPERL="${PERL-perl}"
479ab866d5SAndreas Gruenbacher
484a7efc37SJim Meyeringme=$0
497fa8417cSAndreas Gruenbacher
5009939400SAndreas Gruenbacherdefault_gnulib_url=git://git.sv.gnu.org/gnulib
5109939400SAndreas Gruenbacher
527fa8417cSAndreas Gruenbacherusage() {
537fa8417cSAndreas Gruenbacher  cat <<EOF
544a7efc37SJim MeyeringUsage: $me [OPTION]...
557fa8417cSAndreas GruenbacherBootstrap this package from the checked-out sources.
567fa8417cSAndreas Gruenbacher
577fa8417cSAndreas GruenbacherOptions:
584a7efc37SJim Meyering --gnulib-srcdir=DIRNAME  specify the local directory where gnulib
597fa8417cSAndreas Gruenbacher                          sources reside.  Use this if you already
607fa8417cSAndreas Gruenbacher                          have gnulib sources on your machine, and
617fa8417cSAndreas Gruenbacher                          do not want to waste your bandwidth downloading
624a7efc37SJim Meyering                          them again.  Defaults to \$GNULIB_SRCDIR
634a7efc37SJim Meyering --bootstrap-sync         if this bootstrap script is not identical to
644a7efc37SJim Meyering                          the version in the local gnulib sources,
654a7efc37SJim Meyering                          update this script, and then restart it with
664a7efc37SJim Meyering                          /bin/sh or the shell \$CONFIG_SHELL
674a7efc37SJim Meyering --no-bootstrap-sync      do not check whether bootstrap is out of sync
684a7efc37SJim Meyering --copy                   copy files instead of creating symbolic links
694a7efc37SJim Meyering --force                  attempt to bootstrap even if the sources seem
704a7efc37SJim Meyering                          not to have been checked out
714a7efc37SJim Meyering --no-git                 do not use git to update gnulib.  Requires that
724a7efc37SJim Meyering                          --gnulib-srcdir point to a correct gnulib snapshot
734a7efc37SJim Meyering --skip-po                do not download po files
744a7efc37SJim Meyering
754a7efc37SJim MeyeringIf the file $me.conf exists in the same directory as this script, its
767fa8417cSAndreas Gruenbachercontents are read as shell variables to configure the bootstrap.
777fa8417cSAndreas Gruenbacher
787fa8417cSAndreas GruenbacherFor build prerequisites, environment variables like \$AUTOCONF and \$AMTAR
797fa8417cSAndreas Gruenbacherare honored.
807fa8417cSAndreas Gruenbacher
8109939400SAndreas GruenbacherGnulib sources can be fetched in various ways:
8209939400SAndreas Gruenbacher
8309939400SAndreas Gruenbacher * If this package is in a git repository with a 'gnulib' submodule
8409939400SAndreas Gruenbacher   configured, then that submodule is initialized and updated and sources
8509939400SAndreas Gruenbacher   are fetched from there.  If \$GNULIB_SRCDIR is set (directly or via
8609939400SAndreas Gruenbacher   --gnulib-srcdir) and is a git repository, then it is used as a reference.
8709939400SAndreas Gruenbacher
8809939400SAndreas Gruenbacher * Otherwise, if \$GNULIB_SRCDIR is set (directly or via --gnulib-srcdir),
8909939400SAndreas Gruenbacher   then sources are fetched from that local directory.  If it is a git
9009939400SAndreas Gruenbacher   repository and \$GNULIB_REVISION is set, then that revision is checked
9109939400SAndreas Gruenbacher   out.
9209939400SAndreas Gruenbacher
9309939400SAndreas Gruenbacher * Otherwise, if this package is in a git repository with a 'gnulib'
9409939400SAndreas Gruenbacher   submodule configured, then that submodule is initialized and updated and
9509939400SAndreas Gruenbacher   sources are fetched from there.
9609939400SAndreas Gruenbacher
9709939400SAndreas Gruenbacher * Otherwise, if the 'gnulib' directory does not exist, Gnulib sources are
9809939400SAndreas Gruenbacher   cloned into that directory using git from \$GNULIB_URL, defaulting to
9909939400SAndreas Gruenbacher   $default_gnulib_url.
10009939400SAndreas Gruenbacher   If \$GNULIB_REVISION is set, then that revision is checked out.
10109939400SAndreas Gruenbacher
10209939400SAndreas Gruenbacher * Otherwise, the existing Gnulib sources in the 'gnulib' directory are
10309939400SAndreas Gruenbacher   used.  If it is a git repository and \$GNULIB_REVISION is set, then that
10409939400SAndreas Gruenbacher   revision is checked out.
10509939400SAndreas Gruenbacher
10609939400SAndreas GruenbacherIf you maintain a package and want to pin a particular revision of the
10709939400SAndreas GruenbacherGnulib sources that has been tested with your package, then there are two
10809939400SAndreas Gruenbacherpossible approaches: either configure a 'gnulib' submodule with the
10909939400SAndreas Gruenbacherappropriate revision, or set \$GNULIB_REVISION (and if necessary
11009939400SAndreas Gruenbacher\$GNULIB_URL) in $me.conf.
11109939400SAndreas Gruenbacher
1127fa8417cSAndreas GruenbacherRunning without arguments will suffice in most cases.
1137fa8417cSAndreas GruenbacherEOF
1147fa8417cSAndreas Gruenbacher}
1157fa8417cSAndreas Gruenbacher
116386ae15bSAndreas Gruenbacher# warnf_ FORMAT-STRING ARG1...
117386ae15bSAndreas Gruenbacherwarnf_ ()
118386ae15bSAndreas Gruenbacher{
119386ae15bSAndreas Gruenbacher  warnf_format_=$1
120386ae15bSAndreas Gruenbacher  shift
121386ae15bSAndreas Gruenbacher  nl='
122386ae15bSAndreas Gruenbacher'
123386ae15bSAndreas Gruenbacher  case $* in
124386ae15bSAndreas Gruenbacher    *$nl*) me_=$(printf "$me"|tr "$nl|" '??')
125386ae15bSAndreas Gruenbacher       printf "$warnf_format_" "$@" | sed "s|^|$me_: |" ;;
126386ae15bSAndreas Gruenbacher    *) printf "$me: $warnf_format_" "$@" ;;
127386ae15bSAndreas Gruenbacher  esac >&2
128386ae15bSAndreas Gruenbacher}
129386ae15bSAndreas Gruenbacher
130386ae15bSAndreas Gruenbacher# warn_ WORD1...
131386ae15bSAndreas Gruenbacherwarn_ ()
132386ae15bSAndreas Gruenbacher{
133386ae15bSAndreas Gruenbacher  # If IFS does not start with ' ', set it and emit the warning in a subshell.
134386ae15bSAndreas Gruenbacher  case $IFS in
135386ae15bSAndreas Gruenbacher    ' '*) warnf_ '%s\n' "$*";;
136386ae15bSAndreas Gruenbacher    *)    (IFS=' '; warn_ "$@");;
137386ae15bSAndreas Gruenbacher  esac
138386ae15bSAndreas Gruenbacher}
139386ae15bSAndreas Gruenbacher
140386ae15bSAndreas Gruenbacher# die WORD1...
141386ae15bSAndreas Gruenbacherdie() { warn_ "$@"; exit 1; }
142386ae15bSAndreas Gruenbacher
1437fa8417cSAndreas Gruenbacher# Configuration.
1447fa8417cSAndreas Gruenbacher
1457fa8417cSAndreas Gruenbacher# Name of the Makefile.am
1467fa8417cSAndreas Gruenbachergnulib_mk=gnulib.mk
1477fa8417cSAndreas Gruenbacher
1487fa8417cSAndreas Gruenbacher# List of gnulib modules needed.
1497fa8417cSAndreas Gruenbachergnulib_modules=
1507fa8417cSAndreas Gruenbacher
1517fa8417cSAndreas Gruenbacher# Any gnulib files needed that are not in modules.
1527fa8417cSAndreas Gruenbachergnulib_files=
1537fa8417cSAndreas Gruenbacher
154297f9e7dSJim Meyering: ${AUTOPOINT=autopoint}
155297f9e7dSJim Meyering: ${AUTORECONF=autoreconf}
156297f9e7dSJim Meyering
157297f9e7dSJim Meyering# A function to be called right after gnulib-tool is run.
1584a7efc37SJim Meyering# Override it via your own definition in bootstrap.conf.
159297f9e7dSJim Meyeringbootstrap_post_import_hook() { :; }
1604a7efc37SJim Meyering
1617fa8417cSAndreas Gruenbacher# A function to be called after everything else in this script.
1627fa8417cSAndreas Gruenbacher# Override it via your own definition in bootstrap.conf.
1637fa8417cSAndreas Gruenbacherbootstrap_epilogue() { :; }
1647fa8417cSAndreas Gruenbacher
16509939400SAndreas Gruenbacher# The command to download all .po files for a specified domain into a
16609939400SAndreas Gruenbacher# specified directory.  Fill in the first %s with the destination
16709939400SAndreas Gruenbacher# directory and the second with the domain name.
1687fa8417cSAndreas Gruenbacherpo_download_command_format=\
16909939400SAndreas Gruenbacher"wget --mirror --level=1 -nd -nv -A.po -P '%s' \
1709ab866d5SAndreas Gruenbacher https://translationproject.org/latest/%s/"
171297f9e7dSJim Meyering
1729ab866d5SAndreas Gruenbacher# Prefer a non-empty tarname (4th argument of AC_INIT if given), else
1739ab866d5SAndreas Gruenbacher# fall back to the package name (1st argument with munging)
1747fa8417cSAndreas Gruenbacherextract_package_name='
1759ab866d5SAndreas Gruenbacher  /^AC_INIT(\[*/{
1769ab866d5SAndreas Gruenbacher     s///
1779ab866d5SAndreas Gruenbacher     /^[^,]*,[^,]*,[^,]*,[ []*\([^][ ,)]\)/{
1789ab866d5SAndreas Gruenbacher       s//\1/
1799ab866d5SAndreas Gruenbacher       s/[],)].*//
1807fa8417cSAndreas Gruenbacher       p
1817fa8417cSAndreas Gruenbacher       q
1827fa8417cSAndreas Gruenbacher     }
1839ab866d5SAndreas Gruenbacher     s/[],)].*//
1847fa8417cSAndreas Gruenbacher     s/^GNU //
1857fa8417cSAndreas Gruenbacher     y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
1869ab866d5SAndreas Gruenbacher     s/[^abcdefghijklmnopqrstuvwxyz0123456789_]/-/g
1877fa8417cSAndreas Gruenbacher     p
1887fa8417cSAndreas Gruenbacher  }
1897fa8417cSAndreas Gruenbacher'
190386ae15bSAndreas Gruenbacherpackage=$(sed -n "$extract_package_name" configure.ac) \
191386ae15bSAndreas Gruenbacher  || die 'cannot find package name in configure.ac'
1927fa8417cSAndreas Gruenbachergnulib_name=lib$package
1937fa8417cSAndreas Gruenbacher
1947fa8417cSAndreas Gruenbacherbuild_aux=build-aux
1957fa8417cSAndreas Gruenbachersource_base=lib
1967fa8417cSAndreas Gruenbacherm4_base=m4
1977fa8417cSAndreas Gruenbacherdoc_base=doc
1987fa8417cSAndreas Gruenbachertests_base=tests
19909939400SAndreas Gruenbachergnulib_extra_files="
20009939400SAndreas Gruenbacher        build-aux/install-sh
20109939400SAndreas Gruenbacher        build-aux/mdate-sh
20209939400SAndreas Gruenbacher        build-aux/texinfo.tex
20309939400SAndreas Gruenbacher        build-aux/depcomp
20409939400SAndreas Gruenbacher        build-aux/config.guess
20509939400SAndreas Gruenbacher        build-aux/config.sub
20609939400SAndreas Gruenbacher        doc/INSTALL
20709939400SAndreas Gruenbacher"
2087fa8417cSAndreas Gruenbacher
2097fa8417cSAndreas Gruenbacher# Additional gnulib-tool options to use.  Use "\newline" to break lines.
2107fa8417cSAndreas Gruenbachergnulib_tool_option_extras=
2117fa8417cSAndreas Gruenbacher
2127fa8417cSAndreas Gruenbacher# Other locale categories that need message catalogs.
2137fa8417cSAndreas GruenbacherEXTRA_LOCALE_CATEGORIES=
2147fa8417cSAndreas Gruenbacher
2157fa8417cSAndreas Gruenbacher# Additional xgettext options to use.  Use "\\\newline" to break lines.
2167fa8417cSAndreas GruenbacherXGETTEXT_OPTIONS='\\\
2177fa8417cSAndreas Gruenbacher --flag=_:1:pass-c-format\\\
2187fa8417cSAndreas Gruenbacher --flag=N_:1:pass-c-format\\\
2197fa8417cSAndreas Gruenbacher --flag=error:3:c-format --flag=error_at_line:5:c-format\\\
2207fa8417cSAndreas Gruenbacher'
2217fa8417cSAndreas Gruenbacher
2227fa8417cSAndreas Gruenbacher# Package bug report address and copyright holder for gettext files
2237fa8417cSAndreas GruenbacherCOPYRIGHT_HOLDER='Free Software Foundation, Inc.'
2247fa8417cSAndreas GruenbacherMSGID_BUGS_ADDRESS=bug-$package@gnu.org
2257fa8417cSAndreas Gruenbacher
2267fa8417cSAndreas Gruenbacher# Files we don't want to import.
2277fa8417cSAndreas Gruenbacherexcluded_files=
2287fa8417cSAndreas Gruenbacher
2297fa8417cSAndreas Gruenbacher# File that should exist in the top directory of a checked out hierarchy,
2307fa8417cSAndreas Gruenbacher# but not in a distribution tarball.
2317fa8417cSAndreas Gruenbachercheckout_only_file=README-hacking
2327fa8417cSAndreas Gruenbacher
2337fa8417cSAndreas Gruenbacher# Whether to use copies instead of symlinks.
2347fa8417cSAndreas Gruenbachercopy=false
2357fa8417cSAndreas Gruenbacher
2367fa8417cSAndreas Gruenbacher# Set this to '.cvsignore .gitignore' in bootstrap.conf if you want
2377fa8417cSAndreas Gruenbacher# those files to be generated in directories like lib/, m4/, and po/.
2387fa8417cSAndreas Gruenbacher# Or set it to 'auto' to make this script select which to use based
2397fa8417cSAndreas Gruenbacher# on which version control system (if any) is used in the source directory.
2407fa8417cSAndreas Gruenbachervc_ignore=auto
2417fa8417cSAndreas Gruenbacher
2424a7efc37SJim Meyering# Set this to true in bootstrap.conf to enable --bootstrap-sync by
2434a7efc37SJim Meyering# default.
2444a7efc37SJim Meyeringbootstrap_sync=false
2454a7efc37SJim Meyering
2464a7efc37SJim Meyering# Use git to update gnulib sources
2474a7efc37SJim Meyeringuse_git=true
2484a7efc37SJim Meyering
2499ab866d5SAndreas Gruenbachercheck_exists() {
2509ab866d5SAndreas Gruenbacher  if test "$1" = "--verbose"; then
2519ab866d5SAndreas Gruenbacher    ($2 --version </dev/null) >/dev/null 2>&1
2529ab866d5SAndreas Gruenbacher    if test $? -ge 126; then
2539ab866d5SAndreas Gruenbacher      # If not found, run with diagnostics as one may be
2549ab866d5SAndreas Gruenbacher      # presented with env variables to set to find the right version
2559ab866d5SAndreas Gruenbacher      ($2 --version </dev/null)
2569ab866d5SAndreas Gruenbacher    fi
2579ab866d5SAndreas Gruenbacher  else
2589ab866d5SAndreas Gruenbacher    ($1 --version </dev/null) >/dev/null 2>&1
2599ab866d5SAndreas Gruenbacher  fi
2609ab866d5SAndreas Gruenbacher
2619ab866d5SAndreas Gruenbacher  test $? -lt 126
2629ab866d5SAndreas Gruenbacher}
2639ab866d5SAndreas Gruenbacher
2647fa8417cSAndreas Gruenbacher# find_tool ENVVAR NAMES...
2657fa8417cSAndreas Gruenbacher# -------------------------
2667fa8417cSAndreas Gruenbacher# Search for a required program.  Use the value of ENVVAR, if set,
2679ab866d5SAndreas Gruenbacher# otherwise find the first of the NAMES that can be run.
2689ab866d5SAndreas Gruenbacher# If found, set ENVVAR to the program name, die otherwise.
269386ae15bSAndreas Gruenbacher#
270386ae15bSAndreas Gruenbacher# FIXME: code duplication, see also gnu-web-doc-update.
2717fa8417cSAndreas Gruenbacherfind_tool ()
2727fa8417cSAndreas Gruenbacher{
2737fa8417cSAndreas Gruenbacher  find_tool_envvar=$1
2747fa8417cSAndreas Gruenbacher  shift
2757fa8417cSAndreas Gruenbacher  find_tool_names=$@
2767fa8417cSAndreas Gruenbacher  eval "find_tool_res=\$$find_tool_envvar"
2777fa8417cSAndreas Gruenbacher  if test x"$find_tool_res" = x; then
2789ab866d5SAndreas Gruenbacher    for i; do
2799ab866d5SAndreas Gruenbacher      if check_exists $i; then
2809ab866d5SAndreas Gruenbacher        find_tool_res=$i
2819ab866d5SAndreas Gruenbacher        break
2827fa8417cSAndreas Gruenbacher      fi
2837fa8417cSAndreas Gruenbacher    done
2847fa8417cSAndreas Gruenbacher  fi
2859ab866d5SAndreas Gruenbacher  if test x"$find_tool_res" = x; then
2869ab866d5SAndreas Gruenbacher    warn_ "one of these is required: $find_tool_names;"
2879ab866d5SAndreas Gruenbacher    die   "alternatively set $find_tool_envvar to a compatible tool"
2889ab866d5SAndreas Gruenbacher  fi
2897fa8417cSAndreas Gruenbacher  eval "$find_tool_envvar=\$find_tool_res"
2907fa8417cSAndreas Gruenbacher  eval "export $find_tool_envvar"
2917fa8417cSAndreas Gruenbacher}
2927fa8417cSAndreas Gruenbacher
2937fa8417cSAndreas Gruenbacher# Override the default configuration, if necessary.
2947fa8417cSAndreas Gruenbacher# Make sure that bootstrap.conf is sourced from the current directory
2957fa8417cSAndreas Gruenbacher# if we were invoked as "sh bootstrap".
2967fa8417cSAndreas Gruenbachercase "$0" in
2977fa8417cSAndreas Gruenbacher  */*) test -r "$0.conf" && . "$0.conf" ;;
2987fa8417cSAndreas Gruenbacher  *) test -r "$0.conf" && . ./"$0.conf" ;;
2997fa8417cSAndreas Gruenbacheresac
3007fa8417cSAndreas Gruenbacher
3017fa8417cSAndreas Gruenbacherif test "$vc_ignore" = auto; then
3027fa8417cSAndreas Gruenbacher  vc_ignore=
3037fa8417cSAndreas Gruenbacher  test -d .git && vc_ignore=.gitignore
3047fa8417cSAndreas Gruenbacher  test -d CVS && vc_ignore="$vc_ignore .cvsignore"
3057fa8417cSAndreas Gruenbacherfi
3067fa8417cSAndreas Gruenbacher
30709939400SAndreas Gruenbacherif test x"$gnulib_modules$gnulib_files$gnulib_extra_files" = x; then
30809939400SAndreas Gruenbacher  use_gnulib=false
30909939400SAndreas Gruenbacherelse
31009939400SAndreas Gruenbacher  use_gnulib=true
31109939400SAndreas Gruenbacherfi
31209939400SAndreas Gruenbacher
3137fa8417cSAndreas Gruenbacher# Translate configuration into internal form.
3147fa8417cSAndreas Gruenbacher
3157fa8417cSAndreas Gruenbacher# Parse options.
3167fa8417cSAndreas Gruenbacher
3177fa8417cSAndreas Gruenbacherfor option
3187fa8417cSAndreas Gruenbacherdo
3197fa8417cSAndreas Gruenbacher  case $option in
3207fa8417cSAndreas Gruenbacher  --help)
3217fa8417cSAndreas Gruenbacher    usage
3227fa8417cSAndreas Gruenbacher    exit;;
3237fa8417cSAndreas Gruenbacher  --gnulib-srcdir=*)
324386ae15bSAndreas Gruenbacher    GNULIB_SRCDIR=${option#--gnulib-srcdir=};;
3257fa8417cSAndreas Gruenbacher  --skip-po)
3267fa8417cSAndreas Gruenbacher    SKIP_PO=t;;
3277fa8417cSAndreas Gruenbacher  --force)
3287fa8417cSAndreas Gruenbacher    checkout_only_file=;;
3297fa8417cSAndreas Gruenbacher  --copy)
3307fa8417cSAndreas Gruenbacher    copy=true;;
3314a7efc37SJim Meyering  --bootstrap-sync)
3324a7efc37SJim Meyering    bootstrap_sync=true;;
3334a7efc37SJim Meyering  --no-bootstrap-sync)
3344a7efc37SJim Meyering    bootstrap_sync=false;;
3354a7efc37SJim Meyering  --no-git)
3364a7efc37SJim Meyering    use_git=false;;
3377fa8417cSAndreas Gruenbacher  *)
338386ae15bSAndreas Gruenbacher    die "$option: unknown option";;
3397fa8417cSAndreas Gruenbacher  esac
3407fa8417cSAndreas Gruenbacherdone
3417fa8417cSAndreas Gruenbacher
342386ae15bSAndreas Gruenbacher$use_git || test -d "$GNULIB_SRCDIR" \
343386ae15bSAndreas Gruenbacher  || die "Error: --no-git requires --gnulib-srcdir"
3444a7efc37SJim Meyering
3457fa8417cSAndreas Gruenbacherif test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then
346386ae15bSAndreas Gruenbacher  die "Bootstrapping from a non-checked-out distribution is risky."
3477fa8417cSAndreas Gruenbacherfi
3487fa8417cSAndreas Gruenbacher
3499ab866d5SAndreas Gruenbacher# Strip blank and comment lines to leave significant entries.
3509ab866d5SAndreas Gruenbachergitignore_entries() {
3519ab866d5SAndreas Gruenbacher  sed '/^#/d; /^$/d' "$@"
352297f9e7dSJim Meyering}
353297f9e7dSJim Meyering
3549ab866d5SAndreas Gruenbacher# If $STR is not already on a line by itself in $FILE, insert it at the start.
3559ab866d5SAndreas Gruenbacher# Entries are inserted at the start of the ignore list to ensure existing
3569ab866d5SAndreas Gruenbacher# entries starting with ! are not overridden.  Such entries support
3579ab866d5SAndreas Gruenbacher# whitelisting exceptions after a more generic blacklist pattern.
3589ab866d5SAndreas Gruenbacherinsert_if_absent() {
3597fa8417cSAndreas Gruenbacher  file=$1
3607fa8417cSAndreas Gruenbacher  str=$2
3617fa8417cSAndreas Gruenbacher  test -f $file || touch $file
3629ab866d5SAndreas Gruenbacher  test -r $file || die "Error: failed to read ignore file: $file"
3639ab866d5SAndreas Gruenbacher  duplicate_entries=$(gitignore_entries $file | sort | uniq -d)
3649ab866d5SAndreas Gruenbacher  if [ "$duplicate_entries" ] ; then
3659ab866d5SAndreas Gruenbacher    die "Error: Duplicate entries in $file: " $duplicate_entries
3669ab866d5SAndreas Gruenbacher  fi
3679ab866d5SAndreas Gruenbacher  linesold=$(gitignore_entries $file | wc -l)
3689ab866d5SAndreas Gruenbacher  linesnew=$( { echo "$str"; cat $file; } | gitignore_entries | sort -u | wc -l)
3699ab866d5SAndreas Gruenbacher  if [ $linesold != $linesnew ] ; then
3709ab866d5SAndreas Gruenbacher    { echo "$str" | cat - $file > $file.bak && mv $file.bak $file; } \
3719ab866d5SAndreas Gruenbacher      || die "insert_if_absent $file $str: failed"
3729ab866d5SAndreas Gruenbacher  fi
3737fa8417cSAndreas Gruenbacher}
3747fa8417cSAndreas Gruenbacher
3754a7efc37SJim Meyering# Adjust $PATTERN for $VC_IGNORE_FILE and insert it with
3769ab866d5SAndreas Gruenbacher# insert_if_absent.
3774a7efc37SJim Meyeringinsert_vc_ignore() {
3784a7efc37SJim Meyering  vc_ignore_file="$1"
3794a7efc37SJim Meyering  pattern="$2"
3804a7efc37SJim Meyering  case $vc_ignore_file in
3814a7efc37SJim Meyering  *.gitignore)
382297f9e7dSJim Meyering    # A .gitignore entry that does not start with '/' applies
383297f9e7dSJim Meyering    # recursively to subdirectories, so prepend '/' to every
3844a7efc37SJim Meyering    # .gitignore entry.
385386ae15bSAndreas Gruenbacher    pattern=$(echo "$pattern" | sed s,^,/,);;
3864a7efc37SJim Meyering  esac
3879ab866d5SAndreas Gruenbacher  insert_if_absent "$vc_ignore_file" "$pattern"
3884a7efc37SJim Meyering}
3894a7efc37SJim Meyering
3907fa8417cSAndreas Gruenbacher# Die if there is no AC_CONFIG_AUX_DIR($build_aux) line in configure.ac.
3917fa8417cSAndreas Gruenbacherfound_aux_dir=no
3927fa8417cSAndreas Gruenbachergrep '^[	 ]*AC_CONFIG_AUX_DIR(\['"$build_aux"'\])' configure.ac \
3937fa8417cSAndreas Gruenbacher    >/dev/null && found_aux_dir=yes
3947fa8417cSAndreas Gruenbachergrep '^[	 ]*AC_CONFIG_AUX_DIR('"$build_aux"')' configure.ac \
3957fa8417cSAndreas Gruenbacher    >/dev/null && found_aux_dir=yes
396386ae15bSAndreas Gruenbachertest $found_aux_dir = yes \
397386ae15bSAndreas Gruenbacher  || die "configure.ac lacks 'AC_CONFIG_AUX_DIR([$build_aux])'; add it"
3987fa8417cSAndreas Gruenbacher
3997fa8417cSAndreas Gruenbacher# If $build_aux doesn't exist, create it now, otherwise some bits
4007fa8417cSAndreas Gruenbacher# below will malfunction.  If creating it, also mark it as ignored.
4017fa8417cSAndreas Gruenbacherif test ! -d $build_aux; then
4027fa8417cSAndreas Gruenbacher  mkdir $build_aux
4037fa8417cSAndreas Gruenbacher  for dot_ig in x $vc_ignore; do
4047fa8417cSAndreas Gruenbacher    test $dot_ig = x && continue
4054a7efc37SJim Meyering    insert_vc_ignore $dot_ig $build_aux
4067fa8417cSAndreas Gruenbacher  done
4077fa8417cSAndreas Gruenbacherfi
4087fa8417cSAndreas Gruenbacher
4097fa8417cSAndreas Gruenbacher# Note this deviates from the version comparison in automake
4107fa8417cSAndreas Gruenbacher# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
4117fa8417cSAndreas Gruenbacher# but this should suffice as we won't be specifying old
4127fa8417cSAndreas Gruenbacher# version formats or redundant trailing .0 in bootstrap.conf.
4137fa8417cSAndreas Gruenbacher# If we did want full compatibility then we should probably
4147fa8417cSAndreas Gruenbacher# use m4_version_compare from autoconf.
4157fa8417cSAndreas Gruenbachersort_ver() { # sort -V is not generally available
4167fa8417cSAndreas Gruenbacher  ver1="$1"
4177fa8417cSAndreas Gruenbacher  ver2="$2"
4187fa8417cSAndreas Gruenbacher
4197fa8417cSAndreas Gruenbacher  # split on '.' and compare each component
4207fa8417cSAndreas Gruenbacher  i=1
4217fa8417cSAndreas Gruenbacher  while : ; do
4227fa8417cSAndreas Gruenbacher    p1=$(echo "$ver1" | cut -d. -f$i)
4237fa8417cSAndreas Gruenbacher    p2=$(echo "$ver2" | cut -d. -f$i)
4247fa8417cSAndreas Gruenbacher    if [ ! "$p1" ]; then
4257fa8417cSAndreas Gruenbacher      echo "$1 $2"
4267fa8417cSAndreas Gruenbacher      break
4277fa8417cSAndreas Gruenbacher    elif [ ! "$p2" ]; then
4287fa8417cSAndreas Gruenbacher      echo "$2 $1"
4297fa8417cSAndreas Gruenbacher      break
4307fa8417cSAndreas Gruenbacher    elif [ ! "$p1" = "$p2" ]; then
4317fa8417cSAndreas Gruenbacher      if [ "$p1" -gt "$p2" ] 2>/dev/null; then # numeric comparison
4327fa8417cSAndreas Gruenbacher        echo "$2 $1"
4337fa8417cSAndreas Gruenbacher      elif [ "$p2" -gt "$p1" ] 2>/dev/null; then # numeric comparison
4347fa8417cSAndreas Gruenbacher        echo "$1 $2"
4357fa8417cSAndreas Gruenbacher      else # numeric, then lexicographic comparison
4367fa8417cSAndreas Gruenbacher        lp=$(printf "$p1\n$p2\n" | LANG=C sort -n | tail -n1)
4377fa8417cSAndreas Gruenbacher        if [ "$lp" = "$p2" ]; then
4387fa8417cSAndreas Gruenbacher          echo "$1 $2"
4397fa8417cSAndreas Gruenbacher        else
4407fa8417cSAndreas Gruenbacher          echo "$2 $1"
4417fa8417cSAndreas Gruenbacher        fi
4427fa8417cSAndreas Gruenbacher      fi
4437fa8417cSAndreas Gruenbacher      break
4447fa8417cSAndreas Gruenbacher    fi
4457fa8417cSAndreas Gruenbacher    i=$(($i+1))
4467fa8417cSAndreas Gruenbacher  done
4477fa8417cSAndreas Gruenbacher}
4487fa8417cSAndreas Gruenbacher
4499ab866d5SAndreas Gruenbacherget_version_sed='
4509ab866d5SAndreas Gruenbacher# Move version to start of line.
4519ab866d5SAndreas Gruenbachers/.*[v ]\([0-9]\)/\1/
4529ab866d5SAndreas Gruenbacher
4539ab866d5SAndreas Gruenbacher# Skip lines that do not start with version.
4549ab866d5SAndreas Gruenbacher/^[0-9]/!d
4557fa8417cSAndreas Gruenbacher
4569ab866d5SAndreas Gruenbacher# Remove characters after the version.
4579ab866d5SAndreas Gruenbachers/[^.a-z0-9-].*//
4587fa8417cSAndreas Gruenbacher
4599ab866d5SAndreas Gruenbacher# The first component must be digits only.
4609ab866d5SAndreas Gruenbachers/^\([0-9]*\)[a-z-].*/\1/
4614a7efc37SJim Meyering
4629ab866d5SAndreas Gruenbacher#the following essentially does s/5.005/5.5/
4639ab866d5SAndreas Gruenbachers/\.0*\([1-9]\)/.\1/g
4649ab866d5SAndreas Gruenbacherp
4659ab866d5SAndreas Gruenbacherq'
4667fa8417cSAndreas Gruenbacher
4679ab866d5SAndreas Gruenbacherget_version() {
4689ab866d5SAndreas Gruenbacher  app=$1
4697fa8417cSAndreas Gruenbacher
4709ab866d5SAndreas Gruenbacher  $app --version >/dev/null 2>&1 || { $app --version; return 1; }
4717fa8417cSAndreas Gruenbacher
4729ab866d5SAndreas Gruenbacher  $app --version 2>&1 | sed -n "$get_version_sed"
4737fa8417cSAndreas Gruenbacher}
4747fa8417cSAndreas Gruenbacher
4757fa8417cSAndreas Gruenbachercheck_versions() {
4767fa8417cSAndreas Gruenbacher  ret=0
4777fa8417cSAndreas Gruenbacher
4787fa8417cSAndreas Gruenbacher  while read app req_ver; do
4794a7efc37SJim Meyering    # We only need libtoolize from the libtool package.
4804a7efc37SJim Meyering    if test "$app" = libtool; then
4814a7efc37SJim Meyering      app=libtoolize
4824a7efc37SJim Meyering    fi
4834a7efc37SJim Meyering    # Exempt git if --no-git is in effect.
4844a7efc37SJim Meyering    if test "$app" = git; then
4854a7efc37SJim Meyering      $use_git || continue
4864a7efc37SJim Meyering    fi
4877fa8417cSAndreas Gruenbacher    # Honor $APP variables ($TAR, $AUTOCONF, etc.)
488386ae15bSAndreas Gruenbacher    appvar=$(echo $app | LC_ALL=C tr '[a-z]-' '[A-Z]_')
4897fa8417cSAndreas Gruenbacher    test "$appvar" = TAR && appvar=AMTAR
490297f9e7dSJim Meyering    case $appvar in
491297f9e7dSJim Meyering        GZIP) ;; # Do not use $GZIP:  it contains gzip options.
4929ab866d5SAndreas Gruenbacher        PERL::*) ;; # Keep perl modules as-is
493297f9e7dSJim Meyering        *) eval "app=\${$appvar-$app}" ;;
494297f9e7dSJim Meyering    esac
495386ae15bSAndreas Gruenbacher
496386ae15bSAndreas Gruenbacher    # Handle the still-experimental Automake-NG programs specially.
497386ae15bSAndreas Gruenbacher    # They remain named as the mainstream Automake programs ("automake",
498386ae15bSAndreas Gruenbacher    # and "aclocal") to avoid gratuitous incompatibilities with
499386ae15bSAndreas Gruenbacher    # pre-existing usages (by, say, autoreconf, or custom autogen.sh
500386ae15bSAndreas Gruenbacher    # scripts), but correctly identify themselves (as being part of
501386ae15bSAndreas Gruenbacher    # "GNU automake-ng") when asked their version.
502386ae15bSAndreas Gruenbacher    case $app in
503386ae15bSAndreas Gruenbacher      automake-ng|aclocal-ng)
504386ae15bSAndreas Gruenbacher        app=${app%-ng}
505386ae15bSAndreas Gruenbacher        ($app --version | grep '(GNU automake-ng)') >/dev/null 2>&1 || {
506386ae15bSAndreas Gruenbacher          warn_ "Error: '$app' not found or not from Automake-NG"
507386ae15bSAndreas Gruenbacher          ret=1
508386ae15bSAndreas Gruenbacher          continue
509386ae15bSAndreas Gruenbacher        } ;;
5109ab866d5SAndreas Gruenbacher      # Another check is for perl modules.  These can be written as
5119ab866d5SAndreas Gruenbacher      # e.g. perl::XML::XPath in case of XML::XPath module, etc.
5129ab866d5SAndreas Gruenbacher      perl::*)
5139ab866d5SAndreas Gruenbacher        # Extract module name
5149ab866d5SAndreas Gruenbacher        app="${app#perl::}"
5159ab866d5SAndreas Gruenbacher        if ! $PERL -m"$app" -e 'exit 0' >/dev/null 2>&1; then
5169ab866d5SAndreas Gruenbacher          warn_ "Error: perl module '$app' not found"
5179ab866d5SAndreas Gruenbacher          ret=1
5189ab866d5SAndreas Gruenbacher        fi
5199ab866d5SAndreas Gruenbacher        continue
5209ab866d5SAndreas Gruenbacher        ;;
521386ae15bSAndreas Gruenbacher    esac
522297f9e7dSJim Meyering    if [ "$req_ver" = "-" ]; then
523297f9e7dSJim Meyering      # Merely require app to exist; not all prereq apps are well-behaved
524297f9e7dSJim Meyering      # so we have to rely on $? rather than get_version.
5259ab866d5SAndreas Gruenbacher      if ! check_exists --verbose $app; then
526386ae15bSAndreas Gruenbacher        warn_ "Error: '$app' not found"
5277fa8417cSAndreas Gruenbacher        ret=1
5287fa8417cSAndreas Gruenbacher      fi
529297f9e7dSJim Meyering    else
530297f9e7dSJim Meyering      # Require app to produce a new enough version string.
531297f9e7dSJim Meyering      inst_ver=$(get_version $app)
532297f9e7dSJim Meyering      if [ ! "$inst_ver" ]; then
533386ae15bSAndreas Gruenbacher        warn_ "Error: '$app' not found"
534297f9e7dSJim Meyering        ret=1
535297f9e7dSJim Meyering      else
536297f9e7dSJim Meyering        latest_ver=$(sort_ver $req_ver $inst_ver | cut -d' ' -f2)
537297f9e7dSJim Meyering        if [ ! "$latest_ver" = "$inst_ver" ]; then
538386ae15bSAndreas Gruenbacher          warnf_ '%s\n'                                        \
539386ae15bSAndreas Gruenbacher              "Error: '$app' version == $inst_ver is too old"  \
540386ae15bSAndreas Gruenbacher              "       '$app' version >= $req_ver is required"
541297f9e7dSJim Meyering          ret=1
542297f9e7dSJim Meyering        fi
543297f9e7dSJim Meyering      fi
5447fa8417cSAndreas Gruenbacher    fi
5457fa8417cSAndreas Gruenbacher  done
5467fa8417cSAndreas Gruenbacher
5477fa8417cSAndreas Gruenbacher  return $ret
5487fa8417cSAndreas Gruenbacher}
5497fa8417cSAndreas Gruenbacher
5507fa8417cSAndreas Gruenbacherprint_versions() {
5517fa8417cSAndreas Gruenbacher  echo "Program    Min_version"
5527fa8417cSAndreas Gruenbacher  echo "----------------------"
5534a7efc37SJim Meyering  printf %s "$buildreq"
5547fa8417cSAndreas Gruenbacher  echo "----------------------"
5557fa8417cSAndreas Gruenbacher  # can't depend on column -t
5567fa8417cSAndreas Gruenbacher}
5577fa8417cSAndreas Gruenbacher
5589ab866d5SAndreas Gruenbacher# Find sha1sum, named gsha1sum on MacPorts, shasum on Mac OS X 10.6.
5599ab866d5SAndreas Gruenbacher# Also find the compatible sha1 utility on the BSDs
5609ab866d5SAndreas Gruenbacherif test x"$SKIP_PO" = x; then
5619ab866d5SAndreas Gruenbacher  find_tool SHA1SUM sha1sum gsha1sum shasum sha1
5629ab866d5SAndreas Gruenbacherfi
5639ab866d5SAndreas Gruenbacher
5644a7efc37SJim Meyeringuse_libtool=0
5654a7efc37SJim Meyering# We'd like to use grep -E, to see if any of LT_INIT,
5664a7efc37SJim Meyering# AC_PROG_LIBTOOL, AM_PROG_LIBTOOL is used in configure.ac,
5674a7efc37SJim Meyering# but that's not portable enough (e.g., for Solaris).
5684a7efc37SJim Meyeringgrep '^[	 ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \
5694a7efc37SJim Meyering  && use_libtool=1
5704a7efc37SJim Meyeringgrep '^[	 ]*LT_INIT' configure.ac >/dev/null \
5714a7efc37SJim Meyering  && use_libtool=1
5724a7efc37SJim Meyeringif test $use_libtool = 1; then
5734a7efc37SJim Meyering  find_tool LIBTOOLIZE glibtoolize libtoolize
5744a7efc37SJim Meyeringfi
5754a7efc37SJim Meyering
576297f9e7dSJim Meyering# gnulib-tool requires at least automake and autoconf.
577297f9e7dSJim Meyering# If either is not listed, add it (with minimum version) as a prerequisite.
578297f9e7dSJim Meyeringcase $buildreq in
579297f9e7dSJim Meyering  *automake*) ;;
580297f9e7dSJim Meyering  *) buildreq="automake 1.9
581297f9e7dSJim Meyering$buildreq" ;;
582297f9e7dSJim Meyeringesac
583297f9e7dSJim Meyeringcase $buildreq in
584297f9e7dSJim Meyering  *autoconf*) ;;
585297f9e7dSJim Meyering  *) buildreq="autoconf 2.59
586297f9e7dSJim Meyering$buildreq" ;;
587297f9e7dSJim Meyeringesac
588297f9e7dSJim Meyering
589297f9e7dSJim Meyering# When we can deduce that gnulib-tool will require patch,
590297f9e7dSJim Meyering# and when patch is not already listed as a prerequisite, add it, too.
591386ae15bSAndreas Gruenbacherif test -d "$local_gl_dir" \
592386ae15bSAndreas Gruenbacher    && ! find "$local_gl_dir" -name '*.diff' -exec false {} +; then
593297f9e7dSJim Meyering  case $buildreq in
594297f9e7dSJim Meyering    *patch*) ;;
595297f9e7dSJim Meyering    *) buildreq="patch -
596297f9e7dSJim Meyering$buildreq" ;;
597297f9e7dSJim Meyering  esac
598297f9e7dSJim Meyeringfi
599297f9e7dSJim Meyering
6007fa8417cSAndreas Gruenbacherif ! printf "$buildreq" | check_versions; then
6014a7efc37SJim Meyering  echo >&2
6024a7efc37SJim Meyering  if test -f README-prereq; then
603386ae15bSAndreas Gruenbacher    die "See README-prereq for how to get the prerequisite programs"
6044a7efc37SJim Meyering  else
605386ae15bSAndreas Gruenbacher    die "Please install the prerequisite programs"
6064a7efc37SJim Meyering  fi
6077fa8417cSAndreas Gruenbacherfi
6087fa8417cSAndreas Gruenbacher
6099ab866d5SAndreas Gruenbacher# Warn the user if autom4te appears to be broken; this causes known
6109ab866d5SAndreas Gruenbacher# issues with at least gettext 0.18.3.
6119ab866d5SAndreas Gruenbacherprobe=$(echo 'm4_quote([hi])' | autom4te -l M4sugar -t 'm4_quote:$%' -)
6129ab866d5SAndreas Gruenbacherif test "x$probe" != xhi; then
6139ab866d5SAndreas Gruenbacher  warn_ "WARNING: your autom4te wrapper eats stdin;"
6149ab866d5SAndreas Gruenbacher  warn_ "if bootstrap fails, consider upgrading your autotools"
6159ab866d5SAndreas Gruenbacherfi
6169ab866d5SAndreas Gruenbacher
6177fa8417cSAndreas Gruenbacherecho "$0: Bootstrapping from checked-out $package sources..."
6187fa8417cSAndreas Gruenbacher
6197fa8417cSAndreas Gruenbacher# See if we can use gnulib's git-merge-changelog merge driver.
6209ab866d5SAndreas Gruenbacherif $use_git && test -d .git && check_exists git; then
6217fa8417cSAndreas Gruenbacher  if git config merge.merge-changelog.driver >/dev/null ; then
6227fa8417cSAndreas Gruenbacher    :
6239ab866d5SAndreas Gruenbacher  elif check_exists git-merge-changelog; then
6244a7efc37SJim Meyering    echo "$0: initializing git-merge-changelog driver"
6257fa8417cSAndreas Gruenbacher    git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
6267fa8417cSAndreas Gruenbacher    git config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
6277fa8417cSAndreas Gruenbacher  else
6284a7efc37SJim Meyering    echo "$0: consider installing git-merge-changelog from gnulib"
6297fa8417cSAndreas Gruenbacher  fi
6307fa8417cSAndreas Gruenbacherfi
6317fa8417cSAndreas Gruenbacher
6327fa8417cSAndreas Gruenbacher
6337fa8417cSAndreas Gruenbachercleanup_gnulib() {
6347fa8417cSAndreas Gruenbacher  status=$?
6357fa8417cSAndreas Gruenbacher  rm -fr "$gnulib_path"
6367fa8417cSAndreas Gruenbacher  exit $status
6377fa8417cSAndreas Gruenbacher}
6387fa8417cSAndreas Gruenbacher
6397fa8417cSAndreas Gruenbachergit_modules_config () {
6407fa8417cSAndreas Gruenbacher  test -f .gitmodules && git config --file .gitmodules "$@"
6417fa8417cSAndreas Gruenbacher}
6427fa8417cSAndreas Gruenbacher
64309939400SAndreas Gruenbacherif $use_gnulib; then
64409939400SAndreas Gruenbacher  if $use_git; then
64509939400SAndreas Gruenbacher    gnulib_path=$(git_modules_config submodule.gnulib.path)
64609939400SAndreas Gruenbacher    test -z "$gnulib_path" && gnulib_path=gnulib
64709939400SAndreas Gruenbacher  fi
6487fa8417cSAndreas Gruenbacher
64909939400SAndreas Gruenbacher  # Get gnulib files.  Populate $GNULIB_SRCDIR, possibly updating a
65009939400SAndreas Gruenbacher  # submodule, for use in the rest of the script.
6517fa8417cSAndreas Gruenbacher
65209939400SAndreas Gruenbacher  case ${GNULIB_SRCDIR--} in
65309939400SAndreas Gruenbacher  -)
65409939400SAndreas Gruenbacher    # Note that $use_git is necessarily true in this case.
65509939400SAndreas Gruenbacher    if git_modules_config submodule.gnulib.url >/dev/null; then
65609939400SAndreas Gruenbacher      echo "$0: getting gnulib files..."
65709939400SAndreas Gruenbacher      git submodule init -- "$gnulib_path" || exit $?
65809939400SAndreas Gruenbacher      git submodule update -- "$gnulib_path" || exit $?
6597fa8417cSAndreas Gruenbacher
66009939400SAndreas Gruenbacher    elif [ ! -d "$gnulib_path" ]; then
66109939400SAndreas Gruenbacher      echo "$0: getting gnulib files..."
6627fa8417cSAndreas Gruenbacher
66309939400SAndreas Gruenbacher      trap cleanup_gnulib 1 2 13 15
6647fa8417cSAndreas Gruenbacher
66509939400SAndreas Gruenbacher      shallow=
66609939400SAndreas Gruenbacher      if test -z "$GNULIB_REVISION"; then
66709939400SAndreas Gruenbacher        git clone -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
66809939400SAndreas Gruenbacher      fi
66909939400SAndreas Gruenbacher      git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \
67009939400SAndreas Gruenbacher        || cleanup_gnulib
6717fa8417cSAndreas Gruenbacher
67209939400SAndreas Gruenbacher      trap - 1 2 13 15
67309939400SAndreas Gruenbacher    fi
67409939400SAndreas Gruenbacher    GNULIB_SRCDIR=$gnulib_path
67509939400SAndreas Gruenbacher    ;;
67609939400SAndreas Gruenbacher  *)
67709939400SAndreas Gruenbacher    # Use GNULIB_SRCDIR directly or as a reference.
67809939400SAndreas Gruenbacher    if $use_git && test -d "$GNULIB_SRCDIR"/.git && \
67909939400SAndreas Gruenbacher          git_modules_config submodule.gnulib.url >/dev/null; then
68009939400SAndreas Gruenbacher      echo "$0: getting gnulib files..."
68109939400SAndreas Gruenbacher      if git submodule -h|grep -- --reference > /dev/null; then
68209939400SAndreas Gruenbacher        # Prefer the one-liner available in git 1.6.4 or newer.
68309939400SAndreas Gruenbacher        git submodule update --init --reference "$GNULIB_SRCDIR" \
68409939400SAndreas Gruenbacher          "$gnulib_path" || exit $?
6857fa8417cSAndreas Gruenbacher      else
68609939400SAndreas Gruenbacher        # This fallback allows at least git 1.5.5.
68709939400SAndreas Gruenbacher        if test -f "$gnulib_path"/gnulib-tool; then
68809939400SAndreas Gruenbacher          # Since file already exists, assume submodule init already complete.
68909939400SAndreas Gruenbacher          git submodule update -- "$gnulib_path" || exit $?
69009939400SAndreas Gruenbacher        else
69109939400SAndreas Gruenbacher          # Older git can't clone into an empty directory.
69209939400SAndreas Gruenbacher          rmdir "$gnulib_path" 2>/dev/null
69309939400SAndreas Gruenbacher          git clone --reference "$GNULIB_SRCDIR" \
69409939400SAndreas Gruenbacher            "$(git_modules_config submodule.gnulib.url)" "$gnulib_path" \
69509939400SAndreas Gruenbacher            && git submodule init -- "$gnulib_path" \
69609939400SAndreas Gruenbacher            && git submodule update -- "$gnulib_path" \
69709939400SAndreas Gruenbacher            || exit $?
69809939400SAndreas Gruenbacher        fi
6997fa8417cSAndreas Gruenbacher      fi
70009939400SAndreas Gruenbacher      GNULIB_SRCDIR=$gnulib_path
7017fa8417cSAndreas Gruenbacher    fi
70209939400SAndreas Gruenbacher    ;;
70309939400SAndreas Gruenbacher  esac
70409939400SAndreas Gruenbacher
70509939400SAndreas Gruenbacher  if test -d "$GNULIB_SRCDIR"/.git && test -n "$GNULIB_REVISION" \
70609939400SAndreas Gruenbacher     && ! git_modules_config submodule.gnulib.url >/dev/null; then
70709939400SAndreas Gruenbacher    (cd "$GNULIB_SRCDIR" && git checkout "$GNULIB_REVISION") || cleanup_gnulib
7087fa8417cSAndreas Gruenbacher  fi
7097fa8417cSAndreas Gruenbacher
71009939400SAndreas Gruenbacher  # $GNULIB_SRCDIR now points to the version of gnulib to use, and
71109939400SAndreas Gruenbacher  # we no longer need to use git or $gnulib_path below here.
71209939400SAndreas Gruenbacher
71309939400SAndreas Gruenbacher  if $bootstrap_sync; then
71409939400SAndreas Gruenbacher    cmp -s "$0" "$GNULIB_SRCDIR/build-aux/bootstrap" || {
71509939400SAndreas Gruenbacher      echo "$0: updating bootstrap and restarting..."
71609939400SAndreas Gruenbacher      case $(sh -c 'echo "$1"' -- a) in
71709939400SAndreas Gruenbacher        a) ignored=--;;
71809939400SAndreas Gruenbacher        *) ignored=ignored;;
71909939400SAndreas Gruenbacher      esac
72009939400SAndreas Gruenbacher      exec sh -c \
72109939400SAndreas Gruenbacher        'cp "$1" "$2" && shift && exec "${CONFIG_SHELL-/bin/sh}" "$@"' \
72209939400SAndreas Gruenbacher        $ignored "$GNULIB_SRCDIR/build-aux/bootstrap" \
72309939400SAndreas Gruenbacher        "$0" "$@" --no-bootstrap-sync
72409939400SAndreas Gruenbacher    }
72509939400SAndreas Gruenbacher  fi
7269ab866d5SAndreas Gruenbacher
72709939400SAndreas Gruenbacher  gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
72809939400SAndreas Gruenbacher  <$gnulib_tool || exit $?
7294a7efc37SJim Meyeringfi
7304a7efc37SJim Meyering
7317fa8417cSAndreas Gruenbacher# Get translations.
7327fa8417cSAndreas Gruenbacher
7337fa8417cSAndreas Gruenbacherdownload_po_files() {
7347fa8417cSAndreas Gruenbacher  subdir=$1
7357fa8417cSAndreas Gruenbacher  domain=$2
7364a7efc37SJim Meyering  echo "$me: getting translations into $subdir for $domain..."
73709939400SAndreas Gruenbacher  cmd=$(printf "$po_download_command_format" "$subdir" "$domain")
7387fa8417cSAndreas Gruenbacher  eval "$cmd"
7397fa8417cSAndreas Gruenbacher}
7407fa8417cSAndreas Gruenbacher
7414a7efc37SJim Meyering# Mirror .po files to $po_dir/.reference and copy only the new
7427fa8417cSAndreas Gruenbacher# or modified ones into $po_dir.  Also update $po_dir/LINGUAS.
7434a7efc37SJim Meyering# Note po files that exist locally only are left in $po_dir but will
7444a7efc37SJim Meyering# not be included in LINGUAS and hence will not be distributed.
7457fa8417cSAndreas Gruenbacherupdate_po_files() {
7467fa8417cSAndreas Gruenbacher  # Directory containing primary .po files.
7477fa8417cSAndreas Gruenbacher  # Overwrite them only when we're sure a .po file is new.
7487fa8417cSAndreas Gruenbacher  po_dir=$1
7497fa8417cSAndreas Gruenbacher  domain=$2
7507fa8417cSAndreas Gruenbacher
7514a7efc37SJim Meyering  # Mirror *.po files into this dir.
7527fa8417cSAndreas Gruenbacher  # Usually contains *.s1 checksum files.
7537fa8417cSAndreas Gruenbacher  ref_po_dir="$po_dir/.reference"
7547fa8417cSAndreas Gruenbacher
7557fa8417cSAndreas Gruenbacher  test -d $ref_po_dir || mkdir $ref_po_dir || return
7567fa8417cSAndreas Gruenbacher  download_po_files $ref_po_dir $domain \
7577fa8417cSAndreas Gruenbacher    && ls "$ref_po_dir"/*.po 2>/dev/null |
7584a7efc37SJim Meyering      sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS" || return
7597fa8417cSAndreas Gruenbacher
760386ae15bSAndreas Gruenbacher  langs=$(cd $ref_po_dir && echo *.po | sed 's/\.po//g')
7617fa8417cSAndreas Gruenbacher  test "$langs" = '*' && langs=x
7627fa8417cSAndreas Gruenbacher  for po in $langs; do
7637fa8417cSAndreas Gruenbacher    case $po in x) continue;; esac
7647fa8417cSAndreas Gruenbacher    new_po="$ref_po_dir/$po.po"
7657fa8417cSAndreas Gruenbacher    cksum_file="$ref_po_dir/$po.s1"
7667fa8417cSAndreas Gruenbacher    if ! test -f "$cksum_file" ||
7677fa8417cSAndreas Gruenbacher        ! test -f "$po_dir/$po.po" ||
7689ab866d5SAndreas Gruenbacher        ! $SHA1SUM -c "$cksum_file" < "$new_po" > /dev/null 2>&1; then
7694a7efc37SJim Meyering      echo "$me: updated $po_dir/$po.po..."
7707fa8417cSAndreas Gruenbacher      cp "$new_po" "$po_dir/$po.po" \
7719ab866d5SAndreas Gruenbacher          && $SHA1SUM < "$new_po" > "$cksum_file" || return
7727fa8417cSAndreas Gruenbacher    fi
7737fa8417cSAndreas Gruenbacher  done
7747fa8417cSAndreas Gruenbacher}
7757fa8417cSAndreas Gruenbacher
7767fa8417cSAndreas Gruenbachercase $SKIP_PO in
7777fa8417cSAndreas Gruenbacher'')
7787fa8417cSAndreas Gruenbacher  if test -d po; then
7797fa8417cSAndreas Gruenbacher    update_po_files po $package || exit
7807fa8417cSAndreas Gruenbacher  fi
7817fa8417cSAndreas Gruenbacher
7827fa8417cSAndreas Gruenbacher  if test -d runtime-po; then
7837fa8417cSAndreas Gruenbacher    update_po_files runtime-po $package-runtime || exit
7847fa8417cSAndreas Gruenbacher  fi;;
7857fa8417cSAndreas Gruenbacheresac
7867fa8417cSAndreas Gruenbacher
7877fa8417cSAndreas Gruenbachersymlink_to_dir()
7887fa8417cSAndreas Gruenbacher{
7897fa8417cSAndreas Gruenbacher  src=$1/$2
7907fa8417cSAndreas Gruenbacher  dst=${3-$2}
7917fa8417cSAndreas Gruenbacher
7927fa8417cSAndreas Gruenbacher  test -f "$src" && {
7937fa8417cSAndreas Gruenbacher
7947fa8417cSAndreas Gruenbacher    # If the destination directory doesn't exist, create it.
7957fa8417cSAndreas Gruenbacher    # This is required at least for "lib/uniwidth/cjk.h".
796386ae15bSAndreas Gruenbacher    dst_dir=$(dirname "$dst")
7977fa8417cSAndreas Gruenbacher    if ! test -d "$dst_dir"; then
7987fa8417cSAndreas Gruenbacher      mkdir -p "$dst_dir"
7997fa8417cSAndreas Gruenbacher
8007fa8417cSAndreas Gruenbacher      # If we've just created a directory like lib/uniwidth,
8017fa8417cSAndreas Gruenbacher      # tell version control system(s) it's ignorable.
8027fa8417cSAndreas Gruenbacher      # FIXME: for now, this does only one level
803386ae15bSAndreas Gruenbacher      parent=$(dirname "$dst_dir")
8047fa8417cSAndreas Gruenbacher      for dot_ig in x $vc_ignore; do
8057fa8417cSAndreas Gruenbacher        test $dot_ig = x && continue
8067fa8417cSAndreas Gruenbacher        ig=$parent/$dot_ig
807386ae15bSAndreas Gruenbacher        insert_vc_ignore $ig "${dst_dir##*/}"
8087fa8417cSAndreas Gruenbacher      done
8097fa8417cSAndreas Gruenbacher    fi
8107fa8417cSAndreas Gruenbacher
8117fa8417cSAndreas Gruenbacher    if $copy; then
8127fa8417cSAndreas Gruenbacher      {
8137fa8417cSAndreas Gruenbacher        test ! -h "$dst" || {
8144a7efc37SJim Meyering          echo "$me: rm -f $dst" &&
8157fa8417cSAndreas Gruenbacher          rm -f "$dst"
8167fa8417cSAndreas Gruenbacher        }
8177fa8417cSAndreas Gruenbacher      } &&
8187fa8417cSAndreas Gruenbacher      test -f "$dst" &&
8197fa8417cSAndreas Gruenbacher      cmp -s "$src" "$dst" || {
8204a7efc37SJim Meyering        echo "$me: cp -fp $src $dst" &&
8217fa8417cSAndreas Gruenbacher        cp -fp "$src" "$dst"
8227fa8417cSAndreas Gruenbacher      }
8237fa8417cSAndreas Gruenbacher    else
824297f9e7dSJim Meyering      # Leave any existing symlink alone, if it already points to the source,
825297f9e7dSJim Meyering      # so that broken build tools that care about symlink times
826297f9e7dSJim Meyering      # aren't confused into doing unnecessary builds.  Conversely, if the
8279ab866d5SAndreas Gruenbacher      # existing symlink's timestamp is older than the source, make it afresh,
828297f9e7dSJim Meyering      # so that broken tools aren't confused into skipping needed builds.  See
8299ab866d5SAndreas Gruenbacher      # <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00326.html>.
8307fa8417cSAndreas Gruenbacher      test -h "$dst" &&
831386ae15bSAndreas Gruenbacher      src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 &&
832386ae15bSAndreas Gruenbacher      dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 &&
833297f9e7dSJim Meyering      test "$src_i" = "$dst_i" &&
834386ae15bSAndreas Gruenbacher      both_ls=$(ls -dt "$src" "$dst") &&
835297f9e7dSJim Meyering      test "X$both_ls" = "X$dst$nl$src" || {
8367fa8417cSAndreas Gruenbacher        dot_dots=
8377fa8417cSAndreas Gruenbacher        case $src in
8387fa8417cSAndreas Gruenbacher        /*) ;;
8397fa8417cSAndreas Gruenbacher        *)
8407fa8417cSAndreas Gruenbacher          case /$dst/ in
8417fa8417cSAndreas Gruenbacher          *//* | */../* | */./* | /*/*/*/*/*/)
842386ae15bSAndreas Gruenbacher             die "invalid symlink calculation: $src -> $dst";;
843386ae15bSAndreas Gruenbacher          /*/*/*/*/)    dot_dots=../../../;;
844386ae15bSAndreas Gruenbacher          /*/*/*/)      dot_dots=../../;;
845386ae15bSAndreas Gruenbacher          /*/*/)        dot_dots=../;;
8467fa8417cSAndreas Gruenbacher          esac;;
8477fa8417cSAndreas Gruenbacher        esac
8487fa8417cSAndreas Gruenbacher
8494a7efc37SJim Meyering        echo "$me: ln -fs $dot_dots$src $dst" &&
8507fa8417cSAndreas Gruenbacher        ln -fs "$dot_dots$src" "$dst"
8517fa8417cSAndreas Gruenbacher      }
8527fa8417cSAndreas Gruenbacher    fi
8537fa8417cSAndreas Gruenbacher  }
8547fa8417cSAndreas Gruenbacher}
8557fa8417cSAndreas Gruenbacher
856386ae15bSAndreas Gruenbacherversion_controlled_file() {
857386ae15bSAndreas Gruenbacher  parent=$1
858386ae15bSAndreas Gruenbacher  file=$2
859386ae15bSAndreas Gruenbacher  if test -d .git; then
860386ae15bSAndreas Gruenbacher    git rm -n "$file" > /dev/null 2>&1
861386ae15bSAndreas Gruenbacher  elif test -d .svn; then
862386ae15bSAndreas Gruenbacher    svn log -r HEAD "$file" > /dev/null 2>&1
863386ae15bSAndreas Gruenbacher  elif test -d CVS; then
864386ae15bSAndreas Gruenbacher    grep -F "/${file##*/}/" "$parent/CVS/Entries" 2>/dev/null |
865386ae15bSAndreas Gruenbacher             grep '^/[^/]*/[0-9]' > /dev/null
866386ae15bSAndreas Gruenbacher  else
867386ae15bSAndreas Gruenbacher    warn_ "no version control for $file?"
868386ae15bSAndreas Gruenbacher    false
869386ae15bSAndreas Gruenbacher  fi
870386ae15bSAndreas Gruenbacher}
871386ae15bSAndreas Gruenbacher
872297f9e7dSJim Meyering# NOTE: we have to be careful to run both autopoint and libtoolize
873297f9e7dSJim Meyering# before gnulib-tool, since gnulib-tool is likely to provide newer
874297f9e7dSJim Meyering# versions of files "installed" by these two programs.
875297f9e7dSJim Meyering# Then, *after* gnulib-tool (see below), we have to be careful to
876297f9e7dSJim Meyering# run autoreconf in such a way that it does not run either of these
877297f9e7dSJim Meyering# two just-pre-run programs.
8787fa8417cSAndreas Gruenbacher
879297f9e7dSJim Meyering# Import from gettext.
880297f9e7dSJim Meyeringwith_gettext=yes
881297f9e7dSJim Meyeringgrep '^[	 ]*AM_GNU_GETTEXT_VERSION(' configure.ac >/dev/null || \
882297f9e7dSJim Meyering    with_gettext=no
8837fa8417cSAndreas Gruenbacher
884386ae15bSAndreas Gruenbacherif test $with_gettext = yes || test $use_libtool = 1; then
885297f9e7dSJim Meyering
886386ae15bSAndreas Gruenbacher  tempbase=.bootstrap$$
887386ae15bSAndreas Gruenbacher  trap "rm -f $tempbase.0 $tempbase.1" 1 2 13 15
8887fa8417cSAndreas Gruenbacher
889386ae15bSAndreas Gruenbacher  > $tempbase.0 > $tempbase.1 &&
890386ae15bSAndreas Gruenbacher  find . ! -type d -print | sort > $tempbase.0 || exit
891386ae15bSAndreas Gruenbacher
892386ae15bSAndreas Gruenbacher  if test $with_gettext = yes; then
893386ae15bSAndreas Gruenbacher    # Released autopoint has the tendency to install macros that have been
894386ae15bSAndreas Gruenbacher    # obsoleted in current gnulib, so run this before gnulib-tool.
895386ae15bSAndreas Gruenbacher    echo "$0: $AUTOPOINT --force"
896386ae15bSAndreas Gruenbacher    $AUTOPOINT --force || exit
8977fa8417cSAndreas Gruenbacher  fi
898386ae15bSAndreas Gruenbacher
899386ae15bSAndreas Gruenbacher  # Autoreconf runs aclocal before libtoolize, which causes spurious
900386ae15bSAndreas Gruenbacher  # warnings if the initial aclocal is confused by the libtoolized
901386ae15bSAndreas Gruenbacher  # (or worse out-of-date) macro directory.
902386ae15bSAndreas Gruenbacher  # libtoolize 1.9b added the --install option; but we support back
903386ae15bSAndreas Gruenbacher  # to libtoolize 1.5.22, where the install action was default.
904386ae15bSAndreas Gruenbacher  if test $use_libtool = 1; then
905386ae15bSAndreas Gruenbacher    install=
906386ae15bSAndreas Gruenbacher    case $($LIBTOOLIZE --help) in
907386ae15bSAndreas Gruenbacher      *--install*) install=--install ;;
908386ae15bSAndreas Gruenbacher    esac
909386ae15bSAndreas Gruenbacher    echo "running: $LIBTOOLIZE $install --copy"
910386ae15bSAndreas Gruenbacher    $LIBTOOLIZE $install --copy
911386ae15bSAndreas Gruenbacher  fi
912386ae15bSAndreas Gruenbacher
913386ae15bSAndreas Gruenbacher  find . ! -type d -print | sort >$tempbase.1
914386ae15bSAndreas Gruenbacher  old_IFS=$IFS
915386ae15bSAndreas Gruenbacher  IFS=$nl
916386ae15bSAndreas Gruenbacher  for file in $(comm -13 $tempbase.0 $tempbase.1); do
917386ae15bSAndreas Gruenbacher    IFS=$old_IFS
918386ae15bSAndreas Gruenbacher    parent=${file%/*}
919386ae15bSAndreas Gruenbacher    version_controlled_file "$parent" "$file" || {
920386ae15bSAndreas Gruenbacher      for dot_ig in x $vc_ignore; do
921386ae15bSAndreas Gruenbacher        test $dot_ig = x && continue
922386ae15bSAndreas Gruenbacher        ig=$parent/$dot_ig
923386ae15bSAndreas Gruenbacher        insert_vc_ignore "$ig" "${file##*/}"
924386ae15bSAndreas Gruenbacher      done
925386ae15bSAndreas Gruenbacher    }
926386ae15bSAndreas Gruenbacher  done
927386ae15bSAndreas Gruenbacher  IFS=$old_IFS
928386ae15bSAndreas Gruenbacher
929386ae15bSAndreas Gruenbacher  rm -f $tempbase.0 $tempbase.1
930386ae15bSAndreas Gruenbacher  trap - 1 2 13 15
931386ae15bSAndreas Gruenbacherfi
9327fa8417cSAndreas Gruenbacher
9337fa8417cSAndreas Gruenbacher# Import from gnulib.
9347fa8417cSAndreas Gruenbacher
93509939400SAndreas Gruenbacherif $use_gnulib; then
93609939400SAndreas Gruenbacher  gnulib_tool_options="\
93709939400SAndreas Gruenbacher   --no-changelog\
93809939400SAndreas Gruenbacher   --aux-dir=$build_aux\
93909939400SAndreas Gruenbacher   --doc-base=$doc_base\
94009939400SAndreas Gruenbacher   --lib=$gnulib_name\
94109939400SAndreas Gruenbacher   --m4-base=$m4_base/\
94209939400SAndreas Gruenbacher   --source-base=$source_base/\
94309939400SAndreas Gruenbacher   --tests-base=$tests_base\
94409939400SAndreas Gruenbacher   --local-dir=$local_gl_dir\
94509939400SAndreas Gruenbacher   $gnulib_tool_option_extras\
94609939400SAndreas Gruenbacher  "
94709939400SAndreas Gruenbacher  if test $use_libtool = 1; then
94809939400SAndreas Gruenbacher    case "$gnulib_tool_options " in
94909939400SAndreas Gruenbacher      *' --libtool '*) ;;
95009939400SAndreas Gruenbacher      *) gnulib_tool_options="$gnulib_tool_options --libtool" ;;
95109939400SAndreas Gruenbacher    esac
95209939400SAndreas Gruenbacher  fi
95309939400SAndreas Gruenbacher  echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
95409939400SAndreas Gruenbacher  $gnulib_tool $gnulib_tool_options --import $gnulib_modules \
95509939400SAndreas Gruenbacher    || die "gnulib-tool failed"
9567fa8417cSAndreas Gruenbacher
95709939400SAndreas Gruenbacher  for file in $gnulib_files; do
95809939400SAndreas Gruenbacher    symlink_to_dir "$GNULIB_SRCDIR" $file \
95909939400SAndreas Gruenbacher      || die "failed to symlink $file"
96009939400SAndreas Gruenbacher  done
96109939400SAndreas Gruenbacherfi
9627fa8417cSAndreas Gruenbacher
963297f9e7dSJim Meyeringbootstrap_post_import_hook \
964386ae15bSAndreas Gruenbacher  || die "bootstrap_post_import_hook failed"
9657fa8417cSAndreas Gruenbacher
96609939400SAndreas Gruenbacher# Don't proceed if there are uninitialized submodules.  In particular,
96709939400SAndreas Gruenbacher# the next step will remove dangling links, which might be links into
96809939400SAndreas Gruenbacher# uninitialized submodules.
96909939400SAndreas Gruenbacher#
97009939400SAndreas Gruenbacher# Uninitialized submodules are listed with an initial dash.
97109939400SAndreas Gruenbacherif $use_git && git submodule | grep '^-' >/dev/null; then
97209939400SAndreas Gruenbacher  die "some git submodules are not initialized. "     \
97309939400SAndreas Gruenbacher      "Run 'git submodule update --init' and bootstrap again."
97409939400SAndreas Gruenbacherfi
97509939400SAndreas Gruenbacher
9767fa8417cSAndreas Gruenbacher# Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
9777fa8417cSAndreas Gruenbacher# gnulib-populated directories.  Such .m4 files would cause aclocal to fail.
9787fa8417cSAndreas Gruenbacher# The following requires GNU find 4.2.3 or newer.  Considering the usual
9797fa8417cSAndreas Gruenbacher# portability constraints of this script, that may seem a very demanding
9807fa8417cSAndreas Gruenbacher# requirement, but it should be ok.  Ignore any failure, which is fine,
9817fa8417cSAndreas Gruenbacher# since this is only a convenience to help developers avoid the relatively
9827fa8417cSAndreas Gruenbacher# unusual case in which a symlinked-to .m4 file is git-removed from gnulib
9837fa8417cSAndreas Gruenbacher# between successive runs of this script.
9847fa8417cSAndreas Gruenbacherfind "$m4_base" "$source_base" \
9857fa8417cSAndreas Gruenbacher  -depth \( -name '*.m4' -o -name '*.[ch]' \) \
9867fa8417cSAndreas Gruenbacher  -type l -xtype l -delete > /dev/null 2>&1
9877fa8417cSAndreas Gruenbacher
9889ab866d5SAndreas Gruenbacher# Invoke autoreconf with --force --install to ensure upgrades of tools
9899ab866d5SAndreas Gruenbacher# such as ylwrap.
9909ab866d5SAndreas GruenbacherAUTORECONFFLAGS="--verbose --install --force -I $m4_base $ACLOCAL_FLAGS"
9919ab866d5SAndreas Gruenbacher
992297f9e7dSJim Meyering# Some systems (RHEL 5) are using ancient autotools, for which the
993297f9e7dSJim Meyering# --no-recursive option had not been invented.  Detect that lack and
994297f9e7dSJim Meyering# omit the option when it's not supported.  FIXME in 2017: remove this
995297f9e7dSJim Meyering# hack when RHEL 5 autotools are updated, or when they become irrelevant.
996297f9e7dSJim Meyeringcase $($AUTORECONF --help) in
9979ab866d5SAndreas Gruenbacher  *--no-recursive*) AUTORECONFFLAGS="$AUTORECONFFLAGS --no-recursive";;
998297f9e7dSJim Meyeringesac
9997fa8417cSAndreas Gruenbacher
1000297f9e7dSJim Meyering# Tell autoreconf not to invoke autopoint or libtoolize; they were run above.
10019ab866d5SAndreas Gruenbacherecho "running: AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS"
1003386ae15bSAndreas Gruenbacher  || die "autoreconf failed"
10047fa8417cSAndreas Gruenbacher
10057fa8417cSAndreas Gruenbacher# Get some extra files from gnulib, overriding existing files.
10067fa8417cSAndreas Gruenbacherfor file in $gnulib_extra_files; do
10077fa8417cSAndreas Gruenbacher  case $file in
10087fa8417cSAndreas Gruenbacher  */INSTALL) dst=INSTALL;;
1009386ae15bSAndreas Gruenbacher  build-aux/*) dst=$build_aux/${file#build-aux/};;
10107fa8417cSAndreas Gruenbacher  *) dst=$file;;
10117fa8417cSAndreas Gruenbacher  esac
1012386ae15bSAndreas Gruenbacher  symlink_to_dir "$GNULIB_SRCDIR" $file $dst \
1013386ae15bSAndreas Gruenbacher    || die "failed to symlink $file"
10147fa8417cSAndreas Gruenbacherdone
10157fa8417cSAndreas Gruenbacher
10167fa8417cSAndreas Gruenbacherif test $with_gettext = yes; then
10177fa8417cSAndreas Gruenbacher  # Create gettext configuration.
10187fa8417cSAndreas Gruenbacher  echo "$0: Creating po/Makevars from po/Makevars.template ..."
10197fa8417cSAndreas Gruenbacher  rm -f po/Makevars
10207fa8417cSAndreas Gruenbacher  sed '
10217fa8417cSAndreas Gruenbacher    /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/
10227fa8417cSAndreas Gruenbacher    /^COPYRIGHT_HOLDER *=/s/=.*/= '"$COPYRIGHT_HOLDER"'/
10237fa8417cSAndreas Gruenbacher    /^MSGID_BUGS_ADDRESS *=/s|=.*|= '"$MSGID_BUGS_ADDRESS"'|
10247fa8417cSAndreas Gruenbacher    /^XGETTEXT_OPTIONS *=/{
10257fa8417cSAndreas Gruenbacher      s/$/ \\/
10267fa8417cSAndreas Gruenbacher      a\
10277fa8417cSAndreas Gruenbacher          '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
10287fa8417cSAndreas Gruenbacher    }
1029386ae15bSAndreas Gruenbacher  ' po/Makevars.template >po/Makevars \
1030386ae15bSAndreas Gruenbacher    || die 'cannot generate po/Makevars'
1031386ae15bSAndreas Gruenbacher
1032386ae15bSAndreas Gruenbacher  # If the 'gettext' module is in use, grab the latest Makefile.in.in.
1033386ae15bSAndreas Gruenbacher  # If only the 'gettext-h' module is in use, assume autopoint already
1034386ae15bSAndreas Gruenbacher  # put the correct version of this file into place.
1035386ae15bSAndreas Gruenbacher  case $gnulib_modules in
1036386ae15bSAndreas Gruenbacher  *gettext-h*) ;;
1037386ae15bSAndreas Gruenbacher  *gettext*)
1038386ae15bSAndreas Gruenbacher    cp $GNULIB_SRCDIR/build-aux/po/Makefile.in.in po/Makefile.in.in \
1039386ae15bSAndreas Gruenbacher      || die "cannot create po/Makefile.in.in"
1040386ae15bSAndreas Gruenbacher    ;;
1041386ae15bSAndreas Gruenbacher  esac
10427fa8417cSAndreas Gruenbacher
10437fa8417cSAndreas Gruenbacher  if test -d runtime-po; then
10447fa8417cSAndreas Gruenbacher    # Similarly for runtime-po/Makevars, but not quite the same.
10457fa8417cSAndreas Gruenbacher    rm -f runtime-po/Makevars
10467fa8417cSAndreas Gruenbacher    sed '
10477fa8417cSAndreas Gruenbacher      /^DOMAIN *=.*/s/=.*/= '"$package"'-runtime/
10487fa8417cSAndreas Gruenbacher      /^subdir *=.*/s/=.*/= runtime-po/
10497fa8417cSAndreas Gruenbacher      /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
10507fa8417cSAndreas Gruenbacher      /^XGETTEXT_OPTIONS *=/{
10517fa8417cSAndreas Gruenbacher        s/$/ \\/
10527fa8417cSAndreas Gruenbacher        a\
10537fa8417cSAndreas Gruenbacher            '"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+}
10547fa8417cSAndreas Gruenbacher      }
1055386ae15bSAndreas Gruenbacher    ' po/Makevars.template >runtime-po/Makevars \
1056386ae15bSAndreas Gruenbacher    || die 'cannot generate runtime-po/Makevars'
10577fa8417cSAndreas Gruenbacher
10587fa8417cSAndreas Gruenbacher    # Copy identical files from po to runtime-po.
10597fa8417cSAndreas Gruenbacher    (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
10607fa8417cSAndreas Gruenbacher  fi
10617fa8417cSAndreas Gruenbacherfi
10627fa8417cSAndreas Gruenbacher
10637fa8417cSAndreas Gruenbacherbootstrap_epilogue
10647fa8417cSAndreas Gruenbacher
10657fa8417cSAndreas Gruenbacherecho "$0: done.  Now you can run './configure'."
10667fa8417cSAndreas Gruenbacher
10677fa8417cSAndreas Gruenbacher# Local variables:
106809939400SAndreas Gruenbacher# eval: (add-hook 'before-save-hook 'time-stamp)
10697fa8417cSAndreas Gruenbacher# time-stamp-start: "scriptversion="
10707fa8417cSAndreas Gruenbacher# time-stamp-format: "%:y-%02m-%02d.%02H"
10719ab866d5SAndreas Gruenbacher# time-stamp-time-zone: "UTC0"
10727fa8417cSAndreas Gruenbacher# time-stamp-end: "; # UTC"
10737fa8417cSAndreas Gruenbacher# End: