diff options
author | Mike Frysinger <vapier@gentoo.org> | 2011-10-02 19:39:07 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2011-10-02 19:39:07 +0000 |
commit | 1d659fe7e6736099474a1386fb985f2b96cab8f9 (patch) | |
tree | e2821abeac24c5babccda8f557ea4326b515f3b9 /ac-wrapper.sh | |
parent | Support autoconf-9999 #370753. (diff) | |
download | autotools-wrappers-1d659fe7e6736099474a1386fb985f2b96cab8f9.tar.gz autotools-wrappers-1d659fe7e6736099474a1386fb985f2b96cab8f9.tar.bz2 autotools-wrappers-1d659fe7e6736099474a1386fb985f2b96cab8f9.zip |
Optimize version lookup a bit, and handle the case where $0 is not a full path #385201 by Florian Philipp.ac-12
Package-Manager: portage-2.2.0_alpha59/cvs/Linux x86_64
Diffstat (limited to 'ac-wrapper.sh')
-rwxr-xr-x | ac-wrapper.sh | 58 |
1 files changed, 45 insertions, 13 deletions
diff --git a/ac-wrapper.sh b/ac-wrapper.sh index 3f3ace4..12bb409 100755 --- a/ac-wrapper.sh +++ b/ac-wrapper.sh @@ -1,7 +1,7 @@ #!/bin/sh # Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/sys-devel/autoconf-wrapper/files/ac-wrapper-11.sh,v 1.1 2011/06/11 23:37:38 vapier Exp $ +# $Header: /var/cvsroot/gentoo-x86/sys-devel/autoconf-wrapper/files/ac-wrapper-12.sh,v 1.1 2011/10/02 19:39:07 vapier Exp $ # Based on the ac-wrapper.pl script provided by MandrakeSoft # Rewritten in bash by Gregorio Guidi @@ -18,12 +18,40 @@ warn() { printf "ac-wrapper: $*\n" 1>&2; } err() { warn "$@"; exit 1; } +unset IFS +which() { + local p + IFS=: # we don't use IFS anywhere, so don't bother saving/restoring + for p in ${PATH} ; do + p="${p}/$1" + [ -e "${p}" ] && echo "${p}" && return 0 + done + unset IFS + return 1 +} -if [ "${0##*/}" = "ac-wrapper.sh" ] ; then +# +# Sanitize argv[0] since it isn't always a full path #385201 +# +argv0=${0##*/} +case ${0} in + ${argv0}) + # find it in PATH + if ! full_argv0=$(which "${argv0}") ; then + err "could not locate ${argv0}; file a bug" + fi + ;; + *) + # re-use full/relative paths + full_argv0=$0 + ;; +esac + +if [ "${argv0}" = "ac-wrapper.sh" ] ; then err "Don't call this script directly" fi -if [ "${WANT_AUTOCONF}" = "2.1" ] && [ "${0##*/}" = "autom4te" ] ; then +if [ "${WANT_AUTOCONF}" = "2.1" ] && [ "${argv0}" = "autom4te" ] ; then err "Autoconf 2.13 doesn't contain autom4te.\n" \ " Either unset WANT_AUTOCONF or don't execute anything\n" \ " that would use autom4te." @@ -48,21 +76,24 @@ if ! seq 0 0 2>/dev/null 1>&2 ; then #338518 fi # -# Set up bindings between actual version and WANT_AUTOCONF +# Set up bindings between actual version and WANT_AUTOCONF; +# Start at last known stable to speed up lookup process. # -vers="9999:2.5 $(printf '2.%s:2.5 ' `seq 99 -1 59`) 2.13:2.1" +STABLE_AUTOCONF="2.68:2.5" +vers="${STABLE_AUTOCONF} 9999:2.5 $(printf '2.%s:2.5 ' `seq 99 -1 59`) 2.13:2.1" binary="" for v in ${vers} ; do auto_ver=${v%:*} - if [ -z "${binary}" ] && [ -x "${0}-${auto_ver}" ] ; then - binary="${0}-${auto_ver}" + if [ -z "${binary}" ] && [ -x "${full_argv0}-${auto_ver}" ] ; then + binary="${full_argv0}-${auto_ver}" + break fi done if [ -z "${binary}" ] ; then err "Unable to locate any usuable version of autoconf.\n" \ "\tI tried these versions: ${vers}\n" \ - "\tWith a base name of '${0}'." + "\tWith a base name of '${full_argv0}'." fi # @@ -80,8 +111,8 @@ if [ -n "${WANT_AUTOCONF}" ] ; then auto_ver=${v%:*} want_ver=${v#*:} for wx in ${WANT_AUTOCONF} ; do - if [ "${wx}" = "${want_ver}" ] && [ -x "${0}-${auto_ver}" ] ; then - binary="${0}-${auto_ver}" + if [ "${wx}" = "${want_ver}" ] && [ -x "${full_argv0}-${auto_ver}" ] ; then + binary="${full_argv0}-${auto_ver}" v="x" fi done @@ -135,12 +166,12 @@ if [ "${WANT_AUTOCONF}" != "2.5" ] && [ -n "${WANT_AUTOMAKE}" ] ; then 1.[456]) acfiles=$(ls ac{local,include}.m4 configure.{in,ac} 2>/dev/null) [ -n "${acfiles}" ] && confversion=$(acprereq_version ${acfiles}) - + [ -z "${confversion}" ] && [ -r "configure" ] \ && confversion=$(generated_version configure) if [ "${confversion}" = "2.1" ] && [ ! -f "configure.ac" ] ; then - binary="${0}-2.13" + binary="${full_argv0}-2.13" fi esac fi @@ -158,8 +189,9 @@ fi for v in ${vers} ; do auto_ver=${v%:*} want_ver=${v#*:} - if [ "${binary}" = "${0}-${auto_ver}" ] ; then + if [ "${binary}" = "${full_argv0}-${auto_ver}" ] ; then export WANT_AUTOCONF="${want_ver}" + break fi done |