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/>.
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.
34 ## Note that we respect the values of AUTOCONF etc, like autoreconf does.
37 ## Minimum versions we need:
38 autoconf_min
=`sed -n 's/^ *AC_PREREQ(\([0-9\.]*\)).*/\1/p' configure.ac`
41 ## $1 = program, eg "autoconf".
42 ## Echo the version string, eg "2.59".
43 ## FIXME does not handle things like "1.4a", but AFAIK those are
44 ## all old versions, so it is OK to fail there.
45 ## Also note that we do not handle micro versions.
48 ## Remove eg "./autogen.sh: line 50: autoconf: command not found".
49 $1 --version 2>&1 |
sed -e '/not found/d' -e 's/.* //' -n -e '1 s/\([0-9][0-9\.]*\).*/\1/p'
52 ## $1 = version string, eg "2.59"
53 ## Echo the major version, eg "2".
56 echo $1 |
sed -e 's/\([0-9][0-9]*\)\..*/\1/'
59 ## $1 = version string, eg "2.59"
60 ## Echo the minor version, eg "59".
63 echo $1 |
sed -e 's/[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/'
67 ## $2 = minimum version.
68 ## Return 0 if program is present with version >= minimum version.
69 ## Return 1 if program is missing.
70 ## Return 2 if program is present but too old.
71 ## Return 3 for unexpected error (eg failed to parse version).
74 ## Respect, e.g., $AUTOCONF if it is set, like autoreconf does.
75 uprog
=`echo $1 | sed -e 's/-/_/g' -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
79 [ x
"$uprog" = x
] && uprog
=$1
81 have_version
=`get_version $uprog`
83 [ x
"$have_version" = x
] && return 1
85 have_maj
=`major_version $have_version`
86 need_maj
=`major_version $2`
88 [ x
"$have_maj" != x
] && [ x
"$need_maj" != x
] ||
return 3
90 [ $have_maj -gt $need_maj ] && return 0
91 [ $have_maj -lt $need_maj ] && return 2
93 have_min
=`minor_version $have_version`
94 need_min
=`minor_version $2`
96 [ x
"$have_min" != x
] && [ x
"$need_min" != x
] ||
return 3
98 [ $have_min -ge $need_min ] && return 0
109 exec echo "$0: usage: $0 [--no-check] [target...]
110 Targets are: all autoconf git";;
115 test -e .git
&& do_git
=true
;;
121 echo >&2 "$0: $arg: unknown argument"; exit 1;;
125 case $do_autoconf,$do_git in
130 # Generate Autoconf-related files, if requested.
132 if $do_autoconf; then
136 echo 'Checking whether you have the necessary tools...
137 (Read INSTALL.REPO for more details on building Emacs)'
141 for prog
in $progs; do
143 sprog
=`echo "$prog" | sed 's/-/_/g'`
145 eval min
=\$
${sprog}_min
147 printf '%s' "Checking for $prog (need at least version $min) ... "
149 check_version
$prog $min
157 *) stat
="unable to check" ;;
162 if [ $retval -ne 0 ]; then
163 missing
="$missing $prog"
164 eval ${sprog}_why
=\""$stat"\"
170 if [ x
"$missing" != x
]; then
173 Building Emacs from the repository requires the following specialized programs:'
175 for prog
in $progs; do
176 sprog
=`echo "$prog" | sed 's/-/_/g'`
178 eval min
=\$
${sprog}_min
180 echo "$prog (minimum version $min)"
185 Your system seems to be missing the following tool(s):'
187 for prog
in $missing; do
188 sprog
=`echo "$prog" | sed 's/-/_/g'`
190 eval why
=\$
${sprog}_why
196 If you think you have the required tools, please add them to your PATH
197 and re-run this script.
199 Otherwise, please try installing them.
200 On systems using rpm and yum, try: "yum install PACKAGE"
201 On systems using dpkg and apt, try: "apt-get install PACKAGE"
202 Then re-run this script.
204 If you do not have permission to do this, or if the version provided
205 by your system is too old, it is normally straightforward to build
206 these packages from source. You can find the sources at:
208 ftp://ftp.gnu.org/gnu/PACKAGE/
210 Download the package (make sure you get at least the minimum version
211 listed above), extract it using tar, then run configure, make,
212 make install. Add the installation directory to your PATH and re-run
215 If you know that the required versions are in your PATH, but this
216 script has made an error, then you can simply re-run this script with
217 the --no-check option.
219 Please report any problems with this script to bug-gnu-emacs@gnu.org .'
224 echo 'Your system has the required tools.'
228 # Build aclocal.m4 here so that autoreconf need not use aclocal.
229 # aclocal is part of Automake and might not be installed, and
230 # autoreconf skips aclocal if aclocal.m4 is already supplied.
231 ls m
4/*.
m4 | LC_ALL
=C
sort |
sed 's,.*\.m4$,m4_include([&]),' \
232 > aclocal.
m4.tmp ||
exit
233 if cmp -s aclocal.
m4.tmp aclocal.
m4; then
236 echo "Building aclocal.m4 ..."
237 mv aclocal.
m4.tmp aclocal.
m4
240 echo "Running 'autoreconf -fi -I m4' ..."
242 ## Let autoreconf figure out what, if anything, needs doing.
243 ## Use autoreconf's -f option in case autoreconf itself has changed.
244 autoreconf
-fi -I m4 ||
exit
246 ## Create a timestamp, so that './autogen.sh; make' doesn't
247 ## cause 'make' to needlessly run 'autoheader'.
248 echo timestamp
> src
/stamp-h.
in ||
exit
252 # True if the Git setup was OK before autogen.sh was run.
257 case `cp --help 2>/dev/null` in
258 *--backup*--verbose*)
259 cp_options
='--backup=numbered --verbose';;
266 # Like 'git config NAME VALUE' but verbose on change and exiting on failure.
267 # Also, do not configure unless requested.
274 ovalue
=`git config --get "$name"` && test "$ovalue" = "$value" ||
{
277 echo 'Configuring local git repository...'
280 config
=$git_common_dir/config
281 cp $cp_options --force -- "$config" "$config" ||
exit;;
284 echo "git config $name '$value'"
285 git config
"$name" "$value" ||
exit
291 ## Configure Git, if requested.
293 # Get location of Git's common configuration directory. For older Git
294 # versions this is just '.git'. Newer Git versions support worktrees.
297 git_common_dir
=`git rev-parse --no-flags --git-common-dir 2>/dev/null` &&
298 test -n "$git_common_dir"
299 } || git_common_dir
=.git
300 hooks
=$git_common_dir/hooks
302 # Check hashes when transferring objects among repositories.
304 git_config transfer.fsckObjects true
307 # Configure 'git diff' hunk header format.
309 git_config
diff.elisp.xfuncname \
310 '^\(def[^[:space:]]+[[:space:]]+([^()[:space:]]+)'
311 git_config
'diff.m4.xfuncname' '^((m4_)?define|A._DEFUN(_ONCE)?)\([^),]*'
312 git_config
'diff.make.xfuncname' \
313 '^([$.[:alnum:]_].*:|[[:alnum:]_]+[[:space:]]*([*:+]?[:?]?|!?)=|define .*)'
314 git_config
'diff.shell.xfuncname' \
315 '^([[:space:]]*[[:alpha:]_][[:alnum:]_]*[[:space:]]*\(\)|[[:alpha:]_][[:alnum:]_]*=)'
316 git_config
diff.texinfo.xfuncname \
317 '^@node[[:space:]]+([^,[:space:]][^,]+)'
325 for hook
in commit-msg pre-commit
; do
326 cmp -- build-aux
/git-hooks
/$hook "$hooks/$hook" >/dev
/null
2>&1 ||
327 tailored_hooks
="$tailored_hooks $hook"
329 for hook
in applypatch-msg pre-applypatch
; do
330 cmp -- "$hooks/$hook.sample" "$hooks/$hook" >/dev
/null
2>&1 ||
331 sample_hooks
="$sample_hooks $hook"
334 if test -n "$tailored_hooks$sample_hooks"; then
336 echo "Installing git hooks..."
338 if test -n "$tailored_hooks"; then
339 for hook
in $tailored_hooks; do
341 cp $cp_options -- build-aux
/git-hooks
/$hook "$dst" ||
exit
342 chmod -- a-w
"$dst" ||
exit
346 if test -n "$sample_hooks"; then
347 for hook
in $sample_hooks; do
349 cp $cp_options -- "$dst.sample" "$dst" ||
exit
350 chmod -- a-w
"$dst" ||
exit
358 if test ! -f configure
; then
359 echo "You can now run '$0 autoconf'."
360 elif test -e .git
&& test $git_was_ok = false
&& test $do_git = false
; then
361 echo "You can now run '$0 git'."
362 elif test ! -f config.status ||
363 test -n "`find src/stamp-h.in -newer config.status`"; then
364 echo "You can now run './configure'."
369 ### autogen.sh ends here