Require pkg-config 0.26 or later in autogen.sh only.
[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 # Building from the repository needs pkg-config 0.26 or later; see Bug#17438.
46 case $pkg_config_min in
47 0.[0-9] | 0.[0-9].* | 0.1[0-9] | 0.1[0-9].* | 0.2[0-5] | 0.2[0-5].* )
48 pkg_config_min=0.26
49 esac
50
51 ## $1 = program, eg "autoconf".
52 ## Echo the version string, eg "2.59".
53 ## FIXME does not handle things like "1.4a", but AFAIK those are
54 ## all old versions, so it is OK to fail there.
55 ## Also note that we do not handle micro versions.
56 get_version ()
57 {
58 ## Remove eg "./autogen.sh: line 50: autoconf: command not found".
59 $1 --version 2>&1 | sed -e '/not found/d' -e 's/.* //' -n -e '1 s/\([0-9][0-9\.]*\).*/\1/p'
60 }
61
62 ## $1 = version string, eg "2.59"
63 ## Echo the major version, eg "2".
64 major_version ()
65 {
66 echo $1 | sed -e 's/\([0-9][0-9]*\)\..*/\1/'
67 }
68
69 ## $1 = version string, eg "2.59"
70 ## Echo the minor version, eg "59".
71 minor_version ()
72 {
73 echo $1 | sed -e 's/[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/'
74 }
75
76 ## $1 = program
77 ## $2 = minimum version.
78 ## Return 0 if program is present with version >= minimum version.
79 ## Return 1 if program is missing.
80 ## Return 2 if program is present but too old.
81 ## Return 3 for unexpected error (eg failed to parse version).
82 check_version ()
83 {
84 ## Respect eg $AUTOMAKE if it is set, like autoreconf does.
85 uprog=`echo $1 | sed -e 's/-/_/g' -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
86
87 eval uprog=\$${uprog}
88
89 [ x"$uprog" = x ] && uprog=$1
90
91 have_version=`get_version $uprog`
92
93 [ x"$have_version" = x ] && return 1
94
95 have_maj=`major_version $have_version`
96 need_maj=`major_version $2`
97
98 [ x"$have_maj" != x ] && [ x"$need_maj" != x ] || return 3
99
100 [ $have_maj -gt $need_maj ] && return 0
101 [ $have_maj -lt $need_maj ] && return 2
102
103 have_min=`minor_version $have_version`
104 need_min=`minor_version $2`
105
106 [ x"$have_min" != x ] && [ x"$need_min" != x ] || return 3
107
108 [ $have_min -ge $need_min ] && return 0
109 return 2
110 }
111
112
113 cat <<EOF
114 Checking whether you have the necessary tools...
115 (Read INSTALL.REPO for more details on building Emacs)
116
117 EOF
118
119 missing=
120
121 for prog in $progs; do
122
123 sprog=`echo "$prog" | sed 's/-/_/g'`
124
125 eval min=\$${sprog}_min
126
127 echo "Checking for $prog (need at least version $min)..."
128
129 check_version $prog $min
130
131 retval=$?
132
133 case $retval in
134 0) stat="ok" ;;
135 1) stat="missing" ;;
136 2) stat="too old" ;;
137 *) stat="unable to check" ;;
138 esac
139
140 echo $stat
141
142 if [ $retval -ne 0 ]; then
143 missing="$missing $prog"
144 eval ${sprog}_why=\""$stat"\"
145 fi
146
147 done
148
149
150 if [ x"$missing" != x ]; then
151
152 cat <<EOF
153
154 Building Emacs from Bzr requires the following specialized programs:
155 EOF
156
157 for prog in $progs; do
158 sprog=`echo "$prog" | sed 's/-/_/g'`
159
160 eval min=\$${sprog}_min
161
162 echo "$prog (minimum version $min)"
163 done
164
165
166 cat <<EOF
167
168 Your system seems to be missing the following tool(s):
169 EOF
170
171 for prog in $missing; do
172 sprog=`echo "$prog" | sed 's/-/_/g'`
173
174 eval why=\$${sprog}_why
175
176 echo "$prog ($why)"
177 done
178
179 cat <<EOF
180
181 If you think you have the required tools, please add them to your PATH
182 and re-run this script.
183
184 Otherwise, please try installing them.
185 On systems using rpm and yum, try: "yum install PACKAGE"
186 On systems using dpkg and apt, try: "apt-get install PACKAGE"
187 Then re-run this script.
188
189 If you do not have permission to do this, or if the version provided
190 by your system is too old, it is normally straightforward to build
191 these packages from source. You can find the sources at:
192
193 ftp://ftp.gnu.org/gnu/PACKAGE/
194
195 Download the package (make sure you get at least the minimum version
196 listed above), extract it using tar, then run configure, make,
197 make install. Add the installation directory to your PATH and re-run
198 this script.
199
200 If you know that the required versions are in your PATH, but this
201 script has made an error, then you can simply run
202
203 autoreconf -fi -I m4
204
205 instead of this script.
206
207 Please report any problems with this script to bug-gnu-emacs@gnu.org .
208 EOF
209
210 exit 1
211 fi
212
213 # If automake is installed in a nonstandard location, find the standard
214 # location if possible and append it to ACLOCAL_PATH. That way, it will
215 # find the pkg.m4 that is installed in the standard location.
216 echo "Checking for pkg.m4..."
217 AUTORECONF_ENV=
218 env_space=
219 ac_dir=`aclocal --print-ac-dir` || {
220 cat <<EOF
221 There was a problem running 'aclocal --print-ac-dir'.
222 The aclocal program is part of automake.
223 Please check your automake installation.
224 EOF
225
226 exit 1
227 }
228
229 test -n "$ac_dir" && test -r "$ac_dir/pkg.m4" || {
230
231 # Maybe ACLOCAL_PATH is already set-up.
232 if test -n "$ACLOCAL_PATH"; then
233 oIFS=$IFS
234 IFS=:
235 for dir in $ACLOCAL_PATH; do
236 if test -r "$dir/pkg.m4"; then
237 AUTORECONF_ENV="ACLOCAL_PATH='$ACLOCAL_PATH'"
238 env_space=' '
239 break
240 fi
241 done
242 IFS=$oIFS
243 fi
244
245 if test -z "$AUTORECONF_ENV"; then
246 oIFS=$IFS
247 IFS=:
248 before_first_aclocal=true
249 for dir in $PATH; do
250 if test -x "$dir/aclocal"; then
251 if $before_first_aclocal; then
252 before_first_aclocal=false
253 elif ac_dir=`"$dir/aclocal" --print-ac-dir` && test -r "$ac_dir/pkg.m4"
254 then
255 case $ACLOCAL_PATH in
256 '') ACLOCAL_PATH=$ac_dir;;
257 ?*) ACLOCAL_PATH=$ACLOCAL_PATH:$ac_dir;;
258 esac
259 export ACLOCAL_PATH
260 AUTORECONF_ENV="ACLOCAL_PATH='$ACLOCAL_PATH'"
261 env_space=' '
262 break
263 fi
264 fi
265 done
266 IFS=$oIFS
267 fi
268
269 ## OK, maybe pkg-config is in a weird place (eg on hydra).
270 if test -z "$AUTORECONF_ENV"; then
271 oIFS=$IFS
272 IFS=:
273 for dir in $PATH; do
274 if test -x "$dir/pkg-config"; then
275 ac_dir=`echo "$dir" | sed 's|bin$|share/aclocal|'`
276 if test -r "$ac_dir/pkg.m4"; then
277 case $ACLOCAL_PATH in
278 '') ACLOCAL_PATH=$ac_dir;;
279 ?*) ACLOCAL_PATH=$ACLOCAL_PATH:$ac_dir;;
280 esac
281 export ACLOCAL_PATH
282 AUTORECONF_ENV="ACLOCAL_PATH='$ACLOCAL_PATH'"
283 env_space=' '
284 break
285 fi
286 fi
287 done
288 IFS=$oIFS
289 fi
290
291 if test -z "$AUTORECONF_ENV"; then
292 cat <<EOF
293 The version of aclocal that you are using cannot find the pkg.m4 file that
294 pkg-config provides. If it is installed in some unusual directory /FOO/BAR,
295 set ACLOCAL_PATH='/FOO/BAR' in the environment and run this script again.
296 EOF
297 exit 1
298 fi
299 }
300 echo ok
301
302 echo 'Your system has the required tools.'
303 echo "Running \"$AUTORECONF_ENV${env_space}autoreconf -fi -I m4\" ..."
304
305
306 ## Let autoreconf figure out what, if anything, needs doing.
307 ## Use autoreconf's -f option in case autoreconf itself has changed.
308 autoreconf -fi -I m4 || exit $?
309
310 ## Create a timestamp, so that './autogen.sh; make' doesn't
311 ## cause 'make' to needlessly run 'autoheader'.
312 echo timestamp > src/stamp-h.in || exit
313
314 echo "You can now run \"./configure$env_space$AUTORECONF_ENV\"."
315
316 exit 0
317
318 ### autogen.sh ends here