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/>.
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"
53 die
"Cannot determine vcs"
60 Usage: ${PN} [-f] [-c] [-q] [-A dir] [-I] [-L] [-C] [-- make-flags]
61 Update some auto-generated files in the Emacs tree.
62 By default, only does the versioned loaddefs-like files in lisp/.
63 This requires a build. Passes any non-option args to make (eg -- -j2).
65 -f: force an update even if the source files are locally modified.
66 -c: if the update succeeds and the generated files are modified,
67 commit them (caution).
68 -q: be quiet; only give error messages, not status messages.
69 -A: only update autotools files, copying into specified dir.
70 -I: also update info/dir.
71 -L: also update ldefs-boot.el.
72 -C: start from a clean state. Slower, but more correct.
84 autogendir
= # was "autogen"
90 ldefs_in
=lisp
/loaddefs.el
91 ldefs_out
=lisp
/ldefs-boot.el
92 sources
="configure.ac lib/Makefile.am"
93 ## Files to copy into autogendir.
96 configure aclocal.m4 src/config.in lib/Makefile.in
97 build-aux/compile build-aux/config.guess build-aux/config.sub
98 build-aux/depcomp build-aux/install-sh build-aux/missing
101 genfiles
="src/config.in lib/Makefile.in"
103 for g
in $genfiles; do
104 basegen
="$basegen ${g##*/}"
107 [ "$basegen" ] || die
"internal error"
111 trap "rm -f $tempfile 2> /dev/null" EXIT
114 while getopts ":hcfqA:CIL" option
; do
124 (A
) autogendir
=$OPTARG
125 [ -d "$autogendir" ] || die
"No autogen directory: $autogendir"
134 (\?) die
"Bad option -$OPTARG" ;;
136 (:) die
"Option -$OPTARG requires an argument" ;;
138 (*) die
"getopts error" ;;
141 shift $
(( --OPTIND ))
145 ## Does not work 100% because a lot of Emacs batch output comes on stderr (?).
146 [ "$quiet" ] && exec 1> /dev
/null
149 ## Run status on inputs, list modified files on stdout.
153 [ "$vcs" = "git" ] && statflag
="-s"
155 $vcs status
$statflag "$@" >|
$tempfile || die
"$vcs status error for $@"
157 local stat
file modified
159 while read stat
file; do
161 [ "$stat" != "M" ] && \
162 die
"Unexpected status ($stat) for generated $file"
163 modified
="$modified $file"
173 echo "Checking input file status..."
175 ## The lisp portion could be more permissive, eg only care about .el files.
176 modified
=$
(status
${autogendir:+$sources} ${ldefs_flag:+lisp} ${info_flag:+doc}) || die
179 echo "Locally modified: $modified"
180 [ "$force" ] || die
"There are local modifications"
184 ## Probably this is overkill, and there's no need to "bootstrap" just
185 ## for making autoloads.
188 echo "Running 'make maintainer-clean'..."
190 make maintainer-clean
#|| die "Cleaning error"
196 echo "Running autoreconf..."
198 autoreconf
${clean:+-f} -i -I m4 2>|
$tempfile
202 ## Annoyingly, autoreconf puts the "installing `./foo' messages on stderr.
203 if [ "$quiet" ]; then
204 grep -v 'installing `\.' $tempfile 1>&2
209 [ $retval -ne 0 ] && die
"autoreconf error"
212 ## Uses global $commit.
219 echo "No files were modified"
223 echo "Modified file(s): $@"
225 [ "$commit" ] ||
return 0
229 $vcs commit
-m "Auto-commit of $type files." "$@" ||
return $?
231 [ "$vcs" = "git" ] && {
232 $vcs push ||
return $?
235 echo "Committed files: $@"
239 ## No longer used since info/dir is now generated at install time if needed,
240 ## and is not in the repository any more.
243 local basefile
=build-aux
/dir_top outfile
=info
/dir
245 echo "Regenerating info/dir..."
247 ## Header contains non-printing characters, so this is more
248 ## reliable than using echo.
250 cp $basefile $outfile
252 local topic
file dircat dirent
254 ## FIXME inefficient looping.
255 for topic
in "Texinfo documentation system" "Emacs" "GNU Emacs Lisp" \
256 "Emacs editing modes" "Emacs network features" "Emacs misc features" \
257 "Emacs lisp libraries"; do
259 cat - <<EOF >> $outfile
263 ## Bit faster than doc/*/*.texi.
264 for file in doc
/emacs
/emacs.texi
doc
/lispintro
/*.texi \
265 doc
/lispref
/elisp.texi
doc
/misc
/*.texi
; do
267 ## FIXME do not ignore w32 if OS is w32.
269 *-xtra.texi|
*efaq-w32.texi
) continue ;;
272 dircat
=$
(sed -n -e 's/@value{emacsname}/Emacs/' -e 's/^@dircategory //p' $file)
274 ## TODO warn about unknown topics (check-info in top-level
275 ## Makefile does this).
276 [ "$dircat" = "$topic" ] ||
continue
278 sed -n -e 's/@value{emacsname}/Emacs/' \
279 -e 's/@acronym{\([A-Z]*\)}/\1/' \
280 -e '/^@direntry/,/^@end direntry/ s/^\([^@]\)/\1/p' \
288 modified
=$
(status
$outfile) || die
290 commit
"info/dir" $modified || die
"commit error"
291 } # function info_dir
294 [ "$autogendir" ] && {
298 cp $genfiles $autogendir/
300 cd $autogendir || die
"cd error for $autogendir"
302 echo "Checking status of generated files..."
304 modified
=$
(status
$basegen) || die
306 commit
"generated" $modified || die
"commit error"
312 [ "$info_flag" ] && info_dir
315 [ "$ldefs_flag" ] ||
exit 0
318 echo "Finding loaddef targets..."
320 find lisp
-name '*.el' -exec grep '^;.*generated-autoload-file:' {} + | \
321 sed -e '/loaddefs\|esh-groups/d' -e 's|/[^/]*: "|/|' -e 's/"//g' \
322 >|
$tempfile || die
"Error finding targets"
326 while read genfile
; do
328 ## Or we can just use sort -u when making tempfile...
329 case " $genfiles " in
330 *" $genfile "*) continue ;;
333 [ -r $genfile ] || die
"Unable to read $genfile"
335 genfiles
="$genfiles $genfile"
339 [ "$genfiles" ] || die
"Error setting genfiles"
343 echo "Running ./configure..."
345 ## Minimize required packages.
346 .
/configure
--without-x || die
"configure error"
350 ## Build the minimum needed to get the autoloads.
351 echo "Running lib/ make..."
353 make -C lib
"$@" all || die
"make lib error"
356 echo "Running src/ make..."
358 make -C src
"$@" bootstrap-emacs || die
"make src error"
361 echo "Running lisp/ make..."
363 make -C lisp
"$@" autoloads EMACS
=..
/src
/bootstrap-emacs || die
"make src error"
366 ## Ignore comment differences.
367 [ ! "$lboot_flag" ] || \
368 diff -q -I '^;' $ldefs_in $ldefs_out || \
369 cp $ldefs_in $ldefs_out || die
"cp ldefs_boot error"
372 echo "Checking status of loaddef files..."
374 ## It probably would be fine to just check+commit lisp/, since
375 ## making autoloads should not effect any other files. But better
377 modified
=$
(status
$genfiles $ldefs_out) || die
380 commit
"loaddefs" $modified || die
"commit error"
385 ### update_autogen ends here