* todos.el (todos-modes-set-2): Restore point after finding start
[bpt/emacs.git] / autogen.sh
... / ...
CommitLineData
1#!/bin/sh
2### autogen.sh - tool to help build Emacs from a bzr checkout
3
4## Copyright (C) 2011-2012 Free Software Foundation, Inc.
5
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:
33## Note that we respect the values of AUTOCONF etc, like autoreconf does.
34progs="autoconf automake"
35
36## Minimum versions we need:
37autoconf_min=`sed -n 's/^ *AC_PREREQ(\([0-9\.]*\)).*/\1/p' configure.ac`
38
39## This will need improving if more options are ever added to the
40## AM_INIT_AUTOMAKE call.
41automake_min=`sed -n 's/^ *AM_INIT_AUTOMAKE(\([0-9\.]*\)).*/\1/p' configure.ac`
42
43
44## $1 = program, eg "autoconf".
45## Echo the version string, eg "2.59".
46## FIXME does not handle things like "1.4a", but AFAIK those are
47## all old versions, so it is OK to fail there.
48## Also note that we do not handle micro versions.
49get_version ()
50{
51 ## Remove eg "./autogen.sh: line 50: autoconf: command not found".
52 $1 --version 2>&1 | sed -e '/not found/d' -n -e '1 s/.* \([1-9][0-9\.]*\).*/\1/p'
53}
54
55## $1 = version string, eg "2.59"
56## Echo the major version, eg "2".
57major_version ()
58{
59 echo $1 | sed -e 's/\([0-9][0-9]*\)\..*/\1/'
60}
61
62## $1 = version string, eg "2.59"
63## Echo the minor version, eg "59".
64minor_version ()
65{
66 echo $1 | sed -e 's/[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/'
67}
68
69## $1 = program
70## $2 = minimum version.
71## Return 0 if program is present with version >= minimum version.
72## Return 1 if program is missing.
73## Return 2 if program is present but too old.
74## Return 3 for unexpected error (eg failed to parse version).
75check_version ()
76{
77 ## Respect eg $AUTOMAKE if it is set, like autoreconf does.
78 uprog=`echo $1 | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
79
80 eval uprog=\$${uprog}
81
82 [ x"$uprog" = x ] && uprog=$1
83
84 have_version=`get_version $uprog`
85
86 [ x"$have_version" = x ] && return 1
87
88 have_maj=`major_version $have_version`
89 need_maj=`major_version $2`
90
91 [ x"$have_maj" != x ] && [ x"$need_maj" != x ] || return 3
92
93 [ $have_maj -gt $need_maj ] && return 0
94 [ $have_maj -lt $need_maj ] && return 2
95
96 have_min=`minor_version $have_version`
97 need_min=`minor_version $2`
98
99 [ x"$have_min" != x ] && [ x"$need_min" != x ] || return 3
100
101 [ $have_min -ge $need_min ] && return 0
102 return 2
103}
104
105
106cat <<EOF
107Checking whether you have the necessary tools...
108(Read INSTALL.BZR for more details on building Emacs)
109
110EOF
111
112missing=
113
114for prog in $progs; do
115
116 eval min=\$${prog}_min
117
118 echo "Checking for $prog (need at least version $min)..."
119
120 check_version $prog $min
121
122 retval=$?
123
124 case $retval in
125 0) stat="ok" ;;
126 1) stat="missing" ;;
127 2) stat="too old" ;;
128 *) stat="unable to check" ;;
129 esac
130
131 echo $stat
132
133 if [ $retval -ne 0 ]; then
134 missing="$missing $prog"
135 eval ${prog}_why=\""$stat"\"
136 fi
137
138done
139
140
141if [ x"$missing" != x ]; then
142
143 cat <<EOF
144
145Building Emacs from Bzr requires the following specialized programs:
146EOF
147
148 for prog in $progs; do
149 eval min=\$${prog}_min
150
151 echo "$prog (minimum version $min)"
152 done
153
154
155 cat <<EOF
156
157Your system seems to be missing the following tool(s):
158EOF
159
160 for prog in $missing; do
161 eval why=\$${prog}_why
162
163 echo "$prog ($why)"
164 done
165
166 cat <<EOF
167
168If you think you have the required tools, please add them to your PATH
169and re-run this script.
170
171Otherwise, please try installing them.
172On systems using rpm and yum, try: "yum install PACKAGE"
173On systems using dpkg and apt, try: "apt-get install PACKAGE"
174Then re-run this script.
175
176If you do not have permission to do this, or if the version provided
177by your system is too old, it is normally straightforward to build
178these packages from source. You can find the sources at:
179
180ftp://ftp.gnu.org/gnu/PACKAGE/
181
182Download the package (make sure you get at least the minimum version
183listed above), extract it using tar, then run configure, make,
184make install. Add the installation directory to your PATH and re-run
185this script.
186
187If you know that the required versions are in your PATH, but this
188script has made an error, then you can simply run
189
190autoreconf -i -I m4
191
192instead of this script.
193
194If all else fails, you can try using the pre-built versions of the
195generated files by doing:
196
197./autogen/copy_autogen
198
199This is not recommended - see the comments in \`copy_autogen'.
200
201Please report any problems with this script to bug-gnu-emacs@gnu.org .
202EOF
203
204 exit 101 # Exit status 101 means tools were missing.
205fi
206
207echo "Your system has the required tools, running autoreconf..."
208
209
210## Let autoreconf figure out what, if anything, needs doing.
211autoreconf -i -I m4 || exit $?
212
213## Create a timestamp, so that './autogen.sh; make' doesn't
214## cause 'make' to needlessly run 'autoheader'.
215echo timestamp > src/stamp-h.in || exit
216
217echo "You can now run \`./configure'."
218
219exit 0
220
221### autogen.sh ends here