2 ### update_autogen - update some auto-generated files in the Emacs tree
4 ## Copyright (C) 2011-2018 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 <https://www.gnu.org/licenses/>.
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.
34 die
() # write error to stderr and exit
36 [ $# -gt 0 ] && echo "$PN: $@" >&2
40 PN
=${0##*/} # basename of script
43 [ "$PD" = "$0" ] && PD
=.
# if PATH includes PWD
45 ## This should be the admin directory.
48 [ -d admin
] || die
"Could not locate admin directory"
50 [ -d .git
] || die
"No .git directory"
55 Usage: ${PN} [-f] [-c] [-q] [-A dir] [-I] [-L] [-C] [-- make-flags]
56 Update some auto-generated files in the Emacs tree.
57 By default, only does the versioned loaddefs-like files in lisp/.
58 This requires a build. Passes any non-option args to make (eg -- -j2).
60 -f: force an update even if the source files are locally modified.
61 -c: if the update succeeds and the generated files are modified,
62 commit them (caution).
63 -q: be quiet; only give error messages, not status messages.
64 -A: only update autotools files, copying into specified dir.
65 -H: also update ChangeLog.${changelog_n}
66 -I: also update info/dir.
67 -L: also update ldefs-boot.el.
68 -C: start from a clean state. Slower, but more correct.
80 autogendir
= # was "autogen"
87 ldefs_in
=lisp
/loaddefs.el
88 ldefs_out
=lisp
/ldefs-boot.el
89 changelog_n
=$
(sed -n 's/CHANGELOG_HISTORY_INDEX_MAX *= *//p' Makefile.
in)
90 changelog_files
="ChangeLog.$changelog_n"
91 sources
="configure.ac lib/Makefile.am"
92 ## Files to copy into autogendir.
95 configure aclocal.m4 src/config.in
96 build-aux/config.guess build-aux/config.sub
100 genfiles
="src/config.in"
102 for g
in $genfiles; do
103 basegen
="$basegen ${g##*/}"
106 [ "$basegen" ] || die
"internal error"
110 trap "rm -f $tempfile 2> /dev/null" EXIT
113 while getopts ":hcfqA:HCIL" option
; do
123 (A
) autogendir
=$OPTARG
124 [ -d "$autogendir" ] || die
"No autogen directory: $autogendir"
129 (H
) changelog_flag
=1 ;;
135 (\?) die
"Bad option -$OPTARG" ;;
137 (:) die
"Option -$OPTARG requires an argument" ;;
139 (*) die
"getopts error" ;;
142 shift $
(( --OPTIND ))
146 ## Does not work 100% because a lot of Emacs batch output comes on stderr (?).
147 [ "$quiet" ] && exec 1> /dev
/null
150 ## Run status on inputs, list modified files on stdout.
153 git status
-s "$@" >|
$tempfile || die
"git status error for $@"
155 local stat
file modified
157 while read stat
file; do
159 [ "$stat" != "M" ] && \
160 die
"Unexpected status ($stat) for generated $file"
161 modified
="$modified $file"
171 echo "Checking input file status..."
173 ## The lisp portion could be more permissive, eg only care about .el files.
174 modified
=$
(status
${autogendir:+$sources} ${ldefs_flag:+lisp} ${info_flag:+doc}) || die
177 echo "Locally modified: $modified"
178 [ "$force" ] || die
"There are local modifications"
182 ## Probably this is overkill, and there's no need to "bootstrap" just
183 ## for making autoloads.
186 echo "Running 'make maintainer-clean'..."
188 make maintainer-clean
#|| die "Cleaning error"
194 echo "Running autoreconf..."
196 autoreconf
${clean:+-f} -i -I m4 2>|
$tempfile
200 ## Annoyingly, autoreconf puts the "installing `./foo' messages on stderr.
201 if [ "$quiet" ]; then
202 grep -v 'installing `\.' $tempfile 1>&2
207 [ $retval -ne 0 ] && die
"autoreconf error"
210 ## Uses global $commit.
217 echo "No files were modified"
221 echo "Modified file(s): $@"
223 [ "$commit" ] ||
return 0
227 git commit
-m "; Auto-commit of $type files." "$@" ||
return $?
229 ## In case someone else pushed something while we were working.
230 git pull
--rebase ||
return $?
231 git push ||
return $?
233 echo "Committed files: $@"
237 ## No longer used since info/dir is now generated at install time if needed,
238 ## and is not in the repository any more.
241 local basefile
=build-aux
/dir_top outfile
=info
/dir
243 echo "Regenerating info/dir..."
245 ## Header contains non-printing characters, so this is more
246 ## reliable than using echo.
248 cp $basefile $outfile
250 local topic
file dircat dirent
252 ## FIXME inefficient looping.
253 for topic
in "Texinfo documentation system" "Emacs" "GNU Emacs Lisp" \
254 "Emacs editing modes" "Emacs network features" "Emacs misc features" \
255 "Emacs lisp libraries"; do
257 cat - <<EOF >> $outfile
261 ## Bit faster than doc/*/*.texi.
262 for file in doc
/emacs
/emacs.texi
doc
/lispintro
/*.texi \
263 doc
/lispref
/elisp.texi
doc
/misc
/*.texi
; do
265 ## FIXME do not ignore w32 if OS is w32.
267 *-xtra.texi|
*efaq-w32.texi
) continue ;;
270 dircat
=$
(sed -n -e 's/@value{emacsname}/Emacs/' -e 's/^@dircategory //p' $file)
272 ## TODO warn about unknown topics (check-info in top-level
273 ## Makefile does this).
274 [ "$dircat" = "$topic" ] ||
continue
276 sed -n -e 's/@value{emacsname}/Emacs/' \
277 -e 's/@acronym{\([A-Z]*\)}/\1/' \
278 -e '/^@direntry/,/^@end direntry/ s/^\([^@]\)/\1/p' \
286 modified
=$
(status
$outfile) || die
288 commit
"info/dir" $modified || die
"commit error"
289 } # function info_dir
292 [ "$autogendir" ] && {
296 cp $genfiles $autogendir/
298 cd $autogendir || die
"cd error for $autogendir"
300 echo "Checking status of generated files..."
302 modified
=$
(status
$basegen) || die
304 commit
"generated" $modified || die
"commit error"
310 [ "$info_flag" ] && info_dir
313 [ "$ldefs_flag" ] ||
exit 0
316 echo "Finding loaddef targets..."
318 find lisp
-name '*.el' -exec grep '^;.*generated-autoload-file:' {} + | \
319 sed -e '/loaddefs\|esh-groups/d' -e 's|/[^/]*: "|/|' -e 's/"//g' \
320 >|
$tempfile || die
"Error finding targets"
324 while read genfile
; do
326 ## Or we can just use sort -u when making tempfile...
327 case " $genfiles " in
328 *" $genfile "*) continue ;;
331 [ -r $genfile ] || die
"Unable to read $genfile"
333 genfiles
="$genfiles $genfile"
337 [ "$genfiles" ] || die
"Error setting genfiles"
341 echo "Running ./configure..."
343 ## Minimize required packages.
344 .
/configure
--without-x || die
"configure error"
348 ## Build the minimum needed to get the autoloads.
349 echo "Running lib/ make..."
351 make -C lib
"$@" all || die
"make lib error"
354 echo "Running src/ make..."
356 make -C src
"$@" bootstrap-emacs || die
"make src error"
359 echo "Running lisp/ make..."
361 make -C lisp
"$@" autoloads EMACS
=..
/src
/bootstrap-emacs || die
"make src error"
364 ## Ignore comment differences.
365 [ ! "$lboot_flag" ] || \
366 diff -q -I '^;' $ldefs_in $ldefs_out || \
367 cp $ldefs_in $ldefs_out || die
"cp ldefs_boot error"
370 echo "Checking status of loaddef files..."
372 ## It probably would be fine to just check+commit lisp/, since
373 ## making autoloads should not effect any other files. But better
375 modified
=$
(status
$genfiles $ldefs_out) || die
378 commit
"loaddefs" $modified || die
"commit error"
381 ## Less important than the other stuff, so do it last.
382 [ ! "$changelog_flag" ] ||
{
383 make change-history-nocommit || die
"make change-history error"
384 modified
=$
(status
$changelog_files) || die
385 commit
"ChangeLog" $modified || die
"commit error"
391 ### update_autogen ends here