NASM 2.15.02rc1
[nasm.git] / version.pl
blob634ad311cafa666be00a3f619267d363f1a8a45c
1 #!/usr/bin/perl
2 ## --------------------------------------------------------------------------
3 ##
4 ## Copyright 1996-2016 The NASM Authors - All Rights Reserved
5 ## See the file AUTHORS included with the NASM distribution for
6 ## the specific copyright holders.
7 ##
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted provided that the following
10 ## conditions are met:
12 ## * Redistributions of source code must retain the above copyright
13 ## notice, this list of conditions and the following disclaimer.
14 ## * Redistributions in binary form must reproduce the above
15 ## copyright notice, this list of conditions and the following
16 ## disclaimer in the documentation and/or other materials provided
17 ## with the distribution.
18 ##
19 ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
20 ## CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
21 ## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 ## DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 ## NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 ## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 ## OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 ## EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ## --------------------------------------------------------------------------
36 # version.pl
38 # Parse the NASM version file and produce appropriate macros
40 # The NASM version number is assumed to consist of:
42 # <major>.<minor>[.<subminor>][pl<patchlevel>]]<tail>
44 # ... where <tail> is not necessarily numeric, but if it is of the form
45 # -<digits> it is assumed to be a snapshot release.
47 # This defines the following macros:
49 # version.h:
50 # NASM_MAJOR_VER
51 # NASM_MINOR_VER
52 # NASM_SUBMINOR_VER -- this is zero if no subminor
53 # NASM_PATCHLEVEL_VER -- this is zero is no patchlevel
54 # NASM_SNAPSHOT -- if snapshot
55 # NASM_VERSION_ID -- version number encoded
56 # NASM_VER -- whole version number as a string
58 # version.mac:
59 # __?NASM_MAJOR?__
60 # __?NASM_MINOR?__
61 # __?NASM_SUBMINOR?__
62 # __?NASM_PATCHLEVEL?__
63 # __?NASM_SNAPSHOT?__
64 # __?NASM_VERSION_ID?__
65 # __?NASM_VER?__
68 ($what) = @ARGV;
70 $line = <STDIN>;
71 chomp $line;
73 undef $maj;
74 undef $min;
75 undef $smin;
76 undef $plvl;
77 undef $tail;
78 $is_rc = 0;
80 if ( $line =~ /^([0-9]+)\.([0-9]+)(.*)$/ ) {
81 $maj = $1;
82 $min = $2;
83 $tail = $3;
84 if ( $tail =~ /^\.([0-9]+)(.*)$/ ) {
85 $smin = $1;
86 $tail = $2;
88 if ( $tail =~ /^(pl|\.)([0-9]+)(.*)$/ ) {
89 $plvl = $2;
90 $tail = $3;
91 } elsif ( $tail =~ /^rc([0-9]+)(.*)$/ ) {
92 $is_rc = 1;
93 $plvl = $1;
94 $tail = $2;
96 } else {
97 die "$0: Invalid input format\n";
100 if ($tail =~ /^\-([0-9]+)$/) {
101 $snapshot = $1;
102 } else {
103 undef $snapshot;
106 $nmaj = $maj+0; $nmin = $min+0;
107 $nsmin = $smin+0; $nplvl = $plvl+0;
109 if ($is_rc) {
110 $nplvl += 90;
111 if ($nsmin > 0) {
112 $nsmin--;
113 } else {
114 $nsmin = 99;
115 if ($nmin > 0) {
116 $nmin--;
117 } else {
118 $nmin = 99;
119 $nmaj--;
124 $nasm_id = ($nmaj << 24)+($nmin << 16)+($nsmin << 8)+$nplvl;
126 $mangled_ver = sprintf("%d.%02d", $nmaj, $nmin);
127 if ($nsmin || $nplvl || defined($snapshot)) {
128 $mangled_ver .= sprintf(".%02d", $nsmin);
129 if ($nplvl || defined($snapshot)) {
130 $mangled_ver .= '.'.$nplvl;
133 ($mtail = $tail) =~ tr/-/./;
134 $mangled_ver .= $mtail;
136 if ( $what eq 'h' ) {
137 print "#ifndef NASM_VERSION_H\n";
138 print "#define NASM_VERSION_H\n";
139 printf "#define NASM_MAJOR_VER %d\n", $nmaj;
140 printf "#define NASM_MINOR_VER %d\n", $nmin;
141 printf "#define NASM_SUBMINOR_VER %d\n", $nsmin;
142 printf "#define NASM_PATCHLEVEL_VER %d\n", $nplvl;
143 if (defined($snapshot)) {
144 printf "#define NASM_SNAPSHOT %d\n", $snapshot;
146 printf "#define NASM_VERSION_ID 0x%08x\n", $nasm_id;
147 printf "#define NASM_VER \"%s\"\n", $line;
148 print "#endif /* NASM_VERSION_H */\n";
149 } elsif ( $what eq 'mac' ) {
150 print "STD: version\n";
151 printf "%%define __?NASM_MAJOR?__ %d\n", $nmaj;
152 printf "%%define __?NASM_MINOR?__ %d\n", $nmin;
153 printf "%%define __?NASM_SUBMINOR?__ %d\n", $nsmin;
154 printf "%%define __?NASM_PATCHLEVEL?__ %d\n", $nplvl;
155 if (defined($snapshot)) {
156 printf "%%define __?NASM_SNAPSHOT?__ %d\n", $snapshot;
158 printf "%%define __?NASM_VERSION_ID?__ 0%08Xh\n", $nasm_id;
159 printf "%%define __?NASM_VER?__ \"%s\"\n", $line;
160 } elsif ( $what eq 'sed' ) {
161 printf "s/\@\@NASM_MAJOR\@\@/%d/g\n", $nmaj;
162 printf "s/\@\@NASM_MINOR\@\@/%d/g\n", $nmin;
163 printf "s/\@\@NASM_SUBMINOR\@\@/%d/g\n", $nsmin;
164 printf "s/\@\@NASM_PATCHLEVEL\@\@/%d/g\n", $nplvl;
165 printf "s/\@\@NASM_SNAPSHOT\@\@/%d/g\n", $snapshot; # Possibly empty
166 printf "s/\@\@NASM_VERSION_ID\@\@/%d/g\n", $nasm_id;
167 printf "s/\@\@NASM_VERSION_XID\@\@/0x%08x/g\n", $nasm_id;
168 printf "s/\@\@NASM_VER\@\@/%s/g\n", $line;
169 printf "s/\@\@NASM_MANGLED_VER\@\@/%s/g\n", $mangled_ver;
170 } elsif ( $what eq 'make' ) {
171 printf "NASM_VER=%s\n", $line;
172 printf "NASM_MAJOR_VER=%d\n", $nmaj;
173 printf "NASM_MINOR_VER=%d\n", $nmin;
174 printf "NASM_SUBMINOR_VER=%d\n", $nsmin;
175 printf "NASM_PATCHLEVEL_VER=%d\n", $nplvl;
176 } elsif ( $what eq 'nsis' ) {
177 printf "!define VERSION \"%s\"\n", $line;
178 printf "!define MAJOR_VER %d\n", $nmin;
179 printf "!define MINOR_VER %d\n", $nmin;
180 printf "!define SUBMINOR_VER %d\n", $nsmin;
181 printf "!define PATCHLEVEL_VER %d\n", $nplvl;
182 } elsif ( $what eq 'id' ) {
183 print $nasm_id, "\n"; # Print ID in decimal
184 } elsif ( $what eq 'xid' ) {
185 printf "0x%08x\n", $nasm_id; # Print ID in hexadecimal
186 } elsif ( $what eq 'docsrc' ) {
187 printf "\\M{version}{%s}\n", $line;
188 printf "\\M{subtitle}{version %s}\n", $line;
189 } else {
190 die "$0: Unknown output: $what\n";
193 exit 0;