Merge from emacs-23; up to 2010-06-22T07:41:10Z!rgm@gnu.org
[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
66b87493 4## Copyright (C) 2011 Free Software Foundation, Inc.
067d23c9 5
66b87493
GM
6## Author: Glenn Morris <rgm@gnu.org>
7
8## This file is part of GNU Emacs.
9
10## GNU Emacs is free software: you can redistribute it and/or modify
11## it under the terms of the GNU General Public License as published by
12## the Free Software Foundation, either version 3 of the License, or
13## (at your option) any later version.
14
15## GNU Emacs is distributed in the hope that it will be useful,
16## but WITHOUT ANY WARRANTY; without even the implied warranty of
17## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18## GNU General Public License for more details.
19
20## You should have received a copy of the GNU General Public License
21## along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23### Commentary:
24
25## The Emacs bzr repository does not include the configure script
26## (and associated helpers). The first time you fetch Emacs from bzr,
27## run this script to generate the necessary files.
28## For more details, see the file INSTALL.BZR.
29
30### Code:
31
32## Tools we need:
42e85a8f 33## Note that we respect the values of AUTOCONF etc, like autoreconf does.
66b87493
GM
34progs="autoconf automake"
35
36## Minimum versions we need:
37autoconf_min=`sed -n 's/^ *AC_PREREQ(\([0-9\.]*\)).*/\1/p' configure.in`
38
39## FIXME how to determine this from the sources?
40automake_min=1.11
41
42
43## $1 = program, eg "autoconf".
44## Echo the version string, eg "2.59".
45## FIXME does not handle things like "1.4a", but AFAIK those are
46## all old versions, so it is OK to fail there.
47## Also note that we do not handle micro versions.
48get_version ()
49{
42e85a8f
GM
50 ## Remove eg "./autogen.sh: line 50: autoconf: command not found".
51 $1 --version 2>&1 | sed -e '/not found/d' -n -e '1 s/.* \([1-9][0-9\.]*\).*/\1/p'
66b87493
GM
52}
53
54## $1 = version string, eg "2.59"
55## Echo the major version, eg "2".
56major_version ()
57{
58 echo $1 | sed -e 's/\([0-9][0-9]*\)\..*/\1/'
59}
60
61## $1 = version string, eg "2.59"
62## Echo the minor version, eg "59".
63minor_version ()
64{
65 echo $1 | sed -e 's/[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/'
66}
67
68## $1 = program
69## $2 = minimum version.
70## Return 0 if program is present with version >= minumum version.
71## Return 1 if program is missing.
72## Return 2 if program is present but too old.
73## Return 3 for unexpected error (eg failed to parse version).
74check_version ()
75{
42e85a8f
GM
76 ## Respect eg $AUTOMAKE if it is set, like autoreconf does.
77 uprog=`echo $1 | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
78
79 eval uprog=\$${uprog}
80
81 [ x"$uprog" = x ] && uprog=$1
82
83 have_version=`get_version $uprog`
66b87493
GM
84
85 [ x"$have_version" = x ] && return 1
86
87 have_maj=`major_version $have_version`
88 need_maj=`major_version $2`
89
90 [ x"$have_maj" != x ] && [ x"$need_maj" != x ] || return 3
91
92 [ $have_maj -gt $need_maj ] && return 0
93 [ $have_maj -lt $need_maj ] && return 2
94
95 have_min=`minor_version $have_version`
96 need_min=`minor_version $2`
97
98 [ x"$have_min" != x ] && [ x"$need_min" != x ] || return 3
99
100 [ $have_min -ge $need_min ] && return 0
101 return 2
102}
103
104
105cat <<EOF
106Checking whether you have the necessary tools...
107(Read INSTALL.BZR for more details on building Emacs)
108
109EOF
110
111missing=
112
113for prog in $progs; do
114
115 eval min=\$${prog}_min
116
117 echo "Checking for $prog (need at least version $min)..."
118
119 check_version $prog $min
120
121 retval=$?
122
123 case $retval in
124 0) stat="ok" ;;
125 1) stat="missing" ;;
126 2) stat="too old" ;;
127 *) stat="unable to check" ;;
128 esac
129
130 echo $stat
131
132 if [ $retval -ne 0 ]; then
133 missing="$missing $prog"
134 eval ${prog}_why=\""$stat"\"
135 fi
136
137done
138
139
140if [ x"$missing" != x ]; then
141
142 cat <<EOF
143
144Building Emacs from Bzr requires the following specialized programs:
145EOF
146
147 for prog in $progs; do
148 eval min=\$${prog}_min
149
150 echo "$prog (minimum version $min)"
151 done
152
153
154 cat <<EOF
155
156Your system seems to be missing the following tool(s):
157EOF
158
159 for prog in $missing; do
160 eval why=\$${prog}_why
161
162 echo "$prog ($why)"
163 done
164
165 cat <<EOF
166
167If you think you have the required tools, please add them to your PATH
168and re-run this script.
169
170Otherwise, please try installing them.
171On systems using rpm and yum, try: "yum install PACKAGE"
172On systems using dpkg and apt, try: "apt-get install PACKAGE"
173Then re-run this script.
174
175If you do not have permission to do this, or if the version provided
176by your system is too old, it is normally straightforward to build
177these packages from source. You can find the sources at:
178
179ftp://ftp.gnu.org/gnu/PACKAGE/
180
181Download the package (make sure you get at least the minimum version
182listed above), extract it using tar, then run configure, make,
183make install. Add the installation directory to your PATH and re-run
184this script.
185
186If you know that the required versions are in your PATH, but this
187script has made an error, then you can simply run
188
f6ca84c0 189autoreconf -i -I m4
66b87493
GM
190
191instead of this script.
192
193If all else fails, you can try using the pre-built versions of the
194generated files by doing:
195
34cb1cc6 196./autogen/copy_autogen
66b87493
GM
197
198This is not recommended - see the comments in \`copy_autogen'.
199
200Please report any problems with this script to bug-gnu-emacs@gnu.org .
201EOF
202
203 exit 1
204fi
205
206echo "Your system has the required tools, running autoreconf..."
207
208
209## Let autoreconf figure out what, if anything, needs doing.
f6ca84c0 210autoreconf -i -I m4 || exit $?
66b87493
GM
211
212echo "You can now run \`./configure'."
213
214exit 0
215
216### autogen.sh ends here