Contents of /trunk/automake/am-wrapper-3.sh
Parent Directory | Revision Log
Revision 119 -
(show annotations)
(download)
(as text)
Sun Mar 18 17:05:39 2007 UTC (17 years, 7 months ago) by niro
File MIME type: application/x-sh
File size: 4315 byte(s)
Sun Mar 18 17:05:39 2007 UTC (17 years, 7 months ago) by niro
File MIME type: application/x-sh
File size: 4315 byte(s)
import am-wrapper-3.sh rev 1.3 from gentoo
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-3.sh,v 1.1 2007-03-18 17:05:39 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.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 | |
49 | if [ "${0##*/}" = "am-wrapper.sh" ] ; then |
50 | echo "Don't call this script directly." >&2 |
51 | exit 1 |
52 | fi |
53 | |
54 | vers="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 usuable |
58 | # default (newer versions are preferred) |
59 | # |
60 | binary="" |
61 | for v in ${vers} ; do |
62 | eval binary_${v/./_}="${0}-${v}" |
63 | |
64 | if [ -z "${binary}" ] && [ -x "${0}-${v}" ] ; then |
65 | binary="${0}-${v}" |
66 | fi |
67 | done |
68 | if [ -z "${binary}" ] ; then |
69 | echo "am-wrapper: Unable to locate any usuable version of automake." >&2 |
70 | echo " I tried these versions: ${vers}" >&2 |
71 | echo " With a base name of '${0}'." >&2 |
72 | exit 1 |
73 | fi |
74 | |
75 | # |
76 | # Check the WANT_AUTOMAKE setting. We accept a whitespace delimited |
77 | # list of automake versions. |
78 | # |
79 | if [ -n "${WANT_AUTOMAKE}" ] ; then |
80 | for v in ${vers} x ; do |
81 | if [ "${v}" = "x" ] ; then |
82 | echo "am-wrapper: warning: invalid WANT_AUTOMAKE '${WANT_AUTOMAKE}'; ignoring." >&2 |
83 | unset WANT_AUTOMAKE |
84 | break |
85 | fi |
86 | |
87 | for wx in ${WANT_AUTOMAKE} ; do |
88 | if [ "${wx}" = "${v}" ] ; then |
89 | binary="binary_${v/./_}" |
90 | binary="${!binary}" |
91 | v="x" |
92 | fi |
93 | done |
94 | [ "${v}" = "x" ] && break |
95 | done |
96 | fi |
97 | |
98 | # |
99 | # autodetect helpers |
100 | # |
101 | do_awk() { |
102 | local file=$1 ; shift |
103 | local arg=$1 ; shift |
104 | echo $(gawk "{ if (match(\$0, \"$*\", res)) { print res[${arg}]; exit } }" ${file}) |
105 | } |
106 | |
107 | # |
108 | # autodetect routine |
109 | # |
110 | if [ -z "${WANT_AUTOMAKE}" ] ; then |
111 | if [ -r "Makefile.in" ] ; then |
112 | confversion_mf=$(do_awk Makefile.in 2 "^# Makefile.in generated (automatically )?by automake ([0-9].[0-9]+)") |
113 | fi |
114 | if [ -r "aclocal.m4" ] ; then |
115 | confversion_ac=$(do_awk aclocal.m4 1 'generated automatically by aclocal ([0-9].[0-9]+)') |
116 | confversion_am=$(do_awk aclocal.m4 1 '[[:space:]]*\\[?AM_AUTOMAKE_VERSION\\(\\[?([0-9].[0-9]+)[^)]*\\]?\\)') |
117 | fi |
118 | |
119 | for v in ${vers} ; do |
120 | if [ "${confversion_mf}" = "${v}" ] \ |
121 | || [ "${confversion_ac}" = "${v}" ] \ |
122 | || [ "${confversion_am}" = "${v}" ] ; then |
123 | binary="binary_${v/./_}" |
124 | binary="${!binary}" |
125 | break |
126 | fi |
127 | done |
128 | fi |
129 | |
130 | if [ "${WANT_AMWRAPPER_DEBUG}" ] ; then |
131 | if [ "${WANT_AUTOMAKE}" ] ; then |
132 | echo "am-wrapper: DEBUG: WANT_AUTOMAKE is set to ${WANT_AUTOMAKE}" >&2 |
133 | fi |
134 | echo "am-wrapper: DEBUG: will execute <$binary>" >&2 |
135 | fi |
136 | |
137 | # |
138 | # for further consistency |
139 | # |
140 | for v in ${vers} ; do |
141 | mybin="binary_${v/./_}" |
142 | if [ "${binary}" = "${!mybin}" ] ; then |
143 | export WANT_AUTOMAKE="${v}" |
144 | fi |
145 | done |
146 | |
147 | # |
148 | # Now try to run the binary |
149 | # |
150 | if [ ! -x "${binary}" ] ; then |
151 | echo "am-wrapper: $binary is missing or not executable." >&2 |
152 | echo " Please try emerging the correct version of automake." >&2 |
153 | exit 1 |
154 | fi |
155 | |
156 | exec "$binary" "$@" |
157 | |
158 | echo "am-wrapper: was unable to exec $binary !?" >&2 |
159 | exit 1 |