mirror of
git://git.savannah.gnu.org/libtool.git
synced 2025-02-17 15:10:02 +08:00
maint: factor common shell code into build-aux/funclib.sh.
Moving potentially reusable code into a common file that can be sourced by clients, and adjusting for impedance mismatch or necessary renames during integration. * build-aux/funclib.sh: New file. * build-aux/options-parser (Shell normalisation) (User overrideable command paths, Global variables, func_append) (require_term_colors, func_echo, func_echo_infix_1, func_warn) (func_error, func_fatal_error, func_quote_for_eval, func_verbose): Move from here... * build-aux/funclib.sh (Shell normalisation, User overrideable command paths, Global variables, func_append) (require_term_colors, func_echo, func_echo_infix_1) (func_warn_and_continue, func_error, func_fatal_error) (func_quote_for_eval, func_verbose): ...to here. * build-aux/general.m4sh (func_arith, func_basename) (func_dirname, func_dirname_and_basename, func_echo_all) (func_grep, func_len, func_mkdir_p, func_mktempdir) (func_normal_abspath, func_relative_path, func_quote_for_expand) (func_stripname, func_show_eval, func_tr_sh): Move from here... * build-aux/funclib.sh(func_arith, func_basename) (func_dirname, func_dirname_and_basename, func_echo_all) (func_grep, func_len, func_mkdir_p, func_mktempdir) (func_normal_abspath, func_relative_path, func_quote_for_expand) (func_stripname, func_show_eval, func_tr_sh): ...to here. * bootstrap (usage message): Document `-no-warn' option. (func_append_u, func_warning): Move from here... * build-aux/funclib.sh (func_append_uniq, func_warning): ...to here. * bootstrap, build-aux/extract-trace: Source build-aux/funclib.sh before build-aux/options-parser. * build-aux/options-parser (usage, long_help_message): Set default values to match what is parsed by the unmodified parser. * build-aux/extract-trace (usage, long_help_message): Only set from func_main, so that clients sourcing this file can still use the correct defaults from build-aux/options-parser. * bootstrap (bootstrap_options_prep, bootstrap_parse_options): Move warning option parsing from here... * build-aux/option-parser (func_options_prep) (func_parse_options): ...to here, where all clients can benefit. * Makefile.am (funclib_sh): New macro; path to funclib.sh. (EXTRA_DIST): Add $(funclib_sh). Signed-off-by: Gary V. Vaughan <gary@gnu.org>
This commit is contained in:
parent
2a43c87092
commit
a73a99b88a
@ -86,6 +86,7 @@ CLEANFILES += libtool libtoolize
|
||||
configure_ac = $(srcdir)/configure.ac
|
||||
config_status = $(top_builddir)/config.status
|
||||
extract_trace = $(srcdir)/$(aux_dir)/extract-trace
|
||||
funclib_sh = $(srcdir)/$(aux_dir)/funclib.sh
|
||||
libtoolize_in = $(srcdir)/libtoolize.in
|
||||
ltmain_sh = $(srcdir)/$(aux_dir)/ltmain.sh
|
||||
libtool_m4 = $(srcdir)/$(macro_dir)/libtool.m4
|
||||
@ -93,7 +94,7 @@ ltversion_in = $(srcdir)/$(macro_dir)/ltversion.in
|
||||
ltversion_m4 = $(srcdir)/$(macro_dir)/ltversion.m4
|
||||
options_parser = $(srcdir)/$(aux_dir)/options-parser
|
||||
|
||||
EXTRA_DIST += $(extract_trace) $(libtoolize_in) $(libtoolize_m4sh) \
|
||||
EXTRA_DIST += $(extract_trace) $(funclib_sh) $(libtoolize_in) $(libtoolize_m4sh) \
|
||||
$(ltmain_m4sh) $(ltmain_sh) $(ltversion_in) \
|
||||
$(ltversion_m4) $(options_parser)
|
||||
|
||||
@ -491,6 +492,8 @@ pkgltdl_files = COPYING.LIB \
|
||||
ltdl.mk \
|
||||
slist.c
|
||||
|
||||
helper_scripts = extract-trace funclib.sh options-parser
|
||||
|
||||
install-data-local: $(lt_Makefile_in)
|
||||
@$(NORMAL_INSTALL)
|
||||
## Don't install over the top of an old pkgdatadir
|
||||
@ -503,7 +506,7 @@ install-data-local: $(lt_Makefile_in)
|
||||
$(INSTALL_DATA) "$(srcdir)/$(macro_dir)/$$p" "$(DESTDIR)$(aclocaldir)/$$p"; \
|
||||
done
|
||||
## install the helper scripts
|
||||
@list='extract-trace funclib.sh options-parser $(pkgaux_scripts)' && \
|
||||
@list='$(helper_scripts) $(pkgaux_scripts)' && \
|
||||
for p in $$list; do \
|
||||
d=`echo "$(DESTDIR)$(pkgauxdir)/$$p" |$(SED) 's|[^/]*$$||'`; \
|
||||
test -d "$$d" || $(mkinstalldirs) "$$d"; \
|
||||
@ -597,7 +600,7 @@ uninstall-hook:
|
||||
echo " rm -f '$(DESTDIR)$(pkgdatadir)/$$f'"; \
|
||||
rm -f "$(DESTDIR)$(pkgdatadir)/$$f"; \
|
||||
done
|
||||
@list='extract-trace options-parser $(pkgaux_scripts) $(pkgaux_data_files)'; \
|
||||
@list='$(helper_scripts) $(pkgaux_scripts) $(pkgaux_data_files)'; \
|
||||
for f in $$list; do \
|
||||
echo " rm -f '$(DESTDIR)$(pkgauxdir)/$$f'"; \
|
||||
rm -f "$(DESTDIR)$(pkgauxdir)/$$f"; \
|
||||
|
167
bootstrap
167
bootstrap
@ -1,6 +1,7 @@
|
||||
#! /bin/sh
|
||||
|
||||
# Source required external libraries:
|
||||
. `echo "$0" |${SED-sed} 's|[^/]*$||'`"build-aux/funclib.sh"
|
||||
. `echo "$0" |${SED-sed} 's|[^/]*$||'`"build-aux/options-parser"
|
||||
. `echo "$0" |${SED-sed} 's|[^/]*$||'`"build-aux/extract-trace"
|
||||
|
||||
@ -382,22 +383,22 @@ func_gnulib_tool ()
|
||||
# `gnulib_modules' and others are maintained in `bootstrap.conf`:
|
||||
# Use `gnulib --import` to fetch gnulib modules.
|
||||
test -n "$build_aux" \
|
||||
&& func_append_u gnulib_tool_options " --aux-dir=$build_aux"
|
||||
&& func_append_uniq gnulib_tool_options " --aux-dir=$build_aux"
|
||||
test -n "$macro_dir" \
|
||||
&& func_append_u gnulib_tool_options " --m4-base=$macro_dir"
|
||||
&& func_append_uniq gnulib_tool_options " --m4-base=$macro_dir"
|
||||
test -n "$doc_base" \
|
||||
&& func_append_u gnulib_tool_options " --doc-base=$doc_base"
|
||||
&& func_append_uniq gnulib_tool_options " --doc-base=$doc_base"
|
||||
test -n "$gnulib_name" \
|
||||
&& func_append_u gnulib_tool_options " --lib=$gnulib_name"
|
||||
&& func_append_uniq gnulib_tool_options " --lib=$gnulib_name"
|
||||
test -n "$local_gl_dir" \
|
||||
&& func_append_u gnulib_tool_options " --local-dir=$local_gl_dir"
|
||||
&& func_append_uniq gnulib_tool_options " --local-dir=$local_gl_dir"
|
||||
test -n "$source_base" \
|
||||
&& func_append_u gnulib_tool_options " --source-base=$source_base"
|
||||
&& func_append_uniq gnulib_tool_options " --source-base=$source_base"
|
||||
test -n "$gnulib_mk" \
|
||||
&& func_append_u gnulib_tool_options " --makefile-name=$gnulib_mk"
|
||||
&& func_append_uniq gnulib_tool_options " --makefile-name=$gnulib_mk"
|
||||
test -n "$tests_base" && {
|
||||
func_append_u gnulib_tool_options " --tests-base=$tests_base"
|
||||
func_append_u gnulib_tool_options " --with-tests"
|
||||
func_append_uniq gnulib_tool_options " --tests-base=$tests_base"
|
||||
func_append_uniq gnulib_tool_options " --with-tests"
|
||||
}
|
||||
else
|
||||
|
||||
@ -411,16 +412,16 @@ func_gnulib_tool ()
|
||||
case `echo " "$gnulib_tool_options" "` in
|
||||
*" --no-libtool "*|*" --libtool "*) ;;
|
||||
*) if test true = "$LIBTOOLIZE"; then
|
||||
func_append_u gnulib_tool_options " --no-libtool"
|
||||
func_append_uniq gnulib_tool_options " --no-libtool"
|
||||
else
|
||||
func_append_u gnulib_tool_options " --libtool"
|
||||
func_append_uniq gnulib_tool_options " --libtool"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
$opt_copy || func_append_u gnulib_tool_options " --symlink"
|
||||
$opt_copy || func_append_uniq gnulib_tool_options " --symlink"
|
||||
|
||||
func_append_u gnulib_tool_options " $gnulib_mode"
|
||||
func_append_uniq gnulib_tool_options " $gnulib_mode"
|
||||
func_append gnulib_tool_options " $gnulib_modules"
|
||||
|
||||
# The embedded echo is to squash whitespace before display.
|
||||
@ -1827,30 +1828,6 @@ func_ifcontains ()
|
||||
}
|
||||
|
||||
|
||||
# func_append_u VAR VALUE
|
||||
# -----------------------
|
||||
# Append unique VALUE onto the existing contents of VAR, assuming
|
||||
# entries are delimited by the first character of VALUE. For example:
|
||||
#
|
||||
# func_append_u options " --another-option option-argument"
|
||||
#
|
||||
# will only append to $options if " --another-option option-argument "
|
||||
# is not already present somewhere in $options already (note spaces at
|
||||
# each end implied by leading space in second argument).
|
||||
func_append_u ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
eval _G_current_value='`$bs_echo $'$1'`'
|
||||
_G_delim=`expr "$2" : '\(.\)'`
|
||||
|
||||
case $_G_delim$_G_current_value$_G_delim in
|
||||
*"$2$_G_delim"*) ;;
|
||||
*) func_append "$@" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
# func_strpad STR WIDTH CHAR
|
||||
# --------------------------
|
||||
# Trim STR, or pad with CHAR to force a total length of WIDTH.
|
||||
@ -2016,28 +1993,6 @@ func_permissions_error ()
|
||||
}
|
||||
|
||||
|
||||
# func_warning CATEGORY ARG...
|
||||
# ----------------------------
|
||||
# Echo program name prefixed warning message to standard error. Warning
|
||||
# messages can be filtered according to CATEGORY.
|
||||
func_warning ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
case " $warning_categories " in
|
||||
*" $1 "*) ;;
|
||||
*) func_internal_error "invalid warning category \`$1'" ;;
|
||||
esac
|
||||
|
||||
_G_category=$1
|
||||
shift
|
||||
|
||||
case " $opt_warning " in
|
||||
*" $_G_category "*) $warning_func ${1+"$@"} ;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
# func_show_eval CMD [FAIL_EXP]
|
||||
# -----------------------------
|
||||
# Unless opt_silent is true, then output CMD. Then, if opt_dryrun is
|
||||
@ -2337,38 +2292,36 @@ usage='$progpath [OPTION]...'
|
||||
# Short help message in response to `-h'. Add to this in `bootstrap.conf'
|
||||
# if you accept any additional options.
|
||||
usage_message='Common Bootstrap Options:
|
||||
-c, --copy copy files instead of creating symbolic links.
|
||||
--debug enable verbose shell tracing
|
||||
-n, --dry-run print commands rather than running them
|
||||
-f, --force attempt to bootstrap even if the sources seem not
|
||||
to have been checked out.
|
||||
--gnulib-srcdir=DIRNAME
|
||||
specify a local directory where gnulib sources
|
||||
reside. Use this if you already have the gnulib
|
||||
sources on your machine, and don'\''t want to waste
|
||||
your bandwidth downloading them again. Defaults to
|
||||
\$GNULIB_SRCDIR.
|
||||
--skip-git do not fetch files from remote repositories
|
||||
--skip-po do not download po files.
|
||||
-v, --verbose verbosely report processing
|
||||
--version print version information and exit
|
||||
-W, --warnings=CATEGORY
|
||||
report the warnings falling in CATEGORY [all]
|
||||
-h, --help print short or long help message and exit
|
||||
-c, --copy copy files instead of creating symbolic links.
|
||||
--debug enable verbose shell tracing
|
||||
-n, --dry-run print commands rather than running them
|
||||
-f, --force attempt to bootstrap even if the sources seem not
|
||||
to have been checked out.
|
||||
--gnulib-srcdir=DIRNAME
|
||||
specify a local directory where gnulib sources
|
||||
reside. Use this if you already have the gnulib
|
||||
sources on your machine, and don'\''t want to waste
|
||||
your bandwidth downloading them again. Defaults to
|
||||
\$GNULIB_SRCDIR.
|
||||
--no-warnings equivalent to \`-Wnone'\''
|
||||
--skip-git do not fetch files from remote repositories
|
||||
--skip-po do not download po files.
|
||||
-v, --verbose verbosely report processing
|
||||
--version print version information and exit
|
||||
-W, --warnings=CATEGORY
|
||||
report the warnings falling in CATEGORY [all]
|
||||
-h, --help print short or long help message and exit
|
||||
'
|
||||
|
||||
# Additional text appended to `usage_message' in response to `--help'.
|
||||
long_help_message="
|
||||
Warning categories include:
|
||||
\`all' show all warnings
|
||||
\`none' turn off all the warnings
|
||||
\`error' warnings are treated as fatal errors
|
||||
\`recommend' show warnings about missing recommended packages
|
||||
\`settings' show warnings about missing \`bootstrap.conf' settings
|
||||
\`upgrade' show warnings about out-dated files
|
||||
long_help_message=$long_help_message"
|
||||
\`recommend' show warnings about missing recommended packages
|
||||
\`settings' show warnings about missing \`$progname.conf' settings
|
||||
\`upgrade' show warnings about out-dated files
|
||||
|
||||
If the file $progpath.conf exists in the same directory as this script,
|
||||
its contents are read as shell variables to configure the bootstrap.
|
||||
If the file \`$progname.conf' exists in the same directory as this
|
||||
script, its contents are read as shell variables to configure the
|
||||
bootstrap.
|
||||
|
||||
For build prerequisites, environment variables like \$AUTOCONF and
|
||||
\$AMTAR are honored.
|
||||
@ -2388,8 +2341,6 @@ bootstrap_options_prep ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
warning_func=func_warn
|
||||
|
||||
# Option defaults:
|
||||
opt_copy=${copy-'false'}
|
||||
opt_dry_run=false
|
||||
@ -2397,7 +2348,6 @@ bootstrap_options_prep ()
|
||||
opt_gnulib_srcdir=$GNULIB_SRCDIR
|
||||
opt_skip_git=false
|
||||
opt_skip_po=false
|
||||
opt_warning=
|
||||
|
||||
# Pass back the list of options we consumed.
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
@ -2433,38 +2383,6 @@ bootstrap_parse_options ()
|
||||
--skip-git) opt_skip_git=: ;;
|
||||
--skip-po) opt_skip_po=: ;;
|
||||
|
||||
--warnings|--warning|-W)
|
||||
test $# = 0 && func_missing_arg $_G_opt && break
|
||||
case " $1 " in
|
||||
" all ")
|
||||
opt_warning=" $warning_categories"
|
||||
;;
|
||||
" none ")
|
||||
opt_warning=" none"
|
||||
warning_func=:
|
||||
;;
|
||||
" error ")
|
||||
warning_func=func_fatal_error
|
||||
;;
|
||||
*" $warning_categories "*)
|
||||
func_append_u opt_warning " $1"
|
||||
;;
|
||||
*)
|
||||
func_fatal_error \
|
||||
"unsupported warning category: \`$1'"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
;;
|
||||
|
||||
# Separate optargs to short options:
|
||||
-W*)
|
||||
func_split_short_opt "$_G_opt"
|
||||
set dummy "$func_split_short_opt_name" \
|
||||
"$func_split_short_opt_arg" ${1+"$@"}
|
||||
shift
|
||||
;;
|
||||
|
||||
# Separate non-argument short options:
|
||||
-c*|-f*|-n*)
|
||||
func_split_short_opt "$_G_opt"
|
||||
@ -2492,14 +2410,11 @@ bootstrap_validate_options ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
# Display all warnings if -W was not given.
|
||||
test -n "$opt_warning" || opt_warning=$warning_categories
|
||||
|
||||
# Validate options.
|
||||
test $# -gt 0 \
|
||||
&& func_fatal_help "too many arguments"
|
||||
|
||||
# Pass back the list of unconsumed options left.
|
||||
# Pass back the (empty) list of unconsumed options.
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
bootstrap_validate_options_result=$func_quote_for_eval_result
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
#! /bin/sh
|
||||
|
||||
# Make sure we've evaluated the option-parser library.
|
||||
test -n "$progpath" || . `echo "$0" |${SED-sed} 's|[^/]*$||'`/options-parser
|
||||
# Make sure we've evaluated scripts we depend on.
|
||||
test -n "$progpath" || . `echo "$0" |${SED-sed} 's|[^/]*$||'`/funclib.sh
|
||||
test -n "$usage" || . `echo "$0" |${SED-sed} 's|[^/]*$||'`/options-parser
|
||||
|
||||
# Set a version string.
|
||||
scriptversion=2012-10-07.10; # UTC
|
||||
@ -42,22 +43,6 @@ scriptversion=2012-10-07.10; # UTC
|
||||
# script in its own process on every call.
|
||||
|
||||
|
||||
## -------------- ##
|
||||
## Configuration. ##
|
||||
## -------------- ##
|
||||
|
||||
usage='$progname MACRO_NAME FILE [...]'
|
||||
|
||||
long_help_message='
|
||||
The first argument to this program is the name of an autotools macro
|
||||
whose arguments you want to extract by examining the files listed in the
|
||||
remaining arguments using the same tool that Autoconf and Automake use,
|
||||
GNU M4.
|
||||
|
||||
The arguments are returned separated by colons, with each traced call
|
||||
on a separate line.'
|
||||
|
||||
|
||||
|
||||
## ------------------##
|
||||
## Helper functions. ##
|
||||
@ -369,6 +354,18 @@ func_main ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
# Configuration.
|
||||
usage='$progname MACRO_NAME FILE [...]'
|
||||
|
||||
long_help_message='
|
||||
The first argument to this program is the name of an autotools macro
|
||||
whose arguments you want to extract by examining the files listed in the
|
||||
remaining arguments using the same tool that Autoconf and Automake use,
|
||||
GNU M4.
|
||||
|
||||
The arguments are returned separated by colons, with each traced call
|
||||
on a separate line.'
|
||||
|
||||
# Option processing.
|
||||
func_options "$@"
|
||||
eval set dummy "$func_options_result"; shift
|
||||
|
1143
build-aux/funclib.sh
Normal file
1143
build-aux/funclib.sh
Normal file
File diff suppressed because it is too large
Load Diff
@ -37,6 +37,7 @@ scriptversion=2012-10-07.10; # UTC
|
||||
# For the simplest scripts you might need only:
|
||||
#
|
||||
# #!/bin/sh
|
||||
# . relative/path/to/funclib.sh
|
||||
# . relative/path/to/options-parser
|
||||
# scriptversion=1.0
|
||||
# func_options ${1+"$@"}
|
||||
@ -62,49 +63,6 @@ scriptversion=2012-10-07.10; # UTC
|
||||
# below, and following the instructions in the `Option parsing'
|
||||
# section further down.
|
||||
|
||||
## -------------------- ##
|
||||
## Shell normalisation. ##
|
||||
## -------------------- ##
|
||||
|
||||
# Some shells need a little help to be as Bourne compatible as possible.
|
||||
# Before doing anything else, make sure all that help has been provided!
|
||||
|
||||
DUALCASE=1; export DUALCASE # for MKS sh
|
||||
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
|
||||
emulate sh
|
||||
NULLCMD=:
|
||||
# Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
|
||||
# is contrary to our usage. Disable this feature.
|
||||
alias -g '${1+"$@"}'='"$@"'
|
||||
setopt NO_GLOB_SUBST
|
||||
else
|
||||
case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
|
||||
fi
|
||||
|
||||
# NLS nuisances.
|
||||
LANGUAGE=C
|
||||
export LANGUAGE
|
||||
|
||||
# Ensure file names are sorted consistently across platforms.
|
||||
LC_ALL=C
|
||||
export LC_ALL
|
||||
|
||||
# CDPATH.
|
||||
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
|
||||
|
||||
|
||||
## ------------------------------- ##
|
||||
## User overridable command paths. ##
|
||||
## ------------------------------- ##
|
||||
|
||||
# All uppercase variable names are used for environment variables. These
|
||||
# variables can be overridden by the user before calling a script that
|
||||
# uses them if a suitable command of that name is not already available
|
||||
# in the command search PATH.
|
||||
|
||||
: ${SED="sed"}
|
||||
|
||||
|
||||
## -------------- ##
|
||||
## Configuration. ##
|
||||
## -------------- ##
|
||||
@ -124,106 +82,26 @@ usage='$progpath [OPTION]...'
|
||||
# override it after sourcing this library to reflect the full set of
|
||||
# options your script accepts.
|
||||
usage_message="\
|
||||
--debug enable verbose shell tracing
|
||||
-v, --verbose verbosely report processing
|
||||
--version print version information and exit
|
||||
-h, --help print short or long help message and exit
|
||||
--debug enable verbose shell tracing
|
||||
-W, --warnings=CATEGORY
|
||||
report the warnings falling in CATEGORY [all]
|
||||
-v, --verbose verbosely report processing
|
||||
--version print version information and exit
|
||||
-h, --help print short or long help message and exit
|
||||
"
|
||||
|
||||
# Additional text appended to `usage_message' in response to `--help'.
|
||||
long_help_message=
|
||||
long_help_message="
|
||||
Warning categories include:
|
||||
\`all' show all warnings
|
||||
\`none' turn off all the warnings
|
||||
\`error' warnings are treated as fatal errors"
|
||||
|
||||
# Help message printed before fatal option parsing errors.
|
||||
fatal_help='Try \`$progname --help'\'' for more information.'
|
||||
|
||||
|
||||
|
||||
## ----------------- ##
|
||||
## Global variables. ##
|
||||
## ----------------- ##
|
||||
|
||||
# Except for the global variables explicitly listed below, the following
|
||||
# functions in the '^func_' namespace, and the '^require_' namespace
|
||||
# variables initialised in the `Resource management' section, sourcing
|
||||
# this file will not pollute your global namespace with anything
|
||||
# else. There's no portable way to scope variables in Bourne shell
|
||||
# though, so actually running these functions will sometimes place
|
||||
# results into a variable named after the function, and often use
|
||||
# temporary variables in the `^_G_' namespace. If you are careful to
|
||||
# avoid using those namespaces casually in your sourcing script, things
|
||||
# should continue to work as you expect. And, of course, you can freely
|
||||
# overwrite any of the functions or variables defined here before
|
||||
# calling anything to customize them.
|
||||
|
||||
EXIT_SUCCESS=0
|
||||
EXIT_FAILURE=1
|
||||
EXIT_MISMATCH=63 # $? = 63 is used to indicate version mismatch to missing.
|
||||
EXIT_SKIP=77 # $? = 77 is used to indicate a skipped test to automake.
|
||||
|
||||
# Allow overriding, eg assuming that you follow the convention of
|
||||
# putting `$debug_cmd' at the start of all your functions, you can get
|
||||
# bash to show function call trace with:
|
||||
# debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash bootstrap
|
||||
debug_cmd=${debug_cmd-":"}
|
||||
exit_cmd=:
|
||||
|
||||
dirname='s|/[^/]*$||'
|
||||
basename='s|^.*/||'
|
||||
|
||||
nl='
|
||||
'
|
||||
|
||||
# There are still modern systems that have problems with `echo' mis-
|
||||
# handling backslashes, among others, so make sure $bs_echo is set to a
|
||||
# command that correctly interprets backslashes.
|
||||
# (this code from Autoconf 2.68)
|
||||
|
||||
# Printing a long string crashes Solaris 7 /usr/bin/printf.
|
||||
bs_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
|
||||
bs_echo=$bs_echo$bs_echo$bs_echo$bs_echo$bs_echo
|
||||
bs_echo=$bs_echo$bs_echo$bs_echo$bs_echo$bs_echo$bs_echo
|
||||
# Prefer a ksh shell builtin over an external printf program on Solaris,
|
||||
# but without wasting forks for bash or zsh.
|
||||
if test -z "$BASH_VERSION$ZSH_VERSION" \
|
||||
&& (test "X`print -r -- $bs_echo`" = "X$bs_echo") 2>/dev/null; then
|
||||
bs_echo='print -r --'
|
||||
bs_echo_n='print -rn --'
|
||||
elif (test "X`printf %s $bs_echo`" = "X$bs_echo") 2>/dev/null; then
|
||||
bs_echo='printf %s\n'
|
||||
bs_echo_n='printf %s'
|
||||
else
|
||||
if test "X`(/usr/ucb/echo -n -n $bs_echo) 2>/dev/null`" = "X-n $bs_echo"; then
|
||||
bs_echo_body='eval /usr/ucb/echo -n "$1$nl"'
|
||||
bs_echo_n='/usr/ucb/echo -n'
|
||||
else
|
||||
bs_echo_body='eval expr "X$1" : "X\\(.*\\)"'
|
||||
bs_echo_n_body='eval
|
||||
arg=$1;
|
||||
case $arg in #(
|
||||
*"$nl"*)
|
||||
expr "X$arg" : "X\\(.*\\)$nl";
|
||||
arg=`expr "X$arg" : ".*$nl\\(.*\\)"`;;
|
||||
esac;
|
||||
expr "X$arg" : "X\\(.*\\)" | tr -d "$nl"
|
||||
'
|
||||
export bs_echo_n_body
|
||||
bs_echo_n='sh -c $bs_echo_n_body bs_echo'
|
||||
fi
|
||||
export bs_echo_body
|
||||
bs_echo='sh -c $bs_echo_body bs_echo'
|
||||
fi
|
||||
|
||||
# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
|
||||
# is ksh but when the shell is invoked as "sh" and the current value of
|
||||
# the _XPG environment variable is not equal to 1 (one), the special
|
||||
# positional parameter $0, within a function call, is the name of the
|
||||
# function.
|
||||
progpath=$0
|
||||
|
||||
# The name of this program.
|
||||
progname=`$bs_echo "$progpath" |$SED "$basename"`
|
||||
|
||||
|
||||
## ------------------------- ##
|
||||
## Hook function management. ##
|
||||
## ------------------------- ##
|
||||
@ -232,48 +110,6 @@ progname=`$bs_echo "$progpath" |$SED "$basename"`
|
||||
# to the main code. A hook is just a named list of of function, that can
|
||||
# be run in order later on.
|
||||
|
||||
# We should try to minimise forks, especially on Windows where they are
|
||||
# unreasonably slow, so skip the feature probes when bash or zsh are
|
||||
# being used:
|
||||
if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
|
||||
: ${_G_HAVE_XSI_OPS="yes"}
|
||||
# The += operator was introduced in bash 3.1
|
||||
case $BASH_VERSION in
|
||||
[12].* | 3.0 | 3.0.*) ;;
|
||||
*)
|
||||
: ${_G_HAVE_PLUSEQ_OP="yes"}
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
|
||||
# func_append VAR VALUE
|
||||
# ---------------------
|
||||
# Append VALUE onto the existing contents of VAR.
|
||||
test -z "$_G_HAVE_PLUSEQ_OP" \
|
||||
&& (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
|
||||
&& _G_HAVE_PLUSEQ_OP=yes
|
||||
|
||||
if test yes = "$_G_HAVE_PLUSEQ_OP"
|
||||
then
|
||||
# This is an XSI compatible shell, allowing a faster implementation...
|
||||
eval 'func_append ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
eval "$1+=\$2"
|
||||
}'
|
||||
else
|
||||
# ...otherwise fall back to using expr, which is often a shell builtin.
|
||||
func_append ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
eval "$1=\$$1\$2"
|
||||
}
|
||||
fi
|
||||
|
||||
|
||||
# func_hookable FUNC_NAME
|
||||
# -----------------------
|
||||
# Declare that FUNC_NAME will run hooks added with
|
||||
@ -453,6 +289,7 @@ func_options_prep ()
|
||||
|
||||
# Option defaults:
|
||||
opt_verbose=false
|
||||
opt_warning_types=
|
||||
|
||||
func_run_hooks func_options_prep ${1+"$@"}
|
||||
|
||||
@ -491,6 +328,37 @@ func_parse_options ()
|
||||
$debug_cmd
|
||||
;;
|
||||
|
||||
--no-warnings|--no-warning|--no-warn)
|
||||
set dummy --warnings none ${1+"$@"}
|
||||
shift
|
||||
;;
|
||||
|
||||
--warnings|--warning|-W)
|
||||
test $# = 0 && func_missing_arg $_G_opt && break
|
||||
case " $warning_categories $1" in
|
||||
*" $1 "*)
|
||||
# trailing space prevents matching last $1 above
|
||||
func_append_uniq opt_warning_types " $1"
|
||||
;;
|
||||
*all)
|
||||
opt_warning_types=$warning_categories
|
||||
;;
|
||||
*none)
|
||||
opt_warning_types=none
|
||||
warning_func=:
|
||||
;;
|
||||
*error)
|
||||
opt_warning_types=$warning_categories
|
||||
warning_func=func_fatal_error
|
||||
;;
|
||||
*)
|
||||
func_fatal_error \
|
||||
"unsupported warning category: \`$1'"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
;;
|
||||
|
||||
--verbose|-v) opt_verbose=: ;;
|
||||
--version) func_version ;;
|
||||
-\?|-h) func_usage ;;
|
||||
@ -503,6 +371,14 @@ func_parse_options ()
|
||||
shift
|
||||
;;
|
||||
|
||||
# Separate optargs to short options:
|
||||
-W*)
|
||||
func_split_short_opt "$_G_opt"
|
||||
set dummy "$func_split_short_opt_name" \
|
||||
"$func_split_short_opt_arg" ${1+"$@"}
|
||||
shift
|
||||
;;
|
||||
|
||||
# Separate non-argument short options:
|
||||
-\?*|-h*|-v*|-x*)
|
||||
func_split_short_opt "$_G_opt"
|
||||
@ -511,7 +387,7 @@ func_parse_options ()
|
||||
shift
|
||||
;;
|
||||
|
||||
--) set dummy "$_G_opt" "*"; shift; break ;;
|
||||
--) break ;;
|
||||
-*) func_fatal_help "unrecognised option: \`$_G_opt'" ;;
|
||||
*) set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
|
||||
esac
|
||||
@ -532,6 +408,9 @@ func_validate_options ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
# Display all warnings if -W was not given.
|
||||
test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
|
||||
|
||||
func_run_hooks func_validate_options ${1+"$@"}
|
||||
|
||||
# Bail if the options were screwed!
|
||||
@ -543,47 +422,6 @@ func_validate_options ()
|
||||
|
||||
|
||||
|
||||
## -------------------- ##
|
||||
## Resource management. ##
|
||||
## -------------------- ##
|
||||
|
||||
# This section contains definitions for functions that each ensure a
|
||||
# particular resource (a file, or a non-empty configuration variable for
|
||||
# example) is available, and if appropriate to extract default values
|
||||
# from pertinent package files. Call them using their associated
|
||||
# `require_*' variable to ensure that they are executed, at most, once.
|
||||
#
|
||||
# It's entirely deliberate that calling these functions can set
|
||||
# variables that don't obey the namespace limitations obeyed by the rest
|
||||
# of this file, in order that that they be as useful as possible to
|
||||
# callers.
|
||||
|
||||
|
||||
# require_term_colors
|
||||
# -------------------
|
||||
# Allow display of bold text on terminals that support it.
|
||||
require_term_colors=func_require_term_colors
|
||||
func_require_term_colors ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
test -t 1 && {
|
||||
test -n "`tput sgr0 2>/dev/null`" && {
|
||||
tc_reset=`tput sgr0`
|
||||
test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
|
||||
tc_standout=$tc_bold
|
||||
test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
|
||||
test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
|
||||
test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
|
||||
test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
|
||||
test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
|
||||
}
|
||||
}
|
||||
|
||||
require_term_colors=:
|
||||
}
|
||||
|
||||
|
||||
## ------------------##
|
||||
## Helper functions. ##
|
||||
## ------------------##
|
||||
@ -591,73 +429,6 @@ func_require_term_colors ()
|
||||
# This section contains the helper functions used by the rest of the
|
||||
# hookable option parser framework in ascii-betical order.
|
||||
|
||||
# func_echo ARG...
|
||||
# ----------------
|
||||
# Echo program name prefixed message, taking newlines into account.
|
||||
func_echo ()
|
||||
{
|
||||
_G_message=$*
|
||||
|
||||
save_IFS=$IFS
|
||||
IFS=$nl
|
||||
for _G_line in $_G_message; do
|
||||
IFS=$save_IFS
|
||||
$bs_echo "$progname: $_G_line"
|
||||
done
|
||||
IFS=$save_IFS
|
||||
}
|
||||
|
||||
|
||||
# func_echo_infix_1 INFIX ARG...
|
||||
# ------------------------------
|
||||
# Echo program name, followed by INFIX on the first line, with any
|
||||
# additional lines not showing INFIX.
|
||||
func_echo_infix_1 ()
|
||||
{
|
||||
$require_term_colors
|
||||
|
||||
_G_infix=$1; shift
|
||||
_G_prefix="$progname: $tc_standout$tc_red$_G_infix$tc_reset: "
|
||||
_G_message=$*
|
||||
|
||||
save_IFS=$IFS
|
||||
IFS=$nl
|
||||
for _G_line in $_G_message; do
|
||||
IFS=$save_IFS
|
||||
$bs_echo "$_G_prefix$tc_bold$_G_line$tc_reset" 1>&2
|
||||
_G_prefix="$progname: `echo $_G_infix | sed 's|.| |g'` "
|
||||
done
|
||||
IFS=$save_IFS
|
||||
}
|
||||
|
||||
|
||||
# func_warn ARG...
|
||||
# ----------------
|
||||
# Echo program name (and 'warning') prefixed message to standard error.
|
||||
func_warn ()
|
||||
{
|
||||
func_echo_infix_1 warning "$*"
|
||||
}
|
||||
|
||||
|
||||
# func_error ARG...
|
||||
# -----------------
|
||||
# Echo program name prefixed message to standard error.
|
||||
func_error ()
|
||||
{
|
||||
func_echo_infix_1 error "$*"
|
||||
}
|
||||
|
||||
|
||||
# func_fatal_error ARG...
|
||||
# -----------------------
|
||||
# Echo program name prefixed message to standard error, and exit.
|
||||
func_fatal_error ()
|
||||
{
|
||||
func_error ${1+"$@"}
|
||||
exit $EXIT_FAILURE
|
||||
}
|
||||
|
||||
|
||||
# func_fatal_help ARG...
|
||||
# ----------------------
|
||||
@ -700,48 +471,6 @@ func_missing_arg ()
|
||||
}
|
||||
|
||||
|
||||
# func_quote_for_eval ARG...
|
||||
# --------------------------
|
||||
# Aesthetically quote ARGs to be evaled later.
|
||||
# This function returns two values: FN_QUOTE_FOR_EVAL_RESULT
|
||||
# is double-quoted, suitable for a subsequent eval, whereas
|
||||
# FN_QUOTE_FOR_EVAL_UNQUOTED_RESULT has merely all characters
|
||||
# which are still active within double quotes backslashified.
|
||||
func_quote_for_eval ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
_G_sed_quote_subst='s|\([`"$\\]\)|\\\1|g'
|
||||
|
||||
func_quote_for_eval_result=
|
||||
while test $# -gt 0; do
|
||||
case $1 in
|
||||
*[\\\`\"\$]*)
|
||||
_G_unquoted_arg=`printf '%s\n' "$1" |$SED "$_G_sed_quote_subst"` ;;
|
||||
*)
|
||||
_G_unquoted_arg=$1 ;;
|
||||
esac
|
||||
|
||||
case $_G_unquoted_arg in
|
||||
# Double-quote args containing shell metacharacters to delay
|
||||
# word splitting, command substitution and variable expansion
|
||||
# for a subsequent eval.
|
||||
# Many Bourne shells cannot handle close brackets correctly
|
||||
# in scan sets, so we specify it separately.
|
||||
*[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
|
||||
_G_quoted_arg=\"$_G_unquoted_arg\"
|
||||
;;
|
||||
*)
|
||||
_G_quoted_arg=$_G_unquoted_arg ;;
|
||||
esac
|
||||
test -n "$func_quote_for_eval_result" \
|
||||
&& func_append func_quote_for_eval_result " "
|
||||
func_append func_quote_for_eval_result "$_G_quoted_arg"
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# func_split_equals STRING
|
||||
# ------------------------
|
||||
# Set func_split_equals_lhs and func_split_equals_rhs shell variables after
|
||||
@ -831,15 +560,6 @@ func_usage_message ()
|
||||
}
|
||||
|
||||
|
||||
# func_verbose ARG...
|
||||
# -------------------
|
||||
# Echo program name prefixed message in verbose mode only.
|
||||
func_verbose ()
|
||||
{
|
||||
$opt_verbose && func_echo ${1+"$@"}
|
||||
}
|
||||
|
||||
|
||||
# func_version
|
||||
# ------------
|
||||
# Echo version message to standard output and exit.
|
||||
|
@ -32,6 +32,7 @@ AS_INIT[]m4_divert_push([HEADER-COPYRIGHT])
|
||||
# we also need to be able to find them in $srcdir during testing, or if
|
||||
# executed directly from the build tree.
|
||||
|
||||
. "@auxscriptsdir@/funclib.sh"
|
||||
. "@auxscriptsdir@/options-parser"
|
||||
. "@auxscriptsdir@/extract-trace"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user