international/mule.el (set-keyboard-coding-system): Recover input meta mode when...
[bpt/emacs.git] / autogen / update_autogen
CommitLineData
66b87493
GM
1#!/bin/bash
2### update_autogen - update the generated files in Emacs autogen/ directory
3
acaf905b 4## Copyright (C) 2011-2012 Free Software Foundation, Inc.
66b87493
GM
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.
c0274801
GM
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.
66b87493
GM
31
32### Code:
33
9ee0d174 34die () # write error to stderr and exit
66b87493
GM
35{
36 [ $# -gt 0 ] && echo "$PN: $@" >&2
37 exit 1
38}
39
40PN=${0##*/} # basename of script
41PD=${0%/*}
42
43[ "$PD" = "$0" ] && PD=. # if PATH includes PWD
44
45## This should be the autogen directory.
46cd $PD
47cd ../
48[ -d autogen ] || die "Could not locate autogen directory"
49
50
9ee0d174 51usage ()
66b87493
GM
52{
53 cat 1>&2 <<EOF
11043dbd 54Usage: ${PN} [-f] [-c] [-q] [-l [-L]] [-C] [-- make-flags]
66b87493
GM
55Update the generated files in the Emacs autogen/ directory.
56Options:
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.
c0274801
GM
61-l: also update the versioned loaddefs-like files in lisp/.
62This requires a build. Passes any non-option args to make (eg -- -j2).
11043dbd 63-L: also update ldefs-boot.el.
c0274801 64-C: start from a clean state. Slower, but more correct.
66b87493
GM
65EOF
66 exit 1
67}
68
69
70## Defaults.
71
72force=
73commit=
74quiet=
c0274801
GM
75clean=
76ldefs_flag=
11043dbd 77lboot_flag=
66b87493
GM
78
79## Parameters.
c0274801
GM
80ldefs_in=lisp/loaddefs.el
81ldefs_out=lisp/ldefs-boot.el
c4444d16 82sources="configure.ac lib/Makefile.am"
74b880cb
PE
83genfiles="
84 configure aclocal.m4 src/config.in lib/Makefile.in
85 build-aux/compile build-aux/config.guess build-aux/config.sub
86 build-aux/depcomp build-aux/install-sh build-aux/missing
87"
66b87493
GM
88
89for g in $genfiles; do
90 basegen="$basegen ${g##*/}"
91done
92
93[ "$basegen" ] || die "internal error"
94
95tempfile=/tmp/$PN.$$
96
97trap "rm -f $tempfile 2> /dev/null" EXIT
98
99
11043dbd 100while getopts ":hcflqCL" option ; do
66b87493
GM
101 case $option in
102 (h) usage ;;
103
104 (c) commit=1 ;;
105
106 (f) force=1 ;;
107
c0274801
GM
108 (l) ldefs_flag=1 ;;
109
66b87493
GM
110 (q) quiet=1 ;;
111
c0274801
GM
112 (C) clean=1 ;;
113
11043dbd
GM
114 (L) lboot_flag=1 ;;
115
66b87493
GM
116 (\?) die "Bad option -$OPTARG" ;;
117
118 (:) die "Option -$OPTARG requires an argument" ;;
119
120 (*) die "getopts error" ;;
121 esac
122done
123shift $(( --OPTIND ))
124OPTIND=1
125
66b87493 126
c0274801 127## Does not work 100% because a lot of Emacs batch output comes on stderr (?).
904a432c 128[ "$quiet" ] && exec 1> /dev/null
66b87493
GM
129
130
904a432c 131echo "Running bzr status..."
66b87493 132
c0274801
GM
133bzr status -S $sources ${ldefs_flag:+lisp} >| $tempfile || \
134 die "bzr status error for sources"
66b87493 135
c0274801 136## The lisp portion could be more permissive, eg only care about .el files.
66b87493
GM
137while read stat file; do
138
139 case $stat in
140 M)
904a432c 141 echo "Locally modified: $file"
66b87493
GM
142 [ "$force" ] || die "There are local modifications"
143 ;;
144
145 *) die "Unexpected status ($stat) for $file" ;;
146 esac
147done < $tempfile
148
149
c0274801
GM
150## Probably this is overkill, and there's no need to "bootstrap" just
151## for making autoloads.
152[ "$clean" ] && {
153
154 echo "Running 'make maintainer-clean'..."
155
156 make maintainer-clean #|| die "Cleaning error"
157
158 rm -f $ldefs_in
159}
160
161
904a432c 162echo "Running autoreconf..."
66b87493 163
c0274801 164autoreconf ${clean:+-f} -i -I m4 2>| $tempfile
f6ca84c0
GM
165
166retval=$?
167
168## Annoyingly, autoreconf puts the "installing `./foo' messages on stderr.
169if [ "$quiet" ]; then
170 grep -v 'installing `\.' $tempfile 1>&2
171else
172 cat "$tempfile" 1>&2
173fi
174
175[ $retval -ne 0 ] && die "autoreconf error"
66b87493
GM
176
177
178cp $genfiles autogen/
179
180
181cd autogen
182
904a432c 183echo "Checking status of generated files..."
66b87493
GM
184
185bzr status -S $basegen >| $tempfile || \
186 die "bzr status error for generated files"
187
188
189modified=
190
191while read stat file; do
192
193 [ "$stat" != "M" ] && die "Unexpected status ($stat) for generated $file"
194
195 modified="$modified $file"
196
197done < $tempfile
198
199
c0274801
GM
200cd ../
201
202
203## Uses global $commit.
204commit ()
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
227commit "generated" $modified || die "bzr commit error"
228
229
230[ "$ldefs_flag" ] || exit 0
231
232
233echo "Finding loaddef targets..."
234
235sed -n -e '/^AUTOGEN_VCS/,/^$/ s/\\//p' lisp/Makefile.in | \
236 sed '/AUTOGEN_VCS/d' >| $tempfile || die "sed error"
237
238genfiles=
239
240while read genfile; do
241
242 [ -r lisp/$genfile ] || die "Unable to read $genfile"
243
244 genfiles="$genfiles $genfile"
245done < $tempfile
246
247
248[ "$genfiles" ] || die "Error setting genfiles"
249
250
251[ -e Makefile ] || {
252 echo "Running ./configure..."
253
4cfacdd0
GM
254 ## Minimize required packages.
255 ./configure --without-x || die "configure error"
66b87493
GM
256}
257
66b87493 258
c0274801
GM
259## Build the minimum needed to get the autoloads.
260echo "Running lib/ make..."
261
262make -C lib "$@" all || die "make lib error"
263
264
265echo "Running src/ make..."
266
267make -C src "$@" bootstrap-emacs || die "make src error"
268
269
270echo "Running lisp/ make..."
271
272make -C lisp "$@" autoloads EMACS=../src/bootstrap-emacs || die "make src error"
273
274
5fac7083
GM
275## Ignore comment differences.
276[ ! "$lboot_flag" ] || \
277 diff -q -I '^;' $ldefs_in $ldefs_out || \
278 cp $ldefs_in $ldefs_out || die "cp ldefs_boot error"
66b87493
GM
279
280
c0274801
GM
281cd lisp
282
283echo "Checking status of loaddef files..."
284
285## It probably would be fine to just check+commit lisp/, since
286## making autoloads should not effect any other files. But better
287## safe than sorry.
288bzr status -S $genfiles ${ldefs_out#lisp/} >| $tempfile || \
289 die "bzr status error for generated files"
290
291
292modified=
293
294while read stat file; do
295
296 [ "$stat" != "M" ] && die "Unexpected status ($stat) for generated $file"
297 modified="$modified $file"
298
299done < $tempfile
300
66b87493 301
66b87493
GM
302cd ../
303
66b87493 304
c0274801 305commit "loaddefs" $modified || die "bzr commit error"
66b87493 306
66b87493 307
c0274801 308exit 0
66b87493
GM
309
310### update_autogen ends here