_Noreturn not noreturn
[emacs.git] / admin / update_autogen
blobba4ed00fa39b265a568dba14e0a1db741be017b8
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 [ -d .git ] || die "No .git directory"
52 usage ()
54 cat 1>&2 <<EOF
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).
59 Options:
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.
69 EOF
70 exit 1
74 ## Defaults.
76 force=
77 commit=
78 quiet=
79 clean=
80 autogendir= # was "autogen"
81 ldefs_flag=1
82 lboot_flag=
83 info_flag=
84 changelog_flag=
86 ## Parameters.
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.
93 ## Everything:
94 genfiles="
95 configure aclocal.m4 src/config.in
96 build-aux/config.guess build-aux/config.sub
97 build-aux/install-sh
99 ## msdos-only:
100 genfiles="src/config.in"
102 for g in $genfiles; do
103 basegen="$basegen ${g##*/}"
104 done
106 [ "$basegen" ] || die "internal error"
108 tempfile=/tmp/$PN.$$
110 trap "rm -f $tempfile 2> /dev/null" EXIT
113 while getopts ":hcfqA:HCIL" option ; do
114 case $option in
115 (h) usage ;;
117 (c) commit=1 ;;
119 (f) force=1 ;;
121 (q) quiet=1 ;;
123 (A) autogendir=$OPTARG
124 [ -d "$autogendir" ] || die "No autogen directory: $autogendir"
127 (C) clean=1 ;;
129 (H) changelog_flag=1 ;;
131 (I) info_flag=1 ;;
133 (L) lboot_flag=1 ;;
135 (\?) die "Bad option -$OPTARG" ;;
137 (:) die "Option -$OPTARG requires an argument" ;;
139 (*) die "getopts error" ;;
140 esac
141 done
142 shift $(( --OPTIND ))
143 OPTIND=1
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.
151 status ()
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"
163 done < $tempfile
165 echo "$modified"
167 return 0
168 } # function status
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
176 [ "$modified" ] && {
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.
184 [ "$clean" ] && {
186 echo "Running 'make maintainer-clean'..."
188 make maintainer-clean #|| die "Cleaning error"
190 rm -f $ldefs_in
194 echo "Running autoreconf..."
196 autoreconf ${clean:+-f} -i -I m4 2>| $tempfile
198 retval=$?
200 ## Annoyingly, autoreconf puts the "installing `./foo' messages on stderr.
201 if [ "$quiet" ]; then
202 grep -v 'installing `\.' $tempfile 1>&2
203 else
204 cat "$tempfile" 1>&2
207 [ $retval -ne 0 ] && die "autoreconf error"
210 ## Uses global $commit.
211 commit ()
213 local type=$1
214 shift
216 [ $# -gt 0 ] || {
217 echo "No files were modified"
218 return 0
221 echo "Modified file(s): $@"
223 [ "$commit" ] || return 0
225 echo "Committing..."
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: $@"
234 } # function commit
237 ## No longer used since info/dir is now generated at install time if needed,
238 ## and is not in the repository any more.
239 info_dir ()
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.
247 rm -f $outfile
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
259 $topic
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.
266 case $file in
267 *-xtra.texi|*efaq-w32.texi) continue ;;
268 esac
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' \
279 $file >> $outfile
281 done
282 done
284 local modified
286 modified=$(status $outfile) || die
288 commit "info/dir" $modified || die "commit error"
289 } # function info_dir
292 [ "$autogendir" ] && {
294 oldpwd=$PWD
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"
306 exit 0
307 } # $autogendir
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"
322 genfiles=
324 while read genfile; do
326 ## Or we can just use sort -u when making tempfile...
327 case " $genfiles " in
328 *" $genfile "*) continue ;;
329 esac
331 [ -r $genfile ] || die "Unable to read $genfile"
333 genfiles="$genfiles $genfile"
334 done < $tempfile
337 [ "$genfiles" ] || die "Error setting genfiles"
340 [ -e Makefile ] || {
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
374 ## safe than sorry.
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"
389 exit 0
391 ### update_autogen ends here