Fix computation of regex stack limit
[emacs.git] / autogen.sh
blob2021c771fc85f9ac4965b2c2ca37fafa9df96532
1 #!/bin/sh
2 ### autogen.sh - tool to help build Emacs from a repository checkout
4 ## Copyright (C) 2011-2017 Free Software Foundation, Inc.
6 ## Author: Glenn Morris <rgm@gnu.org>
7 ## Maintainer: emacs-devel@gnu.org
9 ## This file is part of GNU Emacs.
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.
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.
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/>.
24 ### Commentary:
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.
31 ### Code:
33 ## Tools we need:
34 ## Note that we respect the values of AUTOCONF etc, like autoreconf does.
35 progs="autoconf automake"
37 ## Minimum versions we need:
38 autoconf_min=`sed -n 's/^ *AC_PREREQ(\([0-9\.]*\)).*/\1/p' configure.ac`
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`
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 ()
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'
56 ## $1 = version string, eg "2.59"
57 ## Echo the major version, eg "2".
58 major_version ()
60 echo $1 | sed -e 's/\([0-9][0-9]*\)\..*/\1/'
63 ## $1 = version string, eg "2.59"
64 ## Echo the minor version, eg "59".
65 minor_version ()
67 echo $1 | sed -e 's/[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/'
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 ()
78 ## Respect eg $AUTOMAKE if it is set, like autoreconf does.
79 uprog=`echo $1 | sed -e 's/-/_/g' -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
81 eval uprog=\$${uprog}
83 [ x"$uprog" = x ] && uprog=$1
85 have_version=`get_version $uprog`
87 [ x"$have_version" = x ] && return 1
89 have_maj=`major_version $have_version`
90 need_maj=`major_version $2`
92 [ x"$have_maj" != x ] && [ x"$need_maj" != x ] || return 3
94 [ $have_maj -gt $need_maj ] && return 0
95 [ $have_maj -lt $need_maj ] && return 2
97 have_min=`minor_version $have_version`
98 need_min=`minor_version $2`
100 [ x"$have_min" != x ] && [ x"$need_min" != x ] || return 3
102 [ $have_min -ge $need_min ] && return 0
103 return 2
106 do_autoconf=false
107 test $# -eq 0 && do_autoconf=true
108 do_git=false
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
116 test -e .git && do_git=true;;
117 autoconf)
118 do_autoconf=true;;
119 git)
120 do_git=true;;
122 echo >&2 "$0: $arg: unknown argument"; exit 1;;
123 esac
124 done
127 # Generate Autoconf and Automake related files, if requested.
129 if $do_autoconf; then
131 echo 'Checking whether you have the necessary tools...
132 (Read INSTALL.REPO for more details on building Emacs)'
134 missing=
136 for prog in $progs; do
138 sprog=`echo "$prog" | sed 's/-/_/g'`
140 eval min=\$${sprog}_min
142 echo "Checking for $prog (need at least version $min)..."
144 check_version $prog $min
146 retval=$?
148 case $retval in
149 0) stat="ok" ;;
150 1) stat="missing" ;;
151 2) stat="too old" ;;
152 *) stat="unable to check" ;;
153 esac
155 echo $stat
157 if [ $retval -ne 0 ]; then
158 missing="$missing $prog"
159 eval ${sprog}_why=\""$stat"\"
162 done
165 if [ x"$missing" != x ]; then
167 echo '
168 Building Emacs from the repository requires the following specialized programs:'
170 for prog in $progs; do
171 sprog=`echo "$prog" | sed 's/-/_/g'`
173 eval min=\$${sprog}_min
175 echo "$prog (minimum version $min)"
176 done
179 echo '
180 Your system seems to be missing the following tool(s):'
182 for prog in $missing; do
183 sprog=`echo "$prog" | sed 's/-/_/g'`
185 eval why=\$${sprog}_why
187 echo "$prog ($why)"
188 done
190 echo '
191 If you think you have the required tools, please add them to your PATH
192 and re-run this script.
194 Otherwise, please try installing them.
195 On systems using rpm and yum, try: "yum install PACKAGE"
196 On systems using dpkg and apt, try: "apt-get install PACKAGE"
197 Then re-run this script.
199 If you do not have permission to do this, or if the version provided
200 by your system is too old, it is normally straightforward to build
201 these packages from source. You can find the sources at:
203 ftp://ftp.gnu.org/gnu/PACKAGE/
205 Download the package (make sure you get at least the minimum version
206 listed above), extract it using tar, then run configure, make,
207 make install. Add the installation directory to your PATH and re-run
208 this script.
210 If you know that the required versions are in your PATH, but this
211 script has made an error, then you can simply run
213 autoreconf -fi -I m4
215 instead of this script.
217 Please report any problems with this script to bug-gnu-emacs@gnu.org .'
219 exit 1
222 echo 'Your system has the required tools.'
224 ## Create nt/gnulib.mk if it doesn't exist, as autoreconf will need it.
225 if test ! -f nt/gnulib.mk; then
226 echo 'Inferring nt/gnulib.mk from lib/gnulib.mk ...'
227 metascript='/^[^#]/s|^.*$|/^## begin *gnulib module &/,/^## end *gnulib module &/d|p'
228 script=`sed -n "$metascript" nt/gnulib-modules-to-delete.cfg` || exit
229 sed "$script" lib/gnulib.mk > nt/gnulib.mk || exit
232 echo "Running 'autoreconf -fi -I m4' ..."
234 ## Let autoreconf figure out what, if anything, needs doing.
235 ## Use autoreconf's -f option in case autoreconf itself has changed.
236 autoreconf -fi -I m4 || exit $?
238 ## Create a timestamp, so that './autogen.sh; make' doesn't
239 ## cause 'make' to needlessly run 'autoheader'.
240 echo timestamp > src/stamp-h.in || exit
244 # True if the Git setup was OK before autogen.sh was run.
246 git_was_ok=true
248 if $do_git; then
249 case `cp --help 2>/dev/null` in
250 *--backup*--verbose*)
251 cp_options='--backup=numbered --verbose';;
253 cp_options='-f';;
254 esac
258 # Like 'git config NAME VALUE' but verbose on change and exiting on failure.
259 # Also, do not configure unless requested.
261 git_config ()
263 name=$1
264 value=$2
266 ovalue=`git config --get "$name"` && test "$ovalue" = "$value" || {
267 if $do_git; then
268 if $git_was_ok; then
269 echo 'Configuring local git repository...'
270 case $cp_options in
271 --backup=*)
272 config=$git_common_dir/config
273 cp $cp_options --force -- "$config" "$config" || exit;;
274 esac
276 echo "git config $name '$value'"
277 git config "$name" "$value" || exit
279 git_was_ok=false
283 ## Configure Git, if requested.
285 # Get location of Git's common configuration directory. For older Git
286 # versions this is just '.git'. Newer Git versions support worktrees.
288 { test -e .git &&
289 git_common_dir=`git rev-parse --no-flags --git-common-dir 2>/dev/null` &&
290 test -n "$git_common_dir"
291 } || git_common_dir=.git
292 hooks=$git_common_dir/hooks
294 # Check hashes when transferring objects among repositories.
296 git_config transfer.fsckObjects true
299 # Configure 'git diff' hunk header format.
301 git_config diff.elisp.xfuncname \
302 '^\(def[^[:space:]]+[[:space:]]+([^()[:space:]]+)'
303 git_config 'diff.m4.xfuncname' '^((m4_)?define|A._DEFUN(_ONCE)?)\([^),]*'
304 git_config 'diff.make.xfuncname' \
305 '^([$.[:alnum:]_].*:|[[:alnum:]_]+[[:space:]]*([*:+]?[:?]?|!?)=|define .*)'
306 git_config 'diff.shell.xfuncname' \
307 '^([[:space:]]*[[:alpha:]_][[:alnum:]_]*[[:space:]]*\(\)|[[:alpha:]_][[:alnum:]_]*=)'
308 git_config diff.texinfo.xfuncname \
309 '^@node[[:space:]]+([^,[:space:]][^,]+)'
312 # Install Git hooks.
314 tailored_hooks=
315 sample_hooks=
317 for hook in commit-msg pre-commit; do
318 cmp -- build-aux/git-hooks/$hook "$hooks/$hook" >/dev/null 2>&1 ||
319 tailored_hooks="$tailored_hooks $hook"
320 done
321 for hook in applypatch-msg pre-applypatch; do
322 cmp -- "$hooks/$hook.sample" "$hooks/$hook" >/dev/null 2>&1 ||
323 sample_hooks="$sample_hooks $hook"
324 done
326 if test -n "$tailored_hooks$sample_hooks"; then
327 if $do_git; then
328 echo "Installing git hooks..."
330 if test -n "$tailored_hooks"; then
331 for hook in $tailored_hooks; do
332 dst=$hooks/$hook
333 cp $cp_options -- build-aux/git-hooks/$hook "$dst" || exit
334 chmod -- a-w "$dst" || exit
335 done
338 if test -n "$sample_hooks"; then
339 for hook in $sample_hooks; do
340 dst=$hooks/$hook
341 cp $cp_options -- "$dst.sample" "$dst" || exit
342 chmod -- a-w "$dst" || exit
343 done
345 else
346 git_was_ok=false
350 if test ! -f configure; then
351 echo "You can now run '$0 autoconf'."
352 elif test -e .git && test $git_was_ok = false && test $do_git = false; then
353 echo "You can now run '$0 git'."
354 elif test ! -f config.status ||
355 test -n "`find src/stamp-h.in -newer config.status`"; then
356 echo "You can now run './configure'."
359 exit 0
361 ### autogen.sh ends here