outobj: properly error on unsupported relocations
[nasm/nasm.git] / version.pl
blobe4157a2dd567a8f272626cf0a0bc794fe3327040
1 #!/usr/bin/perl
2 ## --------------------------------------------------------------------------
3 ##
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.
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 $man, $min, $smin, $plvl, $tail;
74 $is_rc = 0;
76 if ( $line =~ /^([0-9]+)\.([0-9]+)(.*)$/ ) {
77 $maj = $1;
78 $min = $2;
79 $tail = $3;
80 if ( $tail =~ /^\.([0-9]+)(.*)$/ ) {
81 $smin = $1;
82 $tail = $2;
84 if ( $tail =~ /^(pl|\.)([0-9]+)(.*)$/ ) {
85 $plvl = $2;
86 $tail = $3;
87 } elsif ( $tail =~ /^rc([0-9]+)(.*)$/ ) {
88 $is_rc = 1;
89 $plvl = $1;
90 $tail = $2;
92 } else {
93 die "$0: Invalid input format\n";
96 if ($tail =~ /^\-([0-9]+)$/) {
97 $snapshot = $1;
98 } else {
99 undef $snapshot;
102 $nmaj = $maj+0; $nmin = $min+0;
103 $nsmin = $smin+0; $nplvl = $plvl+0;
105 if ($is_rc) {
106 $nplvl += 90;
107 if ($nsmin > 0) {
108 $nsmin--;
109 } else {
110 $nsmin = 99;
111 if ($nmin > 0) {
112 $nmin--;
113 } else {
114 $nmin = 99;
115 $nmaj--;
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
181 } else {
182 die "$0: Unknown output: $what\n";
185 exit 0;