* make-dist: Add modules/.
[emacs.git] / autogen.sh
blob4a0fbb791e965bf96e15a9f451be9b09bbc9458e
1 #!/bin/sh
2 ### autogen.sh - tool to help build Emacs from a repository checkout
4 ## Copyright (C) 2011-2016 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
107 git_config=true
109 for arg
111 case $arg in
112 --git-config=false) git_config=false;;
113 --git-config=true) git_config=true ;;
114 --help)
115 exec echo "$0: usage: $0 [--help|--git-config=[false|true]]";;
117 echo >&2 "$0: $arg: unknown option"; exit 1;;
118 esac
119 done
122 cat <<EOF
123 Checking whether you have the necessary tools...
124 (Read INSTALL.REPO for more details on building Emacs)
128 missing=
130 for prog in $progs; do
132 sprog=`echo "$prog" | sed 's/-/_/g'`
134 eval min=\$${sprog}_min
136 echo "Checking for $prog (need at least version $min)..."
138 check_version $prog $min
140 retval=$?
142 case $retval in
143 0) stat="ok" ;;
144 1) stat="missing" ;;
145 2) stat="too old" ;;
146 *) stat="unable to check" ;;
147 esac
149 echo $stat
151 if [ $retval -ne 0 ]; then
152 missing="$missing $prog"
153 eval ${sprog}_why=\""$stat"\"
156 done
159 if [ x"$missing" != x ]; then
161 cat <<EOF
163 Building Emacs from the repository requires the following specialized programs:
166 for prog in $progs; do
167 sprog=`echo "$prog" | sed 's/-/_/g'`
169 eval min=\$${sprog}_min
171 echo "$prog (minimum version $min)"
172 done
175 cat <<EOF
177 Your system seems to be missing the following tool(s):
180 for prog in $missing; do
181 sprog=`echo "$prog" | sed 's/-/_/g'`
183 eval why=\$${sprog}_why
185 echo "$prog ($why)"
186 done
188 cat <<EOF
190 If you think you have the required tools, please add them to your PATH
191 and re-run this script.
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.
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:
202 ftp://ftp.gnu.org/gnu/PACKAGE/
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.
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
212 autoreconf -fi -I m4
214 instead of this script.
216 Please report any problems with this script to bug-gnu-emacs@gnu.org .
219 exit 1
222 echo 'Your system has the required tools.'
223 echo "Running 'autoreconf -fi -I m4' ..."
226 ## Let autoreconf figure out what, if anything, needs doing.
227 ## Use autoreconf's -f option in case autoreconf itself has changed.
228 autoreconf -fi -I m4 || exit $?
230 ## Create a timestamp, so that './autogen.sh; make' doesn't
231 ## cause 'make' to needlessly run 'autoheader'.
232 echo timestamp > src/stamp-h.in || exit
235 ## Configure Git, if using Git.
236 if test -d .git && (git status -s) >/dev/null 2>&1; then
238 # Like 'git config NAME VALUE', but conditional on --git-config,
239 # verbose on change, and exiting on failure.
241 git_config ()
243 name=$1
244 value=$2
246 if $git_config; then
247 ovalue=`git config --get "$name"` && test "$ovalue" = "$value" || {
248 echo "${Configuring_git}git config $name '$value'"
249 Configuring_git=
250 git config "$name" "$value" || exit
254 Configuring_git='Configuring git...
257 # Check hashes when transferring objects among repositories.
259 git_config transfer.fsckObjects true
262 # Configure 'git diff' hunk header format.
264 git_config 'diff.elisp.xfuncname' \
265 '^\(def[^[:space:]]+[[:space:]]+([^()[:space:]]+)'
266 git_config 'diff.texinfo.xfuncname' \
267 '^@node[[:space:]]+([^,[:space:]][^,]+)'
270 # Install Git hooks.
272 tailored_hooks=
273 sample_hooks=
275 for hook in commit-msg pre-commit; do
276 cmp build-aux/git-hooks/$hook .git/hooks/$hook >/dev/null 2>&1 ||
277 tailored_hooks="$tailored_hooks $hook"
278 done
279 for hook in applypatch-msg pre-applypatch; do
280 test ! -r .git/hooks/$hook.sample ||
281 cmp .git/hooks/$hook.sample .git/hooks/$hook >/dev/null 2>&1 ||
282 sample_hooks="$sample_hooks $hook"
283 done
285 if test -n "$tailored_hooks$sample_hooks"; then
286 echo "Installing git hooks..."
288 case `cp --help 2>/dev/null` in
289 *--backup*--verbose*)
290 cp_options='--backup=numbered --verbose';;
292 cp_options='-f';;
293 esac
295 if test -n "$tailored_hooks"; then
296 for hook in $tailored_hooks; do
297 cp $cp_options build-aux/git-hooks/$hook .git/hooks || exit
298 chmod a-w .git/hooks/$hook || exit
299 done
302 if test -n "$sample_hooks"; then
303 for hook in $sample_hooks; do
304 cp $cp_options .git/hooks/$hook.sample .git/hooks/$hook || exit
305 chmod a-w .git/hooks/$hook || exit
306 done
311 echo "You can now run './configure'."
313 exit 0
315 ### autogen.sh ends here