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