source: trunk/essentials/sys-devel/autoconf-wrapper/ac-wrapper-4.sh@ 3162

Last change on this file since 3162 was 3162, checked in by bird, 18 years ago

Ported to ash.

File size: 4.2 KB
Line 
1#!sh.exe
2# Copyright 1999-2006 Gentoo Foundation
3# Distributed under the terms of the GNU General Public License v2
4# $Header: /var/cvsroot/gentoo-x86/sys-devel/autoconf-wrapper/files/ac-wrapper-4.sh,v 1.4 2006/11/26 14:35:36 vapier Exp $
5
6# Based on the ac-wrapper.pl script provided by MandrakeSoft
7# Rewritten in bash by Gregorio Guidi
8#
9# Executes the correct autoconf version.
10#
11# - defaults to newest version available (hopefully autoconf-2.60)
12# - runs autoconf 2.13 if:
13# - envvar WANT_AUTOCONF is set to `2.1'
14# -or-
15# - `ac{local,include}.m4' or `configure.{in,ac}' have AC_PREREQ(2.1) (not higher)
16# -or-
17# - `configure' is already present and was generated by autoconf 2.13
18
19if [ "${0##*/}" = "ac-wrapper.sh" ] ; then
20 echo "Don't call this script directly" >&2
21 exit 1
22fi
23
24if [ "${WANT_AUTOCONF}" = "2.1" -a "${0##*/}" = "autom4te" ] ; then
25 echo "ac-wrapper: Autoconf 2.13 doesn't contain autom4te." >&2
26 echo " Either unset WANT_AUTOCONF or don't execute anything" >&2
27 echo " that would use autom4te." >&2
28 exit 1
29fi
30
31#
32# Set up bindings between actual version and WANT_AUTOCONF
33#
34vers="2.61:2.5 2.60:2.5 2.59:2.5 2.13:2.1"
35
36binary=""
37for v in ${vers} ; do
38 auto_ver=${v%:*}
39 if [ -z "${binary}" ] && [ -x "${0}-${auto_ver}" ] ; then
40 binary="${0}-${auto_ver}"
41 fi
42done
43if [ -z "${binary}" ] ; then
44 echo "ac-wrapper: Unable to locate any usuable version of autoconf." >&2
45 echo " I tried these versions: ${vers}" >&2
46 echo " With a base name of '${0}'." >&2
47 exit 1
48fi
49
50#
51# Check the WANT_AUTOCONF setting. We accept a whitespace delimited
52# list of autoconf versions.
53#
54if [ -n "${WANT_AUTOCONF}" ] ; then
55 for v in ${vers} x ; do
56 if [ "${v}" = "x" ] ; then
57 echo "ac-wrapper: warning: invalid WANT_AUTOCONF '${WANT_AUTOCONF}'; ignoring." >&2
58 unset WANT_AUTOCONF
59 break
60 fi
61
62 auto_ver=${v%:*}
63 want_ver=${v#*:}
64 for wx in ${WANT_AUTOCONF} ; do
65 if [ "${wx}" = "${want_ver}" ] && [ -x "${0}-${auto_ver}" ] ; then
66 binary="${0}-${auto_ver}"
67 v="x"
68 fi
69 done
70 [ "${v}" = "x" ] && break
71 done
72fi
73
74#
75# autodetect helpers
76#
77acprereq_version() {
78 gawk \
79 '($0 !~ /^[[:space:]]*(#|dnl)/) {
80 if (match($0, "AC_PREREQ\\(\\[?([0-9]\\.[0-9])", res))
81 VERSIONS[COUNT++] = res[1]
82 }
83
84 END {
85 asort(VERSIONS)
86 print VERSIONS[COUNT]
87 }' "$@"
88}
89
90generated_version() {
91 gawk \
92 '{
93 if (match($0,
94 "^# Generated (by (GNU )?Autoconf|automatically using autoconf version) ([0-9].[0-9])",
95 res)) {
96 print res[3]
97 exit
98 }
99 }' "$@"
100}
101
102#
103# autodetect routine
104#
105if [ "${WANT_AUTOCONF}" = "2.1" -a -f "configure.ac" ] ; then
106 echo "ac-wrapper: Since configure.ac is present, aclocal always use" >&2
107 echo " autoconf 2.59+, which conflicts with your choice and" >&2
108 echo " causes error. You have two options:" >&2
109 echo " 1. Try execute command again after removing configure.ac" >&2
110 echo " 2. Don't set WANT_AUTOCONF" >&2
111 exit 1
112fi
113
114if [ "${WANT_AUTOCONF}" != "2.5" -a -n "${WANT_AUTOMAKE}" ] ; then
115 # Automake-1.7 and better require autoconf-2.5x so if WANT_AUTOMAKE
116 # is set to an older version, let's do some sanity checks.
117 case "${WANT_AUTOMAKE}" in
118 1.[456])
119 acfiles=$(ls ac{local,include}.m4 configure.{in,ac} 2>/dev/null)
120 [ -n "${acfiles}" ] && confversion=$(acprereq_version ${acfiles})
121
122 [ -z "${confversion}" -a -r "configure" ] \
123 && confversion=$(generated_version configure)
124
125 if [ "${confversion}" = "2.1" -a ! -f "configure.ac" ] ; then
126 binary="${0}-2.13"
127 fi
128 esac
129fi
130
131if [ -n "${WANT_ACWRAPPER_DEBUG}" ] ; then
132 if [ -n "${WANT_AUTOCONF}" ] ; then
133 echo "ac-wrapper: DEBUG: WANT_AUTOCONF is set to ${WANT_AUTOCONF}" >&2
134 fi
135 echo "ac-wrapper: DEBUG: will execute <${binary}>" >&2
136fi
137
138#
139# for further consistency
140#
141for v in ${vers} ; do
142 auto_ver=${v%:*}
143 want_ver=${v#*:}
144 if [ "${binary}" = "${0}-${auto_ver}" ] ; then
145 export WANT_AUTOCONF="${want_ver}"
146 fi
147done
148
149#
150# Now try to run the binary
151#
152if [ ! -x "${binary}" ] ; then
153 # this shouldn't happen
154 echo "ac-wrapper: ${binary} is missing or not executable." >&2
155 echo " Please try emerging the correct version of autoconf." >&2
156 exit 1
157fi
158
159exec "${binary}" "$@"
160
161echo "ac-wrapper: was unable to exec ${binary} !?" >&2
162exit 1
Note: See TracBrowser for help on using the repository browser.