From: Gary V. Vaughan <g...@gnu.org> * bootstrap: Add a proper option parsing loop, along with copies of supporting functions from `libltd/m4/getopt.m4sh' and `libltdl/m4/general.m4sh'. Reformat header comments to work with `func_help' and `func_version'. (my_sed_traces): Expanded to extract all parameters from configure.ac, without additional shell munging.
Signed-off-by: Gary V. Vaughan <g...@gnu.org> --- ChangeLog | 11 ++ bootstrap | 561 +++++++++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 461 insertions(+), 111 deletions(-) diff --git a/ChangeLog b/ChangeLog index b8dc314..4e6e5a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2010-08-30 Gary V. Vaughan <g...@gnu.org> + + Rewrite bootstrap script for consistency with our other shell code. + * bootstrap: Add a proper option parsing loop, along with copies + of supporting functions from `libltd/m4/getopt.m4sh' and + `libltdl/m4/general.m4sh'. + Reformat header comments to work with `func_help' and + `func_version'. + (my_sed_traces): Expanded to extract all parameters from + configure.ac, without additional shell munging. + 2010-08-29 Gary V. Vaughan <g...@gnu.org> Support missing detached signatures, like gnulib implementation. diff --git a/bootstrap b/bootstrap index 7ad0979..eab1a3f 100755 --- a/bootstrap +++ b/bootstrap @@ -1,16 +1,16 @@ #! /bin/sh -# bootstrap -- Helps bootstrapping libtool, when checked out from repository. -# -# Copyright (C) 2003, 2004, 2005, 2006, 2009, 2010 Free Software -# Foundation, Inc, -# Mritten by Gary V. Vaughan, 2003 -# -# This file is part of GNU Libtool. -# -# GNU Libtool is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of -# the License, or (at your option) any later version. + +# bootstrap (GNU Libtool) version 2010-08-30 +# Written by Gary V. Vaughan, 2010 + +# Copyright (C) 2010 Free Software Foundation, Inc. +# This is free software; see the source for copying conditions. There is NO +# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +# GNU Libtool is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. # # GNU Libtool is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -22,10 +22,26 @@ # can be downloaded from http://www.gnu.org/licenses/gpl.html, # or obtained by writing to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -#### -# Exit upon failure. -set -e +# Usage: $progname [OPTION]... + +# --debug enable verbose shell tracing +# -n, --dry-run print commands rather than running them +# -f, --force bootstrap even when sources are not from git +# -r, --reconf-dirs=DIR1,DIR2,... +# limit the directories to be bootstrapped to the +# comma delimited list of DIR1,DIR2,.... +# -v, --verbose verbosely report processing +# --version print version information and exit +# -h, --help print short or long help message + +# You can also set the following variables to help $progname +# locate the right tools: +# AUTORECONF, AUTOCONF, AUTOMAKE, AUTOM4TE, CONFIG_SHELL, +# EGREP, FGREP, GREP, LN_S, M4, MAKE, MAKEINFO, RM, SED + +# This script bootstraps a git checkout of GNU Libtool by correctly calling +# out to parts of the GNU Build Platform. # It is okay for the bootstrap process to require unreleased autoconf # or automake, as long as any released libtool will work with at least @@ -33,8 +49,11 @@ set -e # better features, and configure.ac documents oldest version of each # required for bootstrap (AC_PREREQ, and AM_INIT_AUTOMAKE). -SHELL=${CONFIG_SHELL-/bin/sh} -export SHELL +# Report bugs to <bug-libt...@gnu.m4> + +# Exit upon failure. +set -e + : ${AUTORECONF=autoreconf} : ${AUTOCONF=autoconf} : ${AUTOMAKE=automake} @@ -43,127 +62,440 @@ export SHELL : ${GREP=grep} : ${EGREP=egrep} : ${FGREP=fgrep} +: ${RM='rm -f'} : ${SED=sed} : ${LN_S='ln -s'} : ${MAKEINFO=makeinfo} -case $1 in ---help|-h*) - cat <<EOF -`echo $0 | sed 's,^.*/,,g'`: This script is designed to bootstrap a fresh repository checkout -of Libtool. Useful environment variable settings: - reconfdirs='. libltdl' Do not bootstrap the old test suite. -EOF - exit - ;; -esac +SHELL=${CONFIG_SHELL-/bin/sh} +export SHELL + +# Ensure file names are sorted consistently across platforms. +# Also, ensure diagnostics are in English. +LC_ALL=C +export LC_ALL + +package=libtool +ltdldir=libltdl +config_aux_dir=$ltdldir/config +config_macro_dir=$ltdldir/m4 + +# 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=`echo "$progpath" | $SED 's,^.*/,,g'` +PROGRAM=bootstrap + +# Detect whether this is a version control system checkout or a tarball +vcs_only_file= + +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. + +exit_status=$EXIT_SUCCESS -test -f ./configure.ac || { - echo "bootstrap: can't find ./configure.ac, please rerun from top_srcdir" - exit 1 +tab=' ' + +# func_error arg... +# Echo program name prefixed message to standard error. +func_error () +{ + echo $progname: ${1+"$@"} >&2 } +# func_fatal_error arg... +# Echo program name prefixed message to standard error, and exit. +func_fatal_error () +{ + func_error ${1+"$@"} + exit $EXIT_FAILURE +} -# Extract auxdir and m4dir from configure.ac: -lt_tab=' ' -my_sed_traces='s,#.*$,,; s,^dnl .*$,,; s, dnl .*$,,; - /AC_CONFIG_AUX_DIR[^_]/ { - s,^.*AC_CONFIG_AUX_DIR([[ '"$lt_tab"']*\([^])]*\).*$,auxdir=\1,; p; - }; - /AC_CONFIG_MACRO_DIR/ { - s,^.*AC_CONFIG_MACRO_DIR([[ '"$lt_tab"']*\([^])]*\).*$,m4dir=\1,; p; - }; - d;' -eval `cat configure.ac 2>/dev/null | $SED "$my_sed_traces"` - - -# Upgrade caveat: -cat <<'EOF' -WARNING: If bootstrapping with this script fails, it may be due to an -WARNING: incompatible installed `libtool.m4' being pulled in to -WARNING: `aclocal.m4'. The best way to work around such a problem is to -WARNING: uninstall your system libtool files, or failing that, overwrite -WARNING: them with all m4 file as shipped with this distribution (except -WARNING: `lt~obsolete.m4'). After that, retry this bootstrap. -EOF -find . -depth \( -name autom4te.cache -o -name libtool \) -print \ - | grep -v '{arch}' \ - | xargs rm -rf +## -------------------------- ## +## Early failure diagnostics. ## +## -------------------------- ## +{ + test -f ./configure.ac \ + || func_fatal_error \ + "Can't find \`./configure.ac', please rerun from top_srcdir." -# Delete stale files from previous libtool versions. -rm -f acinclude.m4 libltdl/config.h + test -z "$vcs_only_file" \ + || test -r "$vcs_only_file" \ + || func_fatal_error \ + 'Bootstrapping from a non-version-control distribution is risky.' + + (eval 'set 12/34/5; test 5/12/34 = "${1##*/}/${1%/*}"') 2>/dev/null \ + || func_fatal_error \ + 'bootstrap must be run in a shell with XSI features.' +} -for file in argz.c lt__dirent.c lt__strl.c; do - rm -f $file -done -if test -z "$reconfdirs"; then - reconfdirs=". libltdl `ls -1d tests/*demo tests/*demo[0-9]`" -fi -# Extract the package name and version number from configure.ac: -set dummy `$SED -n ' - /AC_INIT/{ - s/[][,()]/ /g - s/ GNU / / +# func_echo arg... +# Echo program name prefixed message. +func_echo () +{ + echo $progname: ${1+"$@"} +} + +# func_verbose arg... +# Echo program prefixed message in verbose mode only. +func_verbose () +{ + $opt_verbose && func_error ${1+"$@"} +} + +# func_fatal_help arg... +# Echo program name prefixed message to standard error, followed by +# a help hint, and exit. +func_fatal_help () +{ + func_error ${1+"$@"} + func_fatal_error "Try \`$progname --help' for more information." +} + +# func_version +# Echo version message to standard output and exit. +func_version () +{ + $opt_debug + + $SED -n '/(C)/!b go + :more + /\./!{ + N + s/\n# / / + b more + } + :go + /^# '$PROGRAM' (GNU /,/# warranty; / { + s/^# // + s/^# *$// + s/\((C)\)[ 0-9,-]*\( [1-9][0-9]*\)/\1\2/ p - }' configure.ac` -shift -PACKAGE=`echo "$2" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` -PACKAGE_NAME=$2 -PACKAGE_URL= -if grep 'AC_INIT.*GNU' configure.ac >/dev/null; then - PACKAGE_NAME="GNU $PACKAGE_NAME" - PACKAGE_URL="http://www.gnu.org/software/$PACKAGE/" -fi -VERSION=$3 + }' < "$progpath" + exit $? +} + +# func_usage +# Echo short help message to standard output and exit. +func_usage () +{ + $opt_debug + + $SED -n '/^# Usage:/,/^# *.*--help/ { + s/^# // + s/^# *$// + s/\$progname/'$progname'/ + p + }' < "$progpath" + echo + echo "Run \`$progname --help | more' for full usage" + exit $? +} + +# func_help +# Echo long help message to standard output and exit. +func_help () +{ + $opt_debug + + $SED -n '/^# Usage:/,/# Report bugs to/ { + s/\$progname/'$progname'/; + s/^# //; s/^# *$//; + p; + }' < "$progpath" + exit $EXIT_SUCCESS +} + +# func_missing_arg argname +# Echo program name prefixed message to standard error and set global +# exit_cmd. +func_missing_arg () +{ + $opt_debug + + func_error "missing argument for $1." + exit_cmd=exit +} + +# func_split_long_opt +# func_split_short_opt shortopt +# Set func_split_short_opt_name and func_split_short_opt_arg shell +# variables after splitting SHORTOPT after the 2nd character. +func_split_short_opt () +{ + func_split_short_opt_arg=${1#??} + func_split_short_opt_name=${1%"$func_split_short_opt_arg"} +} + +# func_split_long_opt longopt +# Set func_split_long_opt_name and func_split_long_opt_arg shell +# variables after splitting LONGOPT at the `=' sign. +func_split_long_opt () +{ + func_split_long_opt_name=${1%%=*} + func_split_long_opt_arg=${1#*=} +} + + +# Standard options: +opt_debug=: +opt_dry_run=false +opt_force=false +opt_help=false +opt_quiet=false +opt_verbose=false +opt_warning=: + +exit_cmd=: + +# This is converted to a comma-delimited opt_ setting below, when +# no option is given to override it. +test -n "$reconfdirs" \ + || reconfdirs=". libltdl `ls -1d tests/*demo tests/*demo[0-9]`" + +# Parse options once, thorougly. This comes as soon as possible in +# the script to make things like `bootstrap --version' happen quickly. +{ + # this just eases exit handling + while test $# -gt 0; do + opt="$1" + shift + case $opt in + --debug|-x) opt_debug='set -x' + func_echo 'enabling shell trace mode' + $opt_debug + ;; + --dry-run|--dryrun|-n) + opt_dry_run=: ;; + --force|-f) opt_force=: ;; + --reconf-dirs|--reconfdirs|--reconf|-r) + test $# = 0 && func_missing_arg $opt && break + # squash spaces so that delimiter is just `,' and nothing else + opt_reconf_dirs=`echo "$1" |$SED 's|, *|,|g'` + shift + ;; + --verbose|-v) opt_verbose=: ;; + + -\?|-h) func_usage ;; + --help) func_help ;; + --version) func_version ;; + + # Separate optargs to long options: + --*=*) + func_split_long_opt "$opt" + set dummy "$func_split_long_opt_name" \ + "$func_split_long_opt_arg" ${1+"$@"} + shift + ;; + + # Separate optargs to short options: + -r*) + func_split_short_opt "$opt" + set dummy "$func_split_short_opt_name" \ + "$func_split_short_opt_arg" ${1+"$@"} + shift + ;; + + # Separate non-argument short options: + -\?*|-f*|-h*|-n*|-v*) + func_split_short_opt "$opt" + set dummy "$func_split_short_opt_name" \ + "-$func_split_short_opt_arg" ${1+"$@"} + shift + ;; + + --) break ;; + -*) func_fatal_help "unrecognized option \`$opt" ;; + *) set dummy "$opt" ${1+"$@"}; shift; break ;; + esac + done + + # Validate options + test $# -gt 0 \ + && func_fatal_help "too many arguments: $@" + + # support the old interface too: `reconfdirs='. libltdl' ./bootstrap' + test -n "$opt_reconf_dirs" \ + || opt_reconf_dirs=`echo $reconfdirs |$SED 's| *|,|g'` + + # validate $opt_reconf_dirs + save_IFS="$IFS" + IFS=, + for reconfdir in $opt_reconf_dirs; do + IFS="$save_IFS" + test -d "$reconfdir" || { + func_error "bad reconf directory \`$reconfdir': directory does not exist" + exit_cmd=exit + } + done + IFS="$save_IFS" + + # Bail if the options were screwed + $exit_cmd $EXIT_FAILURE + +} + + +test $opt_dry_run || { + # Delete stale cache files + # XXX it's bad to take advantage of internal knowledge about autom4te... + find . -depth \( -name autom4te.cache -o -name libtool \) -print \ + | grep -v '{arch}' \ + | xargs rm -rf + + # Delete stale files from previous libtool versions. + $RM acinclude.m4 libltdl/config.h +} + +# func_quote_for_expand arg +# Aesthetically quote ARG to be evaled later; same as above, +# but do not quote variable references. +func_quote_for_expand () +{ + case $1 in + *[\\\`\"]*) + my_arg=`$ECHO "$1" | $SED \ + -e "$double_quote_subst" -e "$sed_double_backslash"` ;; + *) + my_arg="$1" ;; + esac + + case $my_arg in + # Double-quote args containing shell metacharacters to delay + # word splitting and command substitution for a subsequent eval. + # Many Bourne shells cannot handle close brackets correctly + # in scan sets, so we specify it separately. + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + my_arg="\"$my_arg\"" + ;; + esac + + func_quote_for_expand_result="$my_arg" +} + +# func_show_eval cmd [fail_exp] +# Unless opt_silent is true, then output CMD. Then, if opt_dryrun is +# not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP +# is given, then evaluate it. +func_show_eval () +{ + my_cmd="$1" + my_fail_exp="${2-:}" + + ${opt_silent-false} || { + func_quote_for_expand "$my_cmd" + eval "func_echo $func_quote_for_expand_result" + } + + if ${opt_dry_run-false}; then :; else + eval "$my_cmd" + my_status=$? + if test "$my_status" -eq 0; then :; else + eval "(exit $my_status); $my_fail_exp" + fi + fi +} + + +## -------------------------------- ## +## Generate bootstrap dependencies. ## +## -------------------------------- ## # Whip up a dirty Makefile: makes='Makefile.am libltdl/Makefile.inc' -rm -f Makefile +$RM Makefile $SED '/^if /,/^endif$/d;/^else$/,/^endif$/d;/^include /d' $makes > Makefile +# Extract values from configure.ac for make invocation, below: +my_sed_traces='s,#.*$,,; s,^dnl .*$,,; s, dnl .*$,,; + /AC_INIT(/ { + s|^.*AC_INIT([[ '"$tab"']*|| + s|^\([^],]*\)[][ '"$tab"']*,|package="\1"; package_name="\1",| + s|,[[ '"$tab"']*\([^],]*\)[][ '"$tab"']*,|; version="\1",| + s|,[[ '"$tab"']*\([^])]*\).*$|; package_bugreport="\1"| + s|^package="GNU |package="| + h + s|;.*$|| + y|ABCDEFGHIJKLMNOPQRSTUVWXYZ|abcdefghijklmnopqrstuvwxyz| + x + s|^[^;]*; || + G + p + } + /AC_SUBST([[]*PACKAGE_URL/ { + s|.*AC_SUBST([[ '"$tab"']*PACKAGE_URL[] '"$tab"']*,[[ '"$tab"']*|package_url="| + s|[]) '"$tab"']*$|"| + p + } + /AC_CONFIG_AUX_DIR[^_]/ { + s|^.*AC_CONFIG_AUX_DIR([[ '"$tab"']*\([^])]*\).*$|config_aux_dir=\1| + p + } + /AC_CONFIG_MACRO_DIR/ { + s|^.*AC_CONFIG_MACRO_DIR([[ '"$tab"']*\([^])]*\).*$|config_macro_dir=\1| + p + }' +eval `$SED -n "$my_sed_traces" configure.ac 2>/dev/null` + # Building distributed files from configure is bad for automake, so we # generate them here, and have Makefile rules to keep them up to date. # We don't have all the substitution values to build ltmain.sh from this # script yet, but we need config/ltmain.sh for the libtool commands in # configure, and ltversion.m4 to generate configure in the first place: -rm -f $auxdir/ltmain.sh $m4dir/ltversion.m4 +$RM $config_aux_dir/ltmain.sh $config_macro_dir/ltversion.m4 -$MAKE ./$auxdir/ltmain.sh ./$m4dir/ltversion.m4 \ +$MAKE ./$config_aux_dir/ltmain.sh ./$config_macro_dir/ltversion.m4 \ ./libtoolize.in ./tests/defs.in ./tests/package.m4 \ ./tests/testsuite ./libltdl/Makefile.am ./doc/notes.txt \ - srcdir=. top_srcdir=. PACKAGE="$PACKAGE" VERSION="$VERSION" \ - PACKAGE_NAME="$PACKAGE_NAME" PACKAGE_URL="$PACKAGE_URL" \ - PACKAGE_BUGREPORT="bug-$pack...@gnu.org" M4SH="$AUTOM4TE --language=m4sh" \ + srcdir=. top_srcdir=. PACKAGE="$package" VERSION="$version" \ + PACKAGE_NAME="$package_name" PACKAGE_URL="$package_url" \ + PACKAGE_BUGREPORT="$package_bugreport" M4SH="$AUTOM4TE --language=m4sh" \ AUTOTEST="$AUTOM4TE --language=autotest" SED="$SED" MAKEINFO="$MAKEINFO" \ GREP="$GREP" FGREP="$FGREP" EGREP="$EGREP" LN_S="$LN_S" test -f clcommit.m4sh && $MAKE -f Makefile.maint ./commit \ - srcdir=. top_srcdir=. PACKAGE="$PACKAGE" VERSION="$VERSION" \ + srcdir=. top_srcdir=. PACKAGE="$package" VERSION="$version" \ M4SH="$AUTOM4TE -l m4sh" \ SED="$SED" GREP="$GREP" FGREP="$FGREP" EGREP="$EGREP" LN_S="$LN_S" -rm -f Makefile +$RM Makefile + + +## ----------- ## +## Autoreconf. ## +## ----------- ## # Make a dummy libtoolize script for autoreconf: -cat > $auxdir/libtoolize <<'EOF' +cat > $config_aux_dir/libtoolize <<'EOF' #! /bin/sh # This is a dummy file for bootstrapping libtool. echo "$0: Bootstrap detected, no files installed." | sed 's,^.*/,,g' exit 0 EOF -chmod 755 $auxdir/libtoolize +chmod 755 $config_aux_dir/libtoolize # Running the installed `libtoolize' will trash the local (newer) libtool.m4 # among others. Call the dummy script we made earlier. -LIBTOOLIZE=`pwd`/$auxdir/libtoolize +LIBTOOLIZE=`pwd`/$config_aux_dir/libtoolize export LIBTOOLIZE -for sub in $reconfdirs; do - $AUTORECONF --force --verbose --install $sub +save_IFS="$IFS" +IFS=, +for reconfdir in $opt_reconf_dirs; do + IFS="$save_IFS" + func_show_eval "$AUTORECONF --force --verbose --install $reconfdir" done +IFS="$save_IFS" # Autoheader valiantly tries to prevent needless reconfigurations by # not changing the timestamp of config-h.in unless the file contents @@ -173,32 +505,39 @@ done # have it! Fudge the timestamp to prevent that: sleep 2 && touch libltdl/config-h.in -# Remove our dummy libtoolize -rm -f $auxdir/libtoolize +# Remove our dummy files +$RM $config_aux_dir/libtoolize # These files can cause an infinite configure loop if left behind. -rm -f Makefile libltdl/Makefile libtool vcl.tmp +$RM libltdl/Makefile libtool vcl.tmp + -# This file is misgenerated earlier in bootstrap to satisfy automake 1.9.1 -# and earlier, but has a new enough timestamp to not be updated. Force it -# to be regenerated at make-time with proper substitutions in place: -touch $auxdir/ltmain.m4sh +## ------- ## +## Wrapup. ## +## ------- ## +# Ensure aclocal didn't pull external libtool macros into aclocal.m4 for macro in LT_INIT AC_PROG_LIBTOOL AM_PROG_LIBTOOL; do - if grep $macro aclocal.m4 libltdl/aclocal.m4; then - echo "Bogus $macro macro contents in an aclocal.m4 file." >&2 - exit 1 - else :; fi -done + grep $macro aclocal.m4 libltdl/aclocal.m4 && { + func_error "Bogus $macro macro contents in an aclocal.m4 file." -# Commit script caveat: -cat <<EOF -WARNING: You might want to regenerate \`commit' and \`$auxdir/mailnotify' -WARNING: after you have run \`configure' to discover the real whereabouts -WARNING: of \`sed', \`grep' etc. like this: -WARNING: -WARNING: rm -f commit $auxdir/mailnotify -WARNING: make -f Makefile.maint ./commit ./$auxdir/mailnotify + cat <<'EOF' +WARNING: If bootstrapping with this script fails, it may be due to an +WARNING: incompatible installed `libtool.m4' being pulled in to +WARNING: `aclocal.m4'. The best way to work around such a problem is to +WARNING: uninstall your system libtool files, or failing that, overwrite +WARNING: them with all m4 file as shipped with this distribution (except +WARNING: `lt~obsolete.m4'). After that, retry this bootstrap. EOF + exit $EXIT_FAILURE + } +done exit 0 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "# bootstrap (GNU Libtool) version " +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "$" +# End: -- 1.7.2.2