]> code.delx.au - gnu-emacs/blob - autogen.sh
Merge from origin/emacs-25
[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 do_autoconf=false
107 test $# -eq 0 && do_autoconf=true
108 do_git=false
109
110 for arg; do
111 case $arg in
112 --help)
113 exec echo "$0: usage: $0 [all|autoconf|git]";;
114 all)
115 do_autoconf=true do_git=true;;
116 autoconf)
117 do_autoconf=true;;
118 git)
119 do_git=true;;
120 *)
121 echo >&2 "$0: $arg: unknown argument"; exit 1;;
122 esac
123 done
124
125
126 # Generate Autoconf and Automake related files, if requested.
127
128 if $do_autoconf; then
129
130 echo 'Checking whether you have the necessary tools...
131 (Read INSTALL.REPO for more details on building Emacs)'
132
133 missing=
134
135 for prog in $progs; do
136
137 sprog=`echo "$prog" | sed 's/-/_/g'`
138
139 eval min=\$${sprog}_min
140
141 echo "Checking for $prog (need at least version $min)..."
142
143 check_version $prog $min
144
145 retval=$?
146
147 case $retval in
148 0) stat="ok" ;;
149 1) stat="missing" ;;
150 2) stat="too old" ;;
151 *) stat="unable to check" ;;
152 esac
153
154 echo $stat
155
156 if [ $retval -ne 0 ]; then
157 missing="$missing $prog"
158 eval ${sprog}_why=\""$stat"\"
159 fi
160
161 done
162
163
164 if [ x"$missing" != x ]; then
165
166 echo '
167 Building Emacs from the repository requires the following specialized programs:'
168
169 for prog in $progs; do
170 sprog=`echo "$prog" | sed 's/-/_/g'`
171
172 eval min=\$${sprog}_min
173
174 echo "$prog (minimum version $min)"
175 done
176
177
178 echo '
179 Your system seems to be missing the following tool(s):'
180
181 for prog in $missing; do
182 sprog=`echo "$prog" | sed 's/-/_/g'`
183
184 eval why=\$${sprog}_why
185
186 echo "$prog ($why)"
187 done
188
189 echo '
190 If you think you have the required tools, please add them to your PATH
191 and re-run this script.
192
193 Otherwise, please try installing them.
194 On systems using rpm and yum, try: "yum install PACKAGE"
195 On systems using dpkg and apt, try: "apt-get install PACKAGE"
196 Then re-run this script.
197
198 If you do not have permission to do this, or if the version provided
199 by your system is too old, it is normally straightforward to build
200 these packages from source. You can find the sources at:
201
202 ftp://ftp.gnu.org/gnu/PACKAGE/
203
204 Download the package (make sure you get at least the minimum version
205 listed above), extract it using tar, then run configure, make,
206 make install. Add the installation directory to your PATH and re-run
207 this script.
208
209 If you know that the required versions are in your PATH, but this
210 script has made an error, then you can simply run
211
212 autoreconf -fi -I m4
213
214 instead of this script.
215
216 Please report any problems with this script to bug-gnu-emacs@gnu.org .'
217
218 exit 1
219 fi
220
221 echo 'Your system has the required tools.'
222 echo "Running 'autoreconf -fi -I m4' ..."
223
224
225 ## Let autoreconf figure out what, if anything, needs doing.
226 ## Use autoreconf's -f option in case autoreconf itself has changed.
227 autoreconf -fi -I m4 || exit $?
228
229 ## Create a timestamp, so that './autogen.sh; make' doesn't
230 ## cause 'make' to needlessly run 'autoheader'.
231 echo timestamp > src/stamp-h.in || exit
232 fi
233
234
235 # True if the Git setup was OK before autogen.sh was run.
236
237 git_was_ok=true
238
239 if $do_git; then
240 case `cp --help 2>/dev/null` in
241 *--backup*--verbose*)
242 cp_options='--backup=numbered --verbose';;
243 *)
244 cp_options='-f';;
245 esac
246 fi
247
248
249 # Like 'git config NAME VALUE' but verbose on change and exiting on failure.
250 # Also, do not configure unless requested.
251
252 git_config ()
253 {
254 name=$1
255 value=$2
256
257 ovalue=`git config --get "$name"` && test "$ovalue" = "$value" || {
258 if $do_git; then
259 if $git_was_ok; then
260 echo 'Configuring local git repository...'
261 case $cp_options in
262 --backup=*)
263 cp $cp_options --force .git/config .git/config || exit;;
264 esac
265 fi
266 echo "git config $name '$value'"
267 git config "$name" "$value" || exit
268 fi
269 git_was_ok=false
270 }
271 }
272
273 ## Configure Git, if requested.
274
275 # Check hashes when transferring objects among repositories.
276
277 git_config transfer.fsckObjects true
278
279
280 # Configure 'git diff' hunk header format.
281
282 git_config diff.elisp.xfuncname \
283 '^\(def[^[:space:]]+[[:space:]]+([^()[:space:]]+)'
284 git_config 'diff.m4.xfuncname' '^((m4_)?define|A._DEFUN(_ONCE)?)\([^),]*'
285 git_config 'diff.make.xfuncname' \
286 '^([$.[:alnum:]_].*:|[[:alnum:]_]+[[:space:]]*([*:+]?[:?]?|!?)=|define .*)'
287 git_config 'diff.shell.xfuncname' \
288 '^([[:space:]]*[[:alpha:]_][[:alnum:]_]*[[:space:]]*\(\)|[[:alpha:]_][[:alnum:]_]*=)'
289 git_config diff.texinfo.xfuncname \
290 '^@node[[:space:]]+([^,[:space:]][^,]+)'
291
292
293 # Install Git hooks.
294
295 tailored_hooks=
296 sample_hooks=
297
298 for hook in commit-msg pre-commit; do
299 cmp build-aux/git-hooks/$hook .git/hooks/$hook >/dev/null 2>&1 ||
300 tailored_hooks="$tailored_hooks $hook"
301 done
302 for hook in applypatch-msg pre-applypatch; do
303 src=.git/hooks/$hook.sample
304 cmp "$src" .git/hooks/$hook >/dev/null 2>&1 ||
305 sample_hooks="$sample_hooks $hook"
306 done
307
308 if test -n "$tailored_hooks$sample_hooks"; then
309 if $do_git; then
310 echo "Installing git hooks..."
311
312 if test -n "$tailored_hooks"; then
313 for hook in $tailored_hooks; do
314 dst=.git/hooks/$hook
315 cp $cp_options build-aux/git-hooks/$hook "$dst" || exit
316 chmod a-w "$dst" || exit
317 done
318 fi
319
320 if test -n "$sample_hooks"; then
321 for hook in $sample_hooks; do
322 cp $cp_options .git/hooks/$hook.sample .git/hooks/$hook || exit
323 chmod a-w .git/hooks/$hook || exit
324 done
325 fi
326 else
327 git_was_ok=false
328 fi
329 fi
330
331 if test ! -f configure; then
332 echo "You can now run '$0 autoconf'."
333 elif test -d .git && test $git_was_ok = false && test $do_git = false; then
334 echo "You can now run '$0 git'."
335 elif test ! -f config.status ||
336 test -n "`find src/stamp-h.in -newer config.status`"; then
337 echo "You can now run './configure'."
338 fi
339
340 exit 0
341
342 ### autogen.sh ends here