Gentoo Archives: gentoo-commits

From: "Mike Frysinger (vapier)" <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in sys-devel/automake-wrapper/files: am-wrapper-6.sh
Date: Sun, 02 Oct 2011 19:51:29
Message-Id: 20111002195117.768BD2004C@flycatcher.gentoo.org
1 vapier 11/10/02 19:51:17
2
3 Added: am-wrapper-6.sh
4 Log:
5 Optimize version lookup a bit, and handle the case where $0 is not a full path #385201 by Florian Philipp.
6
7 (Portage version: 2.2.0_alpha59/cvs/Linux x86_64)
8
9 Revision Changes Path
10 1.1 sys-devel/automake-wrapper/files/am-wrapper-6.sh
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/sys-devel/automake-wrapper/files/am-wrapper-6.sh?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/sys-devel/automake-wrapper/files/am-wrapper-6.sh?rev=1.1&content-type=text/plain
14
15 Index: am-wrapper-6.sh
16 ===================================================================
17 #!/bin/sh
18 # Copyright 1999-2011 Gentoo Foundation
19 # Distributed under the terms of the GNU General Public License v2
20 # $Header: /var/cvsroot/gentoo-x86/sys-devel/automake-wrapper/files/am-wrapper-6.sh,v 1.1 2011/10/02 19:51:17 vapier Exp $
21
22 # Based on the am-wrapper.pl script provided by MandrakeSoft
23 # Rewritten in bash by Gregorio Guidi
24 #
25 # Executes the correct automake version.
26 #
27 # - defaults to newest version available (hopefully automake-1.10)
28 # - runs automake-1.9 if:
29 # - envvar WANT_AUTOMAKE is set to `1.9'
30 # -or-
31 # - `Makefile.in' was generated by automake-1.9
32 # -or-
33 # - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.9
34 # - runs automake-1.8 if:
35 # - envvar WANT_AUTOMAKE is set to `1.8'
36 # -or-
37 # - `Makefile.in' was generated by automake-1.8
38 # -or-
39 # - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.8
40 # - runs automake-1.7 if:
41 # - envvar WANT_AUTOMAKE is set to `1.7'
42 # -or-
43 # - `Makefile.in' was generated by automake-1.7
44 # -or-
45 # - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.7
46 # - runs automake-1.6 if:
47 # - envvar WANT_AUTOMAKE is set to `1.6'
48 # -or-
49 # - `Makefile.in'
50 # -or-
51 # - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.6
52 # - runs automake-1.5 if:
53 # - envvar WANT_AUTOMAKE is set to `1.5'
54 # -or-
55 # - `Makefile.in' was generated by automake-1.5
56 # -or-
57 # - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.5
58 # - runs automake-1.4 if:
59 # - envvar WANT_AUTOMAKE is set to `1.4'
60 # -or-
61 # - `Makefile.in' was generated by automake-1.4
62 # -or-
63 # - 'aclocal.m4' contain AM_AUTOMAKE_VERSION, specifying the use of 1.4
64
65 warn() { printf 'am-wrapper: %s: %b\n' "${argv0}" "$*" 1>&2; }
66 err() { warn "$@"; exit 1; }
67 unset IFS
68 which() {
69 local p
70 IFS=: # we don't use IFS anywhere, so don't bother saving/restoring
71 for p in ${PATH} ; do
72 p="${p}/$1"
73 [ -e "${p}" ] && echo "${p}" && return 0
74 done
75 unset IFS
76 return 1
77 }
78
79 #
80 # Sanitize argv[0] since it isn't always a full path #385201
81 #
82 argv0=${0##*/}
83 case ${0} in
84 ${argv0})
85 # find it in PATH
86 if ! full_argv0=$(which "${argv0}") ; then
87 err "could not locate ${argv0}; file a bug"
88 fi
89 ;;
90 *)
91 # re-use full/relative paths
92 full_argv0=$0
93 ;;
94 esac
95
96 if [ "${argv0}" = "am-wrapper.sh" ] ; then
97 err "Don't call this script directly"
98 fi
99
100 vers="1.11 1.10 1.9 1.8 1.7 1.6 1.5 1.4"
101
102 #
103 # Export the proper variable/versions and try to locate a usuable
104 # default (newer versions are preferred)
105 #
106 binary=""
107 for v in ${vers} ; do
108 if [ -z "${binary}" ] && [ -x "${full_argv0}-${v}" ] ; then
109 binary="${full_argv0}-${v}"
110 break
111 fi
112 done
113 if [ -z "${binary}" ] ; then
114 err "Unable to locate any usuable version of automake.\n" \
115 "\tI tried these versions: ${vers}\n" \
116 "\tWith a base name of '${full_argv0}'."
117 fi
118
119 #
120 # Check the WANT_AUTOMAKE setting. We accept a whitespace delimited
121 # list of automake versions.
122 #
123 if [ -n "${WANT_AUTOMAKE}" ] ; then
124 for v in ${vers} x ; do
125 if [ "${v}" = "x" ] ; then
126 warn "warning: invalid WANT_AUTOMAKE '${WANT_AUTOMAKE}'; ignoring."
127 unset WANT_AUTOMAKE
128 break
129 fi
130
131 for wx in ${WANT_AUTOMAKE} ; do
132 if [ "${wx}" = "${v}" ] ; then
133 binary="${full_argv0}-${v}"
134 v="x"
135 fi
136 done
137 [ "${v}" = "x" ] && break
138 done
139 fi
140
141 #
142 # autodetect helpers
143 #
144 do_awk() {
145 local file=$1 ; shift
146 local arg=$1 ; shift
147 echo $(gawk "{ if (match(\$0, \"$*\", res)) { print res[${arg}]; exit } }" ${file})
148 }
149
150 #
151 # autodetect routine
152 #
153 if [ -z "${WANT_AUTOMAKE}" ] ; then
154 if [ -r "Makefile.in" ] ; then
155 confversion_mf=$(do_awk Makefile.in 2 "^# Makefile.in generated (automatically )?by automake ([0-9].[0-9]+)")
156 fi
157 if [ -r "aclocal.m4" ] ; then
158 confversion_ac=$(do_awk aclocal.m4 1 'generated automatically by aclocal ([0-9].[0-9]+)')
159 confversion_am=$(do_awk aclocal.m4 1 '[[:space:]]*\\[?AM_AUTOMAKE_VERSION\\(\\[?([0-9].[0-9]+)[^)]*\\]?\\)')
160 fi
161
162 for v in ${vers} ; do
163 if [ "${confversion_mf}" = "${v}" ] || \
164 [ "${confversion_ac}" = "${v}" ] || \
165 [ "${confversion_am}" = "${v}" ]
166 then
167 binary="${full_argv0}-${v}"
168 break
169 fi
170 done
171 fi
172
173 if [ "${WANT_AMWRAPPER_DEBUG}" ] ; then
174 if [ "${WANT_AUTOMAKE}" ] ; then
175 warn "DEBUG: WANT_AUTOMAKE is set to ${WANT_AUTOMAKE}"
176 fi
177 warn "DEBUG: will execute <$binary>"
178 fi
179
180 #
181 # for further consistency
182 #
183 for v in ${vers} ; do
184 if [ "${binary}" = "${full_argv0}-${v}" ] ; then
185 export WANT_AUTOMAKE="${v}"
186 break
187 fi
188 done
189
190 #
191 # Now try to run the binary
192 #
193 if [ ! -x "${binary}" ] ; then
194 err "$binary is missing or not executable.\n" \
195 "\tPlease try emerging the correct version of automake."
196 fi
197
198 exec "$binary" "$@"
199
200 err "was unable to exec $binary !?"