Fix Android build
[emacs.git] / admin / update_autogen
blob224d6c66eededf0f716f2d812d8b5363f55b089b
1 #!/usr/bin/env bash
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/>.
24 ### Commentary:
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.
33 ### Code:
35 source "${0%/*}/emacs-shell-lib"
37 ## This should be the admin directory.
38 cd $PD || exit
39 cd ../
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"
44 usage ()
46 cat 1>&2 <<EOF
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).
51 Options:
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.
59 EOF
60 exit 1
64 ## Defaults.
66 force=
67 commit=
68 quiet=
69 clean=
70 autogendir= # was "autogen"
71 ldefs_flag=1
72 lboot_flag=
74 ## Parameters.
75 ldefs_out=lisp/ldefs-boot.el
76 sources="configure.ac lib/Makefile.am"
77 ## Files to copy into autogendir.
78 ## Everything:
79 genfiles="
80 configure aclocal.m4 src/config.in
81 build-aux/config.guess build-aux/config.sub
82 build-aux/install-sh
84 ## msdos-only:
85 genfiles="src/config.in"
87 basegen=""
88 for g in $genfiles; do
89 basegen="$basegen ${g##*/}"
90 done
92 [ "$basegen" ] || die "internal error"
94 tempfile="$(emacs_mktemp)"
96 while getopts ":hcfqA:CL" option ; do
97 case $option in
98 (h) usage ;;
100 (c) commit=1 ;;
102 (f) force=1 ;;
104 (q) quiet=1 ;;
106 (A) autogendir=$OPTARG
107 [ -d "$autogendir" ] || die "No autogen directory: $autogendir"
110 (C) clean=1 ;;
112 (L) lboot_flag=1 ;;
114 (\?) die "Bad option -$OPTARG" ;;
116 (:) die "Option -$OPTARG requires an argument" ;;
118 (*) die "getopts error" ;;
119 esac
120 done
121 shift $(( --OPTIND ))
122 OPTIND=1
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.
130 status ()
132 git status -s "$@" >| $tempfile || die "git status error for $@"
134 local stat file modified
136 modified=""
137 while read stat file; do
139 [ "$stat" != "M" ] && \
140 die "Unexpected status ($stat) for generated $file"
141 modified="$modified $file"
143 done < $tempfile
145 echo "$modified"
147 return 0
148 } # function status
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
156 [ "$modified" ] && {
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.
164 [ "$clean" ] && {
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
176 retval=$?
178 ## Annoyingly, autoreconf puts the "installing `./foo' messages on stderr.
179 if [ "$quiet" ]; then
180 grep -v 'installing `\.' $tempfile 1>&2
181 else
182 cat "$tempfile" 1>&2
185 [ $retval -ne 0 ] && die "autoreconf error"
188 ## Uses global $commit.
189 commit ()
191 local type=$1
192 shift
194 [ $# -gt 0 ] || {
195 echo "No files were modified"
196 return 0
199 echo "Modified file(s): $@"
201 [ "$commit" ] || return 0
203 echo "Committing..."
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: $@"
212 } # function commit
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"
227 exit 0
228 } # $autogendir
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"
240 genfiles=
242 while read genfile; do
244 ## Or we can just use sort -u when making tempfile...
245 case " $genfiles " in
246 *" $genfile "*) continue ;;
247 esac
249 [ -r $genfile ] || die "Unable to read $genfile"
251 genfiles="$genfiles $genfile"
252 done < $tempfile
255 [ "$genfiles" ] || die "Error setting genfiles"
258 [ -e Makefile ] || {
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
293 ## safe than sorry.
294 modified=$(status $genfiles $ldefs_out $grammar_out) || die
297 commit "loaddefs" $modified || die "commit error"
300 exit 0