2 ### update_autogen - update some auto-generated files in the Emacs tree
4 ## Copyright (C) 2011-2016 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/>.
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"
52 elif [ -e .git
]; then
55 die
"Cannot determine vcs"
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).
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.
87 autogendir
= # was "autogen"
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.
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
107 genfiles
="src/config.in lib/Makefile.in"
109 for g
in $genfiles; do
110 basegen
="$basegen ${g##*/}"
113 [ "$basegen" ] || die
"internal error"
117 trap "rm -f $tempfile 2> /dev/null" EXIT
120 while getopts ":hcfqA:HCIL" option
; do
130 (A
) autogendir
=$OPTARG
131 [ -d "$autogendir" ] || die
"No autogen directory: $autogendir"
136 (H
) changelog_flag
=1 ;;
142 (\?) die
"Bad option -$OPTARG" ;;
144 (:) die
"Option -$OPTARG requires an argument" ;;
146 (*) die
"getopts error" ;;
149 shift $
(( --OPTIND ))
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.
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"
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
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.
196 echo "Running 'make maintainer-clean'..."
198 make maintainer-clean
#|| die "Cleaning error"
204 echo "Running autoreconf..."
206 autoreconf
${clean:+-f} -i -I m4 2>|
$tempfile
210 ## Annoyingly, autoreconf puts the "installing `./foo' messages on stderr.
211 if [ "$quiet" ]; then
212 grep -v 'installing `\.' $tempfile 1>&2
217 [ $retval -ne 0 ] && die
"autoreconf error"
220 ## Uses global $commit.
227 echo "No files were modified"
231 echo "Modified file(s): $@"
233 [ "$commit" ] ||
return 0
237 $vcs commit
-m "; Auto-commit of $type files." "$@" ||
return $?
239 [ "$vcs" = "git" ] && {
240 $vcs push ||
return $?
243 echo "Committed files: $@"
247 ## No longer used since info/dir is now generated at install time if needed,
248 ## and is not in the repository any more.
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.
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
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.
277 *-xtra.texi|
*efaq-w32.texi
) continue ;;
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' \
296 modified
=$
(status
$outfile) || die
298 commit
"info/dir" $modified || die
"commit error"
299 } # function info_dir
302 [ "$autogendir" ] && {
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"
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"
334 while read genfile
; do
336 ## Or we can just use sort -u when making tempfile...
337 case " $genfiles " in
338 *" $genfile "*) continue ;;
341 [ -r $genfile ] || die
"Unable to read $genfile"
343 genfiles
="$genfiles $genfile"
347 [ "$genfiles" ] || die
"Error setting genfiles"
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
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"
401 ### update_autogen ends here