Blame bootstrap

Packit 437b5e
#! /bin/sh
Packit 437b5e
## DO NOT EDIT - This file generated from build-aux/bootstrap.in
Packit 437b5e
##               by inline-source v2014-01-03.01
Packit 437b5e
Packit 437b5e
# Bootstrap an Autotooled package from checked-out sources.
Packit 437b5e
# Written by Gary V. Vaughan, 2010
Packit 437b5e
Packit 437b5e
# Copyright (C) 2010-2015 Free Software Foundation, Inc.
Packit 437b5e
# This is free software; see the source for copying conditions.  There is NO
Packit 437b5e
# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Packit 437b5e
Packit 437b5e
# This program is free software: you can redistribute it and/or modify
Packit 437b5e
# it under the terms of the GNU General Public License as published by
Packit 437b5e
# the Free Software Foundation, either version 3 of the License, or
Packit 437b5e
# (at your option) any later version.
Packit 437b5e
Packit 437b5e
# This program is distributed in the hope that it will be useful,
Packit 437b5e
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 437b5e
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 437b5e
# GNU General Public License for more details.
Packit 437b5e
Packit 437b5e
# You should have received a copy of the GNU General Public License
Packit 437b5e
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 437b5e
Packit 437b5e
# Originally written by Paul Eggert.  The canonical version of this
Packit 437b5e
# script is maintained as build-aux/bootstrap in gnulib, however, to
Packit 437b5e
# be useful to your project, you should place a copy of it under
Packit 437b5e
# version control in the top-level directory of your project.  The
Packit 437b5e
# intent is that all customization can be done with a bootstrap.conf
Packit 437b5e
# file also maintained in your version control; gnulib comes with a
Packit 437b5e
# template build-aux/bootstrap.conf to get you started.
Packit 437b5e
Packit 437b5e
# Please report bugs or propose patches to bug-gnulib@gnu.org.
Packit 437b5e
Packit 437b5e
Packit 437b5e
## ------ ##
Packit 437b5e
## Usage. ##
Packit 437b5e
## ------ ##
Packit 437b5e
Packit 437b5e
# Most GNUish projects do not keep all of the generated Autotool
Packit 437b5e
# files under version control, but running all of the right tools
Packit 437b5e
# with the right arguments, in the correct order to regenerate
Packit 437b5e
# all of those files in readiness for configuration and building
Packit 437b5e
# can be surprisingly involved!  Many projects have a 'bootstrap'
Packit 437b5e
# script under version control to invoke Autotools and perform
Packit 437b5e
# other assorted book-keeping with version numbers and the like.
Packit 437b5e
#
Packit 437b5e
# This bootstrap script aims to probe the configure.ac and top
Packit 437b5e
# Makefile.am of your project to automatically determine what
Packit 437b5e
# the correct ordering and arguments are and then run the tools for
Packit 437b5e
# you.  In order to use it, you can generate an initial standalone
Packit 437b5e
# script with:
Packit 437b5e
#
Packit 437b5e
#   gl/build-aux/inline-source gl/build-aux/bootstrap.in > bootstrap
Packit 437b5e
#
Packit 437b5e
# You should then store than script in version control for other
Packit 437b5e
# developers in you project.  It will give you instructions about
Packit 437b5e
# how to keep it up to date if the sources change.
Packit 437b5e
#
Packit 437b5e
# See gl/doc/bootstrap.texi for documentation on how to write
Packit 437b5e
# a bootstrap.conf to customize it for your project's
Packit 437b5e
# idiosyncracies.
Packit 437b5e
Packit 437b5e
Packit 437b5e
## ================================================================== ##
Packit 437b5e
##                                                                    ##
Packit 437b5e
##     DO NOT EDIT THIS FILE, CUSTOMIZE IT USING A BOOTSTRAP.CONF     ##
Packit 437b5e
##                                                                    ##
Packit 437b5e
## ================================================================== ##
Packit 437b5e
Packit 437b5e
## ------------------------------- ##
Packit 437b5e
## User overridable command paths. ##
Packit 437b5e
## ------------------------------- ##
Packit 437b5e
Packit 437b5e
# All uppercase denotes values stored in the environment.  These
Packit 437b5e
# variables should generally be overridden by the user - however, we do
Packit 437b5e
# set them to 'true' in some parts of this script to prevent them being
Packit 437b5e
# called at the wrong time by other tools that we call ('autoreconf',
Packit 437b5e
# for example).
Packit 437b5e
#
Packit 437b5e
# We also allow 'LIBTOOLIZE', 'M4', 'SHA1SUM' and some others to be
Packit 437b5e
# overridden, and export the result for child processes, but they are
Packit 437b5e
# handled by the function 'func_find_tool' and not defaulted in this
Packit 437b5e
# section.
Packit 437b5e
Packit 437b5e
: ${ACLOCAL="aclocal"}
Packit 437b5e
: ${AUTOCONF="autoconf"}
Packit 437b5e
: ${AUTOHEADER="autoheader"}
Packit 437b5e
: ${AUTOM4TE="autom4te"}
Packit 437b5e
: ${AUTOHEADER="autoheader"}
Packit 437b5e
: ${AUTOMAKE="automake"}
Packit 437b5e
: ${AUTOPOINT="autopoint"}
Packit 437b5e
: ${AUTORECONF="autoreconf"}
Packit 437b5e
: ${CMP="cmp"}
Packit 437b5e
: ${CONFIG_SHELL="/bin/sh"}
Packit 437b5e
: ${DIFF="diff"}
Packit 437b5e
: ${GIT="git"}
Packit 437b5e
: ${LN_S="ln -s"}
Packit 437b5e
: ${RM="rm"}
Packit 437b5e
Packit 437b5e
export ACLOCAL
Packit 437b5e
export AUTOCONF
Packit 437b5e
export AUTOHEADER
Packit 437b5e
export AUTOM4TE
Packit 437b5e
export AUTOHEADER
Packit 437b5e
export AUTOMAKE
Packit 437b5e
export AUTOPOINT
Packit 437b5e
export AUTORECONF
Packit 437b5e
export CONFIG_SHELL
Packit 437b5e
Packit 437b5e
Packit 437b5e
: ${LUAROCKS="luarocks"}
Packit 437b5e
Packit 437b5e
export LUAROCKS
Packit 437b5e
Packit 437b5e
Packit 437b5e
## -------------- ##
Packit 437b5e
## Configuration. ##
Packit 437b5e
## -------------- ##
Packit 437b5e
Packit 437b5e
# A newline delimited list of triples of programs (that respond to
Packit 437b5e
# --version), the minimum version numbers required (or just '-' in the
Packit 437b5e
# version field if any version will be sufficient) and homepage URLs
Packit 437b5e
# to help locate missing packages.
Packit 437b5e
buildreq=
Packit 437b5e
Packit 437b5e
# Name of a file containing instructions on installing missing packages
Packit 437b5e
# required in 'buildreq'.
Packit 437b5e
buildreq_readme=README-hacking
Packit 437b5e
Packit 437b5e
# These are extracted from AC_INIT in configure.ac, though you can
Packit 437b5e
# override those values in 'bootstrap.conf' if you prefer.
Packit 437b5e
build_aux=
Packit 437b5e
macro_dir=
Packit 437b5e
package=
Packit 437b5e
package_name=
Packit 437b5e
package_version=
Packit 437b5e
package_bugreport=
Packit 437b5e
Packit 437b5e
# These are extracted from 'gnulib-cache.m4', or else fall-back
Packit 437b5e
# automatically on the gnulib defaults; unless you set the values
Packit 437b5e
# manually in 'bootstrap.conf'.
Packit 437b5e
doc_base=
Packit 437b5e
gnulib_mk=
Packit 437b5e
gnulib_name=
Packit 437b5e
local_gl_dir=
Packit 437b5e
source_base=
Packit 437b5e
tests_base=
Packit 437b5e
Packit 437b5e
# The list of gnulib modules required at 'gnulib-tool' time.  If you
Packit 437b5e
# check 'gnulib-cache.m4' into your repository, then this list will be
Packit 437b5e
# extracted automatically.
Packit 437b5e
gnulib_modules=
Packit 437b5e
Packit 437b5e
# Extra gnulib files that are not in modules, which override files of
Packit 437b5e
# the same name installed by other bootstrap tools.
Packit 437b5e
gnulib_non_module_files="
Packit 437b5e
        build-aux/compile
Packit 437b5e
        build-aux/install-sh
Packit 437b5e
        build-aux/mdate-sh
Packit 437b5e
        build-aux/texinfo.tex
Packit 437b5e
        build-aux/depcomp
Packit 437b5e
        build-aux/config.guess
Packit 437b5e
        build-aux/config.sub
Packit 437b5e
        doc/INSTALL
Packit 437b5e
"
Packit 437b5e
Packit 437b5e
# Relative path to the local gnulib submodule, and url to the upstream
Packit 437b5e
# git repository. If you have a gnulib entry in your .gitmodules file,
Packit 437b5e
# these values are ignored.
Packit 437b5e
gnulib_path=
Packit 437b5e
gnulib_url=
Packit 437b5e
Packit 437b5e
# Additional gnulib-tool options to use.
Packit 437b5e
gnulib_tool_options="
Packit 437b5e
        --no-changelog
Packit 437b5e
"
Packit 437b5e
Packit 437b5e
# bootstrap removes any macro-files that are not included by aclocal.m4,
Packit 437b5e
# except for files listed in this variable that are always kept.
Packit 437b5e
gnulib_precious="
Packit 437b5e
        gnulib-tool.m4
Packit 437b5e
"
Packit 437b5e
Packit 437b5e
# When truncating long commands for display, always allow at least this
Packit 437b5e
# many characters before truncating.
Packit 437b5e
min_cmd_len=160
Packit 437b5e
Packit 437b5e
# The command to download all .po files for a specified domain into
Packit 437b5e
# a specified directory.  Fill in the first %s is the domain name, and
Packit 437b5e
# the second with the destination directory.  Use rsync's -L and -r
Packit 437b5e
# options because the latest/%s directory and the .po files within are
Packit 437b5e
# all symlinks.
Packit 437b5e
po_download_command_format=\
Packit 437b5e
"rsync --delete --exclude '*.s1' -Lrtvz \
Packit 437b5e
'translationproject.org::tp/latest/%s/' '%s'"
Packit 437b5e
Packit 437b5e
# Other locale categories that need message catalogs.
Packit 437b5e
extra_locale_categories=
Packit 437b5e
Packit 437b5e
# Additional xgettext options to use.  Gnulib might provide you with an
Packit 437b5e
# extensive list of additional options to append to this, but gettext
Packit 437b5e
# 0.16.1 and newer appends them automaticaly, so you can safely ignore
Packit 437b5e
# the complaints from 'gnulib-tool' if your $configure_ac states:
Packit 437b5e
#
Packit 437b5e
#    AM_GNU_GETTEXT_VERSION([0.16.1])
Packit 437b5e
xgettext_options="
Packit 437b5e
        --flag=_:1:pass-c-format
Packit 437b5e
        --flag=N_:1:pass-c-format
Packit 437b5e
"
Packit 437b5e
Packit 437b5e
# Package copyright holder for gettext files.  Defaults to FSF if unset.
Packit 437b5e
copyright_holder=
Packit 437b5e
Packit 437b5e
# File that should exist in the top directory of a checked out hierarchy,
Packit 437b5e
# but not in a distribution tarball.
Packit 437b5e
checkout_only_file=
Packit 437b5e
Packit 437b5e
# Whether to use copies instead of symlinks by default (if set to true,
Packit 437b5e
# the --copy option has no effect).
Packit 437b5e
copy=false
Packit 437b5e
Packit 437b5e
# Set this to ".cvsignore .gitignore" in 'bootstrap.conf' if you want
Packit 437b5e
# those files to be generated in directories like 'lib/', 'm4/', and 'po/',
Packit 437b5e
# or set it to "auto" to make this script select what to use based
Packit 437b5e
# on what version control system (if any) is used in the source directory.
Packit 437b5e
# Or set it to "none" to ignore VCS ignore files entirely.  Default is
Packit 437b5e
# "auto".
Packit 437b5e
vc_ignore=
Packit 437b5e
Packit 437b5e
Packit 437b5e
# List of slingshot files to link into stdlib tree before autotooling.
Packit 437b5e
slingshot_files=$slingshot_files
Packit 437b5e
Packit 437b5e
# Relative path to the local slingshot submodule, and url to the upsream
Packit 437b5e
# git repository.  If you have a slingshot entry in your .gitmodules file,
Packit 437b5e
# these values are ignored.
Packit 437b5e
slingshot_path=$slingshot_path
Packit 437b5e
slingshot_url=$slingshot_url
Packit 437b5e
Packit 437b5e
# NOTE: slingshot bootstrap will check rockspecs listed in $buildreq,
Packit 437b5e
#       according to the URL part of a specification triple ending in
Packit 437b5e
#       `.rockspec`.
Packit 437b5e
Packit 437b5e
Packit 437b5e
## ------------------- ##
Packit 437b5e
## External Libraries. ##
Packit 437b5e
## ------------------- ##
Packit 437b5e
Packit 437b5e
# Source required external libraries:
Packit 437b5e
# Set a version string for this script.
Packit 437b5e
scriptversion=2014-01-03.01; # UTC
Packit 437b5e
Packit 437b5e
# General shell script boiler plate, and helper functions.
Packit 437b5e
# Written by Gary V. Vaughan, 2004
Packit 437b5e
Packit 437b5e
# Copyright (C) 2004-2014 Free Software Foundation, Inc.
Packit 437b5e
# This is free software; see the source for copying conditions.  There is NO
Packit 437b5e
# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Packit 437b5e
Packit 437b5e
# This program is free software; you can redistribute it and/or modify
Packit 437b5e
# it under the terms of the GNU General Public License as published by
Packit 437b5e
# the Free Software Foundation; either version 3 of the License, or
Packit 437b5e
# (at your option) any later version.
Packit 437b5e
Packit 437b5e
# As a special exception to the GNU General Public License, if you distribute
Packit 437b5e
# this file as part of a program or library that is built using GNU Libtool,
Packit 437b5e
# you may include this file under the same distribution terms that you use
Packit 437b5e
# for the rest of that program.
Packit 437b5e
Packit 437b5e
# This program is distributed in the hope that it will be useful,
Packit 437b5e
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 437b5e
# MERCHANTABILITY or FITNES FOR A PARTICULAR PURPOSE. See the GNU
Packit 437b5e
# General Public License for more details.
Packit 437b5e
Packit 437b5e
# You should have received a copy of the GNU General Public License
Packit 437b5e
# along with this program. If not, see <http://www.gnu.org/licenses/>.
Packit 437b5e
Packit 437b5e
# Please report bugs or propose patches to gary@gnu.org.
Packit 437b5e
Packit 437b5e
Packit 437b5e
## ------ ##
Packit 437b5e
## Usage. ##
Packit 437b5e
## ------ ##
Packit 437b5e
Packit 437b5e
# Evaluate this file near the top of your script to gain access to
Packit 437b5e
# the functions and variables defined here:
Packit 437b5e
#
Packit 437b5e
#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
Packit 437b5e
#
Packit 437b5e
# If you need to override any of the default environment variable
Packit 437b5e
# settings, do that before evaluating this file.
Packit 437b5e
Packit 437b5e
Packit 437b5e
## -------------------- ##
Packit 437b5e
## Shell normalisation. ##
Packit 437b5e
## -------------------- ##
Packit 437b5e
Packit 437b5e
# Some shells need a little help to be as Bourne compatible as possible.
Packit 437b5e
# Before doing anything else, make sure all that help has been provided!
Packit 437b5e
Packit 437b5e
DUALCASE=1; export DUALCASE # for MKS sh
Packit 437b5e
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
Packit 437b5e
  emulate sh
Packit 437b5e
  NULLCMD=:
Packit 437b5e
  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
Packit 437b5e
  # is contrary to our usage.  Disable this feature.
Packit 437b5e
  alias -g '${1+"$@"}'='"$@"'
Packit 437b5e
  setopt NO_GLOB_SUBST
Packit 437b5e
else
Packit 437b5e
  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
Packit 437b5e
fi
Packit 437b5e
Packit 437b5e
# NLS nuisances: We save the old values in case they are required later.
Packit 437b5e
_G_user_locale=
Packit 437b5e
_G_safe_locale=
Packit 437b5e
for _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
Packit 437b5e
do
Packit 437b5e
  eval "if test set = \"\${$_G_var+set}\"; then
Packit 437b5e
          save_$_G_var=\$$_G_var
Packit 437b5e
          $_G_var=C
Packit 437b5e
	  export $_G_var
Packit 437b5e
	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
Packit 437b5e
	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
Packit 437b5e
	fi"
Packit 437b5e
done
Packit 437b5e
Packit 437b5e
# CDPATH.
Packit 437b5e
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
Packit 437b5e
Packit 437b5e
# Make sure IFS has a sensible default
Packit 437b5e
sp=' '
Packit 437b5e
nl='
Packit 437b5e
'
Packit 437b5e
IFS="$sp	$nl"
Packit 437b5e
Packit 437b5e
# There are apparently some retarded systems that use ';' as a PATH separator!
Packit 437b5e
if test "${PATH_SEPARATOR+set}" != set; then
Packit 437b5e
  PATH_SEPARATOR=:
Packit 437b5e
  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
Packit 437b5e
    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
Packit 437b5e
      PATH_SEPARATOR=';'
Packit 437b5e
  }
Packit 437b5e
fi
Packit 437b5e
Packit 437b5e
Packit 437b5e
Packit 437b5e
## ------------------------- ##
Packit 437b5e
## Locate command utilities. ##
Packit 437b5e
## ------------------------- ##
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_executable_p FILE
Packit 437b5e
# ----------------------
Packit 437b5e
# Check that FILE is an executable regular file.
Packit 437b5e
func_executable_p ()
Packit 437b5e
{
Packit 437b5e
    test -f "$1" && test -x "$1"
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
Packit 437b5e
# --------------------------------------------
Packit 437b5e
# Search for either a program that responds to --version with output
Packit 437b5e
# containing "GNU", or else returned by CHECK_FUNC otherwise, by
Packit 437b5e
# trying all the directories in PATH with each of the elements of
Packit 437b5e
# PROGS_LIST.
Packit 437b5e
#
Packit 437b5e
# CHECK_FUNC should accept the path to a candidate program, and
Packit 437b5e
# set $func_check_prog_result if it truncates its output less than
Packit 437b5e
# $_G_path_prog_max characters.
Packit 437b5e
func_path_progs ()
Packit 437b5e
{
Packit 437b5e
    _G_progs_list=$1
Packit 437b5e
    _G_check_func=$2
Packit 437b5e
    _G_PATH=${3-"$PATH"}
Packit 437b5e
Packit 437b5e
    _G_path_prog_max=0
Packit 437b5e
    _G_path_prog_found=false
Packit 437b5e
    _G_save_IFS=$IFS; IFS=$PATH_SEPARATOR
Packit 437b5e
    for _G_dir in $_G_PATH; do
Packit 437b5e
      IFS=$_G_save_IFS
Packit 437b5e
      test -z "$_G_dir" && _G_dir=.
Packit 437b5e
      for _G_prog_name in $_G_progs_list; do
Packit 437b5e
        for _exeext in '' .EXE; do
Packit 437b5e
          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
Packit 437b5e
          func_executable_p "$_G_path_prog" || continue
Packit 437b5e
          case `"$_G_path_prog" --version 2>&1` in
Packit 437b5e
            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
Packit 437b5e
            *)     $_G_check_func $_G_path_prog
Packit 437b5e
		   func_path_progs_result=$func_check_prog_result
Packit 437b5e
		   ;;
Packit 437b5e
          esac
Packit 437b5e
          $_G_path_prog_found && break 3
Packit 437b5e
        done
Packit 437b5e
      done
Packit 437b5e
    done
Packit 437b5e
    IFS=$_G_save_IFS
Packit 437b5e
    test -z "$func_path_progs_result" && {
Packit 437b5e
      echo "no acceptable sed could be found in \$PATH" >&2
Packit 437b5e
      exit 1
Packit 437b5e
    }
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# We want to be able to use the functions in this file before configure
Packit 437b5e
# has figured out where the best binaries are kept, which means we have
Packit 437b5e
# to search for them ourselves - except when the results are already set
Packit 437b5e
# where we skip the searches.
Packit 437b5e
Packit 437b5e
# Unless the user overrides by setting SED, search the path for either GNU
Packit 437b5e
# sed, or the sed that truncates its output the least.
Packit 437b5e
test -z "$SED" && {
Packit 437b5e
  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
Packit 437b5e
  for _G_i in 1 2 3 4 5 6 7; do
Packit 437b5e
    _G_sed_script=$_G_sed_script$nl$_G_sed_script
Packit 437b5e
  done
Packit 437b5e
  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
Packit 437b5e
  _G_sed_script=
Packit 437b5e
Packit 437b5e
  func_check_prog_sed ()
Packit 437b5e
  {
Packit 437b5e
    _G_path_prog=$1
Packit 437b5e
Packit 437b5e
    _G_count=0
Packit 437b5e
    printf 0123456789 >conftest.in
Packit 437b5e
    while :
Packit 437b5e
    do
Packit 437b5e
      cat conftest.in conftest.in >conftest.tmp
Packit 437b5e
      mv conftest.tmp conftest.in
Packit 437b5e
      cp conftest.in conftest.nl
Packit 437b5e
      echo '' >> conftest.nl
Packit 437b5e
      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
Packit 437b5e
      diff conftest.out conftest.nl >/dev/null 2>&1 || break
Packit 437b5e
      _G_count=`expr $_G_count + 1`
Packit 437b5e
      if test "$_G_count" -gt "$_G_path_prog_max"; then
Packit 437b5e
        # Best one so far, save it but keep looking for a better one
Packit 437b5e
        func_check_prog_result=$_G_path_prog
Packit 437b5e
        _G_path_prog_max=$_G_count
Packit 437b5e
      fi
Packit 437b5e
      # 10*(2^10) chars as input seems more than enough
Packit 437b5e
      test 10 -lt "$_G_count" && break
Packit 437b5e
    done
Packit 437b5e
    rm -f conftest.in conftest.tmp conftest.nl conftest.out
Packit 437b5e
  }
Packit 437b5e
Packit 437b5e
  func_path_progs "sed gsed" func_check_prog_sed $PATH:/usr/xpg4/bin
Packit 437b5e
  rm -f conftest.sed
Packit 437b5e
  SED=$func_path_progs_result
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# Unless the user overrides by setting GREP, search the path for either GNU
Packit 437b5e
# grep, or the grep that truncates its output the least.
Packit 437b5e
test -z "$GREP" && {
Packit 437b5e
  func_check_prog_grep ()
Packit 437b5e
  {
Packit 437b5e
    _G_path_prog=$1
Packit 437b5e
Packit 437b5e
    _G_count=0
Packit 437b5e
    _G_path_prog_max=0
Packit 437b5e
    printf 0123456789 >conftest.in
Packit 437b5e
    while :
Packit 437b5e
    do
Packit 437b5e
      cat conftest.in conftest.in >conftest.tmp
Packit 437b5e
      mv conftest.tmp conftest.in
Packit 437b5e
      cp conftest.in conftest.nl
Packit 437b5e
      echo 'GREP' >> conftest.nl
Packit 437b5e
      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
Packit 437b5e
      diff conftest.out conftest.nl >/dev/null 2>&1 || break
Packit 437b5e
      _G_count=`expr $_G_count + 1`
Packit 437b5e
      if test "$_G_count" -gt "$_G_path_prog_max"; then
Packit 437b5e
        # Best one so far, save it but keep looking for a better one
Packit 437b5e
        func_check_prog_result=$_G_path_prog
Packit 437b5e
        _G_path_prog_max=$_G_count
Packit 437b5e
      fi
Packit 437b5e
      # 10*(2^10) chars as input seems more than enough
Packit 437b5e
      test 10 -lt "$_G_count" && break
Packit 437b5e
    done
Packit 437b5e
    rm -f conftest.in conftest.tmp conftest.nl conftest.out
Packit 437b5e
  }
Packit 437b5e
Packit 437b5e
  func_path_progs "grep ggrep" func_check_prog_grep $PATH:/usr/xpg4/bin
Packit 437b5e
  GREP=$func_path_progs_result
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
## ------------------------------- ##
Packit 437b5e
## User overridable command paths. ##
Packit 437b5e
## ------------------------------- ##
Packit 437b5e
Packit 437b5e
# All uppercase variable names are used for environment variables.  These
Packit 437b5e
# variables can be overridden by the user before calling a script that
Packit 437b5e
# uses them if a suitable command of that name is not already available
Packit 437b5e
# in the command search PATH.
Packit 437b5e
Packit 437b5e
: ${CP="cp -f"}
Packit 437b5e
: ${ECHO="printf %s\n"}
Packit 437b5e
: ${EGREP="$GREP -E"}
Packit 437b5e
: ${FGREP="$GREP -F"}
Packit 437b5e
: ${LN_S="ln -s"}
Packit 437b5e
: ${MAKE="make"}
Packit 437b5e
: ${MKDIR="mkdir"}
Packit 437b5e
: ${MV="mv -f"}
Packit 437b5e
: ${RM="rm -f"}
Packit 437b5e
: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
Packit 437b5e
Packit 437b5e
Packit 437b5e
## -------------------- ##
Packit 437b5e
## Useful sed snippets. ##
Packit 437b5e
## -------------------- ##
Packit 437b5e
Packit 437b5e
sed_dirname='s|/[^/]*$||'
Packit 437b5e
sed_basename='s|^.*/||'
Packit 437b5e
Packit 437b5e
# Sed substitution that helps us do robust quoting.  It backslashifies
Packit 437b5e
# metacharacters that are still active within double-quoted strings.
Packit 437b5e
sed_quote_subst='s|\([`"$\\]\)|\\\1|g'
Packit 437b5e
Packit 437b5e
# Same as above, but do not quote variable references.
Packit 437b5e
sed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
Packit 437b5e
Packit 437b5e
# Sed substitution that turns a string into a regex matching for the
Packit 437b5e
# string literally.
Packit 437b5e
sed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
Packit 437b5e
Packit 437b5e
# Sed substitution that converts a w32 file name or path
Packit 437b5e
# that contains forward slashes, into one that contains
Packit 437b5e
# (escaped) backslashes.  A very naive implementation.
Packit 437b5e
sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
Packit 437b5e
Packit 437b5e
# Re-'\' parameter expansions in output of sed_double_quote_subst that
Packit 437b5e
# were '\'-ed in input to the same.  If an odd number of '\' preceded a
Packit 437b5e
# '$' in input to sed_double_quote_subst, that '$' was protected from
Packit 437b5e
# expansion.  Since each input '\' is now two '\'s, look for any number
Packit 437b5e
# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
Packit 437b5e
_G_bs='\\'
Packit 437b5e
_G_bs2='\\\\'
Packit 437b5e
_G_bs4='\\\\\\\\'
Packit 437b5e
_G_dollar='\$'
Packit 437b5e
sed_double_backslash="\
Packit 437b5e
  s/$_G_bs4/&\\
Packit 437b5e
/g
Packit 437b5e
  s/^$_G_bs2$_G_dollar/$_G_bs&/
Packit 437b5e
  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
Packit 437b5e
  s/\n//g"
Packit 437b5e
Packit 437b5e
Packit 437b5e
## ----------------- ##
Packit 437b5e
## Global variables. ##
Packit 437b5e
## ----------------- ##
Packit 437b5e
Packit 437b5e
# Except for the global variables explicitly listed below, the following
Packit 437b5e
# functions in the '^func_' namespace, and the '^require_' namespace
Packit 437b5e
# variables initialised in the 'Resource management' section, sourcing
Packit 437b5e
# this file will not pollute your global namespace with anything
Packit 437b5e
# else. There's no portable way to scope variables in Bourne shell
Packit 437b5e
# though, so actually running these functions will sometimes place
Packit 437b5e
# results into a variable named after the function, and often use
Packit 437b5e
# temporary variables in the '^_G_' namespace. If you are careful to
Packit 437b5e
# avoid using those namespaces casually in your sourcing script, things
Packit 437b5e
# should continue to work as you expect. And, of course, you can freely
Packit 437b5e
# overwrite any of the functions or variables defined here before
Packit 437b5e
# calling anything to customize them.
Packit 437b5e
Packit 437b5e
EXIT_SUCCESS=0
Packit 437b5e
EXIT_FAILURE=1
Packit 437b5e
EXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
Packit 437b5e
EXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
Packit 437b5e
Packit 437b5e
# Allow overriding, eg assuming that you follow the convention of
Packit 437b5e
# putting '$debug_cmd' at the start of all your functions, you can get
Packit 437b5e
# bash to show function call trace with:
Packit 437b5e
#
Packit 437b5e
#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
Packit 437b5e
debug_cmd=${debug_cmd-":"}
Packit 437b5e
exit_cmd=:
Packit 437b5e
Packit 437b5e
# By convention, finish your script with:
Packit 437b5e
#
Packit 437b5e
#    exit $exit_status
Packit 437b5e
#
Packit 437b5e
# so that you can set exit_status to non-zero if you want to indicate
Packit 437b5e
# something went wrong during execution without actually bailing out at
Packit 437b5e
# the point of failure.
Packit 437b5e
exit_status=$EXIT_SUCCESS
Packit 437b5e
Packit 437b5e
# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
Packit 437b5e
# is ksh but when the shell is invoked as "sh" and the current value of
Packit 437b5e
# the _XPG environment variable is not equal to 1 (one), the special
Packit 437b5e
# positional parameter $0, within a function call, is the name of the
Packit 437b5e
# function.
Packit 437b5e
progpath=$0
Packit 437b5e
Packit 437b5e
# The name of this program.
Packit 437b5e
progname=`$ECHO "$progpath" |$SED "$sed_basename"`
Packit 437b5e
Packit 437b5e
# Make sure we have an absolute progpath for reexecution:
Packit 437b5e
case $progpath in
Packit 437b5e
  [\\/]*|[A-Za-z]:\\*) ;;
Packit 437b5e
  *[\\/]*)
Packit 437b5e
     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
Packit 437b5e
     progdir=`cd "$progdir" && pwd`
Packit 437b5e
     progpath=$progdir/$progname
Packit 437b5e
     ;;
Packit 437b5e
  *)
Packit 437b5e
     _G_IFS=$IFS
Packit 437b5e
     IFS=${PATH_SEPARATOR-:}
Packit 437b5e
     for progdir in $PATH; do
Packit 437b5e
       IFS=$_G_IFS
Packit 437b5e
       test -x "$progdir/$progname" && break
Packit 437b5e
     done
Packit 437b5e
     IFS=$_G_IFS
Packit 437b5e
     test -n "$progdir" || progdir=`pwd`
Packit 437b5e
     progpath=$progdir/$progname
Packit 437b5e
     ;;
Packit 437b5e
esac
Packit 437b5e
Packit 437b5e
Packit 437b5e
## ----------------- ##
Packit 437b5e
## Standard options. ##
Packit 437b5e
## ----------------- ##
Packit 437b5e
Packit 437b5e
# The following options affect the operation of the functions defined
Packit 437b5e
# below, and should be set appropriately depending on run-time para-
Packit 437b5e
# meters passed on the command line.
Packit 437b5e
Packit 437b5e
opt_dry_run=false
Packit 437b5e
opt_quiet=false
Packit 437b5e
opt_verbose=false
Packit 437b5e
Packit 437b5e
# Categories 'all' and 'none' are always available.  Append any others
Packit 437b5e
# you will pass as the first argument to func_warning from your own
Packit 437b5e
# code.
Packit 437b5e
warning_categories=
Packit 437b5e
Packit 437b5e
# By default, display warnings according to 'opt_warning_types'.  Set
Packit 437b5e
# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
Packit 437b5e
# treat the next displayed warning as a fatal error.
Packit 437b5e
warning_func=func_warn_and_continue
Packit 437b5e
Packit 437b5e
# Set to 'all' to display all warnings, 'none' to suppress all
Packit 437b5e
# warnings, or a space delimited list of some subset of
Packit 437b5e
# 'warning_categories' to display only the listed warnings.
Packit 437b5e
opt_warning_types=all
Packit 437b5e
Packit 437b5e
Packit 437b5e
## -------------------- ##
Packit 437b5e
## Resource management. ##
Packit 437b5e
## -------------------- ##
Packit 437b5e
Packit 437b5e
# This section contains definitions for functions that each ensure a
Packit 437b5e
# particular resource (a file, or a non-empty configuration variable for
Packit 437b5e
# example) is available, and if appropriate to extract default values
Packit 437b5e
# from pertinent package files. Call them using their associated
Packit 437b5e
# 'require_*' variable to ensure that they are executed, at most, once.
Packit 437b5e
#
Packit 437b5e
# It's entirely deliberate that calling these functions can set
Packit 437b5e
# variables that don't obey the namespace limitations obeyed by the rest
Packit 437b5e
# of this file, in order that that they be as useful as possible to
Packit 437b5e
# callers.
Packit 437b5e
Packit 437b5e
Packit 437b5e
# require_term_colors
Packit 437b5e
# -------------------
Packit 437b5e
# Allow display of bold text on terminals that support it.
Packit 437b5e
require_term_colors=func_require_term_colors
Packit 437b5e
func_require_term_colors ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    test -t 1 && {
Packit 437b5e
      # COLORTERM and USE_ANSI_COLORS environment variables take
Packit 437b5e
      # precedence, because most terminfo databases neglect to describe
Packit 437b5e
      # whether color sequences are supported.
Packit 437b5e
      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
Packit 437b5e
Packit 437b5e
      if test 1 = "$USE_ANSI_COLORS"; then
Packit 437b5e
        # Standard ANSI escape sequences
Packit 437b5e
        tc_reset='?[0m'
Packit 437b5e
        tc_bold='?[1m';   tc_standout='?[7m'
Packit 437b5e
        tc_red='?[31m';   tc_green='?[32m'
Packit 437b5e
        tc_blue='?[34m';  tc_cyan='?[36m'
Packit 437b5e
      else
Packit 437b5e
        # Otherwise trust the terminfo database after all.
Packit 437b5e
        test -n "`tput sgr0 2>/dev/null`" && {
Packit 437b5e
          tc_reset=`tput sgr0`
Packit 437b5e
          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
Packit 437b5e
          tc_standout=$tc_bold
Packit 437b5e
          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
Packit 437b5e
          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
Packit 437b5e
          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
Packit 437b5e
          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
Packit 437b5e
          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
Packit 437b5e
        }
Packit 437b5e
      fi
Packit 437b5e
    }
Packit 437b5e
Packit 437b5e
    require_term_colors=:
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# require_rockspecs_req
Packit 437b5e
# ---------------------
Packit 437b5e
# Remove rockspecs from $buildreq, and add them to $rockspecs_req.
Packit 437b5e
require_rockspecs_req=slingshot_require_rockspecs_req
Packit 437b5e
slingshot_require_rockspecs_req ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    test -n "$rockspecs_req" || {
Packit 437b5e
      _G_non_rockspecs=
Packit 437b5e
Packit 437b5e
      set dummy $buildreq; shift
Packit 437b5e
Packit 437b5e
      while test $# -gt 2; do
Packit 437b5e
        case $3 in
Packit 437b5e
          *.rockspec)
Packit 437b5e
            func_append rockspecs_req " $1 $2 $3"
Packit 437b5e
            ;;
Packit 437b5e
          [a-z]*://*)
Packit 437b5e
            func_append _G_non_rockspecs " $1 $2 $3"
Packit 437b5e
            ;;
Packit 437b5e
	  *) func_fatal_error "\
Packit 437b5e
'$3' from the buildreq table in
Packit 437b5e
'bootstrap.conf' does not look like the URL for downloading
Packit 437b5e
$1. Please ensure that buildreq is a strict newline
Packit 437b5e
delimited list of triples; 'program min-version url'."
Packit 437b5e
            ;;
Packit 437b5e
        esac
Packit 437b5e
	shift; shift; shift
Packit 437b5e
      done
Packit 437b5e
Packit 437b5e
      buildreq=$_G_non_rockspecs
Packit 437b5e
    }
Packit 437b5e
Packit 437b5e
    require_rockspecs_req=:
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# require_slingshot_dotgitmodules
Packit 437b5e
# -------------------------------
Packit 437b5e
# Ensure we have a '.gitmodules' file, with appropriate 'slingshot' settings.
Packit 437b5e
require_slingshot_dotgitmodules=slingshot_require_slingshot_dotgitmodules
Packit 437b5e
slingshot_require_slingshot_dotgitmodules ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    $require_git
Packit 437b5e
Packit 437b5e
    test true = "$GIT" || {
Packit 437b5e
      # A slingshot entry in .gitmodules always takes precedence.
Packit 437b5e
      _G_path=`$GIT config --file .gitmodules submodule.slingshot.path 2>/dev/null`
Packit 437b5e
Packit 437b5e
      test -n "$_G_path" || {
Packit 437b5e
        $require_vc_ignore_files
Packit 437b5e
Packit 437b5e
        func_verbose "adding slingshot entries to '.gitmodules'"
Packit 437b5e
Packit 437b5e
        test -n "$slingshot_path" || slingshot_path=slingshot
Packit 437b5e
        test -n "$slingshot_url"  || slingshot_url=git://github.com/gvvaughan/slingshot.git
Packit 437b5e
Packit 437b5e
        {
Packit 437b5e
          echo '[submodule "slingshot"]'
Packit 437b5e
          echo "	path=$slingshot_path"
Packit 437b5e
          echo "	url=$slingshot_url"
Packit 437b5e
        } >> .gitmodules
Packit 437b5e
Packit 437b5e
        test -n "$vc_ignore_files" \
Packit 437b5e
          || func_insert_if_absent ".gitmodules" $vc_ignore_files
Packit 437b5e
      }
Packit 437b5e
    }
Packit 437b5e
Packit 437b5e
    require_slingshot_dotgitmodules=:
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# require_slingshot_path
Packit 437b5e
# require_slingshot_url
Packit 437b5e
# ----------------------
Packit 437b5e
# Ensure 'slingshot_path' and 'slingshot_url' are set.
Packit 437b5e
require_slingshot_path=slingshot_require_slingshot_dotgitmodules_parameters
Packit 437b5e
require_slingshot_url=slingshot_require_slingshot_dotgitmodules_parameters
Packit 437b5e
slingshot_require_slingshot_dotgitmodules_parameters ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    $require_git
Packit 437b5e
    $require_slingshot_dotgitmodules
Packit 437b5e
Packit 437b5e
    test -f .gitmodules \
Packit 437b5e
      || func_fatal_error "Unable to update '.gitmodules' with slingshot submodule"
Packit 437b5e
Packit 437b5e
    test true = "$GIT" || {
Packit 437b5e
      slingshot_path=`$GIT config --file=.gitmodules --get submodule.slingshot.path`
Packit 437b5e
      slingshot_url=`$GIT config --file=.gitmodules --get submodule.slingshot.url`
Packit 437b5e
Packit 437b5e
      func_verbose "slingshot_path='$slingshot_path'"
Packit 437b5e
      func_verbose "slingshot_url='$slingshot_url'"
Packit 437b5e
    }
Packit 437b5e
Packit 437b5e
    require_slingshot_path=:
Packit 437b5e
    require_slingshot_url=:
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# require_slingshot_submodule
Packit 437b5e
# ---------------------------
Packit 437b5e
# Ensure that there is a current slingshot submodule.
Packit 437b5e
require_slingshot_submodule=slingshot_require_slingshot_submodule
Packit 437b5e
slingshot_require_slingshot_submodule ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    $require_git
Packit 437b5e
Packit 437b5e
    if test true = "$GIT"; then
Packit 437b5e
      func_warning recommend \
Packit 437b5e
          "No 'git' found; imported slingshot modules may be missing."
Packit 437b5e
    else
Packit 437b5e
      $require_slingshot_dotgitmodules
Packit 437b5e
Packit 437b5e
      if test -f .gitmodules; then
Packit 437b5e
        $require_slingshot_path
Packit 437b5e
        $require_slingshot_url
Packit 437b5e
Packit 437b5e
        if test -f "slingshot/src/mkrockspecs.in"; then
Packit 437b5e
          : All present and correct.
Packit 437b5e
Packit 437b5e
        else
Packit 437b5e
          trap slingshot_cleanup 1 2 13 15
Packit 437b5e
Packit 437b5e
          shallow=
Packit 437b5e
          $GIT clone -h 2>&1 |func_grep_q -- --depth \
Packit 437b5e
              && shallow='--depth 365'
Packit 437b5e
Packit 437b5e
          func_show_eval "$GIT clone $shallow '$slingshot_url' '$slingshot_path'" \
Packit 437b5e
            slingshot_cleanup
Packit 437b5e
Packit 437b5e
          # FIXME: Solaris /bin/sh will try to execute '-' if any of
Packit 437b5e
          #        these signals are caught after this.
Packit 437b5e
          trap - 1 2 13 15
Packit 437b5e
        fi
Packit 437b5e
Packit 437b5e
        # Make sure we've checked out the correct revision of slingshot.
Packit 437b5e
        func_show_eval "$GIT submodule init -- $slingshot_path" \
Packit 437b5e
          && func_show_eval "$GIT submodule update -- $slingshot_path" \
Packit 437b5e
          || func_fatal_error "Unable to update slingshot submodule."
Packit 437b5e
      fi
Packit 437b5e
    fi
Packit 437b5e
Packit 437b5e
    require_slingshot_submodule=:
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# require_bootstrap_uptodate
Packit 437b5e
# --------------------------
Packit 437b5e
# Complain if the version of bootstrap in the build-aux directory differs
Packit 437b5e
# from the one we are running.
Packit 437b5e
require_bootstrap_uptodate=slingshot_require_bootstrap_uptodate
Packit 437b5e
slingshot_require_bootstrap_uptodate ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    $require_slingshot_submodule
Packit 437b5e
Packit 437b5e
    _G_slingshot_bootstrap=slingshot/bootstrap
Packit 437b5e
Packit 437b5e
    rm -f $progname.new
Packit 437b5e
Packit 437b5e
    if test -f "$_G_slingshot_bootstrap"; then
Packit 437b5e
      if func_cmp_s "$progpath" "$_G_slingshot_bootstrap"; then
Packit 437b5e
	func_verbose "bootstrap script up to date"
Packit 437b5e
      else
Packit 437b5e
        cp -f $_G_slingshot_bootstrap $progname.new
Packit 437b5e
        func_warning upgrade "\
Packit 437b5e
An updated slingshot bootstrap script is ready for you in
Packit 437b5e
'$progname.new'.  After you've verified that you want the
Packit 437b5e
changes, you can update with:
Packit 437b5e
    mv -f $progname.new $progname
Packit 437b5e
    ./$progname
Packit 437b5e
Packit 437b5e
Or you can disable this check permanently by adding the
Packit 437b5e
following to 'bootstrap.conf':
Packit 437b5e
    require_bootstrap_uptodate=:"
Packit 437b5e
      fi
Packit 437b5e
    else
Packit 437b5e
      func_warning upgrade "\
Packit 437b5e
Your slingshot submodule appears to be damagedi, so I can't tell
Packit 437b5e
whether your bootstrap has gone out of sync.  Please check for
Packit 437b5e
and undo any local changes, or revert to the slingshot revision
Packit 437b5e
you were using previously, and rerun this script."
Packit 437b5e
    fi
Packit 437b5e
Packit 437b5e
    require_bootstrap_uptodate=:
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# slingshot_cleanup
Packit 437b5e
# -----------------
Packit 437b5e
# Recursively delete everything at $slingshot_path.
Packit 437b5e
slingshot_cleanup ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    $require_slingshot_path
Packit 437b5e
Packit 437b5e
    _G_status=$?
Packit 437b5e
    $RM -fr $slingshot_path
Packit 437b5e
    exit $_G_status
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
## ----------------- ##
Packit 437b5e
## Function library. ##
Packit 437b5e
## ----------------- ##
Packit 437b5e
Packit 437b5e
# This section contains a variety of useful functions to call in your
Packit 437b5e
# scripts. Take note of the portable wrappers for features provided by
Packit 437b5e
# some modern shells, which will fall back to slower equivalents on
Packit 437b5e
# less featureful shells.
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_append VAR VALUE
Packit 437b5e
# ---------------------
Packit 437b5e
# Append VALUE onto the existing contents of VAR.
Packit 437b5e
Packit 437b5e
  # We should try to minimise forks, especially on Windows where they are
Packit 437b5e
  # unreasonably slow, so skip the feature probes when bash or zsh are
Packit 437b5e
  # being used:
Packit 437b5e
  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
Packit 437b5e
    : ${_G_HAVE_ARITH_OP="yes"}
Packit 437b5e
    : ${_G_HAVE_XSI_OPS="yes"}
Packit 437b5e
    # The += operator was introduced in bash 3.1
Packit 437b5e
    case $BASH_VERSION in
Packit 437b5e
      [12].* | 3.0 | 3.0*) ;;
Packit 437b5e
      *)
Packit 437b5e
        : ${_G_HAVE_PLUSEQ_OP="yes"}
Packit 437b5e
        ;;
Packit 437b5e
    esac
Packit 437b5e
  fi
Packit 437b5e
Packit 437b5e
  # _G_HAVE_PLUSEQ_OP
Packit 437b5e
  # Can be empty, in which case the shell is probed, "yes" if += is
Packit 437b5e
  # useable or anything else if it does not work.
Packit 437b5e
  test -z "$_G_HAVE_PLUSEQ_OP" \
Packit 437b5e
    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
Packit 437b5e
    && _G_HAVE_PLUSEQ_OP=yes
Packit 437b5e
Packit 437b5e
if test yes = "$_G_HAVE_PLUSEQ_OP"
Packit 437b5e
then
Packit 437b5e
  # This is an XSI compatible shell, allowing a faster implementation...
Packit 437b5e
  eval 'func_append ()
Packit 437b5e
  {
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    eval "$1+=\$2"
Packit 437b5e
  }'
Packit 437b5e
else
Packit 437b5e
  # ...otherwise fall back to using expr, which is often a shell builtin.
Packit 437b5e
  func_append ()
Packit 437b5e
  {
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    eval "$1=\$$1\$2"
Packit 437b5e
  }
Packit 437b5e
fi
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_append_quoted VAR VALUE
Packit 437b5e
# ----------------------------
Packit 437b5e
# Quote VALUE and append to the end of shell variable VAR, separated
Packit 437b5e
# by a space.
Packit 437b5e
if test yes = "$_G_HAVE_PLUSEQ_OP"; then
Packit 437b5e
  eval 'func_append_quoted ()
Packit 437b5e
  {
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    func_quote_for_eval "$2"
Packit 437b5e
    eval "$1+=\\ \$func_quote_for_eval_result"
Packit 437b5e
  }'
Packit 437b5e
else
Packit 437b5e
  func_append_quoted ()
Packit 437b5e
  {
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    func_quote_for_eval "$2"
Packit 437b5e
    eval "$1=\$$1\\ \$func_quote_for_eval_result"
Packit 437b5e
  }
Packit 437b5e
fi
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_append_uniq VAR VALUE
Packit 437b5e
# --------------------------
Packit 437b5e
# Append unique VALUE onto the existing contents of VAR, assuming
Packit 437b5e
# entries are delimited by the first character of VALUE.  For example:
Packit 437b5e
#
Packit 437b5e
#   func_append_uniq options " --another-option option-argument"
Packit 437b5e
#
Packit 437b5e
# will only append to $options if " --another-option option-argument "
Packit 437b5e
# is not already present somewhere in $options already (note spaces at
Packit 437b5e
# each end implied by leading space in second argument).
Packit 437b5e
func_append_uniq ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    eval _G_current_value='`$ECHO $'$1'`'
Packit 437b5e
    _G_delim=`expr "$2" : '\(.\)'`
Packit 437b5e
Packit 437b5e
    case $_G_delim$_G_current_value$_G_delim in
Packit 437b5e
      *"$2$_G_delim"*) ;;
Packit 437b5e
      *) func_append "$@" ;;
Packit 437b5e
    esac
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_arith TERM...
Packit 437b5e
# ------------------
Packit 437b5e
# Set func_arith_result to the result of evaluating TERMs.
Packit 437b5e
  test -z "$_G_HAVE_ARITH_OP" \
Packit 437b5e
    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
Packit 437b5e
    && _G_HAVE_ARITH_OP=yes
Packit 437b5e
Packit 437b5e
if test yes = "$_G_HAVE_ARITH_OP"; then
Packit 437b5e
  eval 'func_arith ()
Packit 437b5e
  {
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    func_arith_result=$(( $* ))
Packit 437b5e
  }'
Packit 437b5e
else
Packit 437b5e
  func_arith ()
Packit 437b5e
  {
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    func_arith_result=`expr "$@"`
Packit 437b5e
  }
Packit 437b5e
fi
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_basename FILE
Packit 437b5e
# ------------------
Packit 437b5e
# Set func_basename_result to FILE with everything up to and including
Packit 437b5e
# the last / stripped.
Packit 437b5e
if test yes = "$_G_HAVE_XSI_OPS"; then
Packit 437b5e
  # If this shell supports suffix pattern removal, then use it to avoid
Packit 437b5e
  # forking. Hide the definitions single quotes in case the shell chokes
Packit 437b5e
  # on unsupported syntax...
Packit 437b5e
  _b='func_basename_result=${1##*/}'
Packit 437b5e
  _d='case $1 in
Packit 437b5e
        */*) func_dirname_result=${1%/*}$2 ;;
Packit 437b5e
        *  ) func_dirname_result=$3        ;;
Packit 437b5e
      esac'
Packit 437b5e
Packit 437b5e
else
Packit 437b5e
  # ...otherwise fall back to using sed.
Packit 437b5e
  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
Packit 437b5e
  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
Packit 437b5e
      if test "X$func_dirname_result" = "X$1"; then
Packit 437b5e
        func_dirname_result=$3
Packit 437b5e
      else
Packit 437b5e
        func_append func_dirname_result "$2"
Packit 437b5e
      fi'
Packit 437b5e
fi
Packit 437b5e
Packit 437b5e
eval 'func_basename ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    '"$_b"'
Packit 437b5e
}'
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_dirname FILE APPEND NONDIR_REPLACEMENT
Packit 437b5e
# -------------------------------------------
Packit 437b5e
# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
Packit 437b5e
# otherwise set result to NONDIR_REPLACEMENT.
Packit 437b5e
eval 'func_dirname ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    '"$_d"'
Packit 437b5e
}'
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
Packit 437b5e
# --------------------------------------------------------
Packit 437b5e
# Perform func_basename and func_dirname in a single function
Packit 437b5e
# call:
Packit 437b5e
#   dirname:  Compute the dirname of FILE.  If nonempty,
Packit 437b5e
#             add APPEND to the result, otherwise set result
Packit 437b5e
#             to NONDIR_REPLACEMENT.
Packit 437b5e
#             value returned in "$func_dirname_result"
Packit 437b5e
#   basename: Compute filename of FILE.
Packit 437b5e
#             value retuned in "$func_basename_result"
Packit 437b5e
# For efficiency, we do not delegate to the functions above but instead
Packit 437b5e
# duplicate the functionality here.
Packit 437b5e
eval 'func_dirname_and_basename ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    '"$_b"'
Packit 437b5e
    '"$_d"'
Packit 437b5e
}'
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_echo ARG...
Packit 437b5e
# ----------------
Packit 437b5e
# Echo program name prefixed message.
Packit 437b5e
func_echo ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    _G_message=$*
Packit 437b5e
Packit 437b5e
    func_echo_IFS=$IFS
Packit 437b5e
    IFS=$nl
Packit 437b5e
    for _G_line in $_G_message; do
Packit 437b5e
      IFS=$func_echo_IFS
Packit 437b5e
      $ECHO "$progname: $_G_line"
Packit 437b5e
    done
Packit 437b5e
    IFS=$func_echo_IFS
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_echo_all ARG...
Packit 437b5e
# --------------------
Packit 437b5e
# Invoke $ECHO with all args, space-separated.
Packit 437b5e
func_echo_all ()
Packit 437b5e
{
Packit 437b5e
    $ECHO "$*"
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_echo_infix_1 INFIX ARG...
Packit 437b5e
# ------------------------------
Packit 437b5e
# Echo program name, followed by INFIX on the first line, with any
Packit 437b5e
# additional lines not showing INFIX.
Packit 437b5e
func_echo_infix_1 ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    $require_term_colors
Packit 437b5e
Packit 437b5e
    _G_infix=$1; shift
Packit 437b5e
    _G_indent=$_G_infix
Packit 437b5e
    _G_prefix="$progname: $_G_infix: "
Packit 437b5e
    _G_message=$*
Packit 437b5e
Packit 437b5e
    # Strip color escape sequences before counting printable length
Packit 437b5e
    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
Packit 437b5e
    do
Packit 437b5e
      test -n "$_G_tc" && {
Packit 437b5e
        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
Packit 437b5e
        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
Packit 437b5e
      }
Packit 437b5e
    done
Packit 437b5e
    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
Packit 437b5e
Packit 437b5e
    func_echo_infix_1_IFS=$IFS
Packit 437b5e
    IFS=$nl
Packit 437b5e
    for _G_line in $_G_message; do
Packit 437b5e
      IFS=$func_echo_infix_1_IFS
Packit 437b5e
      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
Packit 437b5e
      _G_prefix=$_G_indent
Packit 437b5e
    done
Packit 437b5e
    IFS=$func_echo_infix_1_IFS
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_error ARG...
Packit 437b5e
# -----------------
Packit 437b5e
# Echo program name prefixed message to standard error.
Packit 437b5e
func_error ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    $require_term_colors
Packit 437b5e
Packit 437b5e
    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_fatal_error ARG...
Packit 437b5e
# -----------------------
Packit 437b5e
# Echo program name prefixed message to standard error, and exit.
Packit 437b5e
func_fatal_error ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    func_error "$*"
Packit 437b5e
    exit $EXIT_FAILURE
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_grep EXPRESSION FILENAME
Packit 437b5e
# -----------------------------
Packit 437b5e
# Check whether EXPRESSION matches any line of FILENAME, without output.
Packit 437b5e
func_grep ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    $GREP "$1" "$2" >/dev/null 2>&1
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_len STRING
Packit 437b5e
# ---------------
Packit 437b5e
# Set func_len_result to the length of STRING. STRING may not
Packit 437b5e
# start with a hyphen.
Packit 437b5e
  test -z "$_G_HAVE_XSI_OPS" \
Packit 437b5e
    && (eval 'x=a/b/c;
Packit 437b5e
      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
Packit 437b5e
    && _G_HAVE_XSI_OPS=yes
Packit 437b5e
Packit 437b5e
if test yes = "$_G_HAVE_XSI_OPS"; then
Packit 437b5e
  eval 'func_len ()
Packit 437b5e
  {
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    func_len_result=${#1}
Packit 437b5e
  }'
Packit 437b5e
else
Packit 437b5e
  func_len ()
Packit 437b5e
  {
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
Packit 437b5e
  }
Packit 437b5e
fi
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_mkdir_p DIRECTORY-PATH
Packit 437b5e
# ---------------------------
Packit 437b5e
# Make sure the entire path to DIRECTORY-PATH is available.
Packit 437b5e
func_mkdir_p ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    _G_directory_path=$1
Packit 437b5e
    _G_dir_list=
Packit 437b5e
Packit 437b5e
    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
Packit 437b5e
Packit 437b5e
      # Protect directory names starting with '-'
Packit 437b5e
      case $_G_directory_path in
Packit 437b5e
        -*) _G_directory_path=./$_G_directory_path ;;
Packit 437b5e
      esac
Packit 437b5e
Packit 437b5e
      # While some portion of DIR does not yet exist...
Packit 437b5e
      while test ! -d "$_G_directory_path"; do
Packit 437b5e
        # ...make a list in topmost first order.  Use a colon delimited
Packit 437b5e
	# list incase some portion of path contains whitespace.
Packit 437b5e
        _G_dir_list=$_G_directory_path:$_G_dir_list
Packit 437b5e
Packit 437b5e
        # If the last portion added has no slash in it, the list is done
Packit 437b5e
        case $_G_directory_path in */*) ;; *) break ;; esac
Packit 437b5e
Packit 437b5e
        # ...otherwise throw away the child directory and loop
Packit 437b5e
        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
Packit 437b5e
      done
Packit 437b5e
      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
Packit 437b5e
Packit 437b5e
      func_mkdir_p_IFS=$IFS; IFS=:
Packit 437b5e
      for _G_dir in $_G_dir_list; do
Packit 437b5e
	IFS=$func_mkdir_p_IFS
Packit 437b5e
        # mkdir can fail with a 'File exist' error if two processes
Packit 437b5e
        # try to create one of the directories concurrently.  Don't
Packit 437b5e
        # stop in that case!
Packit 437b5e
        $MKDIR "$_G_dir" 2>/dev/null || :
Packit 437b5e
      done
Packit 437b5e
      IFS=$func_mkdir_p_IFS
Packit 437b5e
Packit 437b5e
      # Bail out if we (or some other process) failed to create a directory.
Packit 437b5e
      test -d "$_G_directory_path" || \
Packit 437b5e
        func_fatal_error "Failed to create '$1'"
Packit 437b5e
    fi
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_mktempdir [BASENAME]
Packit 437b5e
# -------------------------
Packit 437b5e
# Make a temporary directory that won't clash with other running
Packit 437b5e
# libtool processes, and avoids race conditions if possible.  If
Packit 437b5e
# given, BASENAME is the basename for that directory.
Packit 437b5e
func_mktempdir ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    _G_template=${TMPDIR-/tmp}/${1-$progname}
Packit 437b5e
Packit 437b5e
    if test : = "$opt_dry_run"; then
Packit 437b5e
      # Return a directory name, but don't create it in dry-run mode
Packit 437b5e
      _G_tmpdir=$_G_template-$$
Packit 437b5e
    else
Packit 437b5e
Packit 437b5e
      # If mktemp works, use that first and foremost
Packit 437b5e
      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
Packit 437b5e
Packit 437b5e
      if test ! -d "$_G_tmpdir"; then
Packit 437b5e
        # Failing that, at least try and use $RANDOM to avoid a race
Packit 437b5e
        _G_tmpdir=$_G_template-${RANDOM-0}$$
Packit 437b5e
Packit 437b5e
        func_mktempdir_umask=`umask`
Packit 437b5e
        umask 0077
Packit 437b5e
        $MKDIR "$_G_tmpdir"
Packit 437b5e
        umask $func_mktempdir_umask
Packit 437b5e
      fi
Packit 437b5e
Packit 437b5e
      # If we're not in dry-run mode, bomb out on failure
Packit 437b5e
      test -d "$_G_tmpdir" || \
Packit 437b5e
        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
Packit 437b5e
    fi
Packit 437b5e
Packit 437b5e
    $ECHO "$_G_tmpdir"
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_normal_abspath PATH
Packit 437b5e
# ------------------------
Packit 437b5e
# Remove doubled-up and trailing slashes, "." path components,
Packit 437b5e
# and cancel out any ".." path components in PATH after making
Packit 437b5e
# it an absolute path.
Packit 437b5e
func_normal_abspath ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    # These SED scripts presuppose an absolute path with a trailing slash.
Packit 437b5e
    _G_pathcar='s|^/\([^/]*\).*$|\1|'
Packit 437b5e
    _G_pathcdr='s|^/[^/]*||'
Packit 437b5e
    _G_removedotparts=':dotsl
Packit 437b5e
		s|/\./|/|g
Packit 437b5e
		t dotsl
Packit 437b5e
		s|/\.$|/|'
Packit 437b5e
    _G_collapseslashes='s|/\{1,\}|/|g'
Packit 437b5e
    _G_finalslash='s|/*$|/|'
Packit 437b5e
Packit 437b5e
    # Start from root dir and reassemble the path.
Packit 437b5e
    func_normal_abspath_result=
Packit 437b5e
    func_normal_abspath_tpath=$1
Packit 437b5e
    func_normal_abspath_altnamespace=
Packit 437b5e
    case $func_normal_abspath_tpath in
Packit 437b5e
      "")
Packit 437b5e
        # Empty path, that just means $cwd.
Packit 437b5e
        func_stripname '' '/' "`pwd`"
Packit 437b5e
        func_normal_abspath_result=$func_stripname_result
Packit 437b5e
        return
Packit 437b5e
        ;;
Packit 437b5e
      # The next three entries are used to spot a run of precisely
Packit 437b5e
      # two leading slashes without using negated character classes;
Packit 437b5e
      # we take advantage of case's first-match behaviour.
Packit 437b5e
      ///*)
Packit 437b5e
        # Unusual form of absolute path, do nothing.
Packit 437b5e
        ;;
Packit 437b5e
      //*)
Packit 437b5e
        # Not necessarily an ordinary path; POSIX reserves leading '//'
Packit 437b5e
        # and for example Cygwin uses it to access remote file shares
Packit 437b5e
        # over CIFS/SMB, so we conserve a leading double slash if found.
Packit 437b5e
        func_normal_abspath_altnamespace=/
Packit 437b5e
        ;;
Packit 437b5e
      /*)
Packit 437b5e
        # Absolute path, do nothing.
Packit 437b5e
        ;;
Packit 437b5e
      *)
Packit 437b5e
        # Relative path, prepend $cwd.
Packit 437b5e
        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
Packit 437b5e
        ;;
Packit 437b5e
    esac
Packit 437b5e
Packit 437b5e
    # Cancel out all the simple stuff to save iterations.  We also want
Packit 437b5e
    # the path to end with a slash for ease of parsing, so make sure
Packit 437b5e
    # there is one (and only one) here.
Packit 437b5e
    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
Packit 437b5e
          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
Packit 437b5e
    while :; do
Packit 437b5e
      # Processed it all yet?
Packit 437b5e
      if test / = "$func_normal_abspath_tpath"; then
Packit 437b5e
        # If we ascended to the root using ".." the result may be empty now.
Packit 437b5e
        if test -z "$func_normal_abspath_result"; then
Packit 437b5e
          func_normal_abspath_result=/
Packit 437b5e
        fi
Packit 437b5e
        break
Packit 437b5e
      fi
Packit 437b5e
      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
Packit 437b5e
          -e "$_G_pathcar"`
Packit 437b5e
      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
Packit 437b5e
          -e "$_G_pathcdr"`
Packit 437b5e
      # Figure out what to do with it
Packit 437b5e
      case $func_normal_abspath_tcomponent in
Packit 437b5e
        "")
Packit 437b5e
          # Trailing empty path component, ignore it.
Packit 437b5e
          ;;
Packit 437b5e
        ..)
Packit 437b5e
          # Parent dir; strip last assembled component from result.
Packit 437b5e
          func_dirname "$func_normal_abspath_result"
Packit 437b5e
          func_normal_abspath_result=$func_dirname_result
Packit 437b5e
          ;;
Packit 437b5e
        *)
Packit 437b5e
          # Actual path component, append it.
Packit 437b5e
          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
Packit 437b5e
          ;;
Packit 437b5e
      esac
Packit 437b5e
    done
Packit 437b5e
    # Restore leading double-slash if one was found on entry.
Packit 437b5e
    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_notquiet ARG...
Packit 437b5e
# --------------------
Packit 437b5e
# Echo program name prefixed message only when not in quiet mode.
Packit 437b5e
func_notquiet ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    $opt_quiet || func_echo ${1+"$@"}
Packit 437b5e
Packit 437b5e
    # A bug in bash halts the script if the last line of a function
Packit 437b5e
    # fails when set -e is in force, so we need another command to
Packit 437b5e
    # work around that:
Packit 437b5e
    :
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_relative_path SRCDIR DSTDIR
Packit 437b5e
# --------------------------------
Packit 437b5e
# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
Packit 437b5e
func_relative_path ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    func_relative_path_result=
Packit 437b5e
    func_normal_abspath "$1"
Packit 437b5e
    func_relative_path_tlibdir=$func_normal_abspath_result
Packit 437b5e
    func_normal_abspath "$2"
Packit 437b5e
    func_relative_path_tbindir=$func_normal_abspath_result
Packit 437b5e
Packit 437b5e
    # Ascend the tree starting from libdir
Packit 437b5e
    while :; do
Packit 437b5e
      # check if we have found a prefix of bindir
Packit 437b5e
      case $func_relative_path_tbindir in
Packit 437b5e
        $func_relative_path_tlibdir)
Packit 437b5e
          # found an exact match
Packit 437b5e
          func_relative_path_tcancelled=
Packit 437b5e
          break
Packit 437b5e
          ;;
Packit 437b5e
        $func_relative_path_tlibdir*)
Packit 437b5e
          # found a matching prefix
Packit 437b5e
          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
Packit 437b5e
          func_relative_path_tcancelled=$func_stripname_result
Packit 437b5e
          if test -z "$func_relative_path_result"; then
Packit 437b5e
            func_relative_path_result=.
Packit 437b5e
          fi
Packit 437b5e
          break
Packit 437b5e
          ;;
Packit 437b5e
        *)
Packit 437b5e
          func_dirname $func_relative_path_tlibdir
Packit 437b5e
          func_relative_path_tlibdir=$func_dirname_result
Packit 437b5e
          if test -z "$func_relative_path_tlibdir"; then
Packit 437b5e
            # Have to descend all the way to the root!
Packit 437b5e
            func_relative_path_result=../$func_relative_path_result
Packit 437b5e
            func_relative_path_tcancelled=$func_relative_path_tbindir
Packit 437b5e
            break
Packit 437b5e
          fi
Packit 437b5e
          func_relative_path_result=../$func_relative_path_result
Packit 437b5e
          ;;
Packit 437b5e
      esac
Packit 437b5e
    done
Packit 437b5e
Packit 437b5e
    # Now calculate path; take care to avoid doubling-up slashes.
Packit 437b5e
    func_stripname '' '/' "$func_relative_path_result"
Packit 437b5e
    func_relative_path_result=$func_stripname_result
Packit 437b5e
    func_stripname '/' '/' "$func_relative_path_tcancelled"
Packit 437b5e
    if test -n "$func_stripname_result"; then
Packit 437b5e
      func_append func_relative_path_result "/$func_stripname_result"
Packit 437b5e
    fi
Packit 437b5e
Packit 437b5e
    # Normalisation. If bindir is libdir, return '.' else relative path.
Packit 437b5e
    if test -n "$func_relative_path_result"; then
Packit 437b5e
      func_stripname './' '' "$func_relative_path_result"
Packit 437b5e
      func_relative_path_result=$func_stripname_result
Packit 437b5e
    fi
Packit 437b5e
Packit 437b5e
    test -n "$func_relative_path_result" || func_relative_path_result=.
Packit 437b5e
Packit 437b5e
    :
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_quote_for_eval ARG...
Packit 437b5e
# --------------------------
Packit 437b5e
# Aesthetically quote ARGs to be evaled later.
Packit 437b5e
# This function returns two values:
Packit 437b5e
#   i) func_quote_for_eval_result
Packit 437b5e
#      double-quoted, suitable for a subsequent eval
Packit 437b5e
#  ii) func_quote_for_eval_unquoted_result
Packit 437b5e
#      has all characters that are still active within double
Packit 437b5e
#      quotes backslashified.
Packit 437b5e
func_quote_for_eval ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    func_quote_for_eval_unquoted_result=
Packit 437b5e
    func_quote_for_eval_result=
Packit 437b5e
    while test 0 -lt $#; do
Packit 437b5e
      case $1 in
Packit 437b5e
        *[\\\`\"\$]*)
Packit 437b5e
	  _G_unquoted_arg=`printf '%s\n' "$1" |$SED "$sed_quote_subst"` ;;
Packit 437b5e
        *)
Packit 437b5e
          _G_unquoted_arg=$1 ;;
Packit 437b5e
      esac
Packit 437b5e
      if test -n "$func_quote_for_eval_unquoted_result"; then
Packit 437b5e
	func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg"
Packit 437b5e
      else
Packit 437b5e
        func_append func_quote_for_eval_unquoted_result "$_G_unquoted_arg"
Packit 437b5e
      fi
Packit 437b5e
Packit 437b5e
      case $_G_unquoted_arg in
Packit 437b5e
        # Double-quote args containing shell metacharacters to delay
Packit 437b5e
        # word splitting, command substitution and variable expansion
Packit 437b5e
        # for a subsequent eval.
Packit 437b5e
        # Many Bourne shells cannot handle close brackets correctly
Packit 437b5e
        # in scan sets, so we specify it separately.
Packit 437b5e
        *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
Packit 437b5e
          _G_quoted_arg=\"$_G_unquoted_arg\"
Packit 437b5e
          ;;
Packit 437b5e
        *)
Packit 437b5e
          _G_quoted_arg=$_G_unquoted_arg
Packit 437b5e
	  ;;
Packit 437b5e
      esac
Packit 437b5e
Packit 437b5e
      if test -n "$func_quote_for_eval_result"; then
Packit 437b5e
	func_append func_quote_for_eval_result " $_G_quoted_arg"
Packit 437b5e
      else
Packit 437b5e
        func_append func_quote_for_eval_result "$_G_quoted_arg"
Packit 437b5e
      fi
Packit 437b5e
      shift
Packit 437b5e
    done
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_quote_for_expand ARG
Packit 437b5e
# -------------------------
Packit 437b5e
# Aesthetically quote ARG to be evaled later; same as above,
Packit 437b5e
# but do not quote variable references.
Packit 437b5e
func_quote_for_expand ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    case $1 in
Packit 437b5e
      *[\\\`\"]*)
Packit 437b5e
	_G_arg=`$ECHO "$1" | $SED \
Packit 437b5e
	    -e "$sed_double_quote_subst" -e "$sed_double_backslash"` ;;
Packit 437b5e
      *)
Packit 437b5e
        _G_arg=$1 ;;
Packit 437b5e
    esac
Packit 437b5e
Packit 437b5e
    case $_G_arg in
Packit 437b5e
      # Double-quote args containing shell metacharacters to delay
Packit 437b5e
      # word splitting and command substitution for a subsequent eval.
Packit 437b5e
      # Many Bourne shells cannot handle close brackets correctly
Packit 437b5e
      # in scan sets, so we specify it separately.
Packit 437b5e
      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
Packit 437b5e
        _G_arg=\"$_G_arg\"
Packit 437b5e
        ;;
Packit 437b5e
    esac
Packit 437b5e
Packit 437b5e
    func_quote_for_expand_result=$_G_arg
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_stripname PREFIX SUFFIX NAME
Packit 437b5e
# ---------------------------------
Packit 437b5e
# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
Packit 437b5e
# PREFIX and SUFFIX must not contain globbing or regex special
Packit 437b5e
# characters, hashes, percent signs, but SUFFIX may contain a leading
Packit 437b5e
# dot (in which case that matches only a dot).
Packit 437b5e
if test yes = "$_G_HAVE_XSI_OPS"; then
Packit 437b5e
  eval 'func_stripname ()
Packit 437b5e
  {
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
Packit 437b5e
    # positional parameters, so assign one to ordinary variable first.
Packit 437b5e
    func_stripname_result=$3
Packit 437b5e
    func_stripname_result=${func_stripname_result#"$1"}
Packit 437b5e
    func_stripname_result=${func_stripname_result%"$2"}
Packit 437b5e
  }'
Packit 437b5e
else
Packit 437b5e
  func_stripname ()
Packit 437b5e
  {
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    case $2 in
Packit 437b5e
      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
Packit 437b5e
      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
Packit 437b5e
    esac
Packit 437b5e
  }
Packit 437b5e
fi
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_show_eval CMD [FAIL_EXP]
Packit 437b5e
# -----------------------------
Packit 437b5e
# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
Packit 437b5e
# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
Packit 437b5e
# is given, then evaluate it.
Packit 437b5e
func_show_eval ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    _G_cmd=$1
Packit 437b5e
    _G_fail_exp=${2-':'}
Packit 437b5e
Packit 437b5e
    func_quote_for_expand "$_G_cmd"
Packit 437b5e
    eval "func_notquiet $func_quote_for_expand_result"
Packit 437b5e
Packit 437b5e
    $opt_dry_run || {
Packit 437b5e
      eval "$_G_cmd"
Packit 437b5e
      _G_status=$?
Packit 437b5e
      if test 0 -ne "$_G_status"; then
Packit 437b5e
	eval "(exit $_G_status); $_G_fail_exp"
Packit 437b5e
      fi
Packit 437b5e
    }
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_show_eval_locale CMD [FAIL_EXP]
Packit 437b5e
# ------------------------------------
Packit 437b5e
# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
Packit 437b5e
# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
Packit 437b5e
# is given, then evaluate it.  Use the saved locale for evaluation.
Packit 437b5e
func_show_eval_locale ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    _G_cmd=$1
Packit 437b5e
    _G_fail_exp=${2-':'}
Packit 437b5e
Packit 437b5e
    $opt_quiet || {
Packit 437b5e
      func_quote_for_expand "$_G_cmd"
Packit 437b5e
      eval "func_echo $func_quote_for_expand_result"
Packit 437b5e
    }
Packit 437b5e
Packit 437b5e
    $opt_dry_run || {
Packit 437b5e
      eval "$_G_user_locale
Packit 437b5e
	    $_G_cmd"
Packit 437b5e
      _G_status=$?
Packit 437b5e
      eval "$_G_safe_locale"
Packit 437b5e
      if test 0 -ne "$_G_status"; then
Packit 437b5e
	eval "(exit $_G_status); $_G_fail_exp"
Packit 437b5e
      fi
Packit 437b5e
    }
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_tr_sh
Packit 437b5e
# ----------
Packit 437b5e
# Turn $1 into a string suitable for a shell variable name.
Packit 437b5e
# Result is stored in $func_tr_sh_result.  All characters
Packit 437b5e
# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
Packit 437b5e
# if $1 begins with a digit, a '_' is prepended as well.
Packit 437b5e
func_tr_sh ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    case $1 in
Packit 437b5e
    [0-9]* | *[!a-zA-Z0-9_]*)
Packit 437b5e
      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
Packit 437b5e
      ;;
Packit 437b5e
    * )
Packit 437b5e
      func_tr_sh_result=$1
Packit 437b5e
      ;;
Packit 437b5e
    esac
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_verbose ARG...
Packit 437b5e
# -------------------
Packit 437b5e
# Echo program name prefixed message in verbose mode only.
Packit 437b5e
func_verbose ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    $opt_verbose && func_echo "$*"
Packit 437b5e
Packit 437b5e
    :
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_warn_and_continue ARG...
Packit 437b5e
# -----------------------------
Packit 437b5e
# Echo program name prefixed warning message to standard error.
Packit 437b5e
func_warn_and_continue ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    $require_term_colors
Packit 437b5e
Packit 437b5e
    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_warning CATEGORY ARG...
Packit 437b5e
# ----------------------------
Packit 437b5e
# Echo program name prefixed warning message to standard error. Warning
Packit 437b5e
# messages can be filtered according to CATEGORY, where this function
Packit 437b5e
# elides messages where CATEGORY is not listed in the global variable
Packit 437b5e
# 'opt_warning_types'.
Packit 437b5e
func_warning ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    # CATEGORY must be in the warning_categories list!
Packit 437b5e
    case " $warning_categories " in
Packit 437b5e
      *" $1 "*) ;;
Packit 437b5e
      *) func_internal_error "invalid warning category '$1'" ;;
Packit 437b5e
    esac
Packit 437b5e
Packit 437b5e
    _G_category=$1
Packit 437b5e
    shift
Packit 437b5e
Packit 437b5e
    case " $opt_warning_types " in
Packit 437b5e
      *" $_G_category "*) $warning_func ${1+"$@"} ;;
Packit 437b5e
    esac
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_sort_ver VER1 VER2
Packit 437b5e
# -----------------------
Packit 437b5e
# 'sort -V' is not generally available.
Packit 437b5e
# Note this deviates from the version comparison in automake
Packit 437b5e
# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
Packit 437b5e
# but this should suffice as we won't be specifying old
Packit 437b5e
# version formats or redundant trailing .0 in bootstrap.conf.
Packit 437b5e
# If we did want full compatibility then we should probably
Packit 437b5e
# use m4_version_compare from autoconf.
Packit 437b5e
func_sort_ver ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    printf '%s\n%s\n' "$1" "$2" \
Packit 437b5e
      | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n -k 5,5n -k 6,6n -k 7,7n -k 8,8n -k 9,9n
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
# func_lt_ver PREV CURR
Packit 437b5e
# ---------------------
Packit 437b5e
# Return true if PREV and CURR are in the correct order according to
Packit 437b5e
# func_sort_ver, otherwise false.  Use it like this:
Packit 437b5e
#
Packit 437b5e
#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
Packit 437b5e
func_lt_ver ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# Local variables:
Packit 437b5e
# mode: shell-script
Packit 437b5e
# sh-indentation: 2
Packit 437b5e
# eval: (add-hook 'before-save-hook 'time-stamp)
Packit 437b5e
# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
Packit 437b5e
# time-stamp-time-zone: "UTC"
Packit 437b5e
# End:
Packit 437b5e
#! /bin/sh
Packit 437b5e
Packit 437b5e
# Set a version string for this script.
Packit 437b5e
scriptversion=2014-01-07.03; # UTC
Packit 437b5e
Packit 437b5e
# A portable, pluggable option parser for Bourne shell.
Packit 437b5e
# Written by Gary V. Vaughan, 2010
Packit 437b5e
Packit 437b5e
# Copyright (C) 2010-2014 Free Software Foundation, Inc.
Packit 437b5e
# This is free software; see the source for copying conditions.  There is NO
Packit 437b5e
# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Packit 437b5e
Packit 437b5e
# This program is free software: you can redistribute it and/or modify
Packit 437b5e
# it under the terms of the GNU General Public License as published by
Packit 437b5e
# the Free Software Foundation, either version 3 of the License, or
Packit 437b5e
# (at your option) any later version.
Packit 437b5e
Packit 437b5e
# This program is distributed in the hope that it will be useful,
Packit 437b5e
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 437b5e
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 437b5e
# GNU General Public License for more details.
Packit 437b5e
Packit 437b5e
# You should have received a copy of the GNU General Public License
Packit 437b5e
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 437b5e
Packit 437b5e
# Please report bugs or propose patches to gary@gnu.org.
Packit 437b5e
Packit 437b5e
Packit 437b5e
## ------ ##
Packit 437b5e
## Usage. ##
Packit 437b5e
## ------ ##
Packit 437b5e
Packit 437b5e
# This file is a library for parsing options in your shell scripts along
Packit 437b5e
# with assorted other useful supporting features that you can make use
Packit 437b5e
# of too.
Packit 437b5e
#
Packit 437b5e
# For the simplest scripts you might need only:
Packit 437b5e
#
Packit 437b5e
#   #!/bin/sh
Packit 437b5e
#   . relative/path/to/funclib.sh
Packit 437b5e
#   . relative/path/to/options-parser
Packit 437b5e
#   scriptversion=1.0
Packit 437b5e
#   func_options ${1+"$@"}
Packit 437b5e
#   eval set dummy "$func_options_result"; shift
Packit 437b5e
#   ...rest of your script...
Packit 437b5e
#
Packit 437b5e
# In order for the '--version' option to work, you will need to have a
Packit 437b5e
# suitably formatted comment like the one at the top of this file
Packit 437b5e
# starting with '# Written by ' and ending with '# warranty; '.
Packit 437b5e
#
Packit 437b5e
# For '-h' and '--help' to work, you will also need a one line
Packit 437b5e
# description of your script's purpose in a comment directly above the
Packit 437b5e
# '# Written by ' line, like the one at the top of this file.
Packit 437b5e
#
Packit 437b5e
# The default options also support '--debug', which will turn on shell
Packit 437b5e
# execution tracing (see the comment above debug_cmd below for another
Packit 437b5e
# use), and '--verbose' and the func_verbose function to allow your script
Packit 437b5e
# to display verbose messages only when your user has specified
Packit 437b5e
# '--verbose'.
Packit 437b5e
#
Packit 437b5e
# After sourcing this file, you can plug processing for additional
Packit 437b5e
# options by amending the variables from the 'Configuration' section
Packit 437b5e
# below, and following the instructions in the 'Option parsing'
Packit 437b5e
# section further down.
Packit 437b5e
Packit 437b5e
## -------------- ##
Packit 437b5e
## Configuration. ##
Packit 437b5e
## -------------- ##
Packit 437b5e
Packit 437b5e
# You should override these variables in your script after sourcing this
Packit 437b5e
# file so that they reflect the customisations you have added to the
Packit 437b5e
# option parser.
Packit 437b5e
Packit 437b5e
# The usage line for option parsing errors and the start of '-h' and
Packit 437b5e
# '--help' output messages. You can embed shell variables for delayed
Packit 437b5e
# expansion at the time the message is displayed, but you will need to
Packit 437b5e
# quote other shell meta-characters carefully to prevent them being
Packit 437b5e
# expanded when the contents are evaled.
Packit 437b5e
usage='$progpath [OPTION]...'
Packit 437b5e
Packit 437b5e
# Short help message in response to '-h' and '--help'.  Add to this or
Packit 437b5e
# override it after sourcing this library to reflect the full set of
Packit 437b5e
# options your script accepts.
Packit 437b5e
usage_message="\
Packit 437b5e
       --debug        enable verbose shell tracing
Packit 437b5e
   -W, --warnings=CATEGORY
Packit 437b5e
                      report the warnings falling in CATEGORY [all]
Packit 437b5e
   -v, --verbose      verbosely report processing
Packit 437b5e
       --version      print version information and exit
Packit 437b5e
   -h, --help         print short or long help message and exit
Packit 437b5e
"
Packit 437b5e
Packit 437b5e
# Additional text appended to 'usage_message' in response to '--help'.
Packit 437b5e
long_help_message="
Packit 437b5e
Warning categories include:
Packit 437b5e
       'all'          show all warnings
Packit 437b5e
       'none'         turn off all the warnings
Packit 437b5e
       'error'        warnings are treated as fatal errors"
Packit 437b5e
Packit 437b5e
# Help message printed before fatal option parsing errors.
Packit 437b5e
fatal_help="Try '\$progname --help' for more information."
Packit 437b5e
Packit 437b5e
Packit 437b5e
Packit 437b5e
## ------------------------- ##
Packit 437b5e
## Hook function management. ##
Packit 437b5e
## ------------------------- ##
Packit 437b5e
Packit 437b5e
# This section contains functions for adding, removing, and running hooks
Packit 437b5e
# to the main code.  A hook is just a named list of of function, that can
Packit 437b5e
# be run in order later on.
Packit 437b5e
Packit 437b5e
# func_hookable FUNC_NAME
Packit 437b5e
# -----------------------
Packit 437b5e
# Declare that FUNC_NAME will run hooks added with
Packit 437b5e
# 'func_add_hook FUNC_NAME ...'.
Packit 437b5e
func_hookable ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    func_append hookable_fns " $1"
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_add_hook FUNC_NAME HOOK_FUNC
Packit 437b5e
# ---------------------------------
Packit 437b5e
# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
Packit 437b5e
# first have been declared "hookable" by a call to 'func_hookable'.
Packit 437b5e
func_add_hook ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    case " $hookable_fns " in
Packit 437b5e
      *" $1 "*) ;;
Packit 437b5e
      *) func_fatal_error "'$1' does not accept hook functions." ;;
Packit 437b5e
    esac
Packit 437b5e
Packit 437b5e
    eval func_append ${1}_hooks '" $2"'
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_remove_hook FUNC_NAME HOOK_FUNC
Packit 437b5e
# ------------------------------------
Packit 437b5e
# Remove HOOK_FUNC from the list of functions called by FUNC_NAME.
Packit 437b5e
func_remove_hook ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_run_hooks FUNC_NAME [ARG]...
Packit 437b5e
# ---------------------------------
Packit 437b5e
# Run all hook functions registered to FUNC_NAME.
Packit 437b5e
# It is assumed that the list of hook functions contains nothing more
Packit 437b5e
# than a whitespace-delimited list of legal shell function names, and
Packit 437b5e
# no effort is wasted trying to catch shell meta-characters or preserve
Packit 437b5e
# whitespace.
Packit 437b5e
func_run_hooks ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    case " $hookable_fns " in
Packit 437b5e
      *" $1 "*) ;;
Packit 437b5e
      *) func_fatal_error "'$1' does not support hook funcions.n" ;;
Packit 437b5e
    esac
Packit 437b5e
Packit 437b5e
    eval _G_hook_fns=\$$1_hooks; shift
Packit 437b5e
Packit 437b5e
    for _G_hook in $_G_hook_fns; do
Packit 437b5e
      eval $_G_hook '"$@"'
Packit 437b5e
Packit 437b5e
      # store returned options list back into positional
Packit 437b5e
      # parameters for next 'cmd' execution.
Packit 437b5e
      eval _G_hook_result=\$${_G_hook}_result
Packit 437b5e
      eval set dummy "$_G_hook_result"; shift
Packit 437b5e
    done
Packit 437b5e
Packit 437b5e
    func_quote_for_eval ${1+"$@"}
Packit 437b5e
    func_run_hooks_result=$func_quote_for_eval_result
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
Packit 437b5e
## --------------- ##
Packit 437b5e
## Option parsing. ##
Packit 437b5e
## --------------- ##
Packit 437b5e
Packit 437b5e
# In order to add your own option parsing hooks, you must accept the
Packit 437b5e
# full positional parameter list in your hook function, remove any
Packit 437b5e
# options that you action, and then pass back the remaining unprocessed
Packit 437b5e
# options in '<hooked_function_name>_result', escaped suitably for
Packit 437b5e
# 'eval'.  Like this:
Packit 437b5e
#
Packit 437b5e
#    my_options_prep ()
Packit 437b5e
#    {
Packit 437b5e
#        $debug_cmd
Packit 437b5e
#
Packit 437b5e
#        # Extend the existing usage message.
Packit 437b5e
#        usage_message=$usage_message'
Packit 437b5e
#      -s, --silent       don'\''t print informational messages
Packit 437b5e
#    '
Packit 437b5e
#
Packit 437b5e
#        func_quote_for_eval ${1+"$@"}
Packit 437b5e
#        my_options_prep_result=$func_quote_for_eval_result
Packit 437b5e
#    }
Packit 437b5e
#    func_add_hook func_options_prep my_options_prep
Packit 437b5e
#
Packit 437b5e
#
Packit 437b5e
#    my_silent_option ()
Packit 437b5e
#    {
Packit 437b5e
#        $debug_cmd
Packit 437b5e
#
Packit 437b5e
#        # Note that for efficiency, we parse as many options as we can
Packit 437b5e
#        # recognise in a loop before passing the remainder back to the
Packit 437b5e
#        # caller on the first unrecognised argument we encounter.
Packit 437b5e
#        while test $# -gt 0; do
Packit 437b5e
#          opt=$1; shift
Packit 437b5e
#          case $opt in
Packit 437b5e
#            --silent|-s) opt_silent=: ;;
Packit 437b5e
#            # Separate non-argument short options:
Packit 437b5e
#            -s*)         func_split_short_opt "$_G_opt"
Packit 437b5e
#                         set dummy "$func_split_short_opt_name" \
Packit 437b5e
#                             "-$func_split_short_opt_arg" ${1+"$@"}
Packit 437b5e
#                         shift
Packit 437b5e
#                         ;;
Packit 437b5e
#            *)            set dummy "$_G_opt" "$*"; shift; break ;;
Packit 437b5e
#          esac
Packit 437b5e
#        done
Packit 437b5e
#
Packit 437b5e
#        func_quote_for_eval ${1+"$@"}
Packit 437b5e
#        my_silent_option_result=$func_quote_for_eval_result
Packit 437b5e
#    }
Packit 437b5e
#    func_add_hook func_parse_options my_silent_option
Packit 437b5e
#
Packit 437b5e
#
Packit 437b5e
#    my_option_validation ()
Packit 437b5e
#    {
Packit 437b5e
#        $debug_cmd
Packit 437b5e
#
Packit 437b5e
#        $opt_silent && $opt_verbose && func_fatal_help "\
Packit 437b5e
#    '--silent' and '--verbose' options are mutually exclusive."
Packit 437b5e
#
Packit 437b5e
#        func_quote_for_eval ${1+"$@"}
Packit 437b5e
#        my_option_validation_result=$func_quote_for_eval_result
Packit 437b5e
#    }
Packit 437b5e
#    func_add_hook func_validate_options my_option_validation
Packit 437b5e
#
Packit 437b5e
# You'll alse need to manually amend $usage_message to reflect the extra
Packit 437b5e
# options you parse.  It's preferable to append if you can, so that
Packit 437b5e
# multiple option parsing hooks can be added safely.
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_options [ARG]...
Packit 437b5e
# ---------------------
Packit 437b5e
# All the functions called inside func_options are hookable. See the
Packit 437b5e
# individual implementations for details.
Packit 437b5e
func_hookable func_options
Packit 437b5e
func_options ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    func_options_prep ${1+"$@"}
Packit 437b5e
    eval func_parse_options \
Packit 437b5e
        ${func_options_prep_result+"$func_options_prep_result"}
Packit 437b5e
    eval func_validate_options \
Packit 437b5e
        ${func_parse_options_result+"$func_parse_options_result"}
Packit 437b5e
Packit 437b5e
    eval func_run_hooks func_options \
Packit 437b5e
        ${func_validate_options_result+"$func_validate_options_result"}
Packit 437b5e
Packit 437b5e
    # save modified positional parameters for caller
Packit 437b5e
    func_options_result=$func_run_hooks_result
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_options_prep [ARG]...
Packit 437b5e
# --------------------------
Packit 437b5e
# All initialisations required before starting the option parse loop.
Packit 437b5e
# Note that when calling hook functions, we pass through the list of
Packit 437b5e
# positional parameters.  If a hook function modifies that list, and
Packit 437b5e
# needs to propogate that back to rest of this script, then the complete
Packit 437b5e
# modified list must be put in 'func_run_hooks_result' before
Packit 437b5e
# returning.
Packit 437b5e
func_hookable func_options_prep
Packit 437b5e
func_options_prep ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    # Option defaults:
Packit 437b5e
    opt_verbose=false
Packit 437b5e
    opt_warning_types=
Packit 437b5e
Packit 437b5e
    func_run_hooks func_options_prep ${1+"$@"}
Packit 437b5e
Packit 437b5e
    # save modified positional parameters for caller
Packit 437b5e
    func_options_prep_result=$func_run_hooks_result
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_parse_options [ARG]...
Packit 437b5e
# ---------------------------
Packit 437b5e
# The main option parsing loop.
Packit 437b5e
func_hookable func_parse_options
Packit 437b5e
func_parse_options ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    func_parse_options_result=
Packit 437b5e
Packit 437b5e
    # this just eases exit handling
Packit 437b5e
    while test $# -gt 0; do
Packit 437b5e
      # Defer to hook functions for initial option parsing, so they
Packit 437b5e
      # get priority in the event of reusing an option name.
Packit 437b5e
      func_run_hooks func_parse_options ${1+"$@"}
Packit 437b5e
Packit 437b5e
      # Adjust func_parse_options positional parameters to match
Packit 437b5e
      eval set dummy "$func_run_hooks_result"; shift
Packit 437b5e
Packit 437b5e
      # Break out of the loop if we already parsed every option.
Packit 437b5e
      test $# -gt 0 || break
Packit 437b5e
Packit 437b5e
      _G_opt=$1
Packit 437b5e
      shift
Packit 437b5e
      case $_G_opt in
Packit 437b5e
        --debug|-x)   debug_cmd='set -x'
Packit 437b5e
                      func_echo "enabling shell trace mode"
Packit 437b5e
                      $debug_cmd
Packit 437b5e
                      ;;
Packit 437b5e
Packit 437b5e
        --no-warnings|--no-warning|--no-warn)
Packit 437b5e
                      set dummy --warnings none ${1+"$@"}
Packit 437b5e
                      shift
Packit 437b5e
		      ;;
Packit 437b5e
Packit 437b5e
        --warnings|--warning|-W)
Packit 437b5e
                      test $# = 0 && func_missing_arg $_G_opt && break
Packit 437b5e
                      case " $warning_categories $1" in
Packit 437b5e
                        *" $1 "*)
Packit 437b5e
                          # trailing space prevents matching last $1 above
Packit 437b5e
                          func_append_uniq opt_warning_types " $1"
Packit 437b5e
                          ;;
Packit 437b5e
                        *all)
Packit 437b5e
                          opt_warning_types=$warning_categories
Packit 437b5e
                          ;;
Packit 437b5e
                        *none)
Packit 437b5e
                          opt_warning_types=none
Packit 437b5e
                          warning_func=:
Packit 437b5e
                          ;;
Packit 437b5e
                        *error)
Packit 437b5e
                          opt_warning_types=$warning_categories
Packit 437b5e
                          warning_func=func_fatal_error
Packit 437b5e
                          ;;
Packit 437b5e
                        *)
Packit 437b5e
                          func_fatal_error \
Packit 437b5e
                             "unsupported warning category: '$1'"
Packit 437b5e
                          ;;
Packit 437b5e
                      esac
Packit 437b5e
                      shift
Packit 437b5e
                      ;;
Packit 437b5e
Packit 437b5e
        --verbose|-v) opt_verbose=: ;;
Packit 437b5e
        --version)    func_version ;;
Packit 437b5e
        -\?|-h)       func_usage ;;
Packit 437b5e
        --help)       func_help ;;
Packit 437b5e
Packit 437b5e
	# Separate optargs to long options (plugins may need this):
Packit 437b5e
	--*=*)        func_split_equals "$_G_opt"
Packit 437b5e
	              set dummy "$func_split_equals_lhs" \
Packit 437b5e
                          "$func_split_equals_rhs" ${1+"$@"}
Packit 437b5e
                      shift
Packit 437b5e
                      ;;
Packit 437b5e
Packit 437b5e
       # Separate optargs to short options:
Packit 437b5e
        -W*)
Packit 437b5e
                      func_split_short_opt "$_G_opt"
Packit 437b5e
                      set dummy "$func_split_short_opt_name" \
Packit 437b5e
                          "$func_split_short_opt_arg" ${1+"$@"}
Packit 437b5e
                      shift
Packit 437b5e
                      ;;
Packit 437b5e
Packit 437b5e
        # Separate non-argument short options:
Packit 437b5e
        -\?*|-h*|-v*|-x*)
Packit 437b5e
                      func_split_short_opt "$_G_opt"
Packit 437b5e
                      set dummy "$func_split_short_opt_name" \
Packit 437b5e
                          "-$func_split_short_opt_arg" ${1+"$@"}
Packit 437b5e
                      shift
Packit 437b5e
                      ;;
Packit 437b5e
Packit 437b5e
        --)           break ;;
Packit 437b5e
        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
Packit 437b5e
        *)            set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
Packit 437b5e
      esac
Packit 437b5e
    done
Packit 437b5e
Packit 437b5e
    # save modified positional parameters for caller
Packit 437b5e
    func_quote_for_eval ${1+"$@"}
Packit 437b5e
    func_parse_options_result=$func_quote_for_eval_result
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_validate_options [ARG]...
Packit 437b5e
# ------------------------------
Packit 437b5e
# Perform any sanity checks on option settings and/or unconsumed
Packit 437b5e
# arguments.
Packit 437b5e
func_hookable func_validate_options
Packit 437b5e
func_validate_options ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    # Display all warnings if -W was not given.
Packit 437b5e
    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
Packit 437b5e
Packit 437b5e
    func_run_hooks func_validate_options ${1+"$@"}
Packit 437b5e
Packit 437b5e
    # Bail if the options were screwed!
Packit 437b5e
    $exit_cmd $EXIT_FAILURE
Packit 437b5e
Packit 437b5e
    # save modified positional parameters for caller
Packit 437b5e
    func_validate_options_result=$func_run_hooks_result
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
Packit 437b5e
Packit 437b5e
# slingshot_options_prep
Packit 437b5e
# ----------------------
Packit 437b5e
# Preparation for additional slingshot option parsing.
Packit 437b5e
slingshot_options_prep ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    # Option defaults:
Packit 437b5e
    opt_skip_rock_checks=false
Packit 437b5e
    # opt_luarocks_tree default in *unset*!
Packit 437b5e
Packit 437b5e
    # Extend the existing usage message.
Packit 437b5e
    usage_message=$usage_message'
Packit 437b5e
Slingshot Options:
Packit 437b5e
Packit 437b5e
        --luarocks-tree=DIR
Packit 437b5e
                      check a non-default tree for prerequisite rocks
Packit 437b5e
        --skip-rock-checks
Packit 437b5e
                      ignore Lua rocks in bootstrap.conf:buildreq'
Packit 437b5e
Packit 437b5e
    func_quote_for_eval ${1+"$@"}
Packit 437b5e
    slingshot_options_prep_result=$func_quote_for_eval_result
Packit 437b5e
}
Packit 437b5e
func_add_hook func_options_prep slingshot_options_prep
Packit 437b5e
Packit 437b5e
Packit 437b5e
# slingshot_parse_options OPT...
Packit 437b5e
# ------------------------------
Packit 437b5e
# Called at the end of each main option parse loop to process any
Packit 437b5e
# additional slingshot options.
Packit 437b5e
slingshot_parse_options ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    # Perform our own loop to consume as many options as possible in
Packit 437b5e
    # each iteration.
Packit 437b5e
    while test $# -gt 0; do
Packit 437b5e
      _G_opt=$1
Packit 437b5e
      shift
Packit 437b5e
      case $_G_opt in
Packit 437b5e
        --luarocks-tree)
Packit 437b5e
                      test $# = 0 && func_missing_arg $_G_opt && break
Packit 437b5e
                      opt_luarocks_tree=$1
Packit 437b5e
                      shift
Packit 437b5e
                      ;;
Packit 437b5e
Packit 437b5e
        --skip-rock-checks)
Packit 437b5e
                      opt_skip_rock_checks=:
Packit 437b5e
                      ;;
Packit 437b5e
Packit 437b5e
	# Separate optargs to long options (plugins may need this):
Packit 437b5e
	--*=*)        func_split_equals "$_G_opt"
Packit 437b5e
	              set dummy "$func_split_equals_lhs" \
Packit 437b5e
                          "$func_split_equals_rhs" ${1+"$@"}
Packit 437b5e
                      shift
Packit 437b5e
                      ;;
Packit 437b5e
Packit 437b5e
        *)            set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
Packit 437b5e
      esac
Packit 437b5e
    done
Packit 437b5e
Packit 437b5e
    # save modified positional parameters for caller
Packit 437b5e
    func_quote_for_eval ${1+"$@"}
Packit 437b5e
    slingshot_parse_options_result=$func_quote_for_eval_result
Packit 437b5e
}
Packit 437b5e
func_add_hook func_parse_options slingshot_parse_options
Packit 437b5e
Packit 437b5e
Packit 437b5e
# slingshot_option_validation
Packit 437b5e
# ---------------------------
Packit 437b5e
# Flag any inconsistencies in users' selection of slingshot options.
Packit 437b5e
slingshot_option_validation ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    test -z "$opt_luarocks_tree" \
Packit 437b5e
      || test -d "$opt_luarocks_tree" \
Packit 437b5e
      || func_fatal_help "$opt_luarocks_tree: not a directory"
Packit 437b5e
}
Packit 437b5e
func_add_hook func_validate_options slingshot_option_validation
Packit 437b5e
Packit 437b5e
Packit 437b5e
## ----------------- ##
Packit 437b5e
## Helper functions. ##
Packit 437b5e
## ----------------- ##
Packit 437b5e
Packit 437b5e
# This section contains the helper functions used by the rest of the
Packit 437b5e
# hookable option parser framework in ascii-betical order.
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_fatal_help ARG...
Packit 437b5e
# ----------------------
Packit 437b5e
# Echo program name prefixed message to standard error, followed by
Packit 437b5e
# a help hint, and exit.
Packit 437b5e
func_fatal_help ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    eval \$ECHO \""Usage: $usage"\"
Packit 437b5e
    eval \$ECHO \""$fatal_help"\"
Packit 437b5e
    func_error ${1+"$@"}
Packit 437b5e
    exit $EXIT_FAILURE
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_help
Packit 437b5e
# ---------
Packit 437b5e
# Echo long help message to standard output and exit.
Packit 437b5e
func_help ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    func_usage_message
Packit 437b5e
    $ECHO "$long_help_message"
Packit 437b5e
    exit 0
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_missing_arg ARGNAME
Packit 437b5e
# ------------------------
Packit 437b5e
# Echo program name prefixed message to standard error and set global
Packit 437b5e
# exit_cmd.
Packit 437b5e
func_missing_arg ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    func_error "Missing argument for '$1'."
Packit 437b5e
    exit_cmd=exit
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_split_equals STRING
Packit 437b5e
# ------------------------
Packit 437b5e
# Set func_split_equals_lhs and func_split_equals_rhs shell variables after
Packit 437b5e
# splitting STRING at the '=' sign.
Packit 437b5e
test -z "$_G_HAVE_XSI_OPS" \
Packit 437b5e
    && (eval 'x=a/b/c;
Packit 437b5e
      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
Packit 437b5e
    && _G_HAVE_XSI_OPS=yes
Packit 437b5e
Packit 437b5e
if test yes = "$_G_HAVE_XSI_OPS"
Packit 437b5e
then
Packit 437b5e
  # This is an XSI compatible shell, allowing a faster implementation...
Packit 437b5e
  eval 'func_split_equals ()
Packit 437b5e
  {
Packit 437b5e
      $debug_cmd
Packit 437b5e
Packit 437b5e
      func_split_equals_lhs=${1%%=*}
Packit 437b5e
      func_split_equals_rhs=${1#*=}
Packit 437b5e
      test "x$func_split_equals_lhs" = "x$1" \
Packit 437b5e
        && func_split_equals_rhs=
Packit 437b5e
  }'
Packit 437b5e
else
Packit 437b5e
  # ...otherwise fall back to using expr, which is often a shell builtin.
Packit 437b5e
  func_split_equals ()
Packit 437b5e
  {
Packit 437b5e
      $debug_cmd
Packit 437b5e
Packit 437b5e
      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
Packit 437b5e
      func_split_equals_rhs=
Packit 437b5e
      test "x$func_split_equals_lhs" = "x$1" \
Packit 437b5e
        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
Packit 437b5e
  }
Packit 437b5e
fi #func_split_equals
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_split_short_opt SHORTOPT
Packit 437b5e
# -----------------------------
Packit 437b5e
# Set func_split_short_opt_name and func_split_short_opt_arg shell
Packit 437b5e
# variables after splitting SHORTOPT after the 2nd character.
Packit 437b5e
if test yes = "$_G_HAVE_XSI_OPS"
Packit 437b5e
then
Packit 437b5e
  # This is an XSI compatible shell, allowing a faster implementation...
Packit 437b5e
  eval 'func_split_short_opt ()
Packit 437b5e
  {
Packit 437b5e
      $debug_cmd
Packit 437b5e
Packit 437b5e
      func_split_short_opt_arg=${1#??}
Packit 437b5e
      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
Packit 437b5e
  }'
Packit 437b5e
else
Packit 437b5e
  # ...otherwise fall back to using expr, which is often a shell builtin.
Packit 437b5e
  func_split_short_opt ()
Packit 437b5e
  {
Packit 437b5e
      $debug_cmd
Packit 437b5e
Packit 437b5e
      func_split_short_opt_name=`expr "x$1" : 'x-\(.\)'`
Packit 437b5e
      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
Packit 437b5e
  }
Packit 437b5e
fi #func_split_short_opt
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_usage
Packit 437b5e
# ----------
Packit 437b5e
# Echo short help message to standard output and exit.
Packit 437b5e
func_usage ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    func_usage_message
Packit 437b5e
    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
Packit 437b5e
    exit 0
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_usage_message
Packit 437b5e
# ------------------
Packit 437b5e
# Echo short help message to standard output.
Packit 437b5e
func_usage_message ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    eval \$ECHO \""Usage: $usage"\"
Packit 437b5e
    echo
Packit 437b5e
    $SED -n 's|^# ||
Packit 437b5e
        /^Written by/{
Packit 437b5e
          x;p;x
Packit 437b5e
        }
Packit 437b5e
	h
Packit 437b5e
	/^Written by/q' < "$progpath"
Packit 437b5e
    echo
Packit 437b5e
    eval \$ECHO \""$usage_message"\"
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_version
Packit 437b5e
# ------------
Packit 437b5e
# Echo version message to standard output and exit.
Packit 437b5e
func_version ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    printf '%s\n' "$progname $scriptversion"
Packit 437b5e
    $SED -n '
Packit 437b5e
        /(C)/!b go
Packit 437b5e
        :more
Packit 437b5e
        /\./!{
Packit 437b5e
          N
Packit 437b5e
          s|\n# | |
Packit 437b5e
          b more
Packit 437b5e
        }
Packit 437b5e
        :go
Packit 437b5e
        /^# Written by /,/# warranty; / {
Packit 437b5e
          s|^# ||
Packit 437b5e
          s|^# *$||
Packit 437b5e
          s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
Packit 437b5e
          p
Packit 437b5e
        }
Packit 437b5e
        /^# Written by / {
Packit 437b5e
          s|^# ||
Packit 437b5e
          p
Packit 437b5e
        }
Packit 437b5e
        /^warranty; /q' < "$progpath"
Packit 437b5e
Packit 437b5e
    exit $?
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# Local variables:
Packit 437b5e
# mode: shell-script
Packit 437b5e
# sh-indentation: 2
Packit 437b5e
# eval: (add-hook 'before-save-hook 'time-stamp)
Packit 437b5e
# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
Packit 437b5e
# time-stamp-time-zone: "UTC"
Packit 437b5e
# End:
Packit 437b5e
#! /bin/sh
Packit 437b5e
Packit 437b5e
# Extract macro arguments from autotools input with GNU M4.
Packit 437b5e
# Written by Gary V. Vaughan, 2010
Packit 437b5e
#
Packit 437b5e
# Copyright (C) 2010-2014 Free Software Foundation, Inc.
Packit 437b5e
# This is free software; see the source for copying conditions.  There is NO
Packit 437b5e
# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Packit 437b5e
Packit 437b5e
# Make sure we've evaluated scripts we depend on.
Packit 437b5e
test -z "$progpath" && . `echo "$0" |${SED-sed} 's|[^/]*$||'`/funclib.sh
Packit 437b5e
test extract-trace = "$progname" && . `echo "$0" |${SED-sed} 's|[^/]*$||'`/options-parser
Packit 437b5e
Packit 437b5e
# Set a version string.
Packit 437b5e
scriptversion=2014-12-03.16; # UTC
Packit 437b5e
Packit 437b5e
# This program is free software: you can redistribute it and/or modify
Packit 437b5e
# it under the terms of the GNU General Public License as published by
Packit 437b5e
# the Free Software Foundation, either version 3 of the License, or
Packit 437b5e
# (at your option) any later version.
Packit 437b5e
Packit 437b5e
# This program is distributed in the hope that it will be useful,
Packit 437b5e
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 437b5e
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 437b5e
# GNU General Public License for more details.
Packit 437b5e
Packit 437b5e
# You should have received a copy of the GNU General Public License
Packit 437b5e
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 437b5e
Packit 437b5e
# Please report bugs or propose patches to gary@gnu.org.
Packit 437b5e
Packit 437b5e
Packit 437b5e
# slingshot_copy FILENAME SRCDIR DESTDIR
Packit 437b5e
# --------------------------------------
Packit 437b5e
# If option '--copy' was specified, or soft-linking SRCFILE to DESTFILE
Packit 437b5e
# fails, then try to copy SRCFILE to DESTFILE (making sure to update the
Packit 437b5e
# timestamp so that a series of files with dependencies can be copied
Packit 437b5e
# in the right order that their timestamps won't trigger rebuilds).
Packit 437b5e
slingshot_copy ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    slingshot_srcfile=`echo "$2/$1" |sed -e 's|/\./|/|g'`
Packit 437b5e
    slingshot_destfile=`echo "$3/$1" |sed -e 's|/\./|/|g'`
Packit 437b5e
Packit 437b5e
    $opt_force || {
Packit 437b5e
      # Nothing to do if the files are already identical.
Packit 437b5e
      if func_cmp_s "$slingshot_srcfile" "$slingshot_destfile"; then
Packit 437b5e
        func_verbose "'$slingshot_destfile' is up to date."
Packit 437b5e
        return 0
Packit 437b5e
      fi
Packit 437b5e
    }
Packit 437b5e
Packit 437b5e
    # Require --force to remove existing $slingshot_destfile.
Packit 437b5e
    $opt_force && $RM "$slingshot_destfile"
Packit 437b5e
    test -f "$slingshot_destfile" && {
Packit 437b5e
      func_warn_and_continue "'$slingshot_destfile' exists: use '--force' to overwrite"
Packit 437b5e
      return 0
Packit 437b5e
    }
Packit 437b5e
Packit 437b5e
    # Be careful to support 'func_copy dir/target srcbase destbase'.
Packit 437b5e
    func_dirname "$slingshot_destfile"
Packit 437b5e
    func_mkdir_p "$func_dirname_result"
Packit 437b5e
Packit 437b5e
    # Copy or link according to '--copy' option.
Packit 437b5e
    if $opt_copy; then
Packit 437b5e
      slingshot_copycmd=$CP
Packit 437b5e
      slingshot_copy_type=copying
Packit 437b5e
    else
Packit 437b5e
      slingshot_copycmd=$LN_S
Packit 437b5e
      slingshot_copy_type=linking
Packit 437b5e
Packit 437b5e
      func_relative_path "$3" "$2"
Packit 437b5e
      slingshot_srcfile=$func_relative_path_result/$1
Packit 437b5e
    fi
Packit 437b5e
    slingshot_copy_msg="$slingshot_copy_type file '$slingshot_destfile'"
Packit 437b5e
    $opt_verbose && \
Packit 437b5e
      slingshot_copy_msg="$slingshot_copy_type $slingshot_srcfile $3"
Packit 437b5e
Packit 437b5e
    if $opt_dry_run || {
Packit 437b5e
        ( umask 0
Packit 437b5e
          $slingshot_copycmd "$slingshot_srcfile" "$slingshot_destfile"
Packit 437b5e
        ) >/dev/null 2>&1
Packit 437b5e
      }
Packit 437b5e
    then
Packit 437b5e
      echo "$slingshot_copy_msg"
Packit 437b5e
    else
Packit 437b5e
      func_error "$slingshot_copy_type '$2/$1' to '$3/' failed"
Packit 437b5e
      return 1
Packit 437b5e
    fi
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# slingshot_rockspec_error
Packit 437b5e
# ------------------------
Packit 437b5e
# Called by zile_check_rockspecs for missing rocks.
Packit 437b5e
slingshot_rockspec_error ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    _G_strippedver=`expr "$_G_reqver" : '=*\(.*\)'`
Packit 437b5e
    func_error "\
Packit 437b5e
Prerequisite LuaRock '$_G_rock $_G_strippedver' not found. Please install it."
Packit 437b5e
Packit 437b5e
    rockspecs_uptodate_result=false
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
## ------ ##
Packit 437b5e
## Usage. ##
Packit 437b5e
## ------ ##
Packit 437b5e
Packit 437b5e
# Run './extract-trace --help' for help with using this script from the
Packit 437b5e
# command line.
Packit 437b5e
#
Packit 437b5e
# Or source first 'options-parser' and then this file into your own
Packit 437b5e
# scripts in order to make use of the function and variable framework
Packit 437b5e
# they define, and also to avoid the overhead of forking to run this
Packit 437b5e
# script in its own process on every call.
Packit 437b5e
Packit 437b5e
Packit 437b5e
Packit 437b5e
## ----------------- ##
Packit 437b5e
## Helper functions. ##
Packit 437b5e
## ----------------- ##
Packit 437b5e
Packit 437b5e
# This section contains the helper functions used by the rest of
Packit 437b5e
# 'extract-trace'.
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_autoconf_configure MAYBE-CONFIGURE-FILE
Packit 437b5e
# --------------------------------------------
Packit 437b5e
# Ensure that MAYBE-CONFIGURE-FILE is the name of a file in the current
Packit 437b5e
# directory that contains an uncommented call to AC_INIT.
Packit 437b5e
func_autoconf_configure ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    _G_sed_no_comment='
Packit 437b5e
      s|#.*$||
Packit 437b5e
      s|^dnl .*$||
Packit 437b5e
      s| dnl .*$||'
Packit 437b5e
    _G_ac_init=
Packit 437b5e
Packit 437b5e
    # If we were passed a genuine file, make sure it calls AC_INIT.
Packit 437b5e
    test -f "$1" \
Packit 437b5e
      && _G_ac_init=`$SED "$_G_sed_no_comment" "$1" |$GREP AC_INIT`
Packit 437b5e
Packit 437b5e
    # Otherwise it is not a genuine Autoconf input file.
Packit 437b5e
    test -n "$_G_ac_init"
Packit 437b5e
    _G_status=$?
Packit 437b5e
Packit 437b5e
    test 0 -ne "$_G_status" \
Packit 437b5e
      && func_verbose "'$1' not using Autoconf"
Packit 437b5e
Packit 437b5e
    (exit $_G_status)
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_tool_version_output CMD [FATAL-ERROR-MSG]
Packit 437b5e
# ----------------------------------------------
Packit 437b5e
# Attempt to run 'CMD --version', discarding errors.  The output can be
Packit 437b5e
# ignored by redirecting stdout, and this function used simply to test
Packit 437b5e
# whether the command exists and exits normally when passed a
Packit 437b5e
# '--version' argument.
Packit 437b5e
# When FATAL-ERROR-MSG is given, then this function will display the
Packit 437b5e
# message and exit if running 'CMD --version' returns a non-zero exit
Packit 437b5e
# status.
Packit 437b5e
func_tool_version_output ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    _G_cmd=$1
Packit 437b5e
    _G_fatal_error_msg=$2
Packit 437b5e
Packit 437b5e
    # Some tools, like 'git2cl' produce thousands of lines of output
Packit 437b5e
    # unless stdin is /dev/null - in that case we want to return
Packit 437b5e
    # successfully without saving all of that output.  Other tools,
Packit 437b5e
    # such as 'help2man' exit with a non-zero status when stdin comes
Packit 437b5e
    # from /dev/null, so we re-execute without /dev/null if that
Packit 437b5e
    # happens.  This means that occasionally, the output from both calls
Packit 437b5e
    # ends up in the result, but the alternative would be to discard the
Packit 437b5e
    # output from one call, and hope the other produces something useful.
Packit 437b5e
    { $_G_cmd --version </dev/null || $_G_cmd --version; } 2>/dev/null
Packit 437b5e
    _G_status=$?
Packit 437b5e
Packit 437b5e
    test 0 -ne "$_G_status" && test -n "$_G_fatal_error_msg" \
Packit 437b5e
        && func_fatal_error "$_G_fatal_error_msg"
Packit 437b5e
Packit 437b5e
    (exit $_G_status)
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_tool_version_number CMD [FATAL-ERROR-MSG]
Packit 437b5e
# ----------------------------------------------
Packit 437b5e
# Pass arguments to func_tool_version_output, but set
Packit 437b5e
# $func_tool_version_number_result to the last dot delimited digit string
Packit 437b5e
# on the first line of output.
Packit 437b5e
func_tool_version_number ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    _G_verout=`func_tool_version_output "$@"`
Packit 437b5e
    _G_status=$?
Packit 437b5e
Packit 437b5e
    # A version number starts with a digit following a space on the first
Packit 437b5e
    # line of output from `--version`.
Packit 437b5e
    _G_verout=`echo "$_G_verout" |sed 1q`
Packit 437b5e
    if test -n "$_G_verout"; then
Packit 437b5e
      _G_vernum=`expr "$_G_verout" : '.* \([0-9][^ ]*\)'`
Packit 437b5e
    fi
Packit 437b5e
Packit 437b5e
    if test -n "$_G_vernum"; then
Packit 437b5e
      printf '%s\n' "$_G_vernum"
Packit 437b5e
    else
Packit 437b5e
      printf '%s\n' "$_G_verout"
Packit 437b5e
    fi
Packit 437b5e
Packit 437b5e
    (exit $_G_status)
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_find_tool ENVVAR NAMES...
Packit 437b5e
# ------------------------------
Packit 437b5e
# Search for a required program.  Use the value of ENVVAR, if set,
Packit 437b5e
# otherwise find the first of the NAMES that can be run (i.e.,
Packit 437b5e
# supports --version).  If found, set ENVVAR to the program name,
Packit 437b5e
# die otherwise.
Packit 437b5e
func_find_tool ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    _G_find_tool_envvar=$1
Packit 437b5e
    shift
Packit 437b5e
    _G_find_tool_names=$@
Packit 437b5e
    eval "_G_find_tool_res=\$$_G_find_tool_envvar"
Packit 437b5e
    if test -n "$_G_find_tool_res"; then
Packit 437b5e
      _G_find_tool_error_prefix="\$$find_tool_envvar: "
Packit 437b5e
    else
Packit 437b5e
      _G_find_tool_res=
Packit 437b5e
      _G_bestver=
Packit 437b5e
      for _G_prog
Packit 437b5e
      do
Packit 437b5e
        _G_find_tool_save_IFS=$IFS
Packit 437b5e
	IFS=:
Packit 437b5e
	for _G_dir in $PATH; do
Packit 437b5e
	  IFS=$_G_find_tool_save_IFS
Packit 437b5e
	  _G_progpath=$_G_dir/$_G_prog
Packit 437b5e
          test -r "$_G_progpath" && {
Packit 437b5e
            _G_curver=`func_tool_version_number $_G_progpath`
Packit 437b5e
	    case $_G_bestver,$_G_curver in
Packit 437b5e
	    ,)
Packit 437b5e
	      # first non--version responsive prog sticks!
Packit 437b5e
              test -n "$_G_progpath" || _G_find_tool_res=$_G_progpath
Packit 437b5e
              ;;
Packit 437b5e
            ,*)
Packit 437b5e
	      # first --version responsive prog beats non--version responsive!
Packit 437b5e
	      _G_find_tool_res=$_G_progpath
Packit 437b5e
	      _G_bestver=$_G_curver
Packit 437b5e
	      ;;
Packit 437b5e
	    *,*)
Packit 437b5e
	      # another --version responsive prog must be newer to beat previous one!
Packit 437b5e
	      test "x$_G_curver" = "x$_G_bestver" \
Packit 437b5e
		|| func_lt_ver "$_G_curver" "$_G_bestver" \
Packit 437b5e
		|| {
Packit 437b5e
		     _G_find_tool_res=$_G_progpath
Packit 437b5e
		     _G_bestver=$_G_curver
Packit 437b5e
	           }
Packit 437b5e
	      ;;
Packit 437b5e
	    esac
Packit 437b5e
          }
Packit 437b5e
	done
Packit 437b5e
	IFS=$_G_find_tool_save_IFS
Packit 437b5e
      done
Packit 437b5e
    fi
Packit 437b5e
    if test -n "$_G_find_tool_res"; then
Packit 437b5e
      func_tool_version_number >/dev/null $_G_find_tool_res "\
Packit 437b5e
${_G_find_tool_error_prefix}Cannot run '$_G_find_tool_res --version'"
Packit 437b5e
Packit 437b5e
      # Make sure the result is exported to the environment for children
Packit 437b5e
      # to use.
Packit 437b5e
      eval "$_G_find_tool_envvar=\$_G_find_tool_res"
Packit 437b5e
      eval "export $_G_find_tool_envvar"
Packit 437b5e
    else
Packit 437b5e
      func_error "\
Packit 437b5e
One of these is required:
Packit 437b5e
       $_G_find_tool_names"
Packit 437b5e
    fi
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
Packit 437b5e
## -------------------- ##
Packit 437b5e
## Resource management. ##
Packit 437b5e
## -------------------- ##
Packit 437b5e
Packit 437b5e
# This section contains definitions for functions that each ensure a
Packit 437b5e
# particular resource (a file, or a non-empty configuration variable for
Packit 437b5e
# example) is available, and if appropriate to extract default values
Packit 437b5e
# from pertinent package files.  Where a variable already has a non-
Packit 437b5e
# empty value (as set by the package's 'bootstrap.conf'), that value is
Packit 437b5e
# used in preference to deriving the default. Call them using their
Packit 437b5e
# associated 'require_*' variable to ensure that they are executed, at
Packit 437b5e
# most, once.
Packit 437b5e
#
Packit 437b5e
# It's entirely deliberate that calling these functions can set
Packit 437b5e
# variables that don't obey the namespace limitations obeyed by the rest
Packit 437b5e
# of this file, in order that that they be as useful as possible to
Packit 437b5e
# callers.
Packit 437b5e
Packit 437b5e
Packit 437b5e
# require_configure_ac
Packit 437b5e
# --------------------
Packit 437b5e
# Ensure that there is a 'configure.ac' or 'configure.in' file in the
Packit 437b5e
# current directory that contains an uncommented call to AC_INIT, and
Packit 437b5e
# that '$configure_ac' contains its name.
Packit 437b5e
require_configure_ac=func_require_configure_ac
Packit 437b5e
func_require_configure_ac ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    test -z "$configure_ac" \
Packit 437b5e
      && func_autoconf_configure configure.ac && configure_ac=configure.ac
Packit 437b5e
    test -z "$configure_ac" \
Packit 437b5e
      && func_autoconf_configure configure.in && configure_ac=configure.in
Packit 437b5e
    test -z "$configure_ac" \
Packit 437b5e
      || func_verbose "found '$configure_ac'"
Packit 437b5e
Packit 437b5e
    require_configure_ac=:
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# require_gnu_m4
Packit 437b5e
# --------------
Packit 437b5e
# Search for GNU M4, and export it in $M4.
Packit 437b5e
require_gnu_m4=func_require_gnu_m4
Packit 437b5e
func_require_gnu_m4 ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    test -n "$M4" || {
Packit 437b5e
      # Find the first m4 binary that responds to --version.
Packit 437b5e
      func_find_tool M4 gm4 gnum4 m4
Packit 437b5e
    }
Packit 437b5e
Packit 437b5e
    test -n "$M4" || func_fatal_error "\
Packit 437b5e
Please install GNU M4, or 'export M4=/path/to/gnu/m4'."
Packit 437b5e
Packit 437b5e
    func_verbose "export M4='$M4'"
Packit 437b5e
Packit 437b5e
    # Make sure the search result is visible to subshells
Packit 437b5e
    export M4
Packit 437b5e
Packit 437b5e
    require_gnu_m4=:
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
## --------------- ##
Packit 437b5e
## Core functions. ##
Packit 437b5e
## --------------- ##
Packit 437b5e
Packit 437b5e
# This section contains the high level functions used when calling this
Packit 437b5e
# file as a script. 'func_extract_trace' is probably the only one that you
Packit 437b5e
# won't want to replace if you source this file into your own script.
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_extract_trace MACRO_NAMES [FILENAME]...
Packit 437b5e
# --------------------------------------------
Packit 437b5e
# set '$func_extract_trace_result' to a colon delimited list of arguments
Packit 437b5e
# to any of the comma separated list of MACRO_NAMES in FILENAME. If no
Packit 437b5e
# FILENAME is given, then '$configure_ac' is assumed.
Packit 437b5e
func_extract_trace ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    $require_configure_ac
Packit 437b5e
    $require_gnu_m4
Packit 437b5e
Packit 437b5e
    _G_m4_traces=`$ECHO "--trace=$1" |$SED 's%,% --trace=%g'`
Packit 437b5e
    _G_re_macros=`$ECHO "($1)" |$SED 's%,%|%g'`
Packit 437b5e
    _G_macros="$1"; shift
Packit 437b5e
    test $# -gt 0 || {
Packit 437b5e
      set dummy $configure_ac
Packit 437b5e
      shift
Packit 437b5e
    }
Packit 437b5e
Packit 437b5e
    # Generate an error if the first file is missing
Packit 437b5e
    <"$1"
Packit 437b5e
Packit 437b5e
    # Sadly, we can't use 'autom4te' tracing to extract macro arguments,
Packit 437b5e
    # because it complains about things we want to ignore at bootstrap
Packit 437b5e
    # time - like missing m4_include files; AC_PREREQ being newer than
Packit 437b5e
    # the installed autoconf; and returns nothing when tracing
Packit 437b5e
    # 'AM_INIT_AUTOMAKE' when aclocal hasn't been generated yet.
Packit 437b5e
    #
Packit 437b5e
    # The following tries to emulate a less persnickety version of (and
Packit 437b5e
    # due to not having to wait for Perl startup on every invocation,
Packit 437b5e
    # it's probably faster too):
Packit 437b5e
    #
Packit 437b5e
    #    autom4te --language=Autoconf --trace=$my_macro:\$% "$@"
Packit 437b5e
    #
Packit 437b5e
    # First we give a minimal set of macro declarations to M4 to prime
Packit 437b5e
    # it for reading Autoconf macros, while still providing some of the
Packit 437b5e
    # functionality generally used at m4-time to supply dynamic
Packit 437b5e
    # arguments to Autocof functions, but without following
Packit 437b5e
    # 'm4_s?include' files.
Packit 437b5e
    _G_mini='
Packit 437b5e
        # Initialisation.
Packit 437b5e
        m4_changequote([,])
Packit 437b5e
        m4_define([m4_copy],   [m4_define([$2], m4_defn([$1]))])
Packit 437b5e
        m4_define([m4_rename], [m4_copy([$1], [$2])m4_undefine([$1])])
Packit 437b5e
Packit 437b5e
        # Disable these macros.
Packit 437b5e
        m4_undefine([m4_dnl])
Packit 437b5e
        m4_undefine([m4_include])
Packit 437b5e
        m4_undefine([m4_m4exit])
Packit 437b5e
        m4_undefine([m4_m4wrap])
Packit 437b5e
        m4_undefine([m4_maketemp])
Packit 437b5e
Packit 437b5e
        # Copy and rename macros not handled by "m4 --prefix".
Packit 437b5e
        m4_define([dnl],         [m4_builtin([dnl])])
Packit 437b5e
        m4_copy([m4_define],     [m4_defun])
Packit 437b5e
        m4_rename([m4_ifelse],   [m4_if])
Packit 437b5e
        m4_ifdef([m4_mkstemp],   [m4_undefine([m4_mkstemp])])
Packit 437b5e
        m4_rename([m4_patsubst], [m4_bpatsubst])
Packit 437b5e
        m4_rename([m4_regexp],   [m4_bregexp])
Packit 437b5e
Packit 437b5e
        # "m4sugar.mini" - useful m4-time macros for dynamic arguments.
Packit 437b5e
        # If we discover packages that need more m4 macros defined in
Packit 437b5e
        # order to bootstrap correctly, add them here:
Packit 437b5e
        m4_define([m4_bmatch],
Packit 437b5e
            [m4_if([$#], 0, [], [$#], 1, [], [$#], 2, [$2],
Packit 437b5e
                   [m4_if(m4_bregexp([$1], [$2]), -1,
Packit 437b5e
                          [$0([$1], m4_shift3($@))], [$3])])])
Packit 437b5e
        m4_define([m4_ifndef], [m4_ifdef([$1], [$3], [$2])])
Packit 437b5e
        m4_define([m4_ifset],
Packit 437b5e
            [m4_ifdef([$1], [m4_ifval(m4_defn([$1]), [$2], [$3])], [$3])])
Packit 437b5e
        m4_define([m4_require], [$1])
Packit 437b5e
        m4_define([m4_shift3], [m4_shift(m4shift(m4shift($@)))])
Packit 437b5e
Packit 437b5e
        # "autoconf.mini" - things from autoconf macros we care about.
Packit 437b5e
        m4_copy([m4_defun], [AC_DEFUN])
Packit 437b5e
Packit 437b5e
        # Dummy definitions for the macros we want to trace.
Packit 437b5e
        # AM_INIT_AUTOMAKE at least produces no trace without this.
Packit 437b5e
    '
Packit 437b5e
Packit 437b5e
    _G_save=$IFS
Packit 437b5e
    IFS=,
Packit 437b5e
    for _G_macro in $_G_macros; do
Packit 437b5e
      IFS=$_G_save
Packit 437b5e
      func_append _G_mini "AC_DEFUN([$_G_macro])$nl"
Packit 437b5e
    done
Packit 437b5e
    IFS=$_G_save
Packit 437b5e
Packit 437b5e
    # We discard M4's stdout, but the M4 trace output from reading our
Packit 437b5e
    # "autoconf.mini" followed by any other files passed to this
Packit 437b5e
    # function is then scanned by sed to transform it into a colon
Packit 437b5e
    # delimited argument list assigned to a shell variable.
Packit 437b5e
    _G_transform='s|#.*$||; s|^dnl .*$||; s| dnl .*$||;'
Packit 437b5e
Packit 437b5e
    # Unfortunately, alternation in regexp addresses doesn't work in at
Packit 437b5e
    # least BSD (and hence Mac OS X) sed, so we have to append a capture
Packit 437b5e
    # and print block for each traced macro to the sed transform script.
Packit 437b5e
    _G_save=$IFS
Packit 437b5e
    IFS=,
Packit 437b5e
    for _G_macro in $_G_macros; do
Packit 437b5e
      IFS=$_G_save
Packit 437b5e
      func_append _G_transform '
Packit 437b5e
        /^m4trace: -1- '"$_G_macro"'/ {
Packit 437b5e
          s|^m4trace: -1- '"$_G_macro"'[([]*||
Packit 437b5e
          s|], [[]|:|g
Packit 437b5e
          s|[])]*$|:|
Packit 437b5e
          s|\(.\):$|\1|
Packit 437b5e
          p
Packit 437b5e
        }'
Packit 437b5e
    done
Packit 437b5e
    IFS=$_G_save
Packit 437b5e
Packit 437b5e
    # Save the command pipeline results for further use by callers of
Packit 437b5e
    # this function.
Packit 437b5e
    func_extract_trace_result=`$ECHO "$_G_mini" \
Packit 437b5e
      |$M4 -daq --prefix $_G_m4_traces - "$@" 2>&1 1>/dev/null \
Packit 437b5e
      |$SED -n -e "$_G_transform"`
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_extract_trace_first MACRO_NAMES [FILENAME]...
Packit 437b5e
# --------------------------------------------------
Packit 437b5e
# Exactly like func_extract_trace, except that only the first argument
Packit 437b5e
# to the first invocation of one of the comma separated MACRO_NAMES is
Packit 437b5e
# returned in '$func_extract_trace_first_result'.
Packit 437b5e
func_extract_trace_first ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    func_extract_trace ${1+"$@"}
Packit 437b5e
    func_extract_trace_first_result=`$ECHO "$func_extract_trace_result" \
Packit 437b5e
      |$SED -e 's|:.*$||g' -e 1q`
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_main [ARG]...
Packit 437b5e
# ------------------
Packit 437b5e
func_main ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    # Configuration.
Packit 437b5e
    usage='$progname MACRO_NAME FILE [...]'
Packit 437b5e
Packit 437b5e
    long_help_message='
Packit 437b5e
The first argument to this program is the name of an autotools macro
Packit 437b5e
whose arguments you want to extract by examining the files listed in the
Packit 437b5e
remaining arguments using the same tool that Autoconf and Automake use,
Packit 437b5e
GNU M4.
Packit 437b5e
Packit 437b5e
The arguments are returned separated by colons, with each traced call
Packit 437b5e
on a separate line.'
Packit 437b5e
Packit 437b5e
    # Option processing.
Packit 437b5e
    func_options "$@"
Packit 437b5e
    eval set dummy "$func_options_result"; shift
Packit 437b5e
Packit 437b5e
    # Validate remaining non-option arguments.
Packit 437b5e
    test $# -gt 1 \
Packit 437b5e
        || func_fatal_help "not enough arguments"
Packit 437b5e
Packit 437b5e
    # Pass non-option arguments to extraction function.
Packit 437b5e
    func_extract_trace "$@"
Packit 437b5e
Packit 437b5e
    # Display results.
Packit 437b5e
    test -n "$func_extract_trace_result" \
Packit 437b5e
        && $ECHO "$func_extract_trace_result"
Packit 437b5e
Packit 437b5e
    # The End.
Packit 437b5e
    exit $EXIT_SUCCESS
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
## --------------------------- ##
Packit 437b5e
## Actually perform the trace. ##
Packit 437b5e
## --------------------------- ##
Packit 437b5e
Packit 437b5e
# Only call 'func_main' if this script was called directly.
Packit 437b5e
test extract-trace = "$progname" && func_main "$@"
Packit 437b5e
Packit 437b5e
# Local variables:
Packit 437b5e
# mode: shell-script
Packit 437b5e
# sh-indentation: 2
Packit 437b5e
# eval: (add-hook 'before-save-hook 'time-stamp)
Packit 437b5e
# time-stamp-pattern: "20/scriptversion=%:y-%02m-%02d.%02H; # UTC"
Packit 437b5e
# time-stamp-time-zone: "UTC"
Packit 437b5e
# End:
Packit 437b5e
Packit 437b5e
# Set a version string for *this* script.
Packit 437b5e
scriptversion=2014-11-04.13; # UTC
Packit 437b5e
Packit 437b5e
Packit 437b5e
## ------------------- ##
Packit 437b5e
## Hookable functions. ##
Packit 437b5e
## ------------------- ##
Packit 437b5e
Packit 437b5e
# After 'bootstrap.conf' has been sourced, execution proceeds by calling
Packit 437b5e
# 'func_bootstrap'.  Wherever a function is decorated with
Packit 437b5e
# 'func_hookable func_name', you will find a matching 'func_run_hooks
Packit 437b5e
# func_name', which executes all functions added with 'func_add_hook
Packit 437b5e
# func_name my_func'.
Packit 437b5e
#
Packit 437b5e
# You might notice that many of these functions begin with a series of
Packit 437b5e
# '$require_foo' lines.  See the docu-comments at the start of the
Packit 437b5e
# 'Resource management' section for a description of what these are.
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_bootstrap [ARG]...
Packit 437b5e
# -----------------------
Packit 437b5e
# All the functions called inside func_bootstrap are hookable. See the
Packit 437b5e
# the individual implementations for details.
Packit 437b5e
func_bootstrap ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    # Save the current positional parameters to prevent them being
Packit 437b5e
    # corrupted by calls to 'set' in 'func_init'.
Packit 437b5e
    func_quote_for_eval ${1+"$@"}
Packit 437b5e
    _G_saved_positional_parameters=$func_quote_for_eval_result
Packit 437b5e
Packit 437b5e
    # Initialisation.
Packit 437b5e
    func_init
Packit 437b5e
Packit 437b5e
    # Option processing.
Packit 437b5e
    eval func_options "$_G_saved_positional_parameters"
Packit 437b5e
Packit 437b5e
    # Post-option preparation.
Packit 437b5e
    func_prep
Packit 437b5e
Packit 437b5e
    # Reconfigure the package.
Packit 437b5e
    func_reconfigure
Packit 437b5e
Packit 437b5e
    # Ensure .version is up-to-date.
Packit 437b5e
    func_update_dotversion
Packit 437b5e
Packit 437b5e
    # Finalisation.
Packit 437b5e
    func_fini
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_init
Packit 437b5e
# ---------
Packit 437b5e
# Any early initialisations can be hooked to this function.  Consider
Packit 437b5e
# whether you can hook onto 'func_prep' instead, because if you hook
Packit 437b5e
# any slow to execute code in here, it will also add to the time before
Packit 437b5e
# './bootstrap --version' can respond.
Packit 437b5e
func_hookable func_init
Packit 437b5e
func_init ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    func_run_hooks func_init
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_prep
Packit 437b5e
# ---------
Packit 437b5e
# Function to perform preparation for remaining bootstrap process. If
Packit 437b5e
# your hooked code relies on the outcome of 'func_options' hook it here
Packit 437b5e
# rather than to 'func_init'.
Packit 437b5e
#
Packit 437b5e
# All the functions called inside func_prep are hookable. See the
Packit 437b5e
# individual implementations for details.
Packit 437b5e
func_hookable func_prep
Packit 437b5e
func_prep ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    $require_buildtools_uptodate
Packit 437b5e
    $require_checkout_only_file
Packit 437b5e
Packit 437b5e
    $require_gnulib_merge_changelog
Packit 437b5e
Packit 437b5e
    # Report the results of SED and GREP searches from funclib.sh.
Packit 437b5e
    func_verbose "GREP='$GREP'"
Packit 437b5e
    func_verbose "SED='$SED'"
Packit 437b5e
Packit 437b5e
    # fetch update files from the translation project
Packit 437b5e
    func_update_translations
Packit 437b5e
Packit 437b5e
    func_run_hooks func_prep
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_update_translations
Packit 437b5e
# ------------------------
Packit 437b5e
# Update package po files and translations.
Packit 437b5e
func_hookable func_update_translations
Packit 437b5e
func_update_translations ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    $opt_skip_po || {
Packit 437b5e
      test -d po && {
Packit 437b5e
        $require_package
Packit 437b5e
Packit 437b5e
        func_update_po_files po $package || exit $?
Packit 437b5e
      }
Packit 437b5e
Packit 437b5e
      func_run_hooks func_update_translations
Packit 437b5e
    }
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_reconfigure
Packit 437b5e
# ----------------
Packit 437b5e
# Reconfigure the current package by running the appropriate autotools in a
Packit 437b5e
# suitable order.
Packit 437b5e
func_hookable func_reconfigure
Packit 437b5e
func_reconfigure ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    $require_automake_options
Packit 437b5e
Packit 437b5e
    # Automake (without 'foreign' option) requires that NEWS & README exist.
Packit 437b5e
    case " $automake_options " in
Packit 437b5e
      " foreign ") ;;
Packit 437b5e
      *)
Packit 437b5e
        func_ensure_NEWS
Packit 437b5e
        func_ensure_README
Packit 437b5e
        ;;
Packit 437b5e
    esac
Packit 437b5e
Packit 437b5e
    # Ensure ChangeLog presence.
Packit 437b5e
    if test -n "$gnulib_modules"; then
Packit 437b5e
      func_ifcontains "$gnulib_modules" gitlog-to-changelog \
Packit 437b5e
        func_ensure_changelog
Packit 437b5e
    else
Packit 437b5e
      $require_gnulib_cache
Packit 437b5e
      if $SED -n '/^gl_MODULES(\[/,/^])$/p' $gnulib_cache 2>/dev/null |
Packit 437b5e
         func_grep_q gitlog-to-changelog
Packit 437b5e
      then
Packit 437b5e
        func_ensure_changelog
Packit 437b5e
      fi
Packit 437b5e
    fi
Packit 437b5e
Packit 437b5e
    # Released 'autopoint' has the tendency to install macros that have
Packit 437b5e
    # been obsoleted in current 'gnulib', so run this before 'gnulib-tool'.
Packit 437b5e
    func_autopoint
Packit 437b5e
Packit 437b5e
    # Autoreconf runs 'aclocal' before 'libtoolize', which causes spurious
Packit 437b5e
    # warnings if the initial 'aclocal' is confused by the libtoolized
Packit 437b5e
    # (or worse: out-of-date) macro directory.
Packit 437b5e
    func_libtoolize
Packit 437b5e
Packit 437b5e
    # If you need to do anything after 'gnulib-tool' is done, but before
Packit 437b5e
    # 'autoreconf' runs, you don't need to override this whole function,
Packit 437b5e
    # because 'func_gnulib_tool' is hookable.
Packit 437b5e
    func_gnulib_tool
Packit 437b5e
Packit 437b5e
    func_autoreconf
Packit 437b5e
Packit 437b5e
    func_run_hooks func_reconfigure
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_gnulib_tool
Packit 437b5e
# ----------------
Packit 437b5e
# Run 'gnulib-tool' to fetch gnulib modules into the current package.
Packit 437b5e
#
Packit 437b5e
# It's assumed that since you are using gnulib's 'bootstrap' script,
Packit 437b5e
# you're also using gnulib elsewhere in your package.  If not, then
Packit 437b5e
# you can replace this function in 'bootstrap.conf' with:
Packit 437b5e
#
Packit 437b5e
#   func_gnulib_tool () { :; }
Packit 437b5e
#
Packit 437b5e
# (although the function returns immediately if $gnulib_tool is set to
Packit 437b5e
# true in any case).
Packit 437b5e
func_hookable func_gnulib_tool
Packit 437b5e
func_gnulib_tool ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    $require_gnulib_tool
Packit 437b5e
    $require_libtoolize
Packit 437b5e
Packit 437b5e
    test true = "$gnulib_tool" || {
Packit 437b5e
      # bootstrap.conf written for gnulib bootstrap expects
Packit 437b5e
      # gnulib_tool_option_extras to which --no-changelog is appended,
Packit 437b5e
      # but libtool bootstrap expects you to append to gnulib_tool_options
Packit 437b5e
      # so that you can override the --no-changelog default: make sure we
Packit 437b5e
      # support both styles so users can migrate between them easily.
Packit 437b5e
      gnulib_tool_all_options="$gnulib_tool_options $gnulib_tool_option_extras"
Packit 437b5e
Packit 437b5e
      if test -n "$gnulib_modules"; then
Packit 437b5e
        $require_gnulib_cache
Packit 437b5e
        $require_gnulib_tool_base_options
Packit 437b5e
Packit 437b5e
        gnulib_mode=--import
Packit 437b5e
Packit 437b5e
        # Try not to pick up any stale values from 'gnulib-cache.m4'.
Packit 437b5e
        rm -f "$gnulib_cache"
Packit 437b5e
Packit 437b5e
        test -n "$gnulib_tool_base_options" \
Packit 437b5e
            && func_append_uniq gnulib_tool_all_options " $gnulib_tool_base_options"
Packit 437b5e
        test -n "$gnulib_mk" \
Packit 437b5e
            && func_append_uniq gnulib_tool_all_options " --makefile-name=$gnulib_mk"
Packit 437b5e
        test -n "$tests_base" && {
Packit 437b5e
          func_append_uniq gnulib_tool_all_options " --tests-base=$tests_base"
Packit 437b5e
          func_append_uniq gnulib_tool_all_options " --with-tests"
Packit 437b5e
        }
Packit 437b5e
      else
Packit 437b5e
Packit 437b5e
        # 'gnulib_modules' and others are cached in 'gnulib-cache.m4':
Packit 437b5e
        # Use 'gnulib --update' to fetch gnulib modules.
Packit 437b5e
        gnulib_mode=--update
Packit 437b5e
      fi
Packit 437b5e
Packit 437b5e
      # Add a sensible default libtool option to gnulib_tool_options.
Packit 437b5e
      # The embedded echo is to squash whitespace before globbing.
Packit 437b5e
      case `echo " "$gnulib_tool_all_options" "` in
Packit 437b5e
        *" --no-libtool "*|*" --libtool "*) ;;
Packit 437b5e
        *)  if test true = "$LIBTOOLIZE"; then
Packit 437b5e
              func_append_uniq gnulib_tool_all_options " --no-libtool"
Packit 437b5e
            else
Packit 437b5e
              func_append_uniq gnulib_tool_all_options " --libtool"
Packit 437b5e
            fi
Packit 437b5e
            ;;
Packit 437b5e
      esac
Packit 437b5e
Packit 437b5e
      $opt_copy || func_append_uniq gnulib_tool_all_options " --symlink"
Packit 437b5e
Packit 437b5e
      func_append_uniq gnulib_tool_all_options " $gnulib_mode"
Packit 437b5e
      func_append gnulib_tool_all_options " $gnulib_modules"
Packit 437b5e
Packit 437b5e
      # The embedded echo is to squash whitespace before display.
Packit 437b5e
      gnulib_cmd=`echo $gnulib_tool $gnulib_tool_all_options`
Packit 437b5e
Packit 437b5e
      func_show_eval "$gnulib_cmd" 'exit $?'
Packit 437b5e
Packit 437b5e
      # Use 'gnulib-tool --copy-file' to install non-module files.
Packit 437b5e
      func_install_gnulib_non_module_files
Packit 437b5e
    }
Packit 437b5e
Packit 437b5e
    func_run_hooks func_gnulib_tool
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_fini
Packit 437b5e
# ---------
Packit 437b5e
# Function to perform all finalisation for the bootstrap process.
Packit 437b5e
func_hookable func_fini
Packit 437b5e
func_fini ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    func_gettext_configuration
Packit 437b5e
    func_clean_dangling_symlinks
Packit 437b5e
    func_clean_unused_macros
Packit 437b5e
    func_skip_po_recommendation
Packit 437b5e
Packit 437b5e
    func_run_hooks func_fini
Packit 437b5e
Packit 437b5e
    $require_bootstrap_uptodate
Packit 437b5e
Packit 437b5e
    func_echo "Done.  Now you can run './configure'."
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit 437b5e
# func_gettext_configuration
Packit 437b5e
# --------------------------
Packit 437b5e
# Edit configuration values into po/Makevars.
Packit 437b5e
func_hookable func_gettext_configuration
Packit 437b5e
func_gettext_configuration ()
Packit 437b5e
{
Packit 437b5e
    $debug_cmd
Packit 437b5e
Packit 437b5e
    $require_autopoint
Packit 437b5e
Packit 437b5e
    test true = "$AUTOPOINT" || {
Packit 437b5e
      $require_copyright_holder
Packit 437b5e
      $require_extra_locale_categories
Packit 437b5e
      $require_package_bugreport
Packit 437b5e
Packit 437b5e
      # Escape xgettext options for sed Makevars generation below.
Packit 437b5e
      # We have to delete blank lines in a separate script so that we don't
Packit 437b5e
      # append \\\ to the penultimate line, and then delete the last empty
Packit 437b5e
      # line, which messes up the variable substitution later in this
Packit 437b5e
      # function.  Note that adding a literal \\\ requires double escaping
Packit 437b5e
      # here, once for the execution subshell, and again for the assignment,
Packit 437b5e
      # which is why there are actually 12 (!!) backslashes in the script.
Packit 437b5e
      _G_xgettext_options=`echo "$xgettext_options$nl" |$SED '/^$/d' |$SED '
Packit 437b5e
          $b
Packit 437b5e
          s|$| \\\\\\\\\\\\|'`
Packit 437b5e
Packit 437b5e
      # Create gettext configuration.
Packit 437b5e
      func_echo "Creating po/Makevars from po/Makevars.template ..."
Packit 437b5e
      $RM -f po/Makevars
Packit 437b5e
      $SED '
Packit 437b5e
        /^EXTRA_LOCALE_CATEGORIES *=/s|=.*|= '"$extra_locale_categories"'|
Packit 437b5e
        /^COPYRIGHT_HOLDER *=/s|=.*|= '"$copyright_holder"'|
Packit 437b5e
        /^MSGID_BUGS_ADDRESS *=/s|=.*|= '"$package_bugreport"'|
Packit 437b5e
        /^XGETTEXT_OPTIONS *=/{
Packit 437b5e
          s|$| \\|
Packit 437b5e
          a\
Packit 437b5e
             '"$_G_xgettext_options"' \\\
Packit 437b5e
             $${end_of_xgettext_options+}
Packit 437b5e
        }
Packit 437b5e
      ' po/Makevars.template >po/Makevars || exit 1
Packit 437b5e
    }
Packit 437b5e
Packit 437b5e
    func_run_hooks func_gettext_configuration
Packit 437b5e
}
Packit 437b5e
Packit 437b5e
Packit