]> code.delx.au - gnu-emacs/blob - autogen.sh
Doc fixes for menu-bar.el
[gnu-emacs] / autogen.sh
1 #!/bin/sh
2 ### autogen.sh - tool to help build Emacs from a repository checkout
3
4 ## Copyright (C) 2011-2016 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 repository does not include the configure script (and
27 ## associated helpers). The first time you fetch Emacs from the repo,
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"
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
45 ## $1 = program, eg "autoconf".
46 ## Echo the version string, eg "2.59".
47 ## FIXME does not handle things like "1.4a", but AFAIK those are
48 ## all old versions, so it is OK to fail there.
49 ## Also note that we do not handle micro versions.
50 get_version ()
51 {
52 ## Remove eg "./autogen.sh: line 50: autoconf: command not found".
53 $1 --version 2>&1 | sed -e '/not found/d' -e 's/.* //' -n -e '1 s/\([0-9][0-9\.]*\).*/\1/p'
54 }
55
56 ## $1 = version string, eg "2.59"
57 ## Echo the major version, eg "2".
58 major_version ()
59 {
60 echo $1 | sed -e 's/\([0-9][0-9]*\)\..*/\1/'
61 }
62
63 ## $1 = version string, eg "2.59"
64 ## Echo the minor version, eg "59".
65 minor_version ()
66 {
67 echo $1 | sed -e 's/[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/'
68 }
69
70 ## $1 = program
71 ## $2 = minimum version.
72 ## Return 0 if program is present with version >= minimum version.
73 ## Return 1 if program is missing.
74 ## Return 2 if program is present but too old.
75 ## Return 3 for unexpected error (eg failed to parse version).
76 check_version ()
77 {
78 ## Respect eg $AUTOMAKE if it is set, like autoreconf does.
79 uprog=`echo $1 | sed -e 's/-/_/g' -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
80
81 eval uprog=\$${uprog}
82
83 [ x"$uprog" = x ] && uprog=$1
84
85 have_version=`get_version $uprog`
86
87 [ x"$have_version" = x ] && return 1
88
89 have_maj=`major_version $have_version`
90 need_maj=`major_version $2`
91
92 [ x"$have_maj" != x ] && [ x"$need_maj" != x ] || return 3
93
94 [ $have_maj -gt $need_maj ] && return 0
95 [ $have_maj -lt $need_maj ] && return 2
96
97 have_min=`minor_version $have_version`
98 need_min=`minor_version $2`
99
100 [ x"$have_min" != x ] && [ x"$need_min" != x ] || return 3
101
102 [ $have_min -ge $need_min ] && return 0
103 return 2
104 }
105
106
107 cat <<EOF
108 Checking whether you have the necessary tools...
109 (Read INSTALL.REPO for more details on building Emacs)
110
111 EOF
112
113 missing=
114
115 for prog in $progs; do
116
117 sprog=`echo "$prog" | sed 's/-/_/g'`
118
119 eval min=\$${sprog}_min
120
121 echo "Checking for $prog (need at least version $min)..."
122
123 check_version $prog $min
124
125 retval=$?
126
127 case $retval in
128 0) stat="ok" ;;
129 1) stat="missing" ;;
130 2) stat="too old" ;;
131 *) stat="unable to check" ;;
132 esac
133
134 echo $stat
135
136 if [ $retval -ne 0 ]; then
137 missing="$missing $prog"
138 eval ${sprog}_why=\""$stat"\"
139 fi
140
141 done
142
143
144 if [ x"$missing" != x ]; then
145
146 cat <<EOF
147
148 Building Emacs from the repository requires the following specialized programs:
149 EOF
150
151 for prog in $progs; do
152 sprog=`echo "$prog" | sed 's/-/_/g'`
153
154 eval min=\$${sprog}_min
155
156 echo "$prog (minimum version $min)"
157 done
158
159
160 cat <<EOF
161
162 Your system seems to be missing the following tool(s):
163 EOF
164
165 for prog in $missing; do
166 sprog=`echo "$prog" | sed 's/-/_/g'`
167
168 eval why=\$${sprog}_why
169
170 echo "$prog ($why)"
171 done
172
173 cat <<EOF
174
175 If you think you have the required tools, please add them to your PATH
176 and re-run this script.
177
178 Otherwise, please try installing them.
179 On systems using rpm and yum, try: "yum install PACKAGE"
180 On systems using dpkg and apt, try: "apt-get install PACKAGE"
181 Then re-run this script.
182
183 If you do not have permission to do this, or if the version provided
184 by your system is too old, it is normally straightforward to build
185 these packages from source. You can find the sources at:
186
187 ftp://ftp.gnu.org/gnu/PACKAGE/
188
189 Download the package (make sure you get at least the minimum version
190 listed above), extract it using tar, then run configure, make,
191 make install. Add the installation directory to your PATH and re-run
192 this script.
193
194 If you know that the required versions are in your PATH, but this
195 script has made an error, then you can simply run
196
197 autoreconf -fi -I m4
198
199 instead of this script.
200
201 Please report any problems with this script to bug-gnu-emacs@gnu.org .
202 EOF
203
204 exit 1
205 fi
206
207 echo 'Your system has the required tools.'
208 echo "Running 'autoreconf -fi -I m4' ..."
209
210
211 ## Let autoreconf figure out what, if anything, needs doing.
212 ## Use autoreconf's -f option in case autoreconf itself has changed.
213 autoreconf -fi -I m4 || exit $?
214
215 ## Create a timestamp, so that './autogen.sh; make' doesn't
216 ## cause 'make' to needlessly run 'autoheader'.
217 echo timestamp > src/stamp-h.in || exit
218
219
220 ## Configure Git, if using Git.
221 if test -d .git && (git status -s) >/dev/null 2>&1; then
222
223 # Configure 'git diff' hunk header format.
224
225 git config 'diff.elisp.xfuncname' \
226 '^\(def[^[:space:]]+[[:space:]]+([^()[:space:]]+)' || exit
227 git config 'diff.texinfo.xfuncname' \
228 '^@node[[:space:]]+([^,[:space:]][^,]+)' || exit
229
230
231 # Install Git hooks.
232
233 tailored_hooks=
234 sample_hooks=
235
236 for hook in commit-msg pre-commit; do
237 cmp build-aux/git-hooks/$hook .git/hooks/$hook >/dev/null 2>&1 ||
238 tailored_hooks="$tailored_hooks $hook"
239 done
240 for hook in applypatch-msg pre-applypatch; do
241 test ! -r .git/hooks/$hook.sample ||
242 cmp .git/hooks/$hook.sample .git/hooks/$hook >/dev/null 2>&1 ||
243 sample_hooks="$sample_hooks $hook"
244 done
245
246 if test -n "$tailored_hooks$sample_hooks"; then
247 echo "Installing git hooks..."
248
249 case `cp --help 2>/dev/null` in
250 *--backup*--verbose*)
251 cp_options='--backup=numbered --verbose';;
252 *)
253 cp_options='-f';;
254 esac
255
256 if test -n "$tailored_hooks"; then
257 for hook in $tailored_hooks; do
258 cp $cp_options build-aux/git-hooks/$hook .git/hooks || exit
259 chmod a-w .git/hooks/$hook || exit
260 done
261 fi
262
263 if test -n "$sample_hooks"; then
264 for hook in $sample_hooks; do
265 cp $cp_options .git/hooks/$hook.sample .git/hooks/$hook || exit
266 chmod a-w .git/hooks/$hook || exit
267 done
268 fi
269 fi
270 fi
271
272 echo "You can now run './configure'."
273
274 exit 0
275
276 ### autogen.sh ends here