Add xref-after-jump-hook and xref-after-return-hook
[emacs.git] / admin / update_autogen
blob23e1d4015c6cc55bf4ddd9c4aac40d7deae02580
1 #!/bin/bash
2 ### update_autogen - update some auto-generated files in the Emacs tree
4 ## Copyright (C) 2011-2015 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 -H: also update ChangeLog.${changelog_n}
73 -I: also update info/dir.
74 -L: also update ldefs-boot.el.
75 -C: start from a clean state. Slower, but more correct.
76 EOF
77 exit 1
81 ## Defaults.
83 force=
84 commit=
85 quiet=
86 clean=
87 autogendir= # was "autogen"
88 ldefs_flag=1
89 lboot_flag=
90 info_flag=
91 changelog_flag=
93 ## Parameters.
94 ldefs_in=lisp/loaddefs.el
95 ldefs_out=lisp/ldefs-boot.el
96 changelog_n=$(sed -n 's/CHANGELOG_HISTORY_INDEX_MAX *= *//p' Makefile.in)
97 changelog_files="ChangeLog.$changelog_n"
98 sources="configure.ac lib/Makefile.am"
99 ## Files to copy into autogendir.
100 ## Everything:
101 genfiles="
102 configure aclocal.m4 src/config.in lib/Makefile.in
103 build-aux/compile build-aux/config.guess build-aux/config.sub
104 build-aux/depcomp build-aux/install-sh build-aux/missing
106 ## msdos-only:
107 genfiles="src/config.in lib/Makefile.in"
109 for g in $genfiles; do
110 basegen="$basegen ${g##*/}"
111 done
113 [ "$basegen" ] || die "internal error"
115 tempfile=/tmp/$PN.$$
117 trap "rm -f $tempfile 2> /dev/null" EXIT
120 while getopts ":hcfqA:HCIL" option ; do
121 case $option in
122 (h) usage ;;
124 (c) commit=1 ;;
126 (f) force=1 ;;
128 (q) quiet=1 ;;
130 (A) autogendir=$OPTARG
131 [ -d "$autogendir" ] || die "No autogen directory: $autogendir"
134 (C) clean=1 ;;
136 (H) changelog_flag=1 ;;
138 (I) info_flag=1 ;;
140 (L) lboot_flag=1 ;;
142 (\?) die "Bad option -$OPTARG" ;;
144 (:) die "Option -$OPTARG requires an argument" ;;
146 (*) die "getopts error" ;;
147 esac
148 done
149 shift $(( --OPTIND ))
150 OPTIND=1
153 ## Does not work 100% because a lot of Emacs batch output comes on stderr (?).
154 [ "$quiet" ] && exec 1> /dev/null
157 ## Run status on inputs, list modified files on stdout.
158 status ()
160 local statflag="-S"
161 [ "$vcs" = "git" ] && statflag="-s"
163 $vcs status $statflag "$@" >| $tempfile || die "$vcs status error for $@"
165 local stat file modified
167 while read stat file; do
169 [ "$stat" != "M" ] && \
170 die "Unexpected status ($stat) for generated $file"
171 modified="$modified $file"
173 done < $tempfile
175 echo "$modified"
177 return 0
178 } # function status
181 echo "Checking input file status..."
183 ## The lisp portion could be more permissive, eg only care about .el files.
184 modified=$(status ${autogendir:+$sources} ${ldefs_flag:+lisp} ${info_flag:+doc}) || die
186 [ "$modified" ] && {
187 echo "Locally modified: $modified"
188 [ "$force" ] || die "There are local modifications"
192 ## Probably this is overkill, and there's no need to "bootstrap" just
193 ## for making autoloads.
194 [ "$clean" ] && {
196 echo "Running 'make maintainer-clean'..."
198 make maintainer-clean #|| die "Cleaning error"
200 rm -f $ldefs_in
204 echo "Running autoreconf..."
206 autoreconf ${clean:+-f} -i -I m4 2>| $tempfile
208 retval=$?
210 ## Annoyingly, autoreconf puts the "installing `./foo' messages on stderr.
211 if [ "$quiet" ]; then
212 grep -v 'installing `\.' $tempfile 1>&2
213 else
214 cat "$tempfile" 1>&2
217 [ $retval -ne 0 ] && die "autoreconf error"
220 ## Uses global $commit.
221 commit ()
223 local type=$1
224 shift
226 [ $# -gt 0 ] || {
227 echo "No files were modified"
228 return 0
231 echo "Modified file(s): $@"
233 [ "$commit" ] || return 0
235 echo "Committing..."
237 $vcs commit -m "; Auto-commit of $type files." "$@" || return $?
239 [ "$vcs" = "git" ] && {
240 $vcs push || return $?
243 echo "Committed files: $@"
244 } # function commit
247 ## No longer used since info/dir is now generated at install time if needed,
248 ## and is not in the repository any more.
249 info_dir ()
251 local basefile=build-aux/dir_top outfile=info/dir
253 echo "Regenerating info/dir..."
255 ## Header contains non-printing characters, so this is more
256 ## reliable than using echo.
257 rm -f $outfile
258 cp $basefile $outfile
260 local topic file dircat dirent
262 ## FIXME inefficient looping.
263 for topic in "Texinfo documentation system" "Emacs" "GNU Emacs Lisp" \
264 "Emacs editing modes" "Emacs network features" "Emacs misc features" \
265 "Emacs lisp libraries"; do
267 cat - <<EOF >> $outfile
269 $topic
271 ## Bit faster than doc/*/*.texi.
272 for file in doc/emacs/emacs.texi doc/lispintro/*.texi \
273 doc/lispref/elisp.texi doc/misc/*.texi; do
275 ## FIXME do not ignore w32 if OS is w32.
276 case $file in
277 *-xtra.texi|*efaq-w32.texi) continue ;;
278 esac
280 dircat=$(sed -n -e 's/@value{emacsname}/Emacs/' -e 's/^@dircategory //p' $file)
282 ## TODO warn about unknown topics (check-info in top-level
283 ## Makefile does this).
284 [ "$dircat" = "$topic" ] || continue
286 sed -n -e 's/@value{emacsname}/Emacs/' \
287 -e 's/@acronym{\([A-Z]*\)}/\1/' \
288 -e '/^@direntry/,/^@end direntry/ s/^\([^@]\)/\1/p' \
289 $file >> $outfile
291 done
292 done
294 local modified
296 modified=$(status $outfile) || die
298 commit "info/dir" $modified || die "commit error"
299 } # function info_dir
302 [ "$autogendir" ] && {
304 oldpwd=$PWD
306 cp $genfiles $autogendir/
308 cd $autogendir || die "cd error for $autogendir"
310 echo "Checking status of generated files..."
312 modified=$(status $basegen) || die
314 commit "generated" $modified || die "commit error"
316 exit 0
317 } # $autogendir
320 [ "$info_flag" ] && info_dir
323 [ "$ldefs_flag" ] || exit 0
326 echo "Finding loaddef targets..."
328 find lisp -name '*.el' -exec grep '^;.*generated-autoload-file:' {} + | \
329 sed -e '/loaddefs\|esh-groups/d' -e 's|/[^/]*: "|/|' -e 's/"//g' \
330 >| $tempfile || die "Error finding targets"
332 genfiles=
334 while read genfile; do
336 ## Or we can just use sort -u when making tempfile...
337 case " $genfiles " in
338 *" $genfile "*) continue ;;
339 esac
341 [ -r $genfile ] || die "Unable to read $genfile"
343 genfiles="$genfiles $genfile"
344 done < $tempfile
347 [ "$genfiles" ] || die "Error setting genfiles"
350 [ -e Makefile ] || {
351 echo "Running ./configure..."
353 ## Minimize required packages.
354 ./configure --without-x || die "configure error"
358 ## Build the minimum needed to get the autoloads.
359 echo "Running lib/ make..."
361 make -C lib "$@" all || die "make lib error"
364 echo "Running src/ make..."
366 make -C src "$@" bootstrap-emacs || die "make src error"
369 echo "Running lisp/ make..."
371 make -C lisp "$@" autoloads EMACS=../src/bootstrap-emacs || die "make src error"
374 ## Ignore comment differences.
375 [ ! "$lboot_flag" ] || \
376 diff -q -I '^;' $ldefs_in $ldefs_out || \
377 cp $ldefs_in $ldefs_out || die "cp ldefs_boot error"
380 echo "Checking status of loaddef files..."
382 ## It probably would be fine to just check+commit lisp/, since
383 ## making autoloads should not effect any other files. But better
384 ## safe than sorry.
385 modified=$(status $genfiles $ldefs_out) || die
388 commit "loaddefs" $modified || die "commit error"
391 ## Less important than the other stuff, so do it last.
392 [ ! "$changelog_flag" ] || {
393 make change-history-nocommit || die "make change-history error"
394 modified=$(status $changelog_files) || die
395 commit "ChangeLog" $modified || die "commit error"
399 exit 0
401 ### update_autogen ends here