version.pl: support version numbers of the form X.Y[.Z]rcW
[platform/upstream/nasm.git] / version.pl
1 #!/usr/bin/perl
2 #
3 # version.pl
4 #
5 # Parse the NASM version file and produce appropriate macros
6 #
7 # The NASM version number is assumed to consist of:
8 #
9 # <major>.<minor>[.<subminor>][pl<patchlevel>]]<tail>
10 #
11 # ... where <tail> is not necessarily numeric.
12 #
13 # This defines the following macros:
14 #
15 # version.h:
16 # NASM_MAJOR_VER
17 # NASM_MINOR_VER
18 # NASM_SUBMINOR_VER     -- this is zero if no subminor
19 # NASM_PATCHLEVEL_VER   -- this is zero is no patchlevel
20 # NASM_VERSION_ID       -- version number encoded
21 # NASM_VER              -- whole version number as a string
22 #
23 # version.mac:
24 # __NASM_MAJOR__
25 # __NASM_MINOR__
26 # __NASM_SUBMINOR__
27 # __NASM_PATCHLEVEL__
28 # __NASM_VERSION_ID__
29 # __NASM_VER__
30 #
31
32 ($what) = @ARGV;
33
34 $line = <STDIN>;
35 chomp $line;
36
37 undef $man, $min, $smin, $plvl, $tail;
38 $is_rc = 0;
39
40 if ( $line =~ /^([0-9]+)\.([0-9]+)(.*)$/ ) {
41     $maj  = $1;
42     $min  = $2;
43     $tail = $3;
44     if ( $tail =~ /^\.([0-9]+)(.*)$/ ) {
45         $smin = $1;
46         $tail = $2;
47     }
48     if ( $tail =~ /^(pl|\.)([0-9]+)(.*)$/ ) {
49         $plvl = $2;
50         $tail = $3;
51     } elsif ( $tail =~ /^rc([0-9]+)(.*)$/ ) {
52         $is_rc = 1;
53         $plvl = $1;
54         $tail = $2;
55     }
56 } else {
57     die "$0: Invalid input format\n";
58 }
59
60 $nmaj = $maj+0;   $nmin = $min+0;
61 $nsmin = $smin+0; $nplvl = $plvl+0;
62
63 if ($is_rc) {
64     $nplvl += 90;
65     if ($nsmin > 0) {
66         $nsmin--;
67     } else {
68         $nsmin = 99;
69         if ($nmin > 0) {
70             $nmin--;
71         } else {
72             $nmin = 99;
73             $nmaj--;
74         }
75     }
76 }
77
78 $nasm_id = ($nmaj << 24)+($nmin << 16)+($nsmin << 8)+$nplvl;
79
80 if ( $what eq 'h' ) {
81     print  "#ifndef NASM_VERSION_H\n";
82     print  "#define NASM_VERSION_H\n";
83     printf "#define NASM_MAJOR_VER      %d\n", $nmaj;
84     printf "#define NASM_MINOR_VER      %d\n", $nmin;
85     printf "#define NASM_SUBMINOR_VER   %d\n", $nsmin;
86     printf "#define NASM_PATCHLEVEL_VER %d\n", $nplvl;
87     printf "#define NASM_VERSION_ID     0x%08x\n", $nasm_id;
88     printf "#define NASM_VER            \"%s\"\n", $line;
89     print  "#endif /* NASM_VERSION_H */\n";
90 } elsif ( $what eq 'mac' ) {
91     printf "%%define __NASM_MAJOR__ %d\n", $nmaj;
92     printf "%%define __NASM_MINOR__ %d\n", $nmin;
93     printf "%%define __NASM_SUBMINOR__ %d\n", $nsmin;
94     printf "%%define __NASM_PATCHLEVEL__ %d\n", $nplvl;
95     printf "%%define __NASM_VERSION_ID__ 0%08Xh\n", $nasm_id;
96     printf "%%define __NASM_VER__ \"%s\"\n", $line;
97 } elsif ( $what eq 'id' ) {
98     print $nasm_id, "\n";        # Print ID in decimal
99 } elsif ( $what eq 'xid' ) {
100     printf "0x%08x\n", $nasm_id; # Print ID in hexadecimal
101 } else {
102     die "$0: Unknown output: $what\n";
103 }
104
105 exit 0;
106