summaryrefslogtreecommitdiffstats
path: root/bin/update_version
blob: 893a0e6c8a721dda4ab5567aca850ea0f80380a9 (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
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
#!/usr/bin/perl
#
# Update a NASM version file
#
# The NASM version number is assumed to consist of:
#
# <major>.<minor>[.<subminor>][pl<patchlevel>]]<tail>
#
# ... where <tail> is not necessarily numeric, but if it is of the form
# -<digits> it is assumed to be a snapshot release.
#
# Usage:
#    update_version version file
#
# Returns true on an update
#

($new_ver, $file) = @ARGV;

sub version_id($) {
    my ($line) = @_;
    my ($man, $min, $smin, $plvl, $tail);
    my $is_rc = 0;

    if ( $line =~ /^([0-9]+)\.([0-9]+)(.*)$/ ) {
	$maj  = $1;
	$min  = $2;
	$tail = $3;
	if ( $tail =~ /^\.([0-9]+)(.*)$/ ) {
	    $smin = $1;
	    $tail = $2;
	}
	if ( $tail =~ /^(pl|\.)([0-9]+)(.*)$/ ) {
	    $plvl = $2;
	    $tail = $3;
	} elsif ( $tail =~ /^rc([0-9]+)(.*)$/ ) {
	    $is_rc = 1;
	    $plvl = $1;
	    $tail = $2;
	}
    } else {
	die "$0: Invalid input format\n";
    }

    my $snapshot;
    if ($tail =~ /^\-([0-9]+)/) {
	$snapshot = $1;
    } else {
	undef $snapshot;
    }

    my $nmaj = $maj+0;   my $nmin = $min+0;
    my $nsmin = $smin+0; my $nplvl = $plvl+0;

    if ($is_rc) {
	$nplvl += 90;
	if ($nsmin > 0) {
	    $nsmin--;
	} else {
	    $nsmin = 99;
	    if ($nmin > 0) {
		$nmin--;
	    } else {
		$nmin = 99;
		$nmaj--;
	    }
	}
    }

    my $nasm_id = ($nmaj << 24)+($nmin << 16)+($nsmin << 8)+$nplvl;
    return $nasm_id;
}

$new_id = version_id($new_ver);
$is_rc = ($new_ver =~ /rc/) ? 1 : 0;

require $file;

$change = 0;
if ($is_rc) {
    if (!defined($rc_version) || $new_id > version_id($rc_version)) {
	$rc_version = $new_ver;
	$change = 1;
    }
} else {
    if (!defined($version) || $new_id > version_id($version)) {
	$version = $new_ver;
	$change = 1;
    }
}
if (defined($rc_version) && version_id($rc_version) <= version_id($version)) {
    undef $rc_version;
    $change = 1;
}

if (!$change) {
    exit 1;			# No update happened
}

open(FILE, '>', $file) or die;
# This file is cleverly organized to be valid PHP *and* valid Perl...
print FILE "# <?php\n";
print FILE "\$version=\'$version\';\n";
print FILE "\$rc_version=\'$rc_version\';\n" if (defined($rc_version));
print FILE "1;\n";
print FILE "# ?>\n";
close(FILE);

exit 0;