Make update_autogen handle loaddefs-like files as well.
[bpt/emacs.git] / autogen / update_autogen
1 #!/bin/bash
2 ### update_autogen - update the generated files in Emacs autogen/ directory
3
4 ## Copyright (C) 2011 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 the pre-built generated files in
26 ## the autogen/ directory. This is suitable for running from cron.
27 ## Only Emacs maintainers need use this, so it uses bash features.
28 ##
29 ## With the -l option, it also updates the versioned loaddefs-like
30 ## files in lisp/. These include ldefs-boot, cl-loaddefs, rmail, etc.
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 autogen directory.
46 cd $PD
47 cd ../
48 [ -d autogen ] || die "Could not locate autogen directory"
49
50
51 usage ()
52 {
53 cat 1>&2 <<EOF
54 Usage: ${PN} [-f] [-c] [-q] [-l] [-C] [-- make-flags]
55 Update the generated files in the Emacs autogen/ directory.
56 Options:
57 -f: force an update even if the source files are locally modified.
58 -c: if the update succeeds and the generated files are modified,
59 commit them (caution).
60 -q: be quiet; only give error messages, not status messages.
61 -l: also update the versioned loaddefs-like files in lisp/.
62 This requires a build. Passes any non-option args to make (eg -- -j2).
63 -C: start from a clean state. Slower, but more correct.
64 EOF
65 exit 1
66 }
67
68
69 ## Defaults.
70
71 force=
72 commit=
73 quiet=
74 clean=
75 ldefs_flag=
76
77 ## Parameters.
78 ldefs_in=lisp/loaddefs.el
79 ldefs_out=lisp/ldefs-boot.el
80 sources="configure.in lib/Makefile.am"
81 genfiles="configure aclocal.m4 src/config.in lib/Makefile.in compile config.guess config.sub depcomp install-sh missing"
82
83 for g in $genfiles; do
84 basegen="$basegen ${g##*/}"
85 done
86
87 [ "$basegen" ] || die "internal error"
88
89 tempfile=/tmp/$PN.$$
90
91 trap "rm -f $tempfile 2> /dev/null" EXIT
92
93
94 while getopts ":hcflqC" option ; do
95 case $option in
96 (h) usage ;;
97
98 (c) commit=1 ;;
99
100 (f) force=1 ;;
101
102 (l) ldefs_flag=1 ;;
103
104 (q) quiet=1 ;;
105
106 (C) clean=1 ;;
107
108 (\?) die "Bad option -$OPTARG" ;;
109
110 (:) die "Option -$OPTARG requires an argument" ;;
111
112 (*) die "getopts error" ;;
113 esac
114 done
115 shift $(( --OPTIND ))
116 OPTIND=1
117
118
119 ## Does not work 100% because a lot of Emacs batch output comes on stderr (?).
120 [ "$quiet" ] && exec 1> /dev/null
121
122
123 echo "Running bzr status..."
124
125 bzr status -S $sources ${ldefs_flag:+lisp} >| $tempfile || \
126 die "bzr status error for sources"
127
128 ## The lisp portion could be more permissive, eg only care about .el files.
129 while read stat file; do
130
131 case $stat in
132 M)
133 echo "Locally modified: $file"
134 [ "$force" ] || die "There are local modifications"
135 ;;
136
137 *) die "Unexpected status ($stat) for $file" ;;
138 esac
139 done < $tempfile
140
141
142 ## Probably this is overkill, and there's no need to "bootstrap" just
143 ## for making autoloads.
144 [ "$clean" ] && {
145
146 echo "Running 'make maintainer-clean'..."
147
148 make maintainer-clean #|| die "Cleaning error"
149
150 rm -f $ldefs_in
151 }
152
153
154 echo "Running autoreconf..."
155
156 autoreconf ${clean:+-f} -i -I m4 2>| $tempfile
157
158 retval=$?
159
160 ## Annoyingly, autoreconf puts the "installing `./foo' messages on stderr.
161 if [ "$quiet" ]; then
162 grep -v 'installing `\.' $tempfile 1>&2
163 else
164 cat "$tempfile" 1>&2
165 fi
166
167 [ $retval -ne 0 ] && die "autoreconf error"
168
169
170 cp $genfiles autogen/
171
172
173 cd autogen
174
175 echo "Checking status of generated files..."
176
177 bzr status -S $basegen >| $tempfile || \
178 die "bzr status error for generated files"
179
180
181 modified=
182
183 while read stat file; do
184
185 [ "$stat" != "M" ] && die "Unexpected status ($stat) for generated $file"
186
187 modified="$modified $file"
188
189 done < $tempfile
190
191
192 cd ../
193
194
195 ## Uses global $commit.
196 commit ()
197 {
198 local type=$1
199 shift
200
201 [ $# -gt 0 ] || {
202 echo "No files were modified"
203 return 0
204 }
205
206 echo "Modified file(s): $@"
207
208 [ "$commit" ] || return 0
209
210 echo "Committing..."
211
212 ## bzr status output is always relative to top-level, not PWD.
213 bzr commit -m "Auto-commit of $type files." "$@" || return $?
214
215 echo "Committed files: $@"
216 } # function commit
217
218
219 commit "generated" $modified || die "bzr commit error"
220
221
222 [ "$ldefs_flag" ] || exit 0
223
224
225 echo "Finding loaddef targets..."
226
227 sed -n -e '/^AUTOGEN_VCS/,/^$/ s/\\//p' lisp/Makefile.in | \
228 sed '/AUTOGEN_VCS/d' >| $tempfile || die "sed error"
229
230 genfiles=
231
232 while read genfile; do
233
234 [ -r lisp/$genfile ] || die "Unable to read $genfile"
235
236 genfiles="$genfiles $genfile"
237 done < $tempfile
238
239
240 [ "$genfiles" ] || die "Error setting genfiles"
241
242
243 [ -e Makefile ] || {
244 echo "Running ./configure..."
245
246 ./configure || die "configure error"
247 }
248
249
250 ## Build the minimum needed to get the autoloads.
251 echo "Running lib/ make..."
252
253 make -C lib "$@" all || die "make lib error"
254
255
256 echo "Running src/ make..."
257
258 make -C src "$@" bootstrap-emacs || die "make src error"
259
260
261 echo "Running lisp/ make..."
262
263 make -C lisp "$@" autoloads EMACS=../src/bootstrap-emacs || die "make src error"
264
265
266 cp $ldefs_in $ldefs_out || die "cp ldefs_boot error"
267
268
269 cd lisp
270
271 echo "Checking status of loaddef files..."
272
273 ## It probably would be fine to just check+commit lisp/, since
274 ## making autoloads should not effect any other files. But better
275 ## safe than sorry.
276 bzr status -S $genfiles ${ldefs_out#lisp/} >| $tempfile || \
277 die "bzr status error for generated files"
278
279
280 modified=
281
282 while read stat file; do
283
284 [ "$stat" != "M" ] && die "Unexpected status ($stat) for generated $file"
285 modified="$modified $file"
286
287 done < $tempfile
288
289
290 cd ../
291
292
293 commit "loaddefs" $modified || die "bzr commit error"
294
295
296 exit 0
297
298 ### update_autogen ends here