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