Fix yet another configure error on OSX.
[bpt/emacs.git] / autogen.sh
CommitLineData
067d23c9 1#!/bin/sh
66b87493 2### autogen.sh - tool to help build Emacs from a bzr checkout
067d23c9 3
ba318903 4## Copyright (C) 2011-2014 Free Software Foundation, Inc.
067d23c9 5
66b87493 6## Author: Glenn Morris <rgm@gnu.org>
34dc21db 7## Maintainer: emacs-devel@gnu.org
66b87493
GM
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.
ac4c50ad 29## For more details, see the file INSTALL.REPO.
66b87493
GM
30
31### Code:
32
33## Tools we need:
42e85a8f 34## Note that we respect the values of AUTOCONF etc, like autoreconf does.
b05e08a4 35progs="autoconf automake pkg-config"
66b87493
GM
36
37## Minimum versions we need:
c4444d16 38autoconf_min=`sed -n 's/^ *AC_PREREQ(\([0-9\.]*\)).*/\1/p' configure.ac`
66b87493 39
7d732d1a
GM
40## This will need improving if more options are ever added to the
41## AM_INIT_AUTOMAKE call.
42automake_min=`sed -n 's/^ *AM_INIT_AUTOMAKE(\([0-9\.]*\)).*/\1/p' configure.ac`
66b87493 43
b05e08a4 44pkg_config_min=`sed -n 's/^ *PKG_PROG_PKG_CONFIG(\([0-9\.]*\)).*/\1/p' configure.ac`
66b87493
GM
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.
51get_version ()
52{
42e85a8f 53 ## Remove eg "./autogen.sh: line 50: autoconf: command not found".
5253ea1d 54 $1 --version 2>&1 | sed -e '/not found/d' -e 's/.* //' -n -e '1 s/\([0-9][0-9\.]*\).*/\1/p'
66b87493
GM
55}
56
57## $1 = version string, eg "2.59"
58## Echo the major version, eg "2".
59major_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".
66minor_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.
c80e3b4a 73## Return 0 if program is present with version >= minimum version.
66b87493
GM
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).
77check_version ()
78{
42e85a8f 79 ## Respect eg $AUTOMAKE if it is set, like autoreconf does.
5253ea1d 80 uprog=`echo $1 | sed -e 's/-/_/g' -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
42e85a8f
GM
81
82 eval uprog=\$${uprog}
83
84 [ x"$uprog" = x ] && uprog=$1
85
86 have_version=`get_version $uprog`
66b87493
GM
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
108cat <<EOF
109Checking whether you have the necessary tools...
ac4c50ad 110(Read INSTALL.REPO for more details on building Emacs)
66b87493
GM
111
112EOF
113
114missing=
115
116for prog in $progs; do
117
5253ea1d
GM
118 sprog=`echo "$prog" | sed 's/-/_/g'`
119
120 eval min=\$${sprog}_min
66b87493
GM
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"
5253ea1d 139 eval ${sprog}_why=\""$stat"\"
66b87493
GM
140 fi
141
142done
143
144
145if [ x"$missing" != x ]; then
146
147 cat <<EOF
148
149Building Emacs from Bzr requires the following specialized programs:
150EOF
151
152 for prog in $progs; do
5253ea1d
GM
153 sprog=`echo "$prog" | sed 's/-/_/g'`
154
155 eval min=\$${sprog}_min
66b87493
GM
156
157 echo "$prog (minimum version $min)"
158 done
159
160
161 cat <<EOF
162
163Your system seems to be missing the following tool(s):
164EOF
165
166 for prog in $missing; do
5253ea1d
GM
167 sprog=`echo "$prog" | sed 's/-/_/g'`
168
169 eval why=\$${sprog}_why
66b87493
GM
170
171 echo "$prog ($why)"
172 done
173
174 cat <<EOF
175
176If you think you have the required tools, please add them to your PATH
177and re-run this script.
178
179Otherwise, please try installing them.
180On systems using rpm and yum, try: "yum install PACKAGE"
181On systems using dpkg and apt, try: "apt-get install PACKAGE"
182Then re-run this script.
183
184If you do not have permission to do this, or if the version provided
185by your system is too old, it is normally straightforward to build
186these packages from source. You can find the sources at:
187
188ftp://ftp.gnu.org/gnu/PACKAGE/
189
190Download the package (make sure you get at least the minimum version
191listed above), extract it using tar, then run configure, make,
192make install. Add the installation directory to your PATH and re-run
193this script.
194
195If you know that the required versions are in your PATH, but this
196script has made an error, then you can simply run
197
af3e4d06 198autoreconf -fi -I m4
66b87493
GM
199
200instead of this script.
201
66b87493
GM
202Please report any problems with this script to bug-gnu-emacs@gnu.org .
203EOF
204
dee26dfa 205 exit 1
66b87493
GM
206fi
207
af3e4d06
PE
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.
211echo "Checking for pkg.m4..."
212AUTORECONF_ENV=
541df9f4 213env_space=
98e12950
GM
214ac_dir=`aclocal --print-ac-dir` || {
215 cat <<EOF
216There was a problem running 'aclocal --print-ac-dir'.
217The aclocal program is part of automake.
218Please check your automake installation.
219EOF
220
221 exit 1
222}
223
224test -n "$ac_dir" && test -r "$ac_dir/pkg.m4" || {
e8e2626f
GM
225
226 # Maybe ACLOCAL_PATH is already set-up.
227 if test -n "$ACLOCAL_PATH"; then
228 oIFS=$IFS
229 IFS=:
230 for dir in $ACLOCAL_PATH; do
231 if test -r "$dir/pkg.m4"; then
232 AUTORECONF_ENV="ACLOCAL_PATH='$ACLOCAL_PATH'"
233 env_space=' '
234 break
af3e4d06 235 fi
e8e2626f
GM
236 done
237 IFS=$oIFS
238 fi
239
240 if test -z "$AUTORECONF_ENV"; then
241 oIFS=$IFS
242 IFS=:
243 before_first_aclocal=true
244 for dir in $PATH; do
245 if test -x "$dir/aclocal"; then
246 if $before_first_aclocal; then
247 before_first_aclocal=false
248 elif ac_dir=`"$dir/aclocal" --print-ac-dir` && test -r "$ac_dir/pkg.m4"
249 then
250 case $ACLOCAL_PATH in
251 '') ACLOCAL_PATH=$ac_dir;;
252 ?*) ACLOCAL_PATH=$ACLOCAL_PATH:$ac_dir;;
253 esac
254 export ACLOCAL_PATH
255 AUTORECONF_ENV="ACLOCAL_PATH='$ACLOCAL_PATH'"
256 env_space=' '
257 break
258 fi
259 fi
260 done
261 IFS=$oIFS
262 fi
af3e4d06 263
c3a435fe
GM
264 ## OK, maybe pkg-config is in a weird place (eg on hydra).
265 if test -z "$AUTORECONF_ENV"; then
266 oIFS=$IFS
267 IFS=:
268 for dir in $PATH; do
269 if test -x "$dir/pkg-config"; then
270 ac_dir=`echo "$dir" | sed 's|bin$|share/aclocal|'`
271 if test -r "$ac_dir/pkg.m4"; then
272 case $ACLOCAL_PATH in
273 '') ACLOCAL_PATH=$ac_dir;;
274 ?*) ACLOCAL_PATH=$ACLOCAL_PATH:$ac_dir;;
275 esac
276 export ACLOCAL_PATH
277 AUTORECONF_ENV="ACLOCAL_PATH='$ACLOCAL_PATH'"
278 env_space=' '
279 break
280 fi
281 fi
282 done
283 IFS=$oIFS
284 fi
285
af3e4d06
PE
286 if test -z "$AUTORECONF_ENV"; then
287 cat <<EOF
288The version of aclocal that you are using cannot find the pkg.m4 file that
289pkg-config provides. If it is installed in some unusual directory /FOO/BAR,
290set ACLOCAL_PATH='/FOO/BAR' in the environment and run this script again.
291EOF
292 exit 1
293 fi
294}
295echo ok
296
297echo 'Your system has the required tools.'
541df9f4 298echo "Running \"$AUTORECONF_ENV${env_space}autoreconf -fi -I m4\" ..."
66b87493
GM
299
300
301## Let autoreconf figure out what, if anything, needs doing.
6956b278 302## Use autoreconf's -f option in case autoreconf itself has changed.
af3e4d06 303autoreconf -fi -I m4 || exit $?
66b87493 304
3f750e43
PE
305## Create a timestamp, so that './autogen.sh; make' doesn't
306## cause 'make' to needlessly run 'autoheader'.
307echo timestamp > src/stamp-h.in || exit
308
4a05c50a 309echo "You can now run \"./configure$env_space$AUTORECONF_ENV\"."
66b87493
GM
310
311exit 0
312
313### autogen.sh ends here