--- ac-wrapper-11.sh 2011-10-01 16:26:16.000000000 +0200 +++ ac-wrapper.sh 2011-10-01 16:48:14.000000000 +0200 @@ -29,6 +29,16 @@ " that would use autom4te." fi + +# Sanitize $0 in order to protect against stupid ways of calling this script +# such as `sh autoconf` which prevent $0 from being set to a valid path. +# Since we cannot manipulate $0, use $script instead. +if [ -x "$0" ]; then + script="$0" +else + script=$(which "$0") +fi + if ! seq 0 0 2>/dev/null 1>&2 ; then #338518 seq() { local f l i @@ -55,14 +65,14 @@ 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 "${script}-${auto_ver}" ] ; then + binary="${script}-${auto_ver}" 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 '${script}'." fi # @@ -80,8 +90,8 @@ 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 "${script}-${auto_ver}" ] ; then + binary="${script}-${auto_ver}" v="x" fi done @@ -94,8 +104,8 @@ # acprereq_version() { gawk \ - '($0 !~ /^[[:space:]]*(#|dnl)/) { - if (match($0, "AC_PREREQ\\(\\[?([0-9]\\.[0-9])", res)) + '($script !~ /^[[:space:]]*(#|dnl)/) { + if (match($script, "AC_PREREQ\\(\\[?([0-9]\\.[0-9])", res)) VERSIONS[COUNT++] = res[1] } @@ -108,7 +118,7 @@ generated_version() { gawk \ '{ - if (match($0, + if (match($script, "^# Generated (by (GNU )?Autoconf|automatically using autoconf version) ([0-9].[0-9])", res)) { print res[3] @@ -140,7 +150,7 @@ && confversion=$(generated_version configure) if [ "${confversion}" = "2.1" ] && [ ! -f "configure.ac" ] ; then - binary="${0}-2.13" + binary="${script}-2.13" fi esac fi @@ -158,7 +168,7 @@ for v in ${vers} ; do auto_ver=${v%:*} want_ver=${v#*:} - if [ "${binary}" = "${0}-${auto_ver}" ] ; then + if [ "${binary}" = "${script}-${auto_ver}" ] ; then export WANT_AUTOCONF="${want_ver}" fi done