aboutsummaryrefslogtreecommitdiff
path: root/contrib/updateVersions.pl
blob: 710d7d9359e5aab8af5af4ba64faeabfbf4bad4a (plain)
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
#!/usr/bin/perl -w

$CONFIGURE_IN = './configure.ac';
$ORCONFIG_H = './src/win32/orconfig.h';
$TOR_NSI = './contrib/tor-mingw.nsi.in';

sub demand {
    my $fn = shift;
    die "Missing file $fn" unless (-f $fn);
}

demand($CONFIGURE_IN);
demand($ORCONFIG_H);
demand($TOR_NSI);

# extract version from configure.ac

open(F, $CONFIGURE_IN) or die "$!";
$version = undef;
while (<F>) {
    if (/AC_INIT\(\[tor\],\s*\[([^\]]*)\]\)/) {
	$version = $1;
	last;
    }
}
die "No version found" unless $version;
print "Tor version is $version\n";
close F;

sub correctversion {
    my ($fn, $defchar) = @_;
    undef $/;
    open(F, $fn) or die "$!";
    my $s = <F>;
    close F;
    if ($s =~ /^$defchar(?:)define\s+VERSION\s+\"([^\"]+)\"/m) {
	$oldver = $1;
	if ($oldver ne $version) {
	    print "Version mismatch in $fn: It thinks that the version is $oldver.  Fixing.\n";
	    $line = $defchar . "define VERSION \"$version\"";
	    open(F, ">$fn.bak");
	    print F $s;
	    close F;
	    $s =~ s/^$defchar(?:)define\s+VERSION.*?$/$line/m;
	    open(F, ">$fn");
	    print F $s;
	    close F;	    
	} else {
	    print "$fn has the correct version. Good.\n";
	}
    } else {
	print "Didn't find a version line in $fn -- uh oh.\n";
    }
}

correctversion($TOR_NSI, "!");
correctversion($ORCONFIG_H, "#");