1 | #!/bin/bash
|
---|
2 | # Copyright 1999-2005 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-3.1.sh,v 1.3 2005/07/16 20:42:12 azarah 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 latest version (2.5x)
|
---|
12 | # - runs autoconf 2.13 only 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 |
|
---|
19 | if [[ ${0##*/} == "ac-wrapper.sh" ]] ; then
|
---|
20 | echo "Don't call this script directly" >&2
|
---|
21 | exit 1
|
---|
22 | fi
|
---|
23 |
|
---|
24 | if [[ ${WANT_AUTOCONF} == "2.1" && ${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
|
---|
29 | fi
|
---|
30 |
|
---|
31 | binary_new="${0}-2.59"
|
---|
32 | binary_old="${0}-2.13"
|
---|
33 | binary=${binary_new}
|
---|
34 |
|
---|
35 | acprereq_version() {
|
---|
36 | # Add --posix to below awk to make sure it will run on macosx, etc
|
---|
37 | awk \
|
---|
38 | '($0 !~ /^[[:space:]]*(#|dnl)/) {
|
---|
39 | # The following is replaced by below, as we cannot use match()
|
---|
40 | # with a third argument with non-gawk (posix) versions of awk:
|
---|
41 | #
|
---|
42 | #if (match($0, "AC_PREREQ\\(\\[?([0-9]\\.[0-9])", res))
|
---|
43 | # VERSIONS[COUNT++] = res[1]
|
---|
44 | #
|
---|
45 | sindex = match($0, /AC_PREREQ\(\[?([0-9]\.[0-9])/)
|
---|
46 | if (sindex > 0) {
|
---|
47 | sindex += length("AC_PREREQ(")
|
---|
48 | if (substr($0, sindex, 1) == "[")
|
---|
49 | sindex++
|
---|
50 | VERSIONS[COUNT++] = substr($0, sindex, 3)
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | END {
|
---|
55 | # The following is replaced by below, as we cannot use asort()
|
---|
56 | # with non-gawk (posix) versions of awk:
|
---|
57 | #
|
---|
58 | #asort(VERSIONS)
|
---|
59 | #
|
---|
60 | VERSION = VERSIONS[0]
|
---|
61 | # We need to get the biggest version and print that
|
---|
62 | for (x = 0; x <= COUNT;x++)
|
---|
63 | if (VERSIONS[x] > VERSION)
|
---|
64 | VERSION=VERSIONS[x]
|
---|
65 |
|
---|
66 | print VERSION
|
---|
67 | }' "$@"
|
---|
68 | }
|
---|
69 |
|
---|
70 | generated_version() {
|
---|
71 | # Add --posix to below awk to make sure it will run on macosx, etc
|
---|
72 | awk \
|
---|
73 | '{
|
---|
74 | # The following is replaced by below, as we cannot use match()
|
---|
75 | # with a third argument with non-gawk (posix) versions of awk:
|
---|
76 | #
|
---|
77 | #if (match($0,
|
---|
78 | # "^# Generated (by (GNU )?Autoconf|automatically using autoconf version) ([0-9].[0-9])",
|
---|
79 | # res))
|
---|
80 | # { print res[3]; exit }
|
---|
81 | #
|
---|
82 | # First try for newer versions of autoconf
|
---|
83 | sindex = match($0, /Generated by GNU Autoconf ([0-9]\.[0-9])/)
|
---|
84 | if (sindex > 0)
|
---|
85 | # Now chop the first part before the version
|
---|
86 | sindex += length("Generated by GNU Autoconf ")
|
---|
87 | # No version, so try older versions of autoconf
|
---|
88 | if (sindex <= 0) {
|
---|
89 | sindex = match($0, /Generated automatically using autoconf version ([0-9]\.[0-9])/)
|
---|
90 | if (sindex > 0)
|
---|
91 | sindex += length("Generated automatically using autoconf version ")
|
---|
92 | }
|
---|
93 |
|
---|
94 | # Ok, we got a version
|
---|
95 | if (sindex > 0) {
|
---|
96 | print substr($0, sindex, 3)
|
---|
97 | exit
|
---|
98 | }
|
---|
99 | }' "$@"
|
---|
100 | }
|
---|
101 |
|
---|
102 | #
|
---|
103 | # autodetect routine
|
---|
104 | #
|
---|
105 | if [[ ${WANT_AUTOCONF} != "2.5" ]] ; then
|
---|
106 | if [[ ${WANT_AUTOCONF} == "2.1" ]] ; then
|
---|
107 | if [[ ! -f "configure.ac" ]] ; then
|
---|
108 | binary=${binary_old}
|
---|
109 | else
|
---|
110 | echo "ac-wrapper: Since configure.ac is present, aclocal always use" >&2
|
---|
111 | echo " autoconf 2.59, which conflicts with your choice and" >&2
|
---|
112 | echo " causes error. You have two options:" >&2
|
---|
113 | echo " 1. Try execute command again after removing configure.ac" >&2
|
---|
114 | echo " 2. Don't set WANT_AUTOCONF" >&2
|
---|
115 | exit 1
|
---|
116 | fi
|
---|
117 | else
|
---|
118 | # Automake-1.7 and better requie autoconf-2.5x
|
---|
119 | case "${WANT_AUTOMAKE}" in
|
---|
120 | 1.[7-9]) ;;
|
---|
121 | *)
|
---|
122 | acfiles=$(ls ac{local,include}.m4 configure.{in,ac} 2>/dev/null)
|
---|
123 | [[ -n ${acfiles} ]] && confversion=$(acprereq_version ${acfiles})
|
---|
124 |
|
---|
125 | [[ -z ${confversion} && -r "configure" ]] && \
|
---|
126 | confversion=$(generated_version configure)
|
---|
127 |
|
---|
128 | if [[ ${confversion} == "2.1" && ! -f "configure.ac" ]] ; then
|
---|
129 | binary="${binary_old}"
|
---|
130 | fi
|
---|
131 | esac
|
---|
132 | fi
|
---|
133 | fi
|
---|
134 |
|
---|
135 | if [[ -n ${WANT_ACWRAPPER_DEBUG} ]] ; then
|
---|
136 | if [[ -n ${WANT_AUTOCONF} ]] ; then
|
---|
137 | echo "ac-wrapper: DEBUG: WANT_AUTOCONF is set to ${WANT_AUTOCONF}" >&2
|
---|
138 | fi
|
---|
139 | echo "ac-wrapper: DEBUG: will execute <${binary}>" >&2
|
---|
140 | fi
|
---|
141 |
|
---|
142 | #
|
---|
143 | # for further consistency
|
---|
144 | #
|
---|
145 | if [[ ${binary} == "${binary_new}" ]] ; then
|
---|
146 | export WANT_AUTOCONF="2.5"
|
---|
147 | elif [[ ${binary} == "${binary_old}" ]] ; then
|
---|
148 | export WANT_AUTOCONF="2.1"
|
---|
149 | fi
|
---|
150 |
|
---|
151 | if [[ ! -x ${binary} ]] ; then
|
---|
152 | # this shouldn't happen
|
---|
153 | echo "ac-wrapper: ${binary} is missing or not executable." >&2
|
---|
154 | echo " Please try emerging the correct version of autoconf." >&2
|
---|
155 | exit 1
|
---|
156 | fi
|
---|
157 |
|
---|
158 | exec "${binary}" "$@"
|
---|
159 |
|
---|
160 | echo "ac-wrapper: was unable to exec ${binary} !?" >&2
|
---|
161 | exit 1
|
---|