* admin/notes/multi-tty: Remove some of the more obviously obsolete stuff.
[bpt/emacs.git] / admin / update_autogen
1 #!/bin/bash
2 ### update_autogen - update some auto-generated files in the Emacs tree
3
4 ## Copyright (C) 2011-2014 Free Software Foundation, Inc.
5
6 ## Author: Glenn Morris <rgm@gnu.org>
7
8 ## This file is part of GNU Emacs.
9
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.
14
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.
19
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/>.
22
23 ### Commentary:
24
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.
28 ##
29 ## By default, it updates the versioned loaddefs-like files in lisp,
30 ## except ldefs-boot.el.
31
32 ### Code:
33
34 die () # write error to stderr and exit
35 {
36 [ $# -gt 0 ] && echo "$PN: $@" >&2
37 exit 1
38 }
39
40 PN=${0##*/} # basename of script
41 PD=${0%/*}
42
43 [ "$PD" = "$0" ] && PD=. # if PATH includes PWD
44
45 ## This should be the admin directory.
46 cd $PD
47 cd ../
48 [ -d admin ] || die "Could not locate admin directory"
49
50
51 usage ()
52 {
53 cat 1>&2 <<EOF
54 Usage: ${PN} [-f] [-c] [-q] [-A dir] [-I] [-L] [-C] [-- make-flags]
55 Update some auto-generated files in the Emacs tree.
56 By default, only does the versioned loaddefs-like files in lisp/.
57 This requires a build. Passes any non-option args to make (eg -- -j2).
58 Options:
59 -f: force an update even if the source files are locally modified.
60 -c: if the update succeeds and the generated files are modified,
61 commit them (caution).
62 -q: be quiet; only give error messages, not status messages.
63 -A: only update autotools files, copying into specified dir.
64 -I: also update info/dir.
65 -L: also update ldefs-boot.el.
66 -C: start from a clean state. Slower, but more correct.
67 EOF
68 exit 1
69 }
70
71
72 ## Defaults.
73
74 force=
75 commit=
76 quiet=
77 clean=
78 autogendir= # was "autogen"
79 ldefs_flag=1
80 lboot_flag=
81 info_flag=
82
83 ## Parameters.
84 ldefs_in=lisp/loaddefs.el
85 ldefs_out=lisp/ldefs-boot.el
86 sources="configure.ac lib/Makefile.am"
87 ## Files to copy into autogendir.
88 ## Everything:
89 genfiles="
90 configure aclocal.m4 src/config.in lib/Makefile.in
91 build-aux/compile build-aux/config.guess build-aux/config.sub
92 build-aux/depcomp build-aux/install-sh build-aux/missing
93 "
94 ## msdos-only:
95 genfiles="src/config.in lib/Makefile.in"
96
97 for g in $genfiles; do
98 basegen="$basegen ${g##*/}"
99 done
100
101 [ "$basegen" ] || die "internal error"
102
103 tempfile=/tmp/$PN.$$
104
105 trap "rm -f $tempfile 2> /dev/null" EXIT
106
107
108 while getopts ":hcfqA:CIL" option ; do
109 case $option in
110 (h) usage ;;
111
112 (c) commit=1 ;;
113
114 (f) force=1 ;;
115
116 (q) quiet=1 ;;
117
118 (A) autogendir=$OPTARG
119 [ -d "$autogendir" ] || die "No autogen directory: $autogendir"
120 ;;
121
122 (C) clean=1 ;;
123
124 (I) info_flag=1 ;;
125
126 (L) lboot_flag=1 ;;
127
128 (\?) die "Bad option -$OPTARG" ;;
129
130 (:) die "Option -$OPTARG requires an argument" ;;
131
132 (*) die "getopts error" ;;
133 esac
134 done
135 shift $(( --OPTIND ))
136 OPTIND=1
137
138
139 ## Does not work 100% because a lot of Emacs batch output comes on stderr (?).
140 [ "$quiet" ] && exec 1> /dev/null
141
142
143 ## Run status on inputs, list modified files on stdout.
144 status ()
145 {
146 bzr status -S "$@" >| $tempfile || die "bzr status error for $@"
147
148 local stat file modified
149
150 while read stat file; do
151
152 [ "$stat" != "M" ] && \
153 die "Unexpected status ($stat) for generated $file"
154 modified="$modified $file"
155
156 done < $tempfile
157
158 echo "$modified"
159
160 return 0
161 } # function status
162
163
164 echo "Checking input file status..."
165
166 ## The lisp portion could be more permissive, eg only care about .el files.
167 modified=$(status ${autogendir:+$sources} ${ldefs_flag:+lisp} ${info_flag:+doc}) || die
168
169 [ "$modified" ] && {
170 echo "Locally modified: $modified"
171 [ "$force" ] || die "There are local modifications"
172 }
173
174
175 ## Probably this is overkill, and there's no need to "bootstrap" just
176 ## for making autoloads.
177 [ "$clean" ] && {
178
179 echo "Running 'make maintainer-clean'..."
180
181 make maintainer-clean #|| die "Cleaning error"
182
183 rm -f $ldefs_in
184 }
185
186
187 echo "Running autoreconf..."
188
189 autoreconf ${clean:+-f} -i -I m4 2>| $tempfile
190
191 retval=$?
192
193 ## Annoyingly, autoreconf puts the "installing `./foo' messages on stderr.
194 if [ "$quiet" ]; then
195 grep -v 'installing `\.' $tempfile 1>&2
196 else
197 cat "$tempfile" 1>&2
198 fi
199
200 [ $retval -ne 0 ] && die "autoreconf error"
201
202
203 ## Uses global $commit.
204 commit ()
205 {
206 local type=$1
207 shift
208
209 [ $# -gt 0 ] || {
210 echo "No files were modified"
211 return 0
212 }
213
214 echo "Modified file(s): $@"
215
216 [ "$commit" ] || return 0
217
218 echo "Committing..."
219
220 ## bzr status output is always relative to top-level, not PWD.
221 bzr commit -m "Auto-commit of $type files." "$@" || return $?
222
223 echo "Committed files: $@"
224 } # function commit
225
226
227 ## No longer used since info/dir is now generated at install time if needed,
228 ## and is not in the repository any more.
229 info_dir ()
230 {
231 local basefile=build-aux/dir_top outfile=info/dir
232
233 echo "Regenerating info/dir..."
234
235 ## Header contains non-printing characters, so this is more
236 ## reliable than using echo.
237 rm -f $outfile
238 cp $basefile $outfile
239
240 local topic file dircat dirent
241
242 ## FIXME inefficient looping.
243 for topic in "Texinfo documentation system" "Emacs" "GNU Emacs Lisp" \
244 "Emacs editing modes" "Emacs network features" "Emacs misc features" \
245 "Emacs lisp libraries"; do
246
247 cat - <<EOF >> $outfile
248
249 $topic
250 EOF
251 ## Bit faster than doc/*/*.texi.
252 for file in doc/emacs/emacs.texi doc/lispintro/*.texi \
253 doc/lispref/elisp.texi doc/misc/*.texi; do
254
255 ## FIXME do not ignore w32 if OS is w32.
256 case $file in
257 *-xtra.texi|*efaq-w32.texi) continue ;;
258 esac
259
260 dircat=`sed -n -e 's/@value{emacsname}/Emacs/' -e 's/^@dircategory //p' $file`
261
262 ## TODO warn about unknown topics (check-info in top-level
263 ## Makefile does this).
264 [ "$dircat" = "$topic" ] || continue
265
266 sed -n -e 's/@value{emacsname}/Emacs/' \
267 -e 's/@acronym{\([A-Z]*\)}/\1/' \
268 -e '/^@direntry/,/^@end direntry/ s/^\([^@]\)/\1/p' \
269 $file >> $outfile
270
271 done
272 done
273
274 local modified
275
276 modified=$(status $outfile) || die
277
278 commit "info/dir" $modified || die "commit error"
279 } # function info_dir
280
281
282 [ "$autogendir" ] && {
283
284 oldpwd=$PWD
285
286 cp $genfiles $autogendir/
287
288 cd $autogendir || die "cd error for $autogendir"
289
290 echo "Checking status of generated files..."
291
292 modified=$(status $basegen) || die
293
294 cd $oldpwd
295
296 commit "generated" $modified || die "commit error"
297
298 exit 0
299 } # $autogendir
300
301
302 [ "$info_flag" ] && info_dir
303
304
305 [ "$ldefs_flag" ] || exit 0
306
307
308 echo "Finding loaddef targets..."
309
310 sed -n -e '/^AUTOGEN_VCS/,/^$/p' lisp/Makefile.in | \
311 sed -e '/AUTOGEN_VCS/d' -e '/^$/d' -e 's/\\//' \
312 >| $tempfile || die "sed error"
313
314 genfiles=
315
316 while read genfile; do
317
318 [ -r lisp/$genfile ] || die "Unable to read $genfile"
319
320 genfiles="$genfiles $genfile"
321 done < $tempfile
322
323
324 [ "$genfiles" ] || die "Error setting genfiles"
325
326
327 [ -e Makefile ] || {
328 echo "Running ./configure..."
329
330 ## Minimize required packages.
331 ./configure --without-x || die "configure error"
332 }
333
334
335 ## Build the minimum needed to get the autoloads.
336 echo "Running lib/ make..."
337
338 make -C lib "$@" all || die "make lib error"
339
340
341 echo "Running src/ make..."
342
343 make -C src "$@" bootstrap-emacs || die "make src error"
344
345
346 echo "Running lisp/ make..."
347
348 make -C lisp "$@" autoloads EMACS=../src/bootstrap-emacs || die "make src error"
349
350
351 ## Ignore comment differences.
352 [ ! "$lboot_flag" ] || \
353 diff -q -I '^;' $ldefs_in $ldefs_out || \
354 cp $ldefs_in $ldefs_out || die "cp ldefs_boot error"
355
356
357 cd lisp
358
359 echo "Checking status of loaddef files..."
360
361 ## It probably would be fine to just check+commit lisp/, since
362 ## making autoloads should not effect any other files. But better
363 ## safe than sorry.
364 modified=$(status $genfiles ${ldefs_out#lisp/}) || die
365
366
367 cd ../
368
369
370 commit "loaddefs" $modified || die "commit error"
371
372
373 exit 0
374
375 ### update_autogen ends here