Avoid undefined behavior in color table hashing.
[emacs.git] / admin / update_autogen
blob8b0ae67028a459a836f78d815bd59cc4bbaa817d
1 #!/bin/bash
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/>.
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 .git ]; then
51 vcs=git
52 else
53 die "Cannot determine vcs"
57 usage ()
59 cat 1>&2 <<EOF
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).
64 Options:
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.
73 EOF
74 exit 1
78 ## Defaults.
80 force=
81 commit=
82 quiet=
83 clean=
84 autogendir= # was "autogen"
85 ldefs_flag=1
86 lboot_flag=
87 info_flag=
89 ## Parameters.
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.
94 ## Everything:
95 genfiles="
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
100 ## msdos-only:
101 genfiles="src/config.in lib/Makefile.in"
103 for g in $genfiles; do
104 basegen="$basegen ${g##*/}"
105 done
107 [ "$basegen" ] || die "internal error"
109 tempfile=/tmp/$PN.$$
111 trap "rm -f $tempfile 2> /dev/null" EXIT
114 while getopts ":hcfqA:CIL" option ; do
115 case $option in
116 (h) usage ;;
118 (c) commit=1 ;;
120 (f) force=1 ;;
122 (q) quiet=1 ;;
124 (A) autogendir=$OPTARG
125 [ -d "$autogendir" ] || die "No autogen directory: $autogendir"
128 (C) clean=1 ;;
130 (I) info_flag=1 ;;
132 (L) lboot_flag=1 ;;
134 (\?) die "Bad option -$OPTARG" ;;
136 (:) die "Option -$OPTARG requires an argument" ;;
138 (*) die "getopts error" ;;
139 esac
140 done
141 shift $(( --OPTIND ))
142 OPTIND=1
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.
150 status ()
152 local statflag="-S"
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"
165 done < $tempfile
167 echo "$modified"
169 return 0
170 } # function status
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
178 [ "$modified" ] && {
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.
186 [ "$clean" ] && {
188 echo "Running 'make maintainer-clean'..."
190 make maintainer-clean #|| die "Cleaning error"
192 rm -f $ldefs_in
196 echo "Running autoreconf..."
198 autoreconf ${clean:+-f} -i -I m4 2>| $tempfile
200 retval=$?
202 ## Annoyingly, autoreconf puts the "installing `./foo' messages on stderr.
203 if [ "$quiet" ]; then
204 grep -v 'installing `\.' $tempfile 1>&2
205 else
206 cat "$tempfile" 1>&2
209 [ $retval -ne 0 ] && die "autoreconf error"
212 ## Uses global $commit.
213 commit ()
215 local type=$1
216 shift
218 [ $# -gt 0 ] || {
219 echo "No files were modified"
220 return 0
223 echo "Modified file(s): $@"
225 [ "$commit" ] || return 0
227 echo "Committing..."
229 $vcs commit -m "Auto-commit of $type files." "$@" || return $?
231 [ "$vcs" = "git" ] && {
232 $vcs push || return $?
235 echo "Committed files: $@"
236 } # function commit
239 ## No longer used since info/dir is now generated at install time if needed,
240 ## and is not in the repository any more.
241 info_dir ()
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.
249 rm -f $outfile
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
261 $topic
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.
268 case $file in
269 *-xtra.texi|*efaq-w32.texi) continue ;;
270 esac
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' \
281 $file >> $outfile
283 done
284 done
286 local modified
288 modified=$(status $outfile) || die
290 commit "info/dir" $modified || die "commit error"
291 } # function info_dir
294 [ "$autogendir" ] && {
296 oldpwd=$PWD
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"
308 exit 0
309 } # $autogendir
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"
324 genfiles=
326 while read genfile; do
328 ## Or we can just use sort -u when making tempfile...
329 case " $genfiles " in
330 *" $genfile "*) continue ;;
331 esac
333 [ -r $genfile ] || die "Unable to read $genfile"
335 genfiles="$genfiles $genfile"
336 done < $tempfile
339 [ "$genfiles" ] || die "Error setting genfiles"
342 [ -e Makefile ] || {
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
376 ## safe than sorry.
377 modified=$(status $genfiles $ldefs_out) || die
380 commit "loaddefs" $modified || die "commit error"
383 exit 0
385 ### update_autogen ends here