2 ### update_autogen - update some auto-generated files in the Emacs tree
4 ## Copyright (C) 2011-2024 Free Software Foundation, Inc.
6 ## Author: Glenn Morris <rgm@gnu.org>
7 ## Maintainer: Stefan Kangas <stefankangas@gmail.com>
9 ## This file is part of GNU Emacs.
11 ## GNU Emacs is free software: you can redistribute it and/or modify
12 ## it under the terms of the GNU General Public License as published by
13 ## the Free Software Foundation, either version 3 of the License, or
14 ## (at your option) any later version.
16 ## GNU Emacs is distributed in the hope that it will be useful,
17 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ## GNU General Public License for more details.
21 ## You should have received a copy of the GNU General Public License
22 ## along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
26 ## This is a helper script to update some generated files in the Emacs
27 ## repository. This is suitable for running from cron.
28 ## Only Emacs maintainers need use this, so it uses bash features.
30 ## By default, it updates the versioned loaddefs-like files in lisp,
31 ## except ldefs-boot.el.
35 source "${0%/*}/emacs-shell-lib"
37 ## This should be the admin directory.
40 [ -d admin
] || die
"Could not locate admin directory"
42 [ -d .git
] || git rev-parse
--git-dir > /dev
/null
2>&1 || die
"Not in a git repository"
47 Usage: ${PN} [-f] [-c] [-q] [-A dir] [-L] [-C] [-- make-flags]
48 Update some auto-generated files in the Emacs tree.
49 By default, only does the versioned loaddefs-like files in lisp/.
50 This requires a build. Passes any non-option args to make (eg -- -j2).
52 -f: force an update even if the source files are locally modified.
53 -c: if the update succeeds and the generated files are modified,
54 commit them (caution).
55 -q: be quiet; only give error messages, not status messages.
56 -A: only update autotools files, copying into specified dir.
57 -L: also update ldefs-boot.el.
58 -C: start from a clean state. Slower, but more correct.
70 autogendir
= # was "autogen"
75 ldefs_out
=lisp
/ldefs-boot.el
76 sources
="configure.ac lib/Makefile.am"
77 ## Files to copy into autogendir.
80 configure aclocal.m4 src/config.in
81 build-aux/config.guess build-aux/config.sub
85 genfiles
="src/config.in"
88 for g
in $genfiles; do
89 basegen
="$basegen ${g##*/}"
92 [ "$basegen" ] || die
"internal error"
94 tempfile
="$(emacs_mktemp)"
96 while getopts ":hcfqA:CL" option
; do
106 (A
) autogendir
=$OPTARG
107 [ -d "$autogendir" ] || die
"No autogen directory: $autogendir"
114 (\?) die
"Bad option -$OPTARG" ;;
116 (:) die
"Option -$OPTARG requires an argument" ;;
118 (*) die
"getopts error" ;;
121 shift $
(( --OPTIND ))
125 ## Does not work 100% because a lot of Emacs batch output comes on stderr (?).
126 [ "$quiet" ] && exec 1> /dev
/null
129 ## Run status on inputs, list modified files on stdout.
132 git status
-s "$@" >|
$tempfile || die
"git status error for $@"
134 local stat
file modified
137 while read stat
file; do
139 [ "$stat" != "M" ] && \
140 die
"Unexpected status ($stat) for generated $file"
141 modified
="$modified $file"
151 echo "Checking input file status..."
153 ## The lisp portion could be more permissive, eg only care about .el files.
154 modified
=$
(status
${autogendir:+$sources} ${ldefs_flag:+lisp}) || die
157 echo "Locally modified: $modified"
158 [ "$force" ] || die
"There are local modifications"
162 ## Probably this is overkill, and there's no need to "bootstrap" just
163 ## for making autoloads.
166 echo "Running 'make maintainer-clean'..."
168 make maintainer-clean
#|| die "Cleaning error"
172 echo "Running autoreconf..."
174 autoreconf
${clean:+-f} -i -I m4 2>|
$tempfile
178 ## Annoyingly, autoreconf puts the "installing `./foo' messages on stderr.
179 if [ "$quiet" ]; then
180 grep -v 'installing `\.' $tempfile 1>&2
185 [ $retval -ne 0 ] && die
"autoreconf error"
188 ## Uses global $commit.
195 echo "No files were modified"
199 echo "Modified file(s): $@"
201 [ "$commit" ] ||
return 0
205 git commit
-m "; Auto-commit of $type files." "$@" ||
return $?
207 ## In case someone else pushed something while we were working.
208 git pull
--rebase ||
return $?
209 git push ||
return $?
211 echo "Committed files: $@"
215 [ "$autogendir" ] && {
217 cp $genfiles $autogendir/
219 cd $autogendir || die
"cd error for $autogendir"
221 echo "Checking status of generated files..."
223 modified
=$
(status
$basegen) || die
225 commit
"generated" $modified || die
"commit error"
231 [ "$ldefs_flag" ] ||
exit 0
234 echo "Finding loaddef targets..."
236 find lisp
-name '*.el' -exec grep '^;.*generated-autoload-file:' {} + | \
237 sed -e '/loaddefs\|esh-groups/d' -e 's|/[^/]*: "|/|' -e 's/"//g' \
238 >|
$tempfile || die
"Error finding targets"
242 while read genfile
; do
244 ## Or we can just use sort -u when making tempfile...
245 case " $genfiles " in
246 *" $genfile "*) continue ;;
249 [ -r $genfile ] || die
"Unable to read $genfile"
251 genfiles
="$genfiles $genfile"
255 [ "$genfiles" ] || die
"Error setting genfiles"
259 echo "Running ./configure..."
261 ## Minimize required packages.
262 .
/configure
--without-x || die
"configure error"
266 ## Build the minimum needed to get the autoloads.
267 echo "Running lib/ make..."
269 make -C lib
"$@" all || die
"make lib error"
272 echo "Running src/ make..."
274 make -C src
"$@" bootstrap-emacs || die
"make src error"
277 echo "Running lisp/ make..."
279 make -C lisp
"$@" ldefs-boot.el EMACS
=..
/src
/bootstrap-emacs || die
"make src error"
282 # Refresh the prebuilt grammar-wy.el
283 grammar_in
=lisp
/cedet
/semantic
/grammar-wy.el
284 grammar_out
=lisp
/cedet
/semantic
/grm-wy-boot.el
285 make -C admin
/grammars
/ ..
/..
/$grammar_in EMACS
=..
/..
/src
/bootstrap-emacs
286 cp $grammar_in $grammar_out || die
"cp grm_wy_boot error"
289 echo "Checking status of loaddef files..."
291 ## It probably would be fine to just check+commit lisp/, since
292 ## making autoloads should not effect any other files. But better
294 modified
=$
(status
$genfiles $ldefs_out $grammar_out) || die
297 commit
"loaddefs" $modified || die
"commit error"