Magellan Linux

Contents of /trunk/am-wrapper/am-wrapper.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2851 - (show annotations) (download) (as text)
Tue Jan 27 15:26:28 2015 UTC (9 years, 3 months ago) by niro
File MIME type: application/x-sh
File size: 5654 byte(s)
-support automake-1.15
1 #!/bin/bash
2 # Copyright 1999-2006 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header: /root/magellan-cvs/src/automake/am-wrapper-4.sh,v 1.1 2009-05-23 21:25:25 niro 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.15)
12 # - runs automake-1.15 if:
13 # - envvar WANT_AUTOMAKE is set to `1.15'
14 # -or-
15 # - `Makefile.in' was generated by automake-1.15
16 # -or-
17 # - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.15
18 # - runs automake-1.14 if:
19 # - envvar WANT_AUTOMAKE is set to `1.14'
20 # -or-
21 # - `Makefile.in' was generated by automake-1.14
22 # -or-
23 # - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.14
24 # - runs automake-1.13 if:
25 # - envvar WANT_AUTOMAKE is set to `1.13'
26 # -or-
27 # - `Makefile.in' was generated by automake-1.13
28 # -or-
29 # - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.13
30 # - runs automake-1.12 if:
31 # - envvar WANT_AUTOMAKE is set to `1.12'
32 # -or-
33 # - `Makefile.in' was generated by automake-1.12
34 # -or-
35 # - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.12
36 # - runs automake-1.11 if:
37 # - envvar WANT_AUTOMAKE is set to `1.11'
38 # -or-
39 # - `Makefile.in' was generated by automake-1.11
40 # -or-
41 # - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.11
42 # - runs automake-1.10 if:
43 # - envvar WANT_AUTOMAKE is set to `1.10'
44 # -or-
45 # - `Makefile.in' was generated by automake-1.10
46 # -or-
47 # - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.10
48 # - runs automake-1.9 if:
49 # - envvar WANT_AUTOMAKE is set to `1.9'
50 # -or-
51 # - `Makefile.in' was generated by automake-1.9
52 # -or-
53 # - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.9
54 # - runs automake-1.8 if:
55 # - envvar WANT_AUTOMAKE is set to `1.8'
56 # -or-
57 # - `Makefile.in' was generated by automake-1.8
58 # -or-
59 # - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.8
60 # - runs automake-1.7 if:
61 # - envvar WANT_AUTOMAKE is set to `1.7'
62 # -or-
63 # - `Makefile.in' was generated by automake-1.7
64 # -or-
65 # - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.7
66 # - runs automake-1.6 if:
67 # - envvar WANT_AUTOMAKE is set to `1.6'
68 # -or-
69 # - `Makefile.in'
70 # -or-
71 # - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.6
72 # - runs automake-1.5 if:
73 # - envvar WANT_AUTOMAKE is set to `1.5'
74 # -or-
75 # - `Makefile.in' was generated by automake-1.5
76 # -or-
77 # - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.5
78 # - runs automake-1.4 if:
79 # - envvar WANT_AUTOMAKE is set to `1.4'
80 # -or-
81 # - `Makefile.in' was generated by automake-1.4
82 # -or-
83 # - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.4
84
85 if [ "${0##*/}" = "am-wrapper.sh" ] ; then
86 echo "Don't call this script directly." >&2
87 exit 1
88 fi
89
90 vers="1.15 1.14 1.13 1.12 1.11 1.10 1.9 1.8 1.7 1.6 1.5 1.4"
91
92 #
93 # Export the proper variable/versions and try to locate a usuable
94 # default (newer versions are preferred)
95 #
96 binary=""
97 for v in ${vers} ; do
98 eval binary_${v/./_}="${0}-${v}"
99
100 if [ -z "${binary}" ] && [ -x "${0}-${v}" ] ; then
101 binary="${0}-${v}"
102 fi
103 done
104 if [ -z "${binary}" ] ; then
105 echo "am-wrapper: Unable to locate any usuable version of automake." >&2
106 echo " I tried these versions: ${vers}" >&2
107 echo " With a base name of '${0}'." >&2
108 exit 1
109 fi
110
111 #
112 # Check the WANT_AUTOMAKE setting. We accept a whitespace delimited
113 # list of automake versions.
114 #
115 if [ -n "${WANT_AUTOMAKE}" ] ; then
116 for v in ${vers} x ; do
117 if [ "${v}" = "x" ] ; then
118 echo "am-wrapper: warning: invalid WANT_AUTOMAKE '${WANT_AUTOMAKE}'; ignoring." >&2
119 unset WANT_AUTOMAKE
120 break
121 fi
122
123 for wx in ${WANT_AUTOMAKE} ; do
124 if [ "${wx}" = "${v}" ] ; then
125 binary="binary_${v/./_}"
126 binary="${!binary}"
127 v="x"
128 fi
129 done
130 [ "${v}" = "x" ] && break
131 done
132 fi
133
134 #
135 # autodetect helpers
136 #
137 do_awk() {
138 local file=$1 ; shift
139 local arg=$1 ; shift
140 echo $(gawk "{ if (match(\$0, \"$*\", res)) { print res[${arg}]; exit } }" ${file})
141 }
142
143 #
144 # autodetect routine
145 #
146 if [ -z "${WANT_AUTOMAKE}" ] ; then
147 if [ -r "Makefile.in" ] ; then
148 confversion_mf=$(do_awk Makefile.in 2 "^# Makefile.in generated (automatically )?by automake ([0-9].[0-9]+)")
149 fi
150 if [ -r "aclocal.m4" ] ; then
151 confversion_ac=$(do_awk aclocal.m4 1 'generated automatically by aclocal ([0-9].[0-9]+)')
152 confversion_am=$(do_awk aclocal.m4 1 '[[:space:]]*\\[?AM_AUTOMAKE_VERSION\\(\\[?([0-9].[0-9]+)[^)]*\\]?\\)')
153 fi
154
155 for v in ${vers} ; do
156 if [ "${confversion_mf}" = "${v}" ] \
157 || [ "${confversion_ac}" = "${v}" ] \
158 || [ "${confversion_am}" = "${v}" ] ; then
159 binary="binary_${v/./_}"
160 binary="${!binary}"
161 break
162 fi
163 done
164 fi
165
166 if [ "${WANT_AMWRAPPER_DEBUG}" ] ; then
167 if [ "${WANT_AUTOMAKE}" ] ; then
168 echo "am-wrapper: DEBUG: WANT_AUTOMAKE is set to ${WANT_AUTOMAKE}" >&2
169 fi
170 echo "am-wrapper: DEBUG: will execute <$binary>" >&2
171 fi
172
173 #
174 # for further consistency
175 #
176 for v in ${vers} ; do
177 mybin="binary_${v/./_}"
178 if [ "${binary}" = "${!mybin}" ] ; then
179 export WANT_AUTOMAKE="${v}"
180 fi
181 done
182
183 #
184 # Now try to run the binary
185 #
186 if [ ! -x "${binary}" ] ; then
187 echo "am-wrapper: $binary is missing or not executable." >&2
188 echo " Please try emerging the correct version of automake." >&2
189 exit 1
190 fi
191
192 exec "$binary" "$@"
193
194 echo "am-wrapper: was unable to exec $binary !?" >&2
195 exit 1