diff options
author | Mike Frysinger <vapier@gentoo.org> | 2013-01-02 07:40:09 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2013-01-02 07:40:09 +0000 |
commit | 421d53d8d0dd0490d8544e73014c88542d6f8904 (patch) | |
tree | bff7feba1ddc90ba4e6738449af0a7b15f2d9994 | |
parent | Support new automake-1.12. (diff) | |
download | autotools-wrappers-am-8.tar.gz autotools-wrappers-am-8.tar.bz2 autotools-wrappers-am-8.zip |
Rewrite logic to be more friendly to missing versions #417745 by Toralf Förster.am-8
Package-Manager: portage-2.2.0_alpha144/cvs/Linux x86_64
Manifest-Sign-Key: 0xFB7C4156
-rwxr-xr-x | am-wrapper.sh | 139 |
1 files changed, 68 insertions, 71 deletions
diff --git a/am-wrapper.sh b/am-wrapper.sh index dd0920f..0e2311a 100755 --- a/am-wrapper.sh +++ b/am-wrapper.sh @@ -1,23 +1,25 @@ #!/bin/sh -# Copyright 1999-2012 Gentoo Foundation +# Copyright 1999-2013 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/sys-devel/automake-wrapper/files/am-wrapper-7.sh,v 1.1 2012/04/26 05:42:10 vapier Exp $ +# $Header: /var/cvsroot/gentoo-x86/sys-devel/automake-wrapper/files/am-wrapper-8.sh,v 1.1 2013/01/02 07:40:04 vapier Exp $ -# Based on the am-wrapper.pl script provided by MandrakeSoft -# Rewritten in bash by Gregorio Guidi -# # Executes the correct automake version. # -# - defaults to newest version available (hopefully automake-1.12) -# - runs automake-1.X (where X is a valid automake version) if: -# - envvar WANT_AUTOMAKE is set to `1.X' -# -or- -# - `Makefile.in' was generated by automake-1.X -# -or- -# - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.X - -warn() { printf 'am-wrapper: %s: %b\n' "${argv0}" "$*" 1>&2; } -err() { warn "$@"; exit 1; } +# If WANT_AUTOMAKE is set (can be a whitespace delimited list of versions): +# - attempt to find an installed version using those +# - if magic keyword 'latest' is found, pick the latest version that exists +# - if nothing found, warn, and proceed as if WANT_AUTOMAKE was not set (below) +# If WANT_AUTOMAKE is not set: +# - Try to detect the version of automake used to generate things (look at +# Makefile.in and aclocal.m4 and any other useful file) +# - If detected version is not found, warn and proceed as if blank slate +# - Try to locate the latest version of automake that exists and run it + +(set -o posix) 2>/dev/null && set -o posix + +_stderr() { printf 'am-wrapper: %s: %b\n' "${argv0}" "$*" 1>&2; } +warn() { _stderr "warning: $*"; } +err() { _stderr "error: $*"; exit 1; } unset IFS which() { local p @@ -34,7 +36,7 @@ which() { # Sanitize argv[0] since it isn't always a full path #385201 # argv0=${0##*/} -case ${0} in +case $0 in ${argv0}) # find it in PATH if ! full_argv0=$(which "${argv0}") ; then @@ -47,10 +49,6 @@ case ${0} in ;; esac -if [ "${argv0}" = "am-wrapper.sh" ] ; then - err "Don't call this script directly" -fi - if ! seq 0 0 2>/dev/null 1>&2 ; then #338518 seq() { local f l i @@ -73,24 +71,49 @@ fi # Set up bindings between actual version and WANT_AUTOMAKE; # Start with last known versions to speed up lookup process. # -LAST_KNOWN_AUTOMAKE_VER="12" +LAST_KNOWN_AUTOMAKE_VER="13" vers=$(printf '1.%s ' `seq ${LAST_KNOWN_AUTOMAKE_VER} -1 4`) +# +# Helper to scan for a usable program based on version. +# +binary= +all_vers= find_binary() { local v - all_vers="${all_vers} $*" - for v in "$@" ; do + all_vers="${all_vers} $*" # For error messages. + for v ; do if [ -x "${full_argv0}-${v}" ] ; then binary="${full_argv0}-${v}" + binary_ver=${v} return 0 fi done return 1 } -binary="" -all_vers="" -if ! find_binary ${vers} ; then - find_binary $(printf '1.%s ' `seq 99 -1 ${LAST_KNOWN_AUTOMAKE_VER}`) + +# +# Try and find a usable automake version. First check the WANT_AUTOMAKE +# setting (whitespace delimited list), then fallback to the latest. +# +find_latest() { + if ! find_binary ${vers} ; then + # Brute force it. + find_binary $(printf '1.%s ' `seq 99 -1 ${LAST_KNOWN_AUTOMAKE_VER}`) + fi +} +for wx in ${WANT_AUTOMAKE:-latest} ; do + if [ "${wx}" = "latest" ] ; then + find_latest && break + else + find_binary ${wx} && break + fi +done + +if [ -z "${binary}" ] && [ -n "${WANT_AUTOMAKE}" ] ; then + warn "could not locate installed version for WANT_AUTOMAKE='${WANT_AUTOMAKE}'; ignoring" + unset WANT_AUTOMAKE + find_latest fi if [ -z "${binary}" ] ; then @@ -100,57 +123,37 @@ if [ -z "${binary}" ] ; then fi # -# Check the WANT_AUTOMAKE setting. We accept a whitespace delimited -# list of automake versions. -# -if [ -n "${WANT_AUTOMAKE}" ] ; then - for v in ${vers} x ; do - if [ "${v}" = "x" ] ; then - warn "warning: invalid WANT_AUTOMAKE '${WANT_AUTOMAKE}'; ignoring." - unset WANT_AUTOMAKE - break - fi - - for wx in ${WANT_AUTOMAKE} ; do - if [ "${wx}" = "${v}" ] ; then - binary="${full_argv0}-${v}" - v="x" - fi - done - [ "${v}" = "x" ] && break - done -fi - -# # autodetect helpers # do_awk() { local file=$1 ; shift local arg=$1 ; shift - echo $(gawk "{ if (match(\$0, \"$*\", res)) { print res[${arg}]; exit } }" ${file}) + local v=$(awk "{ if (match(\$0, \"$*\", res)) { print res[${arg}]; exit } }" "${file}") + case " ${auto_vers} " in + *" ${v} "*) ;; + *) auto_vers="${auto_vers:+${auto_vers} }${v}" ;; + esac } # # autodetect routine # if [ -z "${WANT_AUTOMAKE}" ] ; then + auto_vers= if [ -r "Makefile.in" ] ; then - confversion_mf=$(do_awk Makefile.in 2 "^# Makefile.in generated (automatically )?by automake ([0-9].[0-9]+)") + do_awk Makefile.in 2 "^# Makefile.in generated (automatically )?by automake ([0-9].[0-9]+)" fi if [ -r "aclocal.m4" ] ; then - confversion_ac=$(do_awk aclocal.m4 1 'generated automatically by aclocal ([0-9].[0-9]+)') - confversion_am=$(do_awk aclocal.m4 1 '[[:space:]]*\\[?AM_AUTOMAKE_VERSION\\(\\[?([0-9].[0-9]+)[^)]*\\]?\\)') + do_awk aclocal.m4 1 'generated automatically by aclocal ([0-9].[0-9]+)' + do_awk aclocal.m4 1 '[[:space:]]*\\[?AM_AUTOMAKE_VERSION\\(\\[?([0-9].[0-9]+)[^)]*\\]?\\)' fi - - for v in ${vers} ; do - if [ "${confversion_mf}" = "${v}" ] || \ - [ "${confversion_ac}" = "${v}" ] || \ - [ "${confversion_am}" = "${v}" ] - then - binary="${full_argv0}-${v}" - break + # We don't need to set $binary here as it has already been setup for us + # earlier to the latest available version. + if [ -n "${auto_vers}" ] ; then + if ! find_binary ${auto_vers} ; then + warn "auto-detected versions not found (${auto_vers}); falling back to latest available" fi - done + fi fi if [ -n "${WANT_AMWRAPPER_DEBUG}" ] ; then @@ -163,12 +166,7 @@ fi # # for further consistency # -for v in ${vers} ; do - if [ "${binary}" = "${full_argv0}-${v}" ] ; then - export WANT_AUTOMAKE="${v}" - break - fi -done +export WANT_AUTOMAKE="${binary_ver}" # # Now try to run the binary @@ -176,9 +174,8 @@ done if [ ! -x "${binary}" ] ; then # this shouldn't happen err "${binary} is missing or not executable.\n" \ - "\tPlease try emerging the correct version of automake." + "\tPlease try installing the correct version of automake." fi exec "${binary}" "$@" - -err "was unable to exec ${binary} !?" +# The shell will error out if `exec` failed. |