e153146
#! /bin/sh
e153146
# Print a version string.
e153146
scriptversion=2019-01-04.17; # UTC
e153146
e153146
# Bootstrap this package from checked-out sources.
e153146
e153146
# Copyright (C) 2003-2019 Free Software Foundation, Inc.
e153146
e153146
# This program is free software: you can redistribute it and/or modify
e153146
# it under the terms of the GNU General Public License as published by
e153146
# the Free Software Foundation, either version 3 of the License, or
e153146
# (at your option) any later version.
e153146
e153146
# This program is distributed in the hope that it will be useful,
e153146
# but WITHOUT ANY WARRANTY; without even the implied warranty of
e153146
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e153146
# GNU General Public License for more details.
e153146
e153146
# You should have received a copy of the GNU General Public License
e153146
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
e153146
e153146
# Originally written by Paul Eggert.  The canonical version of this
e153146
# script is maintained as build-aux/bootstrap in gnulib, however, to
e153146
# be useful to your project, you should place a copy of it under
e153146
# version control in the top-level directory of your project.  The
e153146
# intent is that all customization can be done with a bootstrap.conf
e153146
# file also maintained in your version control; gnulib comes with a
e153146
# template build-aux/bootstrap.conf to get you started.
e153146
e153146
# Please report bugs or propose patches to bug-gnulib@gnu.org.
e153146
e153146
nl='
e153146
'
e153146
e153146
# Ensure file names are sorted consistently across platforms.
e153146
LC_ALL=C
e153146
export LC_ALL
e153146
e153146
# Ensure that CDPATH is not set.  Otherwise, the output from cd
e153146
# would cause trouble in at least one use below.
e153146
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
e153146
e153146
local_gl_dir=gl
e153146
e153146
# Honor $PERL, but work even if there is none.
e153146
PERL="${PERL-perl}"
e153146
e153146
me=$0
e153146
e153146
default_gnulib_url=git://git.sv.gnu.org/gnulib
e153146
e153146
usage() {
e153146
  cat <
e153146
Usage: $me [OPTION]...
e153146
Bootstrap this package from the checked-out sources.
e153146
e153146
Options:
e153146
 --gnulib-srcdir=DIRNAME  specify the local directory where gnulib
e153146
                          sources reside.  Use this if you already
e153146
                          have gnulib sources on your machine, and
e153146
                          do not want to waste your bandwidth downloading
e153146
                          them again.  Defaults to \$GNULIB_SRCDIR
e153146
 --bootstrap-sync         if this bootstrap script is not identical to
e153146
                          the version in the local gnulib sources,
e153146
                          update this script, and then restart it with
e153146
                          /bin/sh or the shell \$CONFIG_SHELL
e153146
 --no-bootstrap-sync      do not check whether bootstrap is out of sync
e153146
 --copy                   copy files instead of creating symbolic links
e153146
 --force                  attempt to bootstrap even if the sources seem
e153146
                          not to have been checked out
e153146
 --no-git                 do not use git to update gnulib.  Requires that
e153146
                          --gnulib-srcdir point to a correct gnulib snapshot
e153146
 --skip-po                do not download po files
e153146
e153146
If the file $me.conf exists in the same directory as this script, its
e153146
contents are read as shell variables to configure the bootstrap.
e153146
e153146
For build prerequisites, environment variables like \$AUTOCONF and \$AMTAR
e153146
are honored.
e153146
e153146
Gnulib sources can be fetched in various ways:
e153146
e153146
 * If this package is in a git repository with a 'gnulib' submodule
e153146
   configured, then that submodule is initialized and updated and sources
e153146
   are fetched from there.  If \$GNULIB_SRCDIR is set (directly or via
e153146
   --gnulib-srcdir) and is a git repository, then it is used as a reference.
e153146
e153146
 * Otherwise, if \$GNULIB_SRCDIR is set (directly or via --gnulib-srcdir),
e153146
   then sources are fetched from that local directory.  If it is a git
e153146
   repository and \$GNULIB_REVISION is set, then that revision is checked
e153146
   out.
e153146
e153146
 * Otherwise, if this package is in a git repository with a 'gnulib'
e153146
   submodule configured, then that submodule is initialized and updated and
e153146
   sources are fetched from there.
e153146
e153146
 * Otherwise, if the 'gnulib' directory does not exist, Gnulib sources are
e153146
   cloned into that directory using git from \$GNULIB_URL, defaulting to
e153146
   $default_gnulib_url.
e153146
   If \$GNULIB_REVISION is set, then that revision is checked out.
e153146
e153146
 * Otherwise, the existing Gnulib sources in the 'gnulib' directory are
e153146
   used.  If it is a git repository and \$GNULIB_REVISION is set, then that
e153146
   revision is checked out.
e153146
e153146
If you maintain a package and want to pin a particular revision of the
e153146
Gnulib sources that has been tested with your package, then there are two
e153146
possible approaches: either configure a 'gnulib' submodule with the
e153146
appropriate revision, or set \$GNULIB_REVISION (and if necessary
e153146
\$GNULIB_URL) in $me.conf.
e153146
e153146
Running without arguments will suffice in most cases.
e153146
EOF
e153146
}
e153146
e153146
# warnf_ FORMAT-STRING ARG1...
e153146
warnf_ ()
e153146
{
e153146
  warnf_format_=$1
e153146
  shift
e153146
  nl='
e153146
'
e153146
  case $* in
e153146
    *$nl*) me_=$(printf "$me"|tr "$nl|" '??')
e153146
       printf "$warnf_format_" "$@" | sed "s|^|$me_: |" ;;
e153146
    *) printf "$me: $warnf_format_" "$@" ;;
e153146
  esac >&2
e153146
}
e153146
e153146
# warn_ WORD1...
e153146
warn_ ()
e153146
{
e153146
  # If IFS does not start with ' ', set it and emit the warning in a subshell.
e153146
  case $IFS in
e153146
    ' '*) warnf_ '%s\n' "$*";;
e153146
    *)    (IFS=' '; warn_ "$@");;
e153146
  esac
e153146
}
e153146
e153146
# die WORD1...
e153146
die() { warn_ "$@"; exit 1; }
e153146
e153146
# Configuration.
e153146
e153146
# Name of the Makefile.am
e153146
gnulib_mk=gnulib.mk
e153146
e153146
# List of gnulib modules needed.
e153146
gnulib_modules=
e153146
e153146
# Any gnulib files needed that are not in modules.
e153146
gnulib_files=
e153146
e153146
: ${AUTOPOINT=autopoint}
e153146
: ${AUTORECONF=autoreconf}
e153146
e153146
# A function to be called right after gnulib-tool is run.
e153146
# Override it via your own definition in bootstrap.conf.
e153146
bootstrap_post_import_hook() { :; }
e153146
e153146
# A function to be called after everything else in this script.
e153146
# Override it via your own definition in bootstrap.conf.
e153146
bootstrap_epilogue() { :; }
e153146
e153146
# The command to download all .po files for a specified domain into a
e153146
# specified directory.  Fill in the first %s with the destination
e153146
# directory and the second with the domain name.
e153146
po_download_command_format=\
e153146
"wget --mirror --level=1 -nd -q -A.po -P '%s' \
e153146
 https://translationproject.org/latest/%s/"
e153146
e153146
# Prefer a non-empty tarname (4th argument of AC_INIT if given), else
e153146
# fall back to the package name (1st argument with munging)
e153146
extract_package_name='
e153146
  /^AC_INIT(\[*/{
e153146
     s///
e153146
     /^[^,]*,[^,]*,[^,]*,[ []*\([^][ ,)]\)/{
e153146
       s//\1/
e153146
       s/[],)].*//
e153146
       p
e153146
       q
e153146
     }
e153146
     s/[],)].*//
e153146
     s/^GNU //
e153146
     y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
e153146
     s/[^abcdefghijklmnopqrstuvwxyz0123456789_]/-/g
e153146
     p
e153146
  }
e153146
'
e153146
package=$(sed -n "$extract_package_name" configure.ac) \
e153146
  || die 'cannot find package name in configure.ac'
e153146
gnulib_name=lib$package
e153146
e153146
build_aux=build-aux
e153146
source_base=lib
e153146
m4_base=m4
e153146
doc_base=doc
e153146
tests_base=tests
e153146
gnulib_extra_files="
e153146
        build-aux/install-sh
e153146
        build-aux/mdate-sh
e153146
        build-aux/texinfo.tex
e153146
        build-aux/depcomp
e153146
        build-aux/config.guess
e153146
        build-aux/config.sub
e153146
        doc/INSTALL
e153146
"
e153146
e153146
# Additional gnulib-tool options to use.  Use "\newline" to break lines.
e153146
gnulib_tool_option_extras=
e153146
e153146
# Other locale categories that need message catalogs.
e153146
EXTRA_LOCALE_CATEGORIES=
e153146
e153146
# Additional xgettext options to use.  Use "\\\newline" to break lines.
e153146
XGETTEXT_OPTIONS='\\\
e153146
 --flag=_:1:pass-c-format\\\
e153146
 --flag=N_:1:pass-c-format\\\
e153146
 --flag=error:3:c-format --flag=error_at_line:5:c-format\\\
e153146
'
e153146
e153146
# Package bug report address and copyright holder for gettext files
e153146
COPYRIGHT_HOLDER='Free Software Foundation, Inc.'
e153146
MSGID_BUGS_ADDRESS=bug-$package@gnu.org
e153146
e153146
# Files we don't want to import.
e153146
excluded_files=
e153146
e153146
# File that should exist in the top directory of a checked out hierarchy,
e153146
# but not in a distribution tarball.
e153146
checkout_only_file=README-hacking
e153146
e153146
# Whether to use copies instead of symlinks.
e153146
copy=false
e153146
e153146
# Set this to '.cvsignore .gitignore' in bootstrap.conf if you want
e153146
# those files to be generated in directories like lib/, m4/, and po/.
e153146
# Or set it to 'auto' to make this script select which to use based
e153146
# on which version control system (if any) is used in the source directory.
e153146
vc_ignore=auto
e153146
e153146
# Set this to true in bootstrap.conf to enable --bootstrap-sync by
e153146
# default.
e153146
bootstrap_sync=false
e153146
e153146
# Use git to update gnulib sources
e153146
use_git=true
e153146
e153146
check_exists() {
e153146
  if test "$1" = "--verbose"; then
e153146
    ($2 --version </dev/null) >/dev/null 2>&1
e153146
    if test $? -ge 126; then
e153146
      # If not found, run with diagnostics as one may be
e153146
      # presented with env variables to set to find the right version
e153146
      ($2 --version 
e153146
    fi
e153146
  else
e153146
    ($1 --version </dev/null) >/dev/null 2>&1
e153146
  fi
e153146
e153146
  test $? -lt 126
e153146
}
e153146
e153146
# find_tool ENVVAR NAMES...
e153146
# -------------------------
e153146
# Search for a required program.  Use the value of ENVVAR, if set,
e153146
# otherwise find the first of the NAMES that can be run.
e153146
# If found, set ENVVAR to the program name, die otherwise.
e153146
#
e153146
# FIXME: code duplication, see also gnu-web-doc-update.
e153146
find_tool ()
e153146
{
e153146
  find_tool_envvar=$1
e153146
  shift
e153146
  find_tool_names=$@
e153146
  eval "find_tool_res=\$$find_tool_envvar"
e153146
  if test x"$find_tool_res" = x; then
e153146
    for i; do
e153146
      if check_exists $i; then
e153146
        find_tool_res=$i
e153146
        break
e153146
      fi
e153146
    done
e153146
  fi
e153146
  if test x"$find_tool_res" = x; then
e153146
    warn_ "one of these is required: $find_tool_names;"
e153146
    die   "alternatively set $find_tool_envvar to a compatible tool"
e153146
  fi
e153146
  eval "$find_tool_envvar=\$find_tool_res"
e153146
  eval "export $find_tool_envvar"
e153146
}
e153146
e153146
# Override the default configuration, if necessary.
e153146
# Make sure that bootstrap.conf is sourced from the current directory
e153146
# if we were invoked as "sh bootstrap".
e153146
case "$0" in
e153146
  */*) test -r "$0.conf" && . "$0.conf" ;;
e153146
  *) test -r "$0.conf" && . ./"$0.conf" ;;
e153146
esac
e153146
e153146
if test "$vc_ignore" = auto; then
e153146
  vc_ignore=
e153146
  test -d .git && vc_ignore=.gitignore
e153146
  test -d CVS && vc_ignore="$vc_ignore .cvsignore"
e153146
fi
e153146
e153146
if test x"$gnulib_modules$gnulib_files$gnulib_extra_files" = x; then
e153146
  use_gnulib=false
e153146
else
e153146
  use_gnulib=true
e153146
fi
e153146
e153146
# Translate configuration into internal form.
e153146
e153146
# Parse options.
e153146
e153146
for option
e153146
do
e153146
  case $option in
e153146
  --help)
e153146
    usage
e153146
    exit;;
e153146
  --gnulib-srcdir=*)
e153146
    GNULIB_SRCDIR=${option#--gnulib-srcdir=};;
e153146
  --skip-po)
e153146
    SKIP_PO=t;;
e153146
  --force)
e153146
    checkout_only_file=;;
e153146
  --copy)
e153146
    copy=true;;
e153146
  --bootstrap-sync)
e153146
    bootstrap_sync=true;;
e153146
  --no-bootstrap-sync)
e153146
    bootstrap_sync=false;;
e153146
  --no-git)
e153146
    use_git=false;;
e153146
  *)
e153146
    die "$option: unknown option";;
e153146
  esac
e153146
done
e153146
e153146
$use_git || test -d "$GNULIB_SRCDIR" \
e153146
  || die "Error: --no-git requires --gnulib-srcdir"
e153146
e153146
if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then
e153146
  die "Bootstrapping from a non-checked-out distribution is risky."
e153146
fi
e153146
e153146
# Strip blank and comment lines to leave significant entries.
e153146
gitignore_entries() {
e153146
  sed '/^#/d; /^$/d' "$@"
e153146
}
e153146
e153146
# If $STR is not already on a line by itself in $FILE, insert it at the start.
e153146
# Entries are inserted at the start of the ignore list to ensure existing
e153146
# entries starting with ! are not overridden.  Such entries support
e153146
# whitelisting exceptions after a more generic blacklist pattern.
e153146
insert_if_absent() {
e153146
  file=$1
e153146
  str=$2
e153146
  test -f $file || touch $file
e153146
  test -r $file || die "Error: failed to read ignore file: $file"
e153146
  duplicate_entries=$(gitignore_entries $file | sort | uniq -d)
e153146
  if [ "$duplicate_entries" ] ; then
e153146
    die "Error: Duplicate entries in $file: " $duplicate_entries
e153146
  fi
e153146
  linesold=$(gitignore_entries $file | wc -l)
e153146
  linesnew=$( { echo "$str"; cat $file; } | gitignore_entries | sort -u | wc -l)
e153146
  if [ $linesold != $linesnew ] ; then
e153146
    { echo "$str" | cat - $file > $file.bak && mv $file.bak $file; } \
e153146
      || die "insert_if_absent $file $str: failed"
e153146
  fi
e153146
}
e153146
e153146
# Adjust $PATTERN for $VC_IGNORE_FILE and insert it with
e153146
# insert_if_absent.
e153146
insert_vc_ignore() {
e153146
  vc_ignore_file="$1"
e153146
  pattern="$2"
e153146
  case $vc_ignore_file in
e153146
  *.gitignore)
e153146
    # A .gitignore entry that does not start with '/' applies
e153146
    # recursively to subdirectories, so prepend '/' to every
e153146
    # .gitignore entry.
e153146
    pattern=$(echo "$pattern" | sed s,^,/,);;
e153146
  esac
e153146
  insert_if_absent "$vc_ignore_file" "$pattern"
e153146
}
e153146
e153146
# Die if there is no AC_CONFIG_AUX_DIR($build_aux) line in configure.ac.
e153146
found_aux_dir=no
e153146
grep '^[	 ]*AC_CONFIG_AUX_DIR(\['"$build_aux"'\])' configure.ac \
e153146
    >/dev/null && found_aux_dir=yes
e153146
grep '^[	 ]*AC_CONFIG_AUX_DIR('"$build_aux"')' configure.ac \
e153146
    >/dev/null && found_aux_dir=yes
e153146
test $found_aux_dir = yes \
e153146
  || die "configure.ac lacks 'AC_CONFIG_AUX_DIR([$build_aux])'; add it"
e153146
e153146
# If $build_aux doesn't exist, create it now, otherwise some bits
e153146
# below will malfunction.  If creating it, also mark it as ignored.
e153146
if test ! -d $build_aux; then
e153146
  mkdir $build_aux
e153146
  for dot_ig in x $vc_ignore; do
e153146
    test $dot_ig = x && continue
e153146
    insert_vc_ignore $dot_ig $build_aux
e153146
  done
e153146
fi
e153146
e153146
# Note this deviates from the version comparison in automake
e153146
# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
e153146
# but this should suffice as we won't be specifying old
e153146
# version formats or redundant trailing .0 in bootstrap.conf.
e153146
# If we did want full compatibility then we should probably
e153146
# use m4_version_compare from autoconf.
e153146
sort_ver() { # sort -V is not generally available
e153146
  ver1="$1"
e153146
  ver2="$2"
e153146
e153146
  # split on '.' and compare each component
e153146
  i=1
e153146
  while : ; do
e153146
    p1=$(echo "$ver1" | cut -d. -f$i)
e153146
    p2=$(echo "$ver2" | cut -d. -f$i)
e153146
    if [ ! "$p1" ]; then
e153146
      echo "$1 $2"
e153146
      break
e153146
    elif [ ! "$p2" ]; then
e153146
      echo "$2 $1"
e153146
      break
e153146
    elif [ ! "$p1" = "$p2" ]; then
e153146
      if [ "$p1" -gt "$p2" ] 2>/dev/null; then # numeric comparison
e153146
        echo "$2 $1"
e153146
      elif [ "$p2" -gt "$p1" ] 2>/dev/null; then # numeric comparison
e153146
        echo "$1 $2"
e153146
      else # numeric, then lexicographic comparison
e153146
        lp=$(printf "$p1\n$p2\n" | LANG=C sort -n | tail -n1)
e153146
        if [ "$lp" = "$p2" ]; then
e153146
          echo "$1 $2"
e153146
        else
e153146
          echo "$2 $1"
e153146
        fi
e153146
      fi
e153146
      break
e153146
    fi
e153146
    i=$(($i+1))
e153146
  done
e153146
}
e153146
e153146
get_version_sed='
e153146
# Move version to start of line.
e153146
s/.*[v ]\([0-9]\)/\1/
e153146
e153146
# Skip lines that do not start with version.
e153146
/^[0-9]/!d
e153146
e153146
# Remove characters after the version.
e153146
s/[^.a-z0-9-].*//
e153146
e153146
# The first component must be digits only.
e153146
s/^\([0-9]*\)[a-z-].*/\1/
e153146
e153146
#the following essentially does s/5.005/5.5/
e153146
s/\.0*\([1-9]\)/.\1/g
e153146
p
e153146
q'
e153146
e153146
get_version() {
e153146
  app=$1
e153146
e153146
  $app --version >/dev/null 2>&1 || { $app --version; return 1; }
e153146
e153146
  $app --version 2>&1 | sed -n "$get_version_sed"
e153146
}
e153146
e153146
check_versions() {
e153146
  ret=0
e153146
e153146
  while read app req_ver; do
e153146
    # We only need libtoolize from the libtool package.
e153146
    if test "$app" = libtool; then
e153146
      app=libtoolize
e153146
    fi
e153146
    # Exempt git if --no-git is in effect.
e153146
    if test "$app" = git; then
e153146
      $use_git || continue
e153146
    fi
e153146
    # Honor $APP variables ($TAR, $AUTOCONF, etc.)
e153146
    appvar=$(echo $app | LC_ALL=C tr '[a-z]-' '[A-Z]_')
e153146
    test "$appvar" = TAR && appvar=AMTAR
e153146
    case $appvar in
e153146
        GZIP) ;; # Do not use $GZIP:  it contains gzip options.
e153146
        PERL::*) ;; # Keep perl modules as-is
e153146
        *) eval "app=\${$appvar-$app}" ;;
e153146
    esac
e153146
e153146
    # Handle the still-experimental Automake-NG programs specially.
e153146
    # They remain named as the mainstream Automake programs ("automake",
e153146
    # and "aclocal") to avoid gratuitous incompatibilities with
e153146
    # pre-existing usages (by, say, autoreconf, or custom autogen.sh
e153146
    # scripts), but correctly identify themselves (as being part of
e153146
    # "GNU automake-ng") when asked their version.
e153146
    case $app in
e153146
      automake-ng|aclocal-ng)
e153146
        app=${app%-ng}
e153146
        ($app --version | grep '(GNU automake-ng)') >/dev/null 2>&1 || {
e153146
          warn_ "Error: '$app' not found or not from Automake-NG"
e153146
          ret=1
e153146
          continue
e153146
        } ;;
e153146
      # Another check is for perl modules.  These can be written as
e153146
      # e.g. perl::XML::XPath in case of XML::XPath module, etc.
e153146
      perl::*)
e153146
        # Extract module name
e153146
        app="${app#perl::}"
e153146
        if ! $PERL -m"$app" -e 'exit 0' >/dev/null 2>&1; then
e153146
          warn_ "Error: perl module '$app' not found"
e153146
          ret=1
e153146
        fi
e153146
        continue
e153146
        ;;
e153146
    esac
e153146
    if [ "$req_ver" = "-" ]; then
e153146
      # Merely require app to exist; not all prereq apps are well-behaved
e153146
      # so we have to rely on $? rather than get_version.
e153146
      if ! check_exists --verbose $app; then
e153146
        warn_ "Error: '$app' not found"
e153146
        ret=1
e153146
      fi
e153146
    else
e153146
      # Require app to produce a new enough version string.
e153146
      inst_ver=$(get_version $app)
e153146
      if [ ! "$inst_ver" ]; then
e153146
        warn_ "Error: '$app' not found"
e153146
        ret=1
e153146
      else
e153146
        latest_ver=$(sort_ver $req_ver $inst_ver | cut -d' ' -f2)
e153146
        if [ ! "$latest_ver" = "$inst_ver" ]; then
e153146
          warnf_ '%s\n'                                        \
e153146
              "Error: '$app' version == $inst_ver is too old"  \
e153146
              "       '$app' version >= $req_ver is required"
e153146
          ret=1
e153146
        fi
e153146
      fi
e153146
    fi
e153146
  done
e153146
e153146
  return $ret
e153146
}
e153146
e153146
print_versions() {
e153146
  echo "Program    Min_version"
e153146
  echo "----------------------"
e153146
  printf %s "$buildreq"
e153146
  echo "----------------------"
e153146
  # can't depend on column -t
e153146
}
e153146
e153146
# Find sha1sum, named gsha1sum on MacPorts, shasum on Mac OS X 10.6.
e153146
# Also find the compatible sha1 utility on the BSDs
e153146
if test x"$SKIP_PO" = x; then
e153146
  find_tool SHA1SUM sha1sum gsha1sum shasum sha1
e153146
fi
e153146
e153146
use_libtool=0
e153146
# We'd like to use grep -E, to see if any of LT_INIT,
e153146
# AC_PROG_LIBTOOL, AM_PROG_LIBTOOL is used in configure.ac,
e153146
# but that's not portable enough (e.g., for Solaris).
e153146
grep '^[	 ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \
e153146
  && use_libtool=1
e153146
grep '^[	 ]*LT_INIT' configure.ac >/dev/null \
e153146
  && use_libtool=1
e153146
if test $use_libtool = 1; then
e153146
  find_tool LIBTOOLIZE glibtoolize libtoolize
e153146
fi
e153146
e153146
# gnulib-tool requires at least automake and autoconf.
e153146
# If either is not listed, add it (with minimum version) as a prerequisite.
e153146
case $buildreq in
e153146
  *automake*) ;;
e153146
  *) buildreq="automake 1.9
e153146
$buildreq" ;;
e153146
esac
e153146
case $buildreq in
e153146
  *autoconf*) ;;
e153146
  *) buildreq="autoconf 2.59
e153146
$buildreq" ;;
e153146
esac
e153146
e153146
# When we can deduce that gnulib-tool will require patch,
e153146
# and when patch is not already listed as a prerequisite, add it, too.
e153146
if test -d "$local_gl_dir" \
e153146
    && ! find "$local_gl_dir" -name '*.diff' -exec false {} +; then
e153146
  case $buildreq in
e153146
    *patch*) ;;
e153146
    *) buildreq="patch -
e153146
$buildreq" ;;
e153146
  esac
e153146
fi
e153146
e153146
if ! printf "$buildreq" | check_versions; then
e153146
  echo >&2
e153146
  if test -f README-prereq; then
e153146
    die "See README-prereq for how to get the prerequisite programs"
e153146
  else
e153146
    die "Please install the prerequisite programs"
e153146
  fi
e153146
fi
e153146
e153146
# Warn the user if autom4te appears to be broken; this causes known
e153146
# issues with at least gettext 0.18.3.
e153146
probe=$(echo 'm4_quote([hi])' | autom4te -l M4sugar -t 'm4_quote:$%' -)
e153146
if test "x$probe" != xhi; then
e153146
  warn_ "WARNING: your autom4te wrapper eats stdin;"
e153146
  warn_ "if bootstrap fails, consider upgrading your autotools"
e153146
fi
e153146
e153146
echo "$0: Bootstrapping from checked-out $package sources..."
e153146
e153146
# See if we can use gnulib's git-merge-changelog merge driver.
e153146
if $use_git && test -d .git && check_exists git; then
e153146
  if git config merge.merge-changelog.driver >/dev/null ; then
e153146
    :
e153146
  elif check_exists git-merge-changelog; then
e153146
    echo "$0: initializing git-merge-changelog driver"
e153146
    git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
e153146
    git config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
e153146
  else
e153146
    echo "$0: consider installing git-merge-changelog from gnulib"
e153146
  fi
e153146
fi
e153146
e153146
e153146
cleanup_gnulib() {
e153146
  status=$?
e153146
  rm -fr "$gnulib_path"
e153146
  exit $status
e153146
}
e153146
e153146
git_modules_config () {
e153146
  test -f .gitmodules && git config --file .gitmodules "$@"
e153146
}
e153146
e153146
if $use_gnulib; then
e153146
  if $use_git; then
e153146
    gnulib_path=$(git_modules_config submodule.gnulib.path)
e153146
    test -z "$gnulib_path" && gnulib_path=gnulib
e153146
  fi
e153146
e153146
  # Get gnulib files.  Populate $GNULIB_SRCDIR, possibly updating a
e153146
  # submodule, for use in the rest of the script.
e153146
e153146
  case ${GNULIB_SRCDIR--} in
e153146
  -)
e153146
    # Note that $use_git is necessarily true in this case.
e153146
    if git_modules_config submodule.gnulib.url >/dev/null; then
e153146
      echo "$0: getting gnulib files..."
e153146
      git submodule init -- "$gnulib_path" || exit $?
e153146
      git submodule update -- "$gnulib_path" || exit $?
e153146
e153146
    elif [ ! -d "$gnulib_path" ]; then
e153146
      echo "$0: getting gnulib files..."
e153146
e153146
      trap cleanup_gnulib 1 2 13 15
e153146
e153146
      shallow=
e153146
      if test -z "$GNULIB_REVISION"; then
e153146
        git clone -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
e153146
      fi
e153146
      git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \
e153146
        || cleanup_gnulib
e153146
e153146
      trap - 1 2 13 15
e153146
    fi
e153146
    GNULIB_SRCDIR=$gnulib_path
e153146
    ;;
e153146
  *)
e153146
    # Use GNULIB_SRCDIR directly or as a reference.
e153146
    if $use_git && test -d "$GNULIB_SRCDIR"/.git && \
e153146
          git_modules_config submodule.gnulib.url >/dev/null; then
e153146
      echo "$0: getting gnulib files..."
e153146
      if git submodule -h|grep -- --reference > /dev/null; then
e153146
        # Prefer the one-liner available in git 1.6.4 or newer.
e153146
        git submodule update --init --reference "$GNULIB_SRCDIR" \
e153146
          "$gnulib_path" || exit $?
e153146
      else
e153146
        # This fallback allows at least git 1.5.5.
e153146
        if test -f "$gnulib_path"/gnulib-tool; then
e153146
          # Since file already exists, assume submodule init already complete.
e153146
          git submodule update -- "$gnulib_path" || exit $?
e153146
        else
e153146
          # Older git can't clone into an empty directory.
e153146
          rmdir "$gnulib_path" 2>/dev/null
e153146
          git clone --reference "$GNULIB_SRCDIR" \
e153146
            "$(git_modules_config submodule.gnulib.url)" "$gnulib_path" \
e153146
            && git submodule init -- "$gnulib_path" \
e153146
            && git submodule update -- "$gnulib_path" \
e153146
            || exit $?
e153146
        fi
e153146
      fi
e153146
      GNULIB_SRCDIR=$gnulib_path
e153146
    fi
e153146
    ;;
e153146
  esac
e153146
e153146
  if test -d "$GNULIB_SRCDIR"/.git && test -n "$GNULIB_REVISION" \
e153146
     && ! git_modules_config submodule.gnulib.url >/dev/null; then
e153146
    (cd "$GNULIB_SRCDIR" && git checkout "$GNULIB_REVISION") || cleanup_gnulib
e153146
  fi
e153146
e153146
  # $GNULIB_SRCDIR now points to the version of gnulib to use, and
e153146
  # we no longer need to use git or $gnulib_path below here.
e153146
e153146
  if $bootstrap_sync; then
e153146
    cmp -s "$0" "$GNULIB_SRCDIR/build-aux/bootstrap" || {
e153146
      echo "$0: updating bootstrap and restarting..."
e153146
      case $(sh -c 'echo "$1"' -- a) in
e153146
        a) ignored=--;;
e153146
        *) ignored=ignored;;
e153146
      esac
e153146
      exec sh -c \
e153146
        'cp "$1" "$2" && shift && exec "${CONFIG_SHELL-/bin/sh}" "$@"' \
e153146
        $ignored "$GNULIB_SRCDIR/build-aux/bootstrap" \
e153146
        "$0" "$@" --no-bootstrap-sync
e153146
    }
e153146
  fi
e153146
e153146
  gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
e153146
  <$gnulib_tool || exit $?
e153146
fi
e153146
e153146
# Get translations.
e153146
e153146
download_po_files() {
e153146
  subdir=$1
e153146
  domain=$2
e153146
  echo "$me: getting translations into $subdir for $domain..."
e153146
  cmd=$(printf "$po_download_command_format" "$subdir" "$domain")
e153146
  eval "$cmd"
e153146
}
e153146
e153146
# Mirror .po files to $po_dir/.reference and copy only the new
e153146
# or modified ones into $po_dir.  Also update $po_dir/LINGUAS.
e153146
# Note po files that exist locally only are left in $po_dir but will
e153146
# not be included in LINGUAS and hence will not be distributed.
e153146
update_po_files() {
e153146
  # Directory containing primary .po files.
e153146
  # Overwrite them only when we're sure a .po file is new.
e153146
  po_dir=$1
e153146
  domain=$2
e153146
e153146
  # Mirror *.po files into this dir.
e153146
  # Usually contains *.s1 checksum files.
e153146
  ref_po_dir="$po_dir/.reference"
e153146
e153146
  test -d $ref_po_dir || mkdir $ref_po_dir || return
e153146
  download_po_files $ref_po_dir $domain \
e153146
    && ls "$ref_po_dir"/*.po 2>/dev/null |
e153146
      sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS" || return
e153146
e153146
  langs=$(cd $ref_po_dir && echo *.po | sed 's/\.po//g')
e153146
  test "$langs" = '*' && langs=x
e153146
  for po in $langs; do
e153146
    case $po in x) continue;; esac
e153146
    new_po="$ref_po_dir/$po.po"
e153146
    cksum_file="$ref_po_dir/$po.s1"
e153146
    if ! test -f "$cksum_file" ||
e153146
        ! test -f "$po_dir/$po.po" ||
e153146
        ! $SHA1SUM -c "$cksum_file" < "$new_po" > /dev/null 2>&1; then
e153146
      echo "$me: updated $po_dir/$po.po..."
e153146
      cp "$new_po" "$po_dir/$po.po" \
e153146
          && $SHA1SUM < "$new_po" > "$cksum_file" || return
e153146
    fi
e153146
  done
e153146
}
e153146
e153146
case $SKIP_PO in
e153146
'')
e153146
  if test -d po; then
e153146
    update_po_files po $package || exit
e153146
  fi
e153146
e153146
  if test -d runtime-po; then
e153146
    update_po_files runtime-po $package-runtime || exit
e153146
  fi;;
e153146
esac
e153146
e153146
symlink_to_dir()
e153146
{
e153146
  src=$1/$2
e153146
  dst=${3-$2}
e153146
e153146
  test -f "$src" && {
e153146
e153146
    # If the destination directory doesn't exist, create it.
e153146
    # This is required at least for "lib/uniwidth/cjk.h".
e153146
    dst_dir=$(dirname "$dst")
e153146
    if ! test -d "$dst_dir"; then
e153146
      mkdir -p "$dst_dir"
e153146
e153146
      # If we've just created a directory like lib/uniwidth,
e153146
      # tell version control system(s) it's ignorable.
e153146
      # FIXME: for now, this does only one level
e153146
      parent=$(dirname "$dst_dir")
e153146
      for dot_ig in x $vc_ignore; do
e153146
        test $dot_ig = x && continue
e153146
        ig=$parent/$dot_ig
e153146
        insert_vc_ignore $ig "${dst_dir##*/}"
e153146
      done
e153146
    fi
e153146
e153146
    if $copy; then
e153146
      {
e153146
        test ! -h "$dst" || {
e153146
          echo "$me: rm -f $dst" &&
e153146
          rm -f "$dst"
e153146
        }
e153146
      } &&
e153146
      test -f "$dst" &&
e153146
      cmp -s "$src" "$dst" || {
e153146
        echo "$me: cp -fp $src $dst" &&
e153146
        cp -fp "$src" "$dst"
e153146
      }
e153146
    else
e153146
      # Leave any existing symlink alone, if it already points to the source,
e153146
      # so that broken build tools that care about symlink times
e153146
      # aren't confused into doing unnecessary builds.  Conversely, if the
e153146
      # existing symlink's timestamp is older than the source, make it afresh,
e153146
      # so that broken tools aren't confused into skipping needed builds.  See
e153146
      # <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00326.html>.
e153146
      test -h "$dst" &&
e153146
      src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 &&
e153146
      dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 &&
e153146
      test "$src_i" = "$dst_i" &&
e153146
      both_ls=$(ls -dt "$src" "$dst") &&
e153146
      test "X$both_ls" = "X$dst$nl$src" || {
e153146
        dot_dots=
e153146
        case $src in
e153146
        /*) ;;
e153146
        *)
e153146
          case /$dst/ in
e153146
          *//* | */../* | */./* | /*/*/*/*/*/)
e153146
             die "invalid symlink calculation: $src -> $dst";;
e153146
          /*/*/*/*/)    dot_dots=../../../;;
e153146
          /*/*/*/)      dot_dots=../../;;
e153146
          /*/*/)        dot_dots=../;;
e153146
          esac;;
e153146
        esac
e153146
e153146
        echo "$me: ln -fs $dot_dots$src $dst" &&
e153146
        ln -fs "$dot_dots$src" "$dst"
e153146
      }
e153146
    fi
e153146
  }
e153146
}
e153146
e153146
version_controlled_file() {
e153146
  parent=$1
e153146
  file=$2
e153146
  if test -d .git; then
e153146
    git rm -n "$file" > /dev/null 2>&1
e153146
  elif test -d .svn; then
e153146
    svn log -r HEAD "$file" > /dev/null 2>&1
e153146
  elif test -d CVS; then
e153146
    grep -F "/${file##*/}/" "$parent/CVS/Entries" 2>/dev/null |
e153146
             grep '^/[^/]*/[0-9]' > /dev/null
e153146
  else
e153146
    warn_ "no version control for $file?"
e153146
    false
e153146
  fi
e153146
}
e153146
e153146
# NOTE: we have to be careful to run both autopoint and libtoolize
e153146
# before gnulib-tool, since gnulib-tool is likely to provide newer
e153146
# versions of files "installed" by these two programs.
e153146
# Then, *after* gnulib-tool (see below), we have to be careful to
e153146
# run autoreconf in such a way that it does not run either of these
e153146
# two just-pre-run programs.
e153146
e153146
# Import from gettext.
e153146
with_gettext=yes
e153146
grep '^[	 ]*AM_GNU_GETTEXT_VERSION(' configure.ac >/dev/null || \
e153146
    with_gettext=no
e153146
e153146
if test $with_gettext = yes || test $use_libtool = 1; then
e153146
e153146
  tempbase=.bootstrap$$
e153146
  trap "rm -f $tempbase.0 $tempbase.1" 1 2 13 15
e153146
e153146
  > $tempbase.0 > $tempbase.1 &&
e153146
  find . ! -type d -print | sort > $tempbase.0 || exit
e153146
e153146
  if test $with_gettext = yes; then
e153146
    # Released autopoint has the tendency to install macros that have been
e153146
    # obsoleted in current gnulib, so run this before gnulib-tool.
e153146
    echo "$0: $AUTOPOINT --force"
e153146
    $AUTOPOINT --force || exit
e153146
  fi
e153146
e153146
  # Autoreconf runs aclocal before libtoolize, which causes spurious
e153146
  # warnings if the initial aclocal is confused by the libtoolized
e153146
  # (or worse out-of-date) macro directory.
e153146
  # libtoolize 1.9b added the --install option; but we support back
e153146
  # to libtoolize 1.5.22, where the install action was default.
e153146
  if test $use_libtool = 1; then
e153146
    install=
e153146
    case $($LIBTOOLIZE --help) in
e153146
      *--install*) install=--install ;;
e153146
    esac
e153146
    echo "running: $LIBTOOLIZE $install --copy"
e153146
    $LIBTOOLIZE $install --copy
e153146
  fi
e153146
e153146
  find . ! -type d -print | sort >$tempbase.1
e153146
  old_IFS=$IFS
e153146
  IFS=$nl
e153146
  for file in $(comm -13 $tempbase.0 $tempbase.1); do
e153146
    IFS=$old_IFS
e153146
    parent=${file%/*}
e153146
    version_controlled_file "$parent" "$file" || {
e153146
      for dot_ig in x $vc_ignore; do
e153146
        test $dot_ig = x && continue
e153146
        ig=$parent/$dot_ig
e153146
        insert_vc_ignore "$ig" "${file##*/}"
e153146
      done
e153146
    }
e153146
  done
e153146
  IFS=$old_IFS
e153146
e153146
  rm -f $tempbase.0 $tempbase.1
e153146
  trap - 1 2 13 15
e153146
fi
e153146
e153146
# Import from gnulib.
e153146
e153146
if $use_gnulib; then
e153146
  gnulib_tool_options="\
e153146
   --no-changelog\
e153146
   --aux-dir=$build_aux\
e153146
   --doc-base=$doc_base\
e153146
   --lib=$gnulib_name\
e153146
   --m4-base=$m4_base/\
e153146
   --source-base=$source_base/\
e153146
   --tests-base=$tests_base\
e153146
   --local-dir=$local_gl_dir\
e153146
   $gnulib_tool_option_extras\
e153146
  "
e153146
  if test $use_libtool = 1; then
e153146
    case "$gnulib_tool_options " in
e153146
      *' --libtool '*) ;;
e153146
      *) gnulib_tool_options="$gnulib_tool_options --libtool" ;;
e153146
    esac
e153146
  fi
e153146
  echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
e153146
  $gnulib_tool $gnulib_tool_options --import $gnulib_modules \
e153146
    || die "gnulib-tool failed"
e153146
e153146
  for file in $gnulib_files; do
e153146
    symlink_to_dir "$GNULIB_SRCDIR" $file \
e153146
      || die "failed to symlink $file"
e153146
  done
e153146
fi
e153146
e153146
bootstrap_post_import_hook \
e153146
  || die "bootstrap_post_import_hook failed"
e153146
e153146
# Don't proceed if there are uninitialized submodules.  In particular,
e153146
# the next step will remove dangling links, which might be links into
e153146
# uninitialized submodules.
e153146
#
e153146
# Uninitialized submodules are listed with an initial dash.
e153146
if $use_git && git submodule | grep '^-' >/dev/null; then
e153146
  die "some git submodules are not initialized. "     \
e153146
      "Run 'git submodule init' and bootstrap again."
e153146
fi
e153146
e153146
# Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
e153146
# gnulib-populated directories.  Such .m4 files would cause aclocal to fail.
e153146
# The following requires GNU find 4.2.3 or newer.  Considering the usual
e153146
# portability constraints of this script, that may seem a very demanding
e153146
# requirement, but it should be ok.  Ignore any failure, which is fine,
e153146
# since this is only a convenience to help developers avoid the relatively
e153146
# unusual case in which a symlinked-to .m4 file is git-removed from gnulib
e153146
# between successive runs of this script.
e153146
find "$m4_base" "$source_base" \
e153146
  -depth \( -name '*.m4' -o -name '*.[ch]' \) \
e153146
  -type l -xtype l -delete > /dev/null 2>&1
e153146
e153146
# Invoke autoreconf with --force --install to ensure upgrades of tools
e153146
# such as ylwrap.
e153146
AUTORECONFFLAGS="--verbose --install --force -I $m4_base $ACLOCAL_FLAGS"
e153146
e153146
# Some systems (RHEL 5) are using ancient autotools, for which the
e153146
# --no-recursive option had not been invented.  Detect that lack and
e153146
# omit the option when it's not supported.  FIXME in 2017: remove this
e153146
# hack when RHEL 5 autotools are updated, or when they become irrelevant.
e153146
case $($AUTORECONF --help) in
e153146
  *--no-recursive*) AUTORECONFFLAGS="$AUTORECONFFLAGS --no-recursive";;
e153146
esac
e153146
e153146
# Tell autoreconf not to invoke autopoint or libtoolize; they were run above.
e153146
echo "running: AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS"
e153146
AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS \
e153146
  || die "autoreconf failed"
e153146
e153146
# Get some extra files from gnulib, overriding existing files.
e153146
for file in $gnulib_extra_files; do
e153146
  case $file in
e153146
  */INSTALL) dst=INSTALL;;
e153146
  build-aux/*) dst=$build_aux/${file#build-aux/};;
e153146
  *) dst=$file;;
e153146
  esac
e153146
  symlink_to_dir "$GNULIB_SRCDIR" $file $dst \
e153146
    || die "failed to symlink $file"
e153146
done
e153146
e153146
if test $with_gettext = yes; then
e153146
  # Create gettext configuration.
e153146
  echo "$0: Creating po/Makevars from po/Makevars.template ..."
e153146
  rm -f po/Makevars
e153146
  sed '
e153146
    /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/
e153146
    /^COPYRIGHT_HOLDER *=/s/=.*/= '"$COPYRIGHT_HOLDER"'/
e153146
    /^MSGID_BUGS_ADDRESS *=/s|=.*|= '"$MSGID_BUGS_ADDRESS"'|
e153146
    /^XGETTEXT_OPTIONS *=/{
e153146
      s/$/ \\/
e153146
      a\
e153146
          '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
e153146
    }
e153146
  ' po/Makevars.template >po/Makevars \
e153146
    || die 'cannot generate po/Makevars'
e153146
e153146
  # If the 'gettext' module is in use, grab the latest Makefile.in.in.
e153146
  # If only the 'gettext-h' module is in use, assume autopoint already
e153146
  # put the correct version of this file into place.
e153146
  case $gnulib_modules in
e153146
  *gettext-h*) ;;
e153146
  *gettext*)
e153146
    cp $GNULIB_SRCDIR/build-aux/po/Makefile.in.in po/Makefile.in.in \
e153146
      || die "cannot create po/Makefile.in.in"
e153146
    ;;
e153146
  esac
e153146
e153146
  if test -d runtime-po; then
e153146
    # Similarly for runtime-po/Makevars, but not quite the same.
e153146
    rm -f runtime-po/Makevars
e153146
    sed '
e153146
      /^DOMAIN *=.*/s/=.*/= '"$package"'-runtime/
e153146
      /^subdir *=.*/s/=.*/= runtime-po/
e153146
      /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
e153146
      /^XGETTEXT_OPTIONS *=/{
e153146
        s/$/ \\/
e153146
        a\
e153146
            '"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+}
e153146
      }
e153146
    ' po/Makevars.template >runtime-po/Makevars \
e153146
    || die 'cannot generate runtime-po/Makevars'
e153146
e153146
    # Copy identical files from po to runtime-po.
e153146
    (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
e153146
  fi
e153146
fi
e153146
e153146
bootstrap_epilogue
e153146
e153146
echo "$0: done.  Now you can run './configure'."
e153146
e153146
# Local variables:
e153146
# eval: (add-hook 'before-save-hook 'time-stamp)
e153146
# time-stamp-start: "scriptversion="
e153146
# time-stamp-format: "%:y-%02m-%02d.%02H"
e153146
# time-stamp-time-zone: "UTC0"
e153146
# time-stamp-end: "; # UTC"
e153146
# End: