Fix ChangeLog typo.
[emacs.git] / autogen / update_autogen
blob0b26dd27d2b5a3c9c59424f08dcc6643476337f2
1 #!/bin/bash
2 ### update_autogen - update the generated files in Emacs autogen/ directory
4 ## Copyright (C) 2011 Free Software Foundation, Inc.
6 ## Author: Glenn Morris <rgm@gnu.org>
8 ## This file is part of GNU Emacs.
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.
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.
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/>.
23 ### Commentary:
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.
29 ### Code:
31 function die () # write error to stderr and exit
33 [ $# -gt 0 ] && echo "$PN: $@" >&2
34 exit 1
37 PN=${0##*/} # basename of script
38 PD=${0%/*}
40 [ "$PD" = "$0" ] && PD=. # if PATH includes PWD
42 ## This should be the autogen directory.
43 cd $PD
44 cd ../
45 [ -d autogen ] || die "Could not locate autogen directory"
48 function usage ()
50 cat 1>&2 <<EOF
51 Usage: ${PN} [-f] [-c] [-q]
52 Update the generated files in the Emacs autogen/ directory.
53 Options:
54 -f: force an update even if the source files are locally modified.
55 -c: if the update succeeds and the generated files are modified,
56 commit them (caution).
57 -q: be quiet; only give error messages, not status messages.
58 EOF
59 exit 1
63 ## Defaults.
65 force=
66 commit=
67 quiet=
69 ## Parameters.
70 sources="configure.in lib/Makefile.am"
71 genfiles="configure aclocal.m4 src/config.in lib/Makefile.in"
73 for g in $genfiles; do
74 basegen="$basegen ${g##*/}"
75 done
77 [ "$basegen" ] || die "internal error"
79 tempfile=/tmp/$PN.$$
81 trap "rm -f $tempfile 2> /dev/null" EXIT
84 while getopts ":hcfq" option ; do
85 case $option in
86 (h) usage ;;
88 (c) commit=1 ;;
90 (f) force=1 ;;
92 (q) quiet=1 ;;
94 (\?) die "Bad option -$OPTARG" ;;
96 (:) die "Option -$OPTARG requires an argument" ;;
98 (*) die "getopts error" ;;
99 esac
100 done
101 shift $(( --OPTIND ))
102 OPTIND=1
104 [ $# -eq 0 ] || die "Wrong number of arguments"
107 function msg ()
109 [ "$quiet" ] && return 0
110 echo "$@"
111 } # function msg
114 msg "Running bzr status..."
116 bzr status -S $sources >| $tempfile || die "bzr status error for sources"
118 while read stat file; do
120 case $stat in
122 msg "Locally modified: $file"
123 [ "$force" ] || die "There are local modifications"
126 *) die "Unexpected status ($stat) for $file" ;;
127 esac
128 done < $tempfile
131 msg "Running autoreconf..."
133 autoreconf -I m4 || die "autoreconf error"
136 cp $genfiles autogen/
139 cd autogen
142 bzr status -S $basegen >| $tempfile || \
143 die "bzr status error for generated files"
146 modified=
148 while read stat file; do
150 [ "$stat" != "M" ] && die "Unexpected status ($stat) for generated $file"
152 modified="$modified $file"
154 done < $tempfile
157 [ "$modified" ] || {
158 msg "No files were modified"
159 exit 0
162 msg "Modified file(s): $modified"
164 [ "$commit" ] || exit 0
167 msg "Committing..."
169 ## bzr status output is annoyingly always relative to top-level, not PWD.
170 cd ../
172 opt=
173 [ "$quiet" ] || opt=-q
175 bzr commit $opt -m "Auto-commit of generated files." $modified || \
176 die "bzr commit error"
179 msg "Committed files: $modified"
181 exit
183 ### update_autogen ends here