* autogen.sh: Check any pre-existing ACLOCAL_PATH.
[bpt/emacs.git] / autogen.sh
1 #!/bin/sh
2 ### autogen.sh - tool to help build Emacs from a bzr checkout
3
4 ## Copyright (C) 2011-2014 Free Software Foundation, Inc.
5
6 ## Author: Glenn Morris <rgm@gnu.org>
7 ## Maintainer: emacs-devel@gnu.org
8
9 ## This file is part of GNU Emacs.
10
11 ## GNU Emacs is free software: you can redistribute it and/or modify
12 ## it under the terms of the GNU General Public License as published by
13 ## the Free Software Foundation, either version 3 of the License, or
14 ## (at your option) any later version.
15
16 ## GNU Emacs is distributed in the hope that it will be useful,
17 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ## GNU General Public License for more details.
20
21 ## You should have received a copy of the GNU General Public License
22 ## along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24 ### Commentary:
25
26 ## The Emacs bzr repository does not include the configure script
27 ## (and associated helpers). The first time you fetch Emacs from bzr,
28 ## run this script to generate the necessary files.
29 ## For more details, see the file INSTALL.REPO.
30
31 ### Code:
32
33 ## Tools we need:
34 ## Note that we respect the values of AUTOCONF etc, like autoreconf does.
35 progs="autoconf automake pkg-config"
36
37 ## Minimum versions we need:
38 autoconf_min=`sed -n 's/^ *AC_PREREQ(\([0-9\.]*\)).*/\1/p' configure.ac`
39
40 ## This will need improving if more options are ever added to the
41 ## AM_INIT_AUTOMAKE call.
42 automake_min=`sed -n 's/^ *AM_INIT_AUTOMAKE(\([0-9\.]*\)).*/\1/p' configure.ac`
43
44 pkg_config_min=`sed -n 's/^ *PKG_PROG_PKG_CONFIG(\([0-9\.]*\)).*/\1/p' configure.ac`
45
46 ## $1 = program, eg "autoconf".
47 ## Echo the version string, eg "2.59".
48 ## FIXME does not handle things like "1.4a", but AFAIK those are
49 ## all old versions, so it is OK to fail there.
50 ## Also note that we do not handle micro versions.
51 get_version ()
52 {
53 ## Remove eg "./autogen.sh: line 50: autoconf: command not found".
54 $1 --version 2>&1 | sed -e '/not found/d' -e 's/.* //' -n -e '1 s/\([0-9][0-9\.]*\).*/\1/p'
55 }
56
57 ## $1 = version string, eg "2.59"
58 ## Echo the major version, eg "2".
59 major_version ()
60 {
61 echo $1 | sed -e 's/\([0-9][0-9]*\)\..*/\1/'
62 }
63
64 ## $1 = version string, eg "2.59"
65 ## Echo the minor version, eg "59".
66 minor_version ()
67 {
68 echo $1 | sed -e 's/[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/'
69 }
70
71 ## $1 = program
72 ## $2 = minimum version.
73 ## Return 0 if program is present with version >= minimum version.
74 ## Return 1 if program is missing.
75 ## Return 2 if program is present but too old.
76 ## Return 3 for unexpected error (eg failed to parse version).
77 check_version ()
78 {
79 ## Respect eg $AUTOMAKE if it is set, like autoreconf does.
80 uprog=`echo $1 | sed -e 's/-/_/g' -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
81
82 eval uprog=\$${uprog}
83
84 [ x"$uprog" = x ] && uprog=$1
85
86 have_version=`get_version $uprog`
87
88 [ x"$have_version" = x ] && return 1
89
90 have_maj=`major_version $have_version`
91 need_maj=`major_version $2`
92
93 [ x"$have_maj" != x ] && [ x"$need_maj" != x ] || return 3
94
95 [ $have_maj -gt $need_maj ] && return 0
96 [ $have_maj -lt $need_maj ] && return 2
97
98 have_min=`minor_version $have_version`
99 need_min=`minor_version $2`
100
101 [ x"$have_min" != x ] && [ x"$need_min" != x ] || return 3
102
103 [ $have_min -ge $need_min ] && return 0
104 return 2
105 }
106
107
108 cat <<EOF
109 Checking whether you have the necessary tools...
110 (Read INSTALL.REPO for more details on building Emacs)
111
112 EOF
113
114 missing=
115
116 for prog in $progs; do
117
118 sprog=`echo "$prog" | sed 's/-/_/g'`
119
120 eval min=\$${sprog}_min
121
122 echo "Checking for $prog (need at least version $min)..."
123
124 check_version $prog $min
125
126 retval=$?
127
128 case $retval in
129 0) stat="ok" ;;
130 1) stat="missing" ;;
131 2) stat="too old" ;;
132 *) stat="unable to check" ;;
133 esac
134
135 echo $stat
136
137 if [ $retval -ne 0 ]; then
138 missing="$missing $prog"
139 eval ${sprog}_why=\""$stat"\"
140 fi
141
142 done
143
144
145 if [ x"$missing" != x ]; then
146
147 cat <<EOF
148
149 Building Emacs from Bzr requires the following specialized programs:
150 EOF
151
152 for prog in $progs; do
153 sprog=`echo "$prog" | sed 's/-/_/g'`
154
155 eval min=\$${sprog}_min
156
157 echo "$prog (minimum version $min)"
158 done
159
160
161 cat <<EOF
162
163 Your system seems to be missing the following tool(s):
164 EOF
165
166 for prog in $missing; do
167 sprog=`echo "$prog" | sed 's/-/_/g'`
168
169 eval why=\$${sprog}_why
170
171 echo "$prog ($why)"
172 done
173
174 cat <<EOF
175
176 If you think you have the required tools, please add them to your PATH
177 and re-run this script.
178
179 Otherwise, please try installing them.
180 On systems using rpm and yum, try: "yum install PACKAGE"
181 On systems using dpkg and apt, try: "apt-get install PACKAGE"
182 Then re-run this script.
183
184 If you do not have permission to do this, or if the version provided
185 by your system is too old, it is normally straightforward to build
186 these packages from source. You can find the sources at:
187
188 ftp://ftp.gnu.org/gnu/PACKAGE/
189
190 Download the package (make sure you get at least the minimum version
191 listed above), extract it using tar, then run configure, make,
192 make install. Add the installation directory to your PATH and re-run
193 this script.
194
195 If you know that the required versions are in your PATH, but this
196 script has made an error, then you can simply run
197
198 autoreconf -fi -I m4
199
200 instead of this script.
201
202 Please report any problems with this script to bug-gnu-emacs@gnu.org .
203 EOF
204
205 exit 1
206 fi
207
208 # If automake is installed in a nonstandard location, find the standard
209 # location if possible and append it to ACLOCAL_PATH. That way, it will
210 # find the pkg.m4 that is installed in the standard location.
211 echo "Checking for pkg.m4..."
212 AUTORECONF_ENV=
213 env_space=
214 ac_dir=`aclocal --print-ac-dir` && test -r "$ac_dir/pkg.m4" || {
215
216 # Maybe ACLOCAL_PATH is already set-up.
217 if test -n "$ACLOCAL_PATH"; then
218 oIFS=$IFS
219 IFS=:
220 for dir in $ACLOCAL_PATH; do
221 if test -r "$dir/pkg.m4"; then
222 AUTORECONF_ENV="ACLOCAL_PATH='$ACLOCAL_PATH'"
223 env_space=' '
224 break
225 fi
226 done
227 IFS=$oIFS
228 fi
229
230 if test -z "$AUTORECONF_ENV"; then
231 oIFS=$IFS
232 IFS=:
233 before_first_aclocal=true
234 for dir in $PATH; do
235 if test -x "$dir/aclocal"; then
236 if $before_first_aclocal; then
237 before_first_aclocal=false
238 elif ac_dir=`"$dir/aclocal" --print-ac-dir` && test -r "$ac_dir/pkg.m4"
239 then
240 case $ACLOCAL_PATH in
241 '') ACLOCAL_PATH=$ac_dir;;
242 ?*) ACLOCAL_PATH=$ACLOCAL_PATH:$ac_dir;;
243 esac
244 export ACLOCAL_PATH
245 AUTORECONF_ENV="ACLOCAL_PATH='$ACLOCAL_PATH'"
246 env_space=' '
247 break
248 fi
249 fi
250 done
251 IFS=$oIFS
252 fi
253
254 ## OK, maybe pkg-config is in a weird place (eg on hydra).
255 if test -z "$AUTORECONF_ENV"; then
256 oIFS=$IFS
257 IFS=:
258 for dir in $PATH; do
259 if test -x "$dir/pkg-config"; then
260 ac_dir=`echo "$dir" | sed 's|bin$|share/aclocal|'`
261 if test -r "$ac_dir/pkg.m4"; then
262 case $ACLOCAL_PATH in
263 '') ACLOCAL_PATH=$ac_dir;;
264 ?*) ACLOCAL_PATH=$ACLOCAL_PATH:$ac_dir;;
265 esac
266 export ACLOCAL_PATH
267 AUTORECONF_ENV="ACLOCAL_PATH='$ACLOCAL_PATH'"
268 env_space=' '
269 break
270 fi
271 fi
272 done
273 IFS=$oIFS
274 fi
275
276 if test -z "$AUTORECONF_ENV"; then
277 cat <<EOF
278 The version of aclocal that you are using cannot find the pkg.m4 file that
279 pkg-config provides. If it is installed in some unusual directory /FOO/BAR,
280 set ACLOCAL_PATH='/FOO/BAR' in the environment and run this script again.
281 EOF
282 exit 1
283 fi
284 }
285 echo ok
286
287 echo 'Your system has the required tools.'
288 echo "Running \"$AUTORECONF_ENV${env_space}autoreconf -fi -I m4\" ..."
289
290
291 ## Let autoreconf figure out what, if anything, needs doing.
292 ## Use autoreconf's -f option in case autoreconf itself has changed.
293 autoreconf -fi -I m4 || exit $?
294
295 ## Create a timestamp, so that './autogen.sh; make' doesn't
296 ## cause 'make' to needlessly run 'autoheader'.
297 echo timestamp > src/stamp-h.in || exit
298
299 echo "You can now run \"./configure$env_space$AUTORECONF_ENV\"."
300
301 exit 0
302
303 ### autogen.sh ends here