NASM 2.06rc14
[nasm/sigaren-mirror.git] / version.pl
blobd9e9733024f249c2512a81749aead8e18c981920
1 #!/usr/bin/perl
3 # version.pl
5 # Parse the NASM version file and produce appropriate macros
7 # The NASM version number is assumed to consist of:
9 # <major>.<minor>[.<subminor>][pl<patchlevel>]]<tail>
11 # ... where <tail> is not necessarily numeric, but if it is of the form
12 # -<digits> it is assumed to be a snapshot release.
14 # This defines the following macros:
16 # version.h:
17 # NASM_MAJOR_VER
18 # NASM_MINOR_VER
19 # NASM_SUBMINOR_VER -- this is zero if no subminor
20 # NASM_PATCHLEVEL_VER -- this is zero is no patchlevel
21 # NASM_SNAPSHOT -- if snapshot
22 # NASM_VERSION_ID -- version number encoded
23 # NASM_VER -- whole version number as a string
25 # version.mac:
26 # __NASM_MAJOR__
27 # __NASM_MINOR__
28 # __NASM_SUBMINOR__
29 # __NASM_PATCHLEVEL__
30 # __NASM_SNAPSHOT__
31 # __NASM_VERSION_ID__
32 # __NASM_VER__
35 ($what) = @ARGV;
37 $line = <STDIN>;
38 chomp $line;
40 undef $man, $min, $smin, $plvl, $tail;
41 $is_rc = 0;
43 if ( $line =~ /^([0-9]+)\.([0-9]+)(.*)$/ ) {
44 $maj = $1;
45 $min = $2;
46 $tail = $3;
47 if ( $tail =~ /^\.([0-9]+)(.*)$/ ) {
48 $smin = $1;
49 $tail = $2;
51 if ( $tail =~ /^(pl|\.)([0-9]+)(.*)$/ ) {
52 $plvl = $2;
53 $tail = $3;
54 } elsif ( $tail =~ /^rc([0-9]+)(.*)$/ ) {
55 $is_rc = 1;
56 $plvl = $1;
57 $tail = $2;
59 } else {
60 die "$0: Invalid input format\n";
63 if ($tail =~ /^\-([0-9]+)$/) {
64 $snapshot = $1;
65 } else {
66 undef $snapshot;
69 $nmaj = $maj+0; $nmin = $min+0;
70 $nsmin = $smin+0; $nplvl = $plvl+0;
72 if ($is_rc) {
73 $nplvl += 90;
74 if ($nsmin > 0) {
75 $nsmin--;
76 } else {
77 $nsmin = 99;
78 if ($nmin > 0) {
79 $nmin--;
80 } else {
81 $nmin = 99;
82 $nmaj--;
87 $nasm_id = ($nmaj << 24)+($nmin << 16)+($nsmin << 8)+$nplvl;
89 $mangled_ver = sprintf("%d.%02d", $nmaj, $nmin);
90 if ($nsmin || $nplvl || defined($snapshot)) {
91 $mangled_ver .= sprintf(".%02d", $nsmin);
92 if ($nplvl || defined($snapshot)) {
93 $mangled_ver .= '.'.$nplvl;
96 ($mtail = $tail) =~ tr/-/./;
97 $mangled_ver .= $mtail;
99 if ( $what eq 'h' ) {
100 print "#ifndef NASM_VERSION_H\n";
101 print "#define NASM_VERSION_H\n";
102 printf "#define NASM_MAJOR_VER %d\n", $nmaj;
103 printf "#define NASM_MINOR_VER %d\n", $nmin;
104 printf "#define NASM_SUBMINOR_VER %d\n", $nsmin;
105 printf "#define NASM_PATCHLEVEL_VER %d\n", $nplvl;
106 if (defined($snapshot)) {
107 printf "#define NASM_SNAPSHOT %d\n", $snapshot;
109 printf "#define NASM_VERSION_ID 0x%08x\n", $nasm_id;
110 printf "#define NASM_VER \"%s\"\n", $line;
111 print "#endif /* NASM_VERSION_H */\n";
112 } elsif ( $what eq 'mac' ) {
113 printf "%%define __NASM_MAJOR__ %d\n", $nmaj;
114 printf "%%define __NASM_MINOR__ %d\n", $nmin;
115 printf "%%define __NASM_SUBMINOR__ %d\n", $nsmin;
116 printf "%%define __NASM_PATCHLEVEL__ %d\n", $nplvl;
117 if (defined($snapshot)) {
118 printf "%%define __NASM_SNAPSHOT__ %d\n", $snapshot;
120 printf "%%define __NASM_VERSION_ID__ 0%08Xh\n", $nasm_id;
121 printf "%%define __NASM_VER__ \"%s\"\n", $line;
122 } elsif ( $what eq 'sed' ) {
123 printf "s/\@\@NASM_MAJOR\@\@/%d/g\n", $nmaj;
124 printf "s/\@\@NASM_MINOR\@\@/%d/g\n", $nmin;
125 printf "s/\@\@NASM_SUBMINOR\@\@/%d/g\n", $nsmin;
126 printf "s/\@\@NASM_PATCHLEVEL\@\@/%d/g\n", $nplvl;
127 printf "s/\@\@NASM_SNAPSHOT\@\@/%d/g\n", $snapshot; # Possibly empty
128 printf "s/\@\@NASM_VERSION_ID\@\@/%d/g\n", $nasm_id;
129 printf "s/\@\@NASM_VERSION_XID\@\@/0x%08x/g\n", $nasm_id;
130 printf "s/\@\@NASM_VER\@\@/%s/g\n", $line;
131 printf "s/\@\@NASM_MANGLED_VER\@\@/%s/g\n", $mangled_ver;
132 } elsif ( $what eq 'make' ) {
133 printf "NASM_VER=%s\n", $line;
134 printf "NASM_MAJOR_VER=%d\n", $nmaj;
135 printf "NASM_MINOR_VER=%d\n", $nmin;
136 printf "NASM_SUBMINOR_VER=%d\n", $nsmin;
137 printf "NASM_PATCHLEVEL_VER=%d\n", $nplvl;
138 } elsif ( $what eq 'nsis' ) {
139 printf "!define VERSION \"%s\"\n", $line;
140 printf "!define MAJOR_VER %d\n", $nmin;
141 printf "!define MINOR_VER %d\n", $nmin;
142 printf "!define SUBMINOR_VER %d\n", $nsmin;
143 printf "!define PATCHLEVEL_VER %d\n", $nplvl;
144 } elsif ( $what eq 'id' ) {
145 print $nasm_id, "\n"; # Print ID in decimal
146 } elsif ( $what eq 'xid' ) {
147 printf "0x%08x\n", $nasm_id; # Print ID in hexadecimal
148 } else {
149 die "$0: Unknown output: $what\n";
152 exit 0;