r14328@Kushana: nickm | 2007-09-04 20:17:34 -0400
[tor.git] / contrib / updateVersions.pl
blob76b6fe56779a9054d7ba00fa95a9f3018faa4a9f
1 #!/usr/bin/perl -w
3 $CONFIGURE_IN = './configure.in';
4 $ORCONFIG_H = './src/win32/orconfig.h';
5 $TOR_NSI = './contrib/tor-mingw.nsi.in';
7 sub demand {
8 my $fn = shift;
9 die "Missing file $fn" unless (-f $fn);
12 demand($CONFIGURE_IN);
13 demand($ORCONFIG_H);
14 demand($TOR_NSI);
16 # extract version from configure.in
18 open(F, $CONFIGURE_IN) or die "$!";
19 $version = undef;
20 while (<F>) {
21 if (/AM_INIT_AUTOMAKE\(tor,\s*([^\)]*)\)/) {
22 $version = $1;
23 last;
26 die "No version found" unless $version;
27 print "Tor version is $version\n";
28 close F;
30 sub correctversion {
31 my ($fn, $defchar) = @_;
32 undef $/;
33 open(F, $fn) or die "$!";
34 my $s = <F>;
35 close F;
36 if ($s =~ /^$defchar(?:)define\s+VERSION\s+\"([^\"]+)\"/m) {
37 $oldver = $1;
38 if ($oldver ne $version) {
39 print "Version mismatch in $fn: It thinks that the version is $oldver. Fixing.\n";
40 $line = $defchar . "define VERSION \"$version\"";
41 open(F, ">$fn.bak");
42 print F $s;
43 close F;
44 $s =~ s/^$defchar(?:)define\s+VERSION.*?$/$line/m;
45 open(F, ">$fn");
46 print F $s;
47 close F;
48 } else {
49 print "$fn has the correct version. Good.\n";
51 } else {
52 print "Didn't find a version line in $fn -- uh oh.\n";
56 correctversion($TOR_NSI, "!");
57 correctversion($ORCONFIG_H, "#");