aboutsummaryrefslogtreecommitdiffstats
path: root/autogen/update_autogen
diff options
context:
space:
mode:
Diffstat (limited to 'autogen/update_autogen')
-rwxr-xr-xautogen/update_autogen183
1 files changed, 183 insertions, 0 deletions
diff --git a/autogen/update_autogen b/autogen/update_autogen
new file mode 100755
index 00000000000..0b26dd27d2b
--- /dev/null
+++ b/autogen/update_autogen
@@ -0,0 +1,183 @@
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.
28
29### Code:
30
31function die () # write error to stderr and exit
32{
33 [ $# -gt 0 ] && echo "$PN: $@" >&2
34 exit 1
35}
36
37PN=${0##*/} # basename of script
38PD=${0%/*}
39
40[ "$PD" = "$0" ] && PD=. # if PATH includes PWD
41
42## This should be the autogen directory.
43cd $PD
44cd ../
45[ -d autogen ] || die "Could not locate autogen directory"
46
47
48function usage ()
49{
50 cat 1>&2 <<EOF
51Usage: ${PN} [-f] [-c] [-q]
52Update the generated files in the Emacs autogen/ directory.
53Options:
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.
58EOF
59 exit 1
60}
61
62
63## Defaults.
64
65force=
66commit=
67quiet=
68
69## Parameters.
70sources="configure.in lib/Makefile.am"
71genfiles="configure aclocal.m4 src/config.in lib/Makefile.in"
72
73for g in $genfiles; do
74 basegen="$basegen ${g##*/}"
75done
76
77[ "$basegen" ] || die "internal error"
78
79tempfile=/tmp/$PN.$$
80
81trap "rm -f $tempfile 2> /dev/null" EXIT
82
83
84while getopts ":hcfq" option ; do
85 case $option in
86 (h) usage ;;
87
88 (c) commit=1 ;;
89
90 (f) force=1 ;;
91
92 (q) quiet=1 ;;
93
94 (\?) die "Bad option -$OPTARG" ;;
95
96 (:) die "Option -$OPTARG requires an argument" ;;
97
98 (*) die "getopts error" ;;
99 esac
100done
101shift $(( --OPTIND ))
102OPTIND=1
103
104[ $# -eq 0 ] || die "Wrong number of arguments"
105
106
107function msg ()
108{
109 [ "$quiet" ] && return 0
110 echo "$@"
111} # function msg
112
113
114msg "Running bzr status..."
115
116bzr status -S $sources >| $tempfile || die "bzr status error for sources"
117
118while read stat file; do
119
120 case $stat in
121 M)
122 msg "Locally modified: $file"
123 [ "$force" ] || die "There are local modifications"
124 ;;
125
126 *) die "Unexpected status ($stat) for $file" ;;
127 esac
128done < $tempfile
129
130
131msg "Running autoreconf..."
132
133autoreconf -I m4 || die "autoreconf error"
134
135
136cp $genfiles autogen/
137
138
139cd autogen
140
141
142bzr status -S $basegen >| $tempfile || \
143 die "bzr status error for generated files"
144
145
146modified=
147
148while read stat file; do
149
150 [ "$stat" != "M" ] && die "Unexpected status ($stat) for generated $file"
151
152 modified="$modified $file"
153
154done < $tempfile
155
156
157[ "$modified" ] || {
158 msg "No files were modified"
159 exit 0
160}
161
162msg "Modified file(s): $modified"
163
164[ "$commit" ] || exit 0
165
166
167msg "Committing..."
168
169## bzr status output is annoyingly always relative to top-level, not PWD.
170cd ../
171
172opt=
173[ "$quiet" ] || opt=-q
174
175bzr commit $opt -m "Auto-commit of generated files." $modified || \
176 die "bzr commit error"
177
178
179msg "Committed files: $modified"
180
181exit
182
183### update_autogen ends here