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