* lib/m4sugar/Makefile.am (version.m4): Another bash bug workaround.
[autoconf/tsuna.git] / config / announce-gen
blobfec3df82aa1ec1a0f35111a052c3dd92d861f725
1 #!/usr/bin/perl -w
2 # Generate an announcement message.
4 # Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 use strict;
21 use Getopt::Long;
22 use Digest::MD5;
23 use Digest::SHA1;
25 (my $VERSION = '$Revision$ ') =~ tr/[0-9].//cd;
26 (my $ME = $0) =~ s|.*/||;
28 my %valid_release_types = map {$_ => 1} qw (alpha beta major);
30 END
32 # Nobody ever checks the status of print()s. That's okay, because
33 # if any do fail, we're guaranteed to get an indicator when we close()
34 # the filehandle.
36 # Close stdout now, and if there were no errors, return happy status.
37 # If stdout has already been closed by the script, though, do nothing.
38 defined fileno STDOUT
39 or return;
40 close STDOUT
41 and return;
43 # Errors closing stdout. Indicate that, and hope stderr is OK.
44 warn "$ME: closing standard output: $!\n";
46 # Don't be so arrogant as to assume that we're the first END handler
47 # defined, and thus the last one invoked. There may be others yet
48 # to come. $? will be passed on to them, and to the final _exit().
50 # If it isn't already an error, make it one (and if it _is_ an error,
51 # preserve the value: it might be important).
52 $? ||= 1;
55 sub usage ($)
57 my ($exit_code) = @_;
58 my $STREAM = ($exit_code == 0 ? *STDOUT : *STDERR);
59 if ($exit_code != 0)
61 print $STREAM "Try `$ME --help' for more information.\n";
63 else
65 my @types = sort keys %valid_release_types;
66 print $STREAM <<EOF;
67 Usage: $ME [OPTIONS]
69 OPTIONS:
71 Generate an announcement message.
73 FIXME: describe the following
75 --release-type=TYPE TYPE must be one of @types
76 --package-name=PACKAGE_NAME
77 --previous-version=VER
78 --current-version=VER
79 --gpg-key-id=ID The GnuPG ID of the key used to sign the tarballs
80 --release-archive-directory=DIR
81 --url-directory=URL_DIR
82 --news=NEWS_FILE optional
84 --help display this help and exit
85 --version output version information and exit
87 EOF
89 exit $exit_code;
93 =item C<%size> = C<sizes (@file)>
95 Compute the sizes of the C<@file> and return them as a hash. Return
96 C<undef> if one of the computation failed.
98 =cut
100 sub sizes (@)
102 my (@file) = @_;
104 my $fail = 0;
105 my %res;
106 foreach my $f (@file)
108 my $cmd = "du --human $f";
109 my $t = `$cmd`;
110 # FIXME-someday: give a better diagnostic, a la $PROCESS_STATUS
112 and (warn "$ME: command failed: `$cmd'\n"), $fail = 1;
113 chomp $t;
114 $t =~ s/^([\d.]+[MkK]).*/${1}B/;
115 $res{$f} = $t;
117 return $fail ? undef : %res;
120 =item C<print_locations ($title, \@url, \%size, @file)
122 Print a section C<$title> dedicated to the list of <@file>, which
123 sizes are stored in C<%size>, and which are available from the C<@url>.
125 =cut
127 sub print_locations ($\@\%@)
129 my ($title, $url, $size, @file) = @_;
130 print "Here are the $title:\n";
131 foreach my $url (@{$url})
133 for my $file (@file)
135 print " $url/$file";
136 print " (", $$size{$file}, ")"
137 if exists $$size{$file};
138 print "\n";
141 print "\n";
144 =item C<print_checksums (@file)
146 Print the MD5 and SHA1 signature section for each C<@file>.
148 =cut
150 sub print_checksums (@)
152 my (@file) = @_;
154 print "Here are the MD5 and SHA1 checksums:\n";
155 print "\n";
157 foreach my $meth (qw (md5 sha1))
159 foreach my $f (@file)
161 open IN, '<', $f
162 or die "$ME: $f: cannot open for reading: $!\n";
163 binmode IN;
164 my $dig =
165 ($meth eq 'md5'
166 ? Digest::MD5->new->addfile(*IN)->hexdigest
167 : Digest::SHA1->new->addfile(*IN)->hexdigest);
168 close IN;
169 print "$dig $f\n";
176 =item C<print_news_deltas ($news_file, $prev_version, $curr_version)
178 Print the section of the NEWS file C<$news_file> addressing changes
179 between versions C<$prev_version> and C<$curr_version>.
181 =cut
183 sub print_news_deltas ($$$)
185 my ($news_file, $prev_version, $curr_version) = @_;
187 print "\n$news_file\n\n";
189 # Print all lines from $news_file, starting with the first one
190 # that mentions $curr_version up to but not including
191 # the first occurrence of $prev_version.
192 my $in_items;
194 open NEWS, '<', $news_file
195 or die "$ME: $news_file: cannot open for reading: $!\n";
196 while (defined (my $line = <NEWS>))
198 if ( ! $in_items)
200 # Match lines like this one:
201 # * Major changes in release 5.0.1:
202 # but not any other line that starts with a space, *, or -.
203 $line =~ /^(\* Major changes.*|[^ *-].*)\Q$curr_version\E/o
204 or next;
205 $in_items = 1;
206 print $line;
208 else
210 # Be careful that this regexp cannot match version numbers
211 # in NEWS items -- they might well say `introduced in 4.5.5',
212 # and we don't want that to match.
213 $line =~ /^(\* Major changes.*|[^ *-].*)\Q$prev_version\E/o
214 and last;
215 print $line;
218 close NEWS;
220 $in_items
221 or die "$ME: $news_file: no matching lines for `$curr_version'\n";
224 sub print_changelog_deltas ($$)
226 my ($package_name, $prev_version) = @_;
228 # Print new ChangeLog entries.
230 # First find all CVS-controlled ChangeLog files.
231 use File::Find;
232 my @changelog;
233 find ({wanted => sub {$_ eq 'ChangeLog' && -d 'CVS'
234 and push @changelog, $File::Find::name}},
235 '.');
237 # If there are no ChangeLog files, we're done.
238 @changelog
239 or return;
240 my %changelog = map {$_ => 1} @changelog;
242 # Reorder the list of files so that if there are ChangeLog
243 # files in the specified directories, they're listed first,
244 # in this order:
245 my @dir = qw ( . src lib m4 config doc );
247 # A typical @changelog array might look like this:
248 # ./ChangeLog
249 # ./po/ChangeLog
250 # ./m4/ChangeLog
251 # ./lib/ChangeLog
252 # ./doc/ChangeLog
253 # ./config/ChangeLog
254 my @reordered;
255 foreach my $d (@dir)
257 my $dot_slash = $d eq '.' ? $d : "./$d";
258 my $target = "$dot_slash/ChangeLog";
259 delete $changelog{$target}
260 and push @reordered, $target;
263 # Append any remaining ChangeLog files.
264 push @reordered, sort keys %changelog;
266 # Remove leading `./'.
267 @reordered = map { s!^\./!!; $_ } @reordered;
269 print "\nChangeLog entries:\n\n";
270 # print join ("\n", @reordered), "\n";
272 $prev_version =~ s/\./_/g;
273 my $prev_cvs_tag = "\U$package_name\E-$prev_version";
275 my $cmd = "cvs -n diff -u -r$prev_cvs_tag -rHEAD @reordered";
276 open DIFF, '-|', $cmd
277 or die "$ME: cannot run `$cmd': $!\n";
278 # Print two types of lines, making minor changes:
279 # Lines starting with `+++ ', e.g.,
280 # +++ ChangeLog 22 Feb 2003 16:52:51 -0000 1.247
281 # and those starting with `+'.
282 # Don't print the others.
283 my $prev_printed_line_empty = 1;
284 while (defined (my $line = <DIFF>))
286 if ($line =~ /^\+\+\+ /)
288 my $separator = "*"x70 ."\n";
289 $line =~ s///;
290 $line =~ s/\s.*//;
291 $prev_printed_line_empty
292 or print "\n";
293 print $separator, $line, $separator;
295 elsif ($line =~ /^\+/)
297 $line =~ s///;
298 print $line;
299 $prev_printed_line_empty = ($line =~ /^$/);
302 close DIFF;
304 # The exit code should be 1.
305 # Allow in case there are no modified ChangeLog entries.
306 $? == 256 || $? == 128
307 or warn "$ME: warning: `cmd' had unexpected exit code or signal ($?)\n";
311 # Neutralize the locale, so that, for instance, "du" does not
312 # issue "1,2" instead of "1.2", what confuses our regexps.
313 $ENV{LC_ALL} = "C";
315 my $release_type;
316 my $package_name;
317 my $prev_version;
318 my $curr_version;
319 my $release_archive_dir;
320 my $gpg_key_id;
321 my @url_dir_list;
322 my @news_file;
324 GetOptions
326 'release-type=s' => \$release_type,
327 'package-name=s' => \$package_name,
328 'previous-version=s' => \$prev_version,
329 'current-version=s' => \$curr_version,
330 'gpg-key-id=s' => \$gpg_key_id,
331 'release-archive-directory=s' => \$release_archive_dir,
332 'url-directory=s' => \@url_dir_list,
333 'news=s' => \@news_file,
335 help => sub { usage 0 },
336 version => sub { print "$ME version $VERSION\n"; exit },
337 ) or usage 1;
339 my $fail = 0;
340 # Ensure that sure each required option is specified.
341 $release_type
342 or (warn "$ME: release type not specified\n"), $fail = 1;
343 $package_name
344 or (warn "$ME: package name not specified\n"), $fail = 1;
345 $prev_version
346 or (warn "$ME: previous version string not specified\n"), $fail = 1;
347 $curr_version
348 or (warn "$ME: current version string not specified\n"), $fail = 1;
349 $release_archive_dir
350 or (warn "$ME: release directory name not specified\n"), $fail = 1;
351 @url_dir_list
352 or (warn "$ME: URL directory name(s) not specified\n"), $fail = 1;
354 exists $valid_release_types{$release_type}
355 or (warn "$ME: `$release_type': invalid release type\n"), $fail = 1;
357 @ARGV
358 and (warn "$ME: too many arguments\n"), $fail = 1;
359 $fail
360 and usage 1;
362 my $my_distdir = "$package_name-$curr_version";
363 my $tgz = "$my_distdir.tar.gz";
364 my $tbz = "$my_distdir.tar.bz2";
365 my $xd = "$package_name-$prev_version-$curr_version.xdelta";
367 my %size = sizes ($tgz, $tbz, $xd);
368 %size
369 or exit 1;
371 # The markup is escaped as <\# so that when this script is sent by
372 # mail (or part of a diff), Gnus is not triggered.
373 print <<EOF;
375 Subject: $my_distdir released
377 <\#secure method=pgpmime mode=sign>
379 FIXME: put comments here
383 print_locations ("compressed sources", @url_dir_list, %size,
384 $tgz, $tbz);
385 print_locations ("xdelta-style diffs", @url_dir_list, %size,
386 $xd);
387 print_locations ("GPG detached signatures[*]", @url_dir_list, %size,
388 "$tgz.sig", "$tbz.sig");
390 print_checksums ($tgz, $tbz, $xd);
392 print <<EOF;
394 [*] You can use either of the above signature files to verify that
395 the corresponding file (without the .sig suffix) is intact. First,
396 be sure to download both the .sig file and the corresponding tarball.
397 Then, run a command like this:
399 gpg --verify $tgz.sig
401 If that command fails because you don't have the required public key,
402 then run this command to import it:
404 gpg --keyserver wwwkeys.pgp.net --recv-keys $gpg_key_id
406 and rerun the \`gpg --verify' command.
409 print_news_deltas ($_, $prev_version, $curr_version)
410 foreach @news_file;
412 $release_type eq 'major'
413 or print_changelog_deltas ($package_name, $prev_version);
415 exit 0;
420 ### Setup "GNU" style for perl-mode and cperl-mode.
421 ## Local Variables:
422 ## perl-indent-level: 2
423 ## perl-continued-statement-offset: 2
424 ## perl-continued-brace-offset: 0
425 ## perl-brace-offset: 0
426 ## perl-brace-imaginary-offset: 0
427 ## perl-label-offset: -2
428 ## cperl-indent-level: 2
429 ## cperl-brace-offset: 0
430 ## cperl-continued-brace-offset: 0
431 ## cperl-label-offset: -2
432 ## cperl-extra-newline-before-brace: t
433 ## cperl-merge-trailing-else: nil
434 ## cperl-continued-statement-offset: 2
435 ## End: