source: trunk/essentials/sys-devel/automake-wrapper/am-wrapper-3.sh@ 3158

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

quick port to ash.

File size: 4.5 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/automake-wrapper/files/am-wrapper-3.sh,v 1.3 2006/11/05 10:22:00 vapier Exp $
5
6# Based on the am-wrapper.pl script provided by MandrakeSoft
7# Rewritten in bash by Gregorio Guidi
8#
9# Executes the correct automake version.
10#
11# - defaults to newest version available (hopefully automake-1.10)
12# - runs automake-1.9 if:
13# - envvar WANT_AUTOMAKE is set to `1.9'
14# -or-
15# - `Makefile.in' was generated by automake-1.9
16# -or-
17# - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.9
18# - runs automake-1.8 if:
19# - envvar WANT_AUTOMAKE is set to `1.8'
20# -or-
21# - `Makefile.in' was generated by automake-1.8
22# -or-
23# - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.8
24# - runs automake-1.7 if:
25# - envvar WANT_AUTOMAKE is set to `1.7'
26# -or-
27# - `Makefile.in' was generated by automake-1.7
28# -or-
29# - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.7
30# - runs automake-1.6 if:
31# - envvar WANT_AUTOMAKE is set to `1.6'
32# -or-
33# - `Makefile.in'
34# -or-
35# - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.6
36# - runs automake-1.5 if:
37# - envvar WANT_AUTOMAKE is set to `1.5'
38# -or-
39# - `Makefile.in' was generated by automake-1.5
40# -or-
41# - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.5
42# - runs automake-1.4 if:
43# - envvar WANT_AUTOMAKE is set to `1.4'
44# -or-
45# - `Makefile.in' was generated by automake-1.4
46# -or-
47# - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.4
48
49if [ "${0##*/}" = "am-wrapper.sh" ] ; then
50 echo "Don't call this script directly." >&2
51 exit 1
52fi
53
54vers="1.10 1.9 1.8 1.7 1.6 1.5 1.4"
55
56#
57# Export the proper variable/versions and try to locate a usable
58# default (newer versions are preferred)
59#
60binary=""
61for v in ${vers} ; do
62 _v=`echo ${v} | sed -e 's/\./_/'`
63 eval binary_${v_}="${0}-${v}"
64
65 if [ -z "${binary}" ] && [ -x "${0}-${v}" ] ; then
66 binary="${0}-${v}"
67 fi
68done
69if [ -z "${binary}" ] ; then
70 echo "am-wrapper: Unable to locate any usuable version of automake." >&2
71 echo " I tried these versions: ${vers}" >&2
72 echo " With a base name of '${0}'." >&2
73 exit 1
74fi
75
76#
77# Check the WANT_AUTOMAKE setting. We accept a whitespace delimited
78# list of automake versions.
79#
80if [ -n "${WANT_AUTOMAKE}" ] ; then
81 for v in ${vers} x ; do
82 if [ "${v}" = "x" ] ; then
83 echo "am-wrapper: warning: invalid WANT_AUTOMAKE '${WANT_AUTOMAKE}'; ignoring." >&2
84 unset WANT_AUTOMAKE
85 break
86 fi
87
88 for wx in ${WANT_AUTOMAKE} ; do
89 if [ "${wx}" = "${v}" ] ; then
90 _v=`echo ${v} | sed -e 's/\./_/'`
91 binary="binary_${_v}"
92 #binary="${!binary}"
93 eval binary=$`echo "${binary}"`
94 v="x"
95 fi
96 done
97 [ "${v}" = "x" ] && break
98 done
99fi
100
101#
102# autodetect helpers
103#
104do_awk() {
105 local file=$1 ; shift
106 local arg=$1 ; shift
107 echo $(gawk "{ if (match(\$0, \"$*\", res)) { print res[${arg}]; exit } }" ${file})
108}
109
110#
111# autodetect routine
112#
113if [ -z "${WANT_AUTOMAKE}" ] ; then
114 if [ -r "Makefile.in" ] ; then
115 confversion_mf=$(do_awk Makefile.in 2 "^# Makefile.in generated (automatically )?by automake ([0-9].[0-9]+)")
116 fi
117 if [ -r "aclocal.m4" ] ; then
118 confversion_ac=$(do_awk aclocal.m4 1 'generated automatically by aclocal ([0-9].[0-9]+)')
119 confversion_am=$(do_awk aclocal.m4 1 '[[:space:]]*\\[?AM_AUTOMAKE_VERSION\\(\\[?([0-9].[0-9]+)[^)]*\\]?\\)')
120 fi
121
122 for v in ${vers} ; do
123 if [ "${confversion_mf}" = "${v}" ] \
124 || [ "${confversion_ac}" = "${v}" ] \
125 || [ "${confversion_am}" = "${v}" ] ; then
126 _v=`echo ${v} | sed -e 's/\./_/'`
127 binary="binary_${v_}"
128 #binary="${!binary}"
129 eval binary=$`echo "${binary}"`
130 break
131 fi
132 done
133fi
134
135if [ "${WANT_AMWRAPPER_DEBUG}" ] ; then
136 if [ "${WANT_AUTOMAKE}" ] ; then
137 echo "am-wrapper: DEBUG: WANT_AUTOMAKE is set to ${WANT_AUTOMAKE}" >&2
138 fi
139 echo "am-wrapper: DEBUG: will execute <$binary>" >&2
140fi
141
142#
143# for further consistency
144#
145for v in ${vers} ; do
146 _v=`echo ${v} | sed -e 's/\./_/'`
147 mybin="binary_${v_}"
148 #if [ "${binary}" = "${!mybin}" ] ; then
149 eval mybin=$`echo "${mybin}"`
150 if [ "${binary}" = "${mybin}" ] ; then
151 export WANT_AUTOMAKE="${v}"
152 fi
153done
154
155#
156# Now try to run the binary
157#
158if [ ! -x "${binary}" ] ; then
159 echo "am-wrapper: $binary is missing or not executable." >&2
160 echo " Please try emerging the correct version of automake." >&2
161 exit 1
162fi
163
164exec "$binary" "$@"
165
166echo "am-wrapper: was unable to exec $binary !?" >&2
167exit 1
Note: See TracBrowser for help on using the repository browser.