Win64: IMAGEREL references (SEH support for Win64)
[nasm/nasm.git] / version.pl
blob008460b373576aabd7d127f8d63db229556b70ef
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.%02d", $nmaj, $nmin, $nsmin);
90 $mangled_ver .= '.'.$nplvl if ($nplvl != 0);
91 ($mtail = $tail) =~ tr/-/./;
92 $mangled_ver .= $mtail;
94 if ( $what eq 'h' ) {
95 print "#ifndef NASM_VERSION_H\n";
96 print "#define NASM_VERSION_H\n";
97 printf "#define NASM_MAJOR_VER %d\n", $nmaj;
98 printf "#define NASM_MINOR_VER %d\n", $nmin;
99 printf "#define NASM_SUBMINOR_VER %d\n", $nsmin;
100 printf "#define NASM_PATCHLEVEL_VER %d\n", $nplvl;
101 if (defined($snapshot)) {
102 printf "#define NASM_SNAPSHOT %d\n", $snapshot;
104 printf "#define NASM_VERSION_ID 0x%08x\n", $nasm_id;
105 printf "#define NASM_VER \"%s\"\n", $line;
106 print "#endif /* NASM_VERSION_H */\n";
107 } elsif ( $what eq 'mac' ) {
108 printf "%%define __NASM_MAJOR__ %d\n", $nmaj;
109 printf "%%define __NASM_MINOR__ %d\n", $nmin;
110 printf "%%define __NASM_SUBMINOR__ %d\n", $nsmin;
111 printf "%%define __NASM_PATCHLEVEL__ %d\n", $nplvl;
112 if (defined($snapshot)) {
113 printf "%%define __NASM_SNAPSHOT__ %d\n", $snapshot;
115 printf "%%define __NASM_VERSION_ID__ 0%08Xh\n", $nasm_id;
116 printf "%%define __NASM_VER__ \"%s\"\n", $line;
117 } elsif ( $what eq 'sed' ) {
118 printf "s/\@\@NASM_MAJOR\@\@/%d/g\n", $nmaj;
119 printf "s/\@\@NASM_MINOR\@\@/%d/g\n", $nmin;
120 printf "s/\@\@NASM_SUBMINOR\@\@/%d/g\n", $nsmin;
121 printf "s/\@\@NASM_PATCHLEVEL\@\@/%d/g\n", $nplvl;
122 printf "s/\@\@NASM_SNAPSHOT\@\@/%d/g\n", $snapshot; # Possibly empty
123 printf "s/\@\@NASM_VERSION_ID\@\@/%d/g\n", $nasm_id;
124 printf "s/\@\@NASM_VERSION_XID\@\@/0x%08x/g\n", $nasm_id;
125 printf "s/\@\@NASM_VER\@\@/%s/g\n", $line;
126 printf "s/\@\@NASM_MANGLED_VER\@\@/%s/g\n", $mangled_ver;
127 } elsif ( $what eq 'make' ) {
128 printf "NASM_VER=%s\n", $line;
129 printf "NASM_MAJOR_VER=%d\n", $nmaj;
130 printf "NASM_MINOR_VER=%d\n", $nmin;
131 printf "NASM_SUBMINOR_VER=%d\n", $nsmin;
132 printf "NASM_PATCHLEVEL_VER=%d\n", $nplvl;
133 } elsif ( $what eq 'id' ) {
134 print $nasm_id, "\n"; # Print ID in decimal
135 } elsif ( $what eq 'xid' ) {
136 printf "0x%08x\n", $nasm_id; # Print ID in hexadecimal
137 } else {
138 die "$0: Unknown output: $what\n";
141 exit 0;