2 ## --------------------------------------------------------------------------
4 ## Copyright 1996-2009 The NASM Authors - All Rights Reserved
5 ## See the file AUTHORS included with the NASM distribution for
6 ## the specific copyright holders.
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.
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 ## --------------------------------------------------------------------------
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:
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
73 undef $man, $min, $smin, $plvl, $tail;
76 if ( $line =~ /^([0-9]+)\.([0-9]+)(.*)$/ ) {
80 if ( $tail =~ /^\.([0-9]+)(.*)$/ ) {
84 if ( $tail =~ /^(pl|\.)([0-9]+)(.*)$/ ) {
87 } elsif ( $tail =~ /^rc([0-9]+)(.*)$/ ) {
93 die "$0: Invalid input format\n";
96 if ($tail =~ /^\-([0-9]+)$/) {
102 $nmaj = $maj+0; $nmin = $min+0;
103 $nsmin = $smin+0; $nplvl = $plvl+0;
120 $nasm_id = ($nmaj << 24)+($nmin << 16)+($nsmin << 8)+$nplvl;
122 $mangled_ver = sprintf("%d.%02d", $nmaj, $nmin);
123 if ($nsmin || $nplvl || defined($snapshot)) {
124 $mangled_ver .= sprintf(".%02d", $nsmin);
125 if ($nplvl || defined($snapshot)) {
126 $mangled_ver .= '.'.$nplvl;
129 ($mtail = $tail) =~ tr/-/./;
130 $mangled_ver .= $mtail;
132 if ( $what eq 'h' ) {
133 print "#ifndef NASM_VERSION_H\n";
134 print "#define NASM_VERSION_H\n";
135 printf "#define NASM_MAJOR_VER %d\n", $nmaj;
136 printf "#define NASM_MINOR_VER %d\n", $nmin;
137 printf "#define NASM_SUBMINOR_VER %d\n", $nsmin;
138 printf "#define NASM_PATCHLEVEL_VER %d\n", $nplvl;
139 if (defined($snapshot)) {
140 printf "#define NASM_SNAPSHOT %d\n", $snapshot;
142 printf "#define NASM_VERSION_ID 0x%08x\n", $nasm_id;
143 printf "#define NASM_VER \"%s\"\n", $line;
144 print "#endif /* NASM_VERSION_H */\n";
145 } elsif ( $what eq 'mac' ) {
146 printf "%%define __NASM_MAJOR__ %d\n", $nmaj;
147 printf "%%define __NASM_MINOR__ %d\n", $nmin;
148 printf "%%define __NASM_SUBMINOR__ %d\n", $nsmin;
149 printf "%%define __NASM_PATCHLEVEL__ %d\n", $nplvl;
150 if (defined($snapshot)) {
151 printf "%%define __NASM_SNAPSHOT__ %d\n", $snapshot;
153 printf "%%define __NASM_VERSION_ID__ 0%08Xh\n", $nasm_id;
154 printf "%%define __NASM_VER__ \"%s\"\n", $line;
155 } elsif ( $what eq 'sed' ) {
156 printf "s/\@\@NASM_MAJOR\@\@/%d/g\n", $nmaj;
157 printf "s/\@\@NASM_MINOR\@\@/%d/g\n", $nmin;
158 printf "s/\@\@NASM_SUBMINOR\@\@/%d/g\n", $nsmin;
159 printf "s/\@\@NASM_PATCHLEVEL\@\@/%d/g\n", $nplvl;
160 printf "s/\@\@NASM_SNAPSHOT\@\@/%d/g\n", $snapshot; # Possibly empty
161 printf "s/\@\@NASM_VERSION_ID\@\@/%d/g\n", $nasm_id;
162 printf "s/\@\@NASM_VERSION_XID\@\@/0x%08x/g\n", $nasm_id;
163 printf "s/\@\@NASM_VER\@\@/%s/g\n", $line;
164 printf "s/\@\@NASM_MANGLED_VER\@\@/%s/g\n", $mangled_ver;
165 } elsif ( $what eq 'make' ) {
166 printf "NASM_VER=%s\n", $line;
167 printf "NASM_MAJOR_VER=%d\n", $nmaj;
168 printf "NASM_MINOR_VER=%d\n", $nmin;
169 printf "NASM_SUBMINOR_VER=%d\n", $nsmin;
170 printf "NASM_PATCHLEVEL_VER=%d\n", $nplvl;
171 } elsif ( $what eq 'nsis' ) {
172 printf "!define VERSION \"%s\"\n", $line;
173 printf "!define MAJOR_VER %d\n", $nmin;
174 printf "!define MINOR_VER %d\n", $nmin;
175 printf "!define SUBMINOR_VER %d\n", $nsmin;
176 printf "!define PATCHLEVEL_VER %d\n", $nplvl;
177 } elsif ( $what eq 'id' ) {
178 print $nasm_id, "\n"; # Print ID in decimal
179 } elsif ( $what eq 'xid' ) {
180 printf "0x%08x\n", $nasm_id; # Print ID in hexadecimal
182 die "$0: Unknown output: $what\n";