Script for synchronizing with gnulib
Showing
1 changed file
with
356 additions
and
0 deletions
scripts/gnulib-sync
0 → 100755
1 | #! /bin/sh | ||
2 | # Copyright (C) 2005 Free Software Foundation, Inc. | ||
3 | # | ||
4 | # GNU Mailutils is free software; you can redistribute it and/or | ||
5 | # modify it under the terms of the GNU General Public License as | ||
6 | # published by the Free Software Foundation; either version 2, or (at | ||
7 | # your option) any later version. | ||
8 | # | ||
9 | # This program is distributed in the hope that it will be useful, but | ||
10 | # WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | # General Public License for more details. | ||
13 | # | ||
14 | # You should have received a copy of the GNU General Public License | ||
15 | # along with this program; if not, write to the Free Software | ||
16 | # Foundation, Inc. | ||
17 | # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | |||
19 | LC_ALL=C | ||
20 | export LC_ALL | ||
21 | CVSFILES=cvsfiles.$$ | ||
22 | CHANGELOG=changelog.$$ | ||
23 | |||
24 | usage() { | ||
25 | cat <<-EOF | ||
26 | usage: $0 GNULIB-DIR | ||
27 | $0 synchronizes mailutils library with gnulib. | ||
28 | |||
29 | GNULIB-DIR is the directory where gnulib sources reside. The program | ||
30 | reads file gnulib.modules, populates the mailutils tree with the | ||
31 | necessary files from GNULIB-DIR and updates Makefile.am-s. | ||
32 | |||
33 | Options: | ||
34 | |||
35 | --verbose Display every operation | ||
36 | --dry-run Do not do anything, just print what would have been done | ||
37 | --help Display this help list | ||
38 | |||
39 | EOF | ||
40 | } | ||
41 | |||
42 | error() { | ||
43 | echo $* >&2 | ||
44 | echo "Try $0 --help for more information" >&2 | ||
45 | exit 1 | ||
46 | } | ||
47 | |||
48 | DRY_RUN= | ||
49 | VERBOSE= | ||
50 | while [ $# -ne 0 ] | ||
51 | do | ||
52 | case $1 in | ||
53 | --help) | ||
54 | usage | ||
55 | exit 0;; | ||
56 | --dry-run) | ||
57 | DRY_RUN=1; shift;; | ||
58 | --verbose) | ||
59 | VERBOSE=1; shift;; | ||
60 | --*) | ||
61 | echo >&2 "$0: $1: unknown option" | ||
62 | exit 1;; | ||
63 | *) | ||
64 | break;; | ||
65 | esac | ||
66 | done | ||
67 | |||
68 | if [ $# -ne 1 ]; then | ||
69 | error "Wrong number of arguments" | ||
70 | fi | ||
71 | |||
72 | GNULIB_SRCDIR=$1 | ||
73 | |||
74 | |||
75 | # Check the correctness of the invocation | ||
76 | |||
77 | if [ -r configure.ac ]; then | ||
78 | if grep -q 'AC_INIT(\[GNU Mailutils' configure.ac; then | ||
79 | : | ||
80 | else | ||
81 | error "This does not seem a mailutils package." | ||
82 | fi | ||
83 | else | ||
84 | error "Cannot find configure.ac" | ||
85 | fi | ||
86 | |||
87 | if [ -r gnulib.modules ]; then | ||
88 | : | ||
89 | else | ||
90 | error "gnulib.modules does not exist." | ||
91 | exit 1 | ||
92 | fi | ||
93 | |||
94 | if [ -d $GNULIB_SRCDIR ]; then | ||
95 | : | ||
96 | else | ||
97 | echo "$GNULIB_SRCDIR: not found or is not a directory" >&2 | ||
98 | exit 1 | ||
99 | fi | ||
100 | |||
101 | <$GNULIB_SRCDIR/gnulib-tool || error "gnulib-tool is not present?!?" | ||
102 | |||
103 | ##################### | ||
104 | ## Functions | ||
105 | ##################### | ||
106 | |||
107 | get_modules() { | ||
108 | while read NAME | ||
109 | do | ||
110 | case $NAME in | ||
111 | "") ;; | ||
112 | \#*) ;; | ||
113 | :*) variable=`echo $NAME | cut -c2-` | ||
114 | case $variable in | ||
115 | lib|mailbox) ;; | ||
116 | *) echo "Unknown variable $variable" >&2 | ||
117 | exit 1;; | ||
118 | esac;; | ||
119 | *) eval ${variable}_modules=\"\$${variable}_modules $NAME\" | ||
120 | esac | ||
121 | done < $1 | ||
122 | } | ||
123 | |||
124 | expand_modules() { | ||
125 | eval gnulib_modules="\$${1}" | ||
126 | gnulib_modules="`echo $gnulib_modules | sort -u -`" | ||
127 | previous_gnulib_modules= | ||
128 | while [ "$gnulib_modules" != "$previous_gnulib_modules" ] | ||
129 | do | ||
130 | previous_gnulib_modules=$gnulib_modules | ||
131 | gnulib_modules=`(echo "$gnulib_modules" | ||
132 | for module in $gnulib_modules; do | ||
133 | $GNULIB_SRCDIR/gnulib-tool --extract-dependencies $module | ||
134 | done) | sort -u | ||
135 | ` | ||
136 | done | ||
137 | eval ${1}=\"$gnulib_modules\" | ||
138 | } | ||
139 | |||
140 | verbose() { | ||
141 | [ -n "$VERBOSE" ] && echo $* | ||
142 | } | ||
143 | |||
144 | do_copy() { | ||
145 | case $1 in | ||
146 | *.m4) verbose "${3:-Copying} $1 to $2" | ||
147 | if [ -z "$DRY_RUN" ]; then | ||
148 | if [ -n "$3" ]; then | ||
149 | sed "$3" $1 > $2 || exit | ||
150 | else | ||
151 | cp $1 $2 || exit | ||
152 | fi | ||
153 | fi;; | ||
154 | *) verbose "Copying $1 to $2" | ||
155 | if [ -z "$DRY_RUN" ]; then | ||
156 | cp $1 $2 || exit | ||
157 | fi;; | ||
158 | esac | ||
159 | echo $2 >> $CVSFILES | ||
160 | } | ||
161 | |||
162 | # copy_files dir | ||
163 | copy_files() { | ||
164 | eval list="\$${1}_modules" | ||
165 | files=`$GNULIB_SRCDIR/gnulib-tool --extract-filelist $list | sort -u` | ||
166 | |||
167 | echo "$files" | sed 's,/[^/]*$,,' | sort -u | | ||
168 | sed "s/lib/$1/;s/config/scripts/" | | ||
169 | while read DIR | ||
170 | do | ||
171 | if [ -d $DIR ]; then | ||
172 | : | ||
173 | else | ||
174 | echo "Directory $DIR does not exist!" >&2 | ||
175 | echo "Update gnulib-sync script!" >&2 | ||
176 | exit 1 | ||
177 | fi | ||
178 | done | ||
179 | |||
180 | for file in $files | ||
181 | do | ||
182 | dest=`echo $file | sed "s/lib/$1/;s/config\//scripts\//"` | ||
183 | |||
184 | case $file in | ||
185 | m4/codeset.m4) continue;; | ||
186 | m4/intdiv0.m4) continue;; | ||
187 | m4/inttypes-pri.m4) continue;; | ||
188 | m4/isc-posix.m4) continue;; | ||
189 | m4/lcmessage.m4) continue;; | ||
190 | m4/onceonly_2_57.m4) dest=m4/onceonly.m4;; | ||
191 | # These will be overwritten by autopoint, which still uses | ||
192 | # old jm_.* macro names, so we have to keep both copies. | ||
193 | m4/gettext.m4 | m4/glibc21.m4 | m4/inttypes_h.m4 | m4/lib-ld.m4 | \ | ||
194 | m4/lib-prefix.m4 | m4/po.m4 | m4/stdint_h.m4 | m4/uintmax_t.m4 | \ | ||
195 | m4/longlong.m4 | m4/ulonglong.m4) | ||
196 | dest=`expr $file : '\(.*\).m4'`_gl.m4;; | ||
197 | esac | ||
198 | |||
199 | rm -f $dest && | ||
200 | do_copy $GNULIB_SRCDIR/$file $dest $2 | ||
201 | done | ||
202 | } | ||
203 | |||
204 | create_m4_wrapper() { | ||
205 | (eval list="\$${1}_modules" | ||
206 | if [ $# -eq 1 ]; then | ||
207 | libname=lib$1 | ||
208 | else | ||
209 | libname=$2 | ||
210 | fi | ||
211 | echo "AC_DEFUN([${libname}_GNULIB],[" | ||
212 | for module in $list | ||
213 | do | ||
214 | echo "# $module" | ||
215 | $GNULIB_SRCDIR/gnulib-tool --extract-autoconf-snippet $module | ||
216 | done | ||
217 | echo "])") | sed '/AM_GNU_GETTEXT/d' | ||
218 | } | ||
219 | |||
220 | update_makefile_am() { | ||
221 | eval list="\$${1}_modules" | ||
222 | if [ $# -eq 1 ]; then | ||
223 | libname=lib$1 | ||
224 | else | ||
225 | libname=$2 | ||
226 | fi | ||
227 | cat $1/Makefile.am | sed '/##:##.*##:##/,$d' | ||
228 | echo "##:## EOF marker for gnulib-sync script. Please, do not remove ##:##" | ||
229 | echo "## Do not change anything below this line ##" | ||
230 | $GNULIB_SRCDIR/gnulib-tool --extract-automake-snippet $list | | ||
231 | sed "s/lib_/${libname}_la_/g" | ||
232 | } | ||
233 | |||
234 | # Update EXTRA_DIST variables based on MU_LIBSOURCES and MU_LIBOBJ | ||
235 | # FIXME: This needs cleaning up. First, the output list should be | ||
236 | # filtered through `sort -u'. Secondly, the actual value of EXTRA_DIST | ||
237 | # must be considered too. | ||
238 | update_extra_dist() { | ||
239 | file=$1/Makefile.am | ||
240 | shift | ||
241 | |||
242 | # The following sed program does not work: s/[\[\]]//g. A bug in sed? | ||
243 | # | ||
244 | find m4 -name '*.m4' -not -name mu_libobj.m4 | | ||
245 | xargs sed -n \ | ||
246 | '/MU_LIBSOURCES/{s/,//g;s/.*MU_LIBSOURCES *( *\[\(.*\)\]).*/\1/p;};/MU_LIBOBJ/{s/\[//g;s/\]//g;s/.*MU_LIBOBJ *(\(.*\)).*/\1.c/p;};/MU_REPLACE_FUNCS/{s/\[//g;s/\]//g;s/.*MU_REPLACE_FUNCS *(\(.*\)).*/\1.c/p;}' | | ||
247 | (EXTRA_DIST= | ||
248 | while read NAME; do EXTRA_DIST="$EXTRA_DIST $NAME"; done | ||
249 | if [ -n "$EXTRA_DIST" ]; then | ||
250 | echo "EXTRA_DIST +=$EXTRA_DIST" | ||
251 | fi) | ||
252 | } | ||
253 | |||
254 | cvs_commands() { | ||
255 | echo "<<<<<< Update by gnulib-sync. Please edit before applying" > $CHANGELOG | ||
256 | echo "" >> $CHANGELOG | ||
257 | |||
258 | echo "# CVS commands generated by gnulib-sync at `date`" | ||
259 | echo "# Please edit before applying" | ||
260 | |||
261 | sort $CVSFILES | | ||
262 | while read NAME | ||
263 | do | ||
264 | dir=`expr $NAME : '\(.*\)/.*'` | ||
265 | name=`expr $NAME : '.*/\(.*\)'` | ||
266 | if [ -r $dir/CVS/Entries ]; then | ||
267 | if grep -q $name $dir/CVS/Entries; then | ||
268 | comment="Updated" | ||
269 | else | ||
270 | comment="Added to the repository" | ||
271 | echo "cvs add $NAME" | ||
272 | fi | ||
273 | echo "cvs commit -m '$comment by gnulib-sync' $NAME" | ||
274 | echo " * $NAME: $comment" >> $CHANGELOG | ||
275 | fi | ||
276 | done | ||
277 | echo ">>>>>>" >> $CHANGELOG | ||
278 | } | ||
279 | |||
280 | cleanup() { | ||
281 | rm -f $CVSFILES $CHANGELOG | ||
282 | } | ||
283 | |||
284 | ##################### | ||
285 | ## OK, let's start! | ||
286 | ##################### | ||
287 | |||
288 | cat /dev/null > $CVSFILES | ||
289 | trap cleanup 1 2 13 15 | ||
290 | |||
291 | get_modules gnulib.modules | ||
292 | |||
293 | expand_modules lib_modules | ||
294 | expand_modules mailbox_modules | ||
295 | |||
296 | MODLIST= | ||
297 | for mod in $lib_modules | ||
298 | do | ||
299 | if echo "$mailbox_modules" | grep -q " $mod " -; then | ||
300 | : | ||
301 | else | ||
302 | MODLIST="$MODLIST $mod" | ||
303 | fi | ||
304 | done | ||
305 | |||
306 | lib_modules=`echo $MODLIST | sort -u` | ||
307 | mailbox_modules=`echo $mailbox_modules | sort -u` | ||
308 | |||
309 | copy_files lib | ||
310 | copy_files mailbox 's/AC_LIBSOURCES/MU_LIBSOURCES/;s/AC_REPLACE_FUNCS/MU_REPLACE_FUNCS/;s/AC_LIBOBJ/MU_LIBOBJ/' | ||
311 | |||
312 | if [ -n "$DRY_RUN" ]; then | ||
313 | echo "-----BEGIN gnulib.m4 FILE-----" | ||
314 | create_m4_wrapper lib mailutils | ||
315 | create_m4_wrapper mailbox | ||
316 | echo "-----END gnulib.m4 FILE-----" | ||
317 | echo "" | ||
318 | echo "-----BEGIN lib/Makefile.am FILE-----" | ||
319 | update_makefile_am lib libmailutils | ||
320 | echo "-----END lib/Makefile.am FILE-----" | ||
321 | echo "" | ||
322 | echo "-----BEGIN mailbox/Makefile.am FILE-----" | ||
323 | update_makefile_am mailbox | ||
324 | update_extra_dist mailbox m4/*.m4 | ||
325 | echo "-----END mailbox/Makefile.am FILE-----" | ||
326 | echo "-----BEGIN CVS COMMANDS-----" | ||
327 | cvs_commands | ||
328 | echo "-----END CVS COMMANDS-----" | ||
329 | echo "-----BEGIN ChangeLog ENTRY-----" | ||
330 | cat $CHANGELOG | ||
331 | echo "-----END ChangeLog ENTRY-----" | ||
332 | else | ||
333 | verbose "Creating gnulib.m4" | ||
334 | (echo "# This file is generated automatically. Please, do not edit." | ||
335 | echo "#" | ||
336 | create_m4_wrapper lib libmailutils | ||
337 | create_m4_wrapper mailbox) > m4/gnulib.m4 | ||
338 | |||
339 | verbose "Creating lib/Makefile.am" | ||
340 | update_makefile_am lib libmailutils > lib/Makefile.am.$$ | ||
341 | mv lib/Makefile.am.$$ lib/Makefile.am | ||
342 | |||
343 | verbose "Creating mailbox/Makefile.am" | ||
344 | (update_makefile_am mailbox | ||
345 | update_extra_dist mailbox m4/*.m4) > mailbox/Makefile.am.$$ | ||
346 | mv mailbox/Makefile.am.$$ mailbox/Makefile.am | ||
347 | |||
348 | cvs_commands > gnulib.cvs | ||
349 | mv $CHANGELOG gnulib.changelog | ||
350 | echo "See gnulib.cvs and gnulib.changelog" | ||
351 | fi | ||
352 | |||
353 | cleanup | ||
354 | |||
355 | exit 0 | ||
356 |
-
Please register or sign in to post a comment