* admin/update_autogen (commit): With git, call "add" before "commit".
[emacs.git] / admin / update_autogen
blob84e0584f220d71381e09bb83e15a53b42495e3ad
1 #!/bin/bash
2 ### update_autogen - update some auto-generated files in the Emacs tree
4 ## Copyright (C) 2011-2014 Free Software Foundation, Inc.
6 ## Author: Glenn Morris <rgm@gnu.org>
8 ## This file is part of GNU Emacs.
10 ## GNU Emacs is free software: you can redistribute it and/or modify
11 ## it under the terms of the GNU General Public License as published by
12 ## the Free Software Foundation, either version 3 of the License, or
13 ## (at your option) any later version.
15 ## GNU Emacs is distributed in the hope that it will be useful,
16 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ## GNU General Public License for more details.
20 ## You should have received a copy of the GNU General Public License
21 ## along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ### Commentary:
25 ## This is a helper script to update some generated files in the Emacs
26 ## repository. This is suitable for running from cron.
27 ## Only Emacs maintainers need use this, so it uses bash features.
29 ## By default, it updates the versioned loaddefs-like files in lisp,
30 ## except ldefs-boot.el.
32 ### Code:
34 die () # write error to stderr and exit
36 [ $# -gt 0 ] && echo "$PN: $@" >&2
37 exit 1
40 PN=${0##*/} # basename of script
41 PD=${0%/*}
43 [ "$PD" = "$0" ] && PD=. # if PATH includes PWD
45 ## This should be the admin directory.
46 cd $PD
47 cd ../
48 [ -d admin ] || die "Could not locate admin directory"
50 if [ -d .bzr ]; then
51 vcs=bzr
52 elif [ -d .git ]; then
53 vcs=git
54 else
55 die "Cannot determine vcs"
59 usage ()
61 cat 1>&2 <<EOF
62 Usage: ${PN} [-f] [-c] [-q] [-A dir] [-I] [-L] [-C] [-- make-flags]
63 Update some auto-generated files in the Emacs tree.
64 By default, only does the versioned loaddefs-like files in lisp/.
65 This requires a build. Passes any non-option args to make (eg -- -j2).
66 Options:
67 -f: force an update even if the source files are locally modified.
68 -c: if the update succeeds and the generated files are modified,
69 commit them (caution).
70 -q: be quiet; only give error messages, not status messages.
71 -A: only update autotools files, copying into specified dir.
72 -I: also update info/dir.
73 -L: also update ldefs-boot.el.
74 -C: start from a clean state. Slower, but more correct.
75 EOF
76 exit 1
80 ## Defaults.
82 force=
83 commit=
84 quiet=
85 clean=
86 autogendir= # was "autogen"
87 ldefs_flag=1
88 lboot_flag=
89 info_flag=
91 ## Parameters.
92 ldefs_in=lisp/loaddefs.el
93 ldefs_out=lisp/ldefs-boot.el
94 sources="configure.ac lib/Makefile.am"
95 ## Files to copy into autogendir.
96 ## Everything:
97 genfiles="
98 configure aclocal.m4 src/config.in lib/Makefile.in
99 build-aux/compile build-aux/config.guess build-aux/config.sub
100 build-aux/depcomp build-aux/install-sh build-aux/missing
102 ## msdos-only:
103 genfiles="src/config.in lib/Makefile.in"
105 for g in $genfiles; do
106 basegen="$basegen ${g##*/}"
107 done
109 [ "$basegen" ] || die "internal error"
111 tempfile=/tmp/$PN.$$
113 trap "rm -f $tempfile 2> /dev/null" EXIT
116 while getopts ":hcfqA:CIL" option ; do
117 case $option in
118 (h) usage ;;
120 (c) commit=1 ;;
122 (f) force=1 ;;
124 (q) quiet=1 ;;
126 (A) autogendir=$OPTARG
127 [ -d "$autogendir" ] || die "No autogen directory: $autogendir"
130 (C) clean=1 ;;
132 (I) info_flag=1 ;;
134 (L) lboot_flag=1 ;;
136 (\?) die "Bad option -$OPTARG" ;;
138 (:) die "Option -$OPTARG requires an argument" ;;
140 (*) die "getopts error" ;;
141 esac
142 done
143 shift $(( --OPTIND ))
144 OPTIND=1
147 ## Does not work 100% because a lot of Emacs batch output comes on stderr (?).
148 [ "$quiet" ] && exec 1> /dev/null
151 ## Run status on inputs, list modified files on stdout.
152 status ()
154 local statflag="-S"
155 [ "$vcs" = "git" ] && statflag="-s"
157 $vcs status $statflag "$@" >| $tempfile || die "$vcs status error for $@"
159 local stat file modified
161 while read stat file; do
163 [ "$stat" != "M" ] && \
164 die "Unexpected status ($stat) for generated $file"
165 modified="$modified $file"
167 done < $tempfile
169 echo "$modified"
171 return 0
172 } # function status
175 echo "Checking input file status..."
177 ## The lisp portion could be more permissive, eg only care about .el files.
178 modified=$(status ${autogendir:+$sources} ${ldefs_flag:+lisp} ${info_flag:+doc}) || die
180 [ "$modified" ] && {
181 echo "Locally modified: $modified"
182 [ "$force" ] || die "There are local modifications"
186 ## Probably this is overkill, and there's no need to "bootstrap" just
187 ## for making autoloads.
188 [ "$clean" ] && {
190 echo "Running 'make maintainer-clean'..."
192 make maintainer-clean #|| die "Cleaning error"
194 rm -f $ldefs_in
198 echo "Running autoreconf..."
200 autoreconf ${clean:+-f} -i -I m4 2>| $tempfile
202 retval=$?
204 ## Annoyingly, autoreconf puts the "installing `./foo' messages on stderr.
205 if [ "$quiet" ]; then
206 grep -v 'installing `\.' $tempfile 1>&2
207 else
208 cat "$tempfile" 1>&2
211 [ $retval -ne 0 ] && die "autoreconf error"
214 ## Uses global $commit.
215 commit ()
217 local type=$1
218 shift
220 [ $# -gt 0 ] || {
221 echo "No files were modified"
222 return 0
225 echo "Modified file(s): $@"
227 [ "$commit" ] || return 0
229 echo "Committing..."
231 [ "$vcs" = "git" ] && {
232 $vcs add "$@" || return $?
235 $vcs commit -m "Auto-commit of $type files." "$@" || return $?
237 [ "$vcs" = "git" ] && {
238 $vcs push || return $?
241 echo "Committed files: $@"
242 } # function commit
245 ## No longer used since info/dir is now generated at install time if needed,
246 ## and is not in the repository any more.
247 info_dir ()
249 local basefile=build-aux/dir_top outfile=info/dir
251 echo "Regenerating info/dir..."
253 ## Header contains non-printing characters, so this is more
254 ## reliable than using echo.
255 rm -f $outfile
256 cp $basefile $outfile
258 local topic file dircat dirent
260 ## FIXME inefficient looping.
261 for topic in "Texinfo documentation system" "Emacs" "GNU Emacs Lisp" \
262 "Emacs editing modes" "Emacs network features" "Emacs misc features" \
263 "Emacs lisp libraries"; do
265 cat - <<EOF >> $outfile
267 $topic
269 ## Bit faster than doc/*/*.texi.
270 for file in doc/emacs/emacs.texi doc/lispintro/*.texi \
271 doc/lispref/elisp.texi doc/misc/*.texi; do
273 ## FIXME do not ignore w32 if OS is w32.
274 case $file in
275 *-xtra.texi|*efaq-w32.texi) continue ;;
276 esac
278 dircat=$(sed -n -e 's/@value{emacsname}/Emacs/' -e 's/^@dircategory //p' $file)
280 ## TODO warn about unknown topics (check-info in top-level
281 ## Makefile does this).
282 [ "$dircat" = "$topic" ] || continue
284 sed -n -e 's/@value{emacsname}/Emacs/' \
285 -e 's/@acronym{\([A-Z]*\)}/\1/' \
286 -e '/^@direntry/,/^@end direntry/ s/^\([^@]\)/\1/p' \
287 $file >> $outfile
289 done
290 done
292 local modified
294 modified=$(status $outfile) || die
296 commit "info/dir" $modified || die "commit error"
297 } # function info_dir
300 [ "$autogendir" ] && {
302 oldpwd=$PWD
304 cp $genfiles $autogendir/
306 cd $autogendir || die "cd error for $autogendir"
308 echo "Checking status of generated files..."
310 modified=$(status $basegen) || die
312 ## bzr status output is always relative to top-level, not PWD.
313 [ "$vcs" = "bzr" ] && cd $oldpwd
315 commit "generated" $modified || die "commit error"
317 exit 0
318 } # $autogendir
321 [ "$info_flag" ] && info_dir
324 [ "$ldefs_flag" ] || exit 0
327 echo "Finding loaddef targets..."
329 sed -n -e '/^AUTOGEN_VCS/,/^$/p' lisp/Makefile.in | \
330 sed -e '/AUTOGEN_VCS/d' -e '/^$/d' -e 's/\\//' \
331 >| $tempfile || die "sed error"
333 genfiles=
335 while read genfile; do
337 [ -r lisp/$genfile ] || die "Unable to read $genfile"
339 genfiles="$genfiles $genfile"
340 done < $tempfile
343 [ "$genfiles" ] || die "Error setting genfiles"
346 [ -e Makefile ] || {
347 echo "Running ./configure..."
349 ## Minimize required packages.
350 ./configure --without-x || die "configure error"
354 ## Build the minimum needed to get the autoloads.
355 echo "Running lib/ make..."
357 make -C lib "$@" all || die "make lib error"
360 echo "Running src/ make..."
362 make -C src "$@" bootstrap-emacs || die "make src error"
365 echo "Running lisp/ make..."
367 make -C lisp "$@" autoloads EMACS=../src/bootstrap-emacs || die "make src error"
370 ## Ignore comment differences.
371 [ ! "$lboot_flag" ] || \
372 diff -q -I '^;' $ldefs_in $ldefs_out || \
373 cp $ldefs_in $ldefs_out || die "cp ldefs_boot error"
376 cd lisp
378 echo "Checking status of loaddef files..."
380 ## It probably would be fine to just check+commit lisp/, since
381 ## making autoloads should not effect any other files. But better
382 ## safe than sorry.
383 modified=$(status $genfiles ${ldefs_out#lisp/}) || die
386 ## bzr status output is always relative to top-level, not PWD.
387 [ "$vcs" = "bzr" ] && cd ../
390 commit "loaddefs" $modified || die "commit error"
393 exit 0
395 ### update_autogen ends here