2 ## --------------------------------------------------------------------------
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.
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
80 if ( $line =~ /^([0-9]+)\.([0-9]+)(.*)$/ ) {
84 if ( $tail =~ /^\.([0-9]+)(.*)$/ ) {
88 if ( $tail =~ /^(pl|\.)([0-9]+)(.*)$/ ) {
91 } elsif ( $tail =~ /^rc([0-9]+)(.*)$/ ) {
97 die "$0: Invalid input format\n";
100 if ($tail =~ /^\-([0-9]+)$/) {
106 $nmaj = $maj+0; $nmin = $min+0;
107 $nsmin = $smin+0; $nplvl = $plvl+0;
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;
190 die "$0: Unknown output: $what\n";