Allow 'browse-url-emacs' to fetch URL in the selected window
[emacs.git] / autogen.sh
blob518e5dbe830c21865faeee67ced17cf53e57f5ca
1 #!/bin/sh
2 ### autogen.sh - tool to help build Emacs from a repository checkout
4 ## Copyright (C) 2011-2018 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 <https://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"
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.
46 get_version ()
48 vers=`($1 --version) 2> /dev/null` && expr "$vers" : '[^
49 ]* \([0-9][0-9.]*\).*'
52 ## $1 = version string, eg "2.59"
53 ## Echo the major version, eg "2".
54 major_version ()
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".
61 minor_version ()
63 echo $1 | sed -e 's/[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/'
66 ## $1 = program
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).
72 check_version ()
74 ## Respect, e.g., $AUTOCONF if it is set, like autoreconf does.
75 uprog0=`echo $1 | sed -e 's/-/_/g' -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
77 eval uprog=\$${uprog0}
79 if [ x"$uprog" = x ]; then
80 uprog=$1
81 else
82 printf '%s' "(using $uprog0=$uprog) "
85 ## /bin/sh should always define the "command" builtin, but for
86 ## some odd reason sometimes it does not on hydra.nixos.org.
87 ## /bin/sh = "BusyBox v1.27.2", "built-in shell (ash)". ?
88 if command -v command > /dev/null 2>&1; then
89 command -v $uprog > /dev/null || return 1
90 else
91 $uprog --version > /dev/null 2>&1 || return 1
93 have_version=`get_version $uprog` || return 4
95 have_maj=`major_version $have_version`
96 need_maj=`major_version $2`
98 [ x"$have_maj" != x ] && [ x"$need_maj" != x ] || return 3
100 [ $have_maj -gt $need_maj ] && return 0
101 [ $have_maj -lt $need_maj ] && return 2
103 have_min=`minor_version $have_version`
104 need_min=`minor_version $2`
106 [ x"$have_min" != x ] && [ x"$need_min" != x ] || return 3
108 [ $have_min -ge $need_min ] && return 0
109 return 2
112 do_check=true
113 do_autoconf=false
114 do_git=false
116 for arg; do
117 case $arg in
118 --help)
119 exec echo "$0: usage: $0 [--no-check] [target...]
120 Targets are: all autoconf git";;
121 --no-check)
122 do_check=false;;
123 all)
124 do_autoconf=true
125 test -r .git && do_git=true;;
126 autoconf)
127 do_autoconf=true;;
128 git)
129 do_git=true;;
131 echo >&2 "$0: $arg: unknown argument"; exit 1;;
132 esac
133 done
135 case $do_autoconf,$do_git in
136 false,false)
137 do_autoconf=true
138 test -r .git && do_git=true;;
139 esac
141 # Generate Autoconf-related files, if requested.
143 if $do_autoconf; then
145 if $do_check; then
147 echo 'Checking whether you have the necessary tools...
148 (Read INSTALL.REPO for more details on building Emacs)'
150 missing=
152 for prog in $progs; do
154 sprog=`echo "$prog" | sed 's/-/_/g'`
156 eval min=\$${sprog}_min
158 printf '%s' "Checking for $prog (need at least version $min) ... "
160 check_version $prog $min
162 retval=$?
164 case $retval in
165 0) stat="ok" ;;
166 1) stat="missing" ;;
167 2) stat="too old" ;;
168 4) stat="broken?" ;;
169 *) stat="unable to check" ;;
170 esac
172 echo $stat
174 if [ $retval -ne 0 ]; then
175 missing="$missing $prog"
176 eval ${sprog}_why=\""$stat"\"
179 done
182 if [ x"$missing" != x ]; then
184 echo '
185 Building Emacs from the repository requires the following specialized programs:'
187 for prog in $progs; do
188 sprog=`echo "$prog" | sed 's/-/_/g'`
190 eval min=\$${sprog}_min
192 echo "$prog (minimum version $min)"
193 done
196 echo '
197 Your system seems to be missing the following tool(s):'
199 for prog in $missing; do
200 sprog=`echo "$prog" | sed 's/-/_/g'`
202 eval why=\$${sprog}_why
204 echo "$prog ($why)"
205 done
207 echo '
208 If you think you have the required tools, please add them to your PATH
209 and re-run this script.
211 Otherwise, please try installing them.
212 On systems using rpm and yum, try: "yum install PACKAGE"
213 On systems using dpkg and apt, try: "apt-get install PACKAGE"
214 Then re-run this script.
216 If you do not have permission to do this, or if the version provided
217 by your system is too old, it is normally straightforward to build
218 these packages from source. You can find the sources at:
220 https://ftp.gnu.org/gnu/PACKAGE/
222 Download the package (make sure you get at least the minimum version
223 listed above), extract it using tar, then run configure, make,
224 make install. Add the installation directory to your PATH and re-run
225 this script.
227 If you know that the required versions are in your PATH, but this
228 script has made an error, then you can simply re-run this script with
229 the --no-check option.
231 Please report any problems with this script to bug-gnu-emacs@gnu.org .'
233 exit 1
236 echo 'Your system has the required tools.'
238 fi # do_check
240 # Build aclocal.m4 here so that autoreconf need not use aclocal.
241 # aclocal is part of Automake and might not be installed, and
242 # autoreconf skips aclocal if aclocal.m4 is already supplied.
243 ls m4/*.m4 | LC_ALL=C sort | sed 's,.*\.m4$,m4_include([&]),' \
244 > aclocal.m4.tmp || exit
245 if cmp -s aclocal.m4.tmp aclocal.m4; then
246 rm -f aclocal.m4.tmp
247 else
248 echo "Building aclocal.m4 ..."
249 mv aclocal.m4.tmp aclocal.m4
250 fi || exit
252 echo "Running 'autoreconf -fi -I m4' ..."
254 ## Let autoreconf figure out what, if anything, needs doing.
255 ## Use autoreconf's -f option in case autoreconf itself has changed.
256 autoreconf -fi -I m4 || exit
260 # True if the Git setup was OK before autogen.sh was run.
262 git_was_ok=true
264 if $do_git; then
265 case `cp --help 2>/dev/null` in
266 *--backup*--verbose*)
267 cp_options='--backup=numbered --verbose';;
269 cp_options='-f';;
270 esac
274 # Like 'git config NAME VALUE' but verbose on change and exiting on failure.
275 # Also, do not configure unless requested.
277 git_config ()
279 $do_git || return
281 name=$1
282 value=$2
284 ovalue=`git config --get "$name"` && test "$ovalue" = "$value" || {
285 if $git_was_ok; then
286 echo 'Configuring local git repository...'
287 case $cp_options in
288 --backup=*)
289 config=$git_common_dir/config
290 cp $cp_options --force -- "$config" "$config" || exit;;
291 esac
293 echo "git config $name '$value'"
294 git config "$name" "$value" || exit
295 git_was_ok=false
299 ## Configure Git, if requested.
301 # Get location of Git's common configuration directory. For older Git
302 # versions this is just '.git'. Newer Git versions support worktrees.
304 { test -r .git &&
305 git_common_dir=`git rev-parse --no-flags --git-common-dir 2>/dev/null` &&
306 test -n "$git_common_dir"
307 } || git_common_dir=.git
308 hooks=$git_common_dir/hooks
310 # Check hashes when transferring objects among repositories.
312 git_config transfer.fsckObjects true
315 # Configure 'git diff' hunk header format.
317 git_config diff.elisp.xfuncname \
318 '^\(def[^[:space:]]+[[:space:]]+([^()[:space:]]+)'
319 git_config 'diff.m4.xfuncname' '^((m4_)?define|A._DEFUN(_ONCE)?)\([^),]*'
320 git_config 'diff.make.xfuncname' \
321 '^([$.[:alnum:]_].*:|[[:alnum:]_]+[[:space:]]*([*:+]?[:?]?|!?)=|define .*)'
322 git_config 'diff.shell.xfuncname' \
323 '^([[:space:]]*[[:alpha:]_][[:alnum:]_]*[[:space:]]*\(\)|[[:alpha:]_][[:alnum:]_]*=)'
324 git_config diff.texinfo.xfuncname \
325 '^@node[[:space:]]+([^,[:space:]][^,]+)'
328 # Install Git hooks.
330 tailored_hooks=
331 sample_hooks=
333 for hook in commit-msg pre-commit; do
334 cmp -- build-aux/git-hooks/$hook "$hooks/$hook" >/dev/null 2>&1 ||
335 tailored_hooks="$tailored_hooks $hook"
336 done
338 git_sample_hook_src ()
340 hook=$1
341 src=$hooks/$hook.sample
342 if test ! -r "$src"; then
343 case $hook in
344 applypatch-msg) src=build-aux/git-hooks/commit-msg;;
345 pre-applypatch) src=build-aux/git-hooks/pre-commit;;
346 esac
349 for hook in applypatch-msg pre-applypatch; do
350 git_sample_hook_src $hook
351 cmp -- "$src" "$hooks/$hook" >/dev/null 2>&1 ||
352 sample_hooks="$sample_hooks $hook"
353 done
355 if test -n "$tailored_hooks$sample_hooks"; then
356 if $do_git; then
357 echo "Installing git hooks..."
359 if test ! -d "$hooks"; then
360 printf "mkdir -p -- '%s'\\n" "$hooks"
361 mkdir -p -- "$hooks" || exit
364 if test -n "$tailored_hooks"; then
365 for hook in $tailored_hooks; do
366 dst=$hooks/$hook
367 cp $cp_options -- build-aux/git-hooks/$hook "$dst" || exit
368 chmod -- a-w "$dst" || exit
369 done
372 if test -n "$sample_hooks"; then
373 for hook in $sample_hooks; do
374 git_sample_hook_src $hook
375 dst=$hooks/$hook
376 cp $cp_options -- "$src" "$dst" || exit
377 chmod -- a-w "$dst" || exit
378 done
380 else
381 git_was_ok=false
385 if test ! -f configure; then
386 echo "You can now run '$0 autoconf'."
387 elif test -r .git && test $git_was_ok = false && test $do_git = false; then
388 echo "You can now run '$0 git'."
389 elif test ! -f config.status ||
390 test -n "`find configure src/config.in -newer config.status`"; then
391 echo "You can now run './configure'."
394 exit 0
396 ### autogen.sh ends here