* etc/NEWS: Adjust to match previous patch.
[emacs.git] / admin / update_autogen
blob73141f8ccead1e3d77b1824a80ff6c2ff0d3c7bc
1 #!/usr/bin/env bash
2 ### update_autogen - update some auto-generated files in the Emacs tree
4 ## Copyright (C) 2011-2017 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 [ -e .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 [ -e nt/gnulib.mk ] || touch nt/gnulib.mk # bug#25359
206 echo "Running autoreconf..."
208 autoreconf ${clean:+-f} -i -I m4 2>| $tempfile
210 retval=$?
212 ## Annoyingly, autoreconf puts the "installing `./foo' messages on stderr.
213 if [ "$quiet" ]; then
214 grep -v 'installing `\.' $tempfile 1>&2
215 else
216 cat "$tempfile" 1>&2
219 [ $retval -ne 0 ] && die "autoreconf error"
222 ## Uses global $commit.
223 commit ()
225 local type=$1
226 shift
228 [ $# -gt 0 ] || {
229 echo "No files were modified"
230 return 0
233 echo "Modified file(s): $@"
235 [ "$commit" ] || return 0
237 echo "Committing..."
239 $vcs commit -m "; Auto-commit of $type files." "$@" || return $?
241 [ "$vcs" = "git" ] && {
242 $vcs push || return $?
245 echo "Committed files: $@"
246 } # function commit
249 ## No longer used since info/dir is now generated at install time if needed,
250 ## and is not in the repository any more.
251 info_dir ()
253 local basefile=build-aux/dir_top outfile=info/dir
255 echo "Regenerating info/dir..."
257 ## Header contains non-printing characters, so this is more
258 ## reliable than using echo.
259 rm -f $outfile
260 cp $basefile $outfile
262 local topic file dircat dirent
264 ## FIXME inefficient looping.
265 for topic in "Texinfo documentation system" "Emacs" "GNU Emacs Lisp" \
266 "Emacs editing modes" "Emacs network features" "Emacs misc features" \
267 "Emacs lisp libraries"; do
269 cat - <<EOF >> $outfile
271 $topic
273 ## Bit faster than doc/*/*.texi.
274 for file in doc/emacs/emacs.texi doc/lispintro/*.texi \
275 doc/lispref/elisp.texi doc/misc/*.texi; do
277 ## FIXME do not ignore w32 if OS is w32.
278 case $file in
279 *-xtra.texi|*efaq-w32.texi) continue ;;
280 esac
282 dircat=$(sed -n -e 's/@value{emacsname}/Emacs/' -e 's/^@dircategory //p' $file)
284 ## TODO warn about unknown topics (check-info in top-level
285 ## Makefile does this).
286 [ "$dircat" = "$topic" ] || continue
288 sed -n -e 's/@value{emacsname}/Emacs/' \
289 -e 's/@acronym{\([A-Z]*\)}/\1/' \
290 -e '/^@direntry/,/^@end direntry/ s/^\([^@]\)/\1/p' \
291 $file >> $outfile
293 done
294 done
296 local modified
298 modified=$(status $outfile) || die
300 commit "info/dir" $modified || die "commit error"
301 } # function info_dir
304 [ "$autogendir" ] && {
306 oldpwd=$PWD
308 cp $genfiles $autogendir/
310 cd $autogendir || die "cd error for $autogendir"
312 echo "Checking status of generated files..."
314 modified=$(status $basegen) || die
316 commit "generated" $modified || die "commit error"
318 exit 0
319 } # $autogendir
322 [ "$info_flag" ] && info_dir
325 [ "$ldefs_flag" ] || exit 0
328 echo "Finding loaddef targets..."
330 find lisp -name '*.el' -exec grep '^;.*generated-autoload-file:' {} + | \
331 sed -e '/loaddefs\|esh-groups/d' -e 's|/[^/]*: "|/|' -e 's/"//g' \
332 >| $tempfile || die "Error finding targets"
334 genfiles=
336 while read genfile; do
338 ## Or we can just use sort -u when making tempfile...
339 case " $genfiles " in
340 *" $genfile "*) continue ;;
341 esac
343 [ -r $genfile ] || die "Unable to read $genfile"
345 genfiles="$genfiles $genfile"
346 done < $tempfile
349 [ "$genfiles" ] || die "Error setting genfiles"
352 [ -e Makefile ] || {
353 echo "Running ./configure..."
355 ## Minimize required packages.
356 ./configure --without-x || die "configure error"
360 ## Build the minimum needed to get the autoloads.
361 echo "Running lib/ make..."
363 make -C lib "$@" all || die "make lib error"
366 echo "Running src/ make..."
368 make -C src "$@" bootstrap-emacs || die "make src error"
371 echo "Running lisp/ make..."
373 make -C lisp "$@" autoloads EMACS=../src/bootstrap-emacs || die "make src error"
376 ## Ignore comment differences.
377 [ ! "$lboot_flag" ] || \
378 diff -q -I '^;' $ldefs_in $ldefs_out || \
379 cp $ldefs_in $ldefs_out || die "cp ldefs_boot error"
382 echo "Checking status of loaddef files..."
384 ## It probably would be fine to just check+commit lisp/, since
385 ## making autoloads should not effect any other files. But better
386 ## safe than sorry.
387 modified=$(status $genfiles $ldefs_out) || die
390 commit "loaddefs" $modified || die "commit error"
393 ## Less important than the other stuff, so do it last.
394 [ ! "$changelog_flag" ] || {
395 make change-history-nocommit || die "make change-history error"
396 modified=$(status $changelog_files) || die
397 commit "ChangeLog" $modified || die "commit error"
401 exit 0
403 ### update_autogen ends here