blob: d8fdad49ffcf7c415496dd0459e809a7052715b9 [file] [log] [blame]
H. Peter Anvine87613b2002-05-04 03:57:52 +00001#!/usr/bin/perl
2#
3# version.pl
H. Peter Anvine87613b2002-05-04 03:57:52 +00004#
5# Parse the NASM version file and produce appropriate macros
6#
7# The NASM version number is assumed to consist of:
8#
H. Peter Anvinf29b1282002-05-21 02:28:51 +00009# <major>.<minor>[.<subminor>][pl<patchlevel>]]<tail>
H. Peter Anvine87613b2002-05-04 03:57:52 +000010#
11# ... where <tail> is not necessarily numeric.
12#
13# This defines the following macros:
14#
15# version.h:
16# NASM_MAJOR_VER
17# NASM_MINOR_VER
18# NASM_SUBMINOR_VER -- this is zero if no subminor
H. Peter Anvin5a09ee32002-05-20 01:04:34 +000019# NASM_PATCHLEVEL_VER -- this is zero is no patchlevel
20# NASM_VERSION_ID -- version number encoded
H. Peter Anvine87613b2002-05-04 03:57:52 +000021# NASM_VER -- whole version number as a string
22#
23# version.mac:
24# __NASM_MAJOR__
25# __NASM_MINOR__
26# __NASM_SUBMINOR__
H. Peter Anvin5a09ee32002-05-20 01:04:34 +000027# __NASM_PATCHLEVEL__
28# __NASM_VERSION_ID__
H. Peter Anvine87613b2002-05-04 03:57:52 +000029# __NASM_VER__
30#
31
32($what) = @ARGV;
33
34$line = <STDIN>;
35chomp $line;
36
H. Peter Anvinf29b1282002-05-21 02:28:51 +000037undef $man, $min, $smin, $plvl, $tail;
38
39if ( $line =~ /^([0-9]+)\.([0-9]+)/ ) {
40 $maj = $1;
41 $min = $2;
H. Peter Anvin5a09ee32002-05-20 01:04:34 +000042 $tail = $';
H. Peter Anvinf29b1282002-05-21 02:28:51 +000043 if ( $tail =~ /^\.([0-9]+)/ ) {
44 $smin = $1;
45 $tail = $';
46 }
47 if ( $tail =~ /^(pl|\.)([0-9]+)/ ) {
48 $plvl = $2;
49 $tail = $';
50 }
H. Peter Anvine87613b2002-05-04 03:57:52 +000051} else {
52 die "$0: Invalid input format\n";
53}
54
H. Peter Anvinf29b1282002-05-21 02:28:51 +000055$nmaj = $maj+0; $nmin = $min+0;
56$nsmin = $smin+0; $nplvl = $plvl+0;
57
H. Peter Anvin5a09ee32002-05-20 01:04:34 +000058$nasm_id = ($nmaj << 24)+($nmin << 16)+($nsmin << 8)+$nplvl;
59
H. Peter Anvine87613b2002-05-04 03:57:52 +000060if ( $what eq 'h' ) {
61 print "#ifndef NASM_VERSION_H\n";
62 print "#define NASM_VERSION_H\n";
H. Peter Anvin5a09ee32002-05-20 01:04:34 +000063 printf "#define NASM_MAJOR_VER %d\n", $nmaj;
64 printf "#define NASM_MINOR_VER %d\n", $nmin;
65 printf "#define NASM_SUBMINOR_VER %d\n", $nsmin;
66 printf "#define NASM_PATCHLEVEL_VER %d\n", $nplvl;
67 printf "#define NASM_VERSION_ID 0x%08x\n", $nasm_id;
68 printf "#define NASM_VER \"%s\"\n", $line;
H. Peter Anvine87613b2002-05-04 03:57:52 +000069 print "#endif /* NASM_VERSION_H */\n";
70} elsif ( $what eq 'mac' ) {
H. Peter Anvin00edfad2002-05-04 04:10:09 +000071 printf "%%define __NASM_MAJOR__ %d\n", $nmaj;
72 printf "%%define __NASM_MINOR__ %d\n", $nmin;
H. Peter Anvine87613b2002-05-04 03:57:52 +000073 printf "%%define __NASM_SUBMINOR__ %d\n", $nsmin;
H. Peter Anvin5a09ee32002-05-20 01:04:34 +000074 printf "%%define __NASM_PATCHLEVEL__ %d\n", $nplvl;
75 printf "%%define __NASM_VERSION_ID__ 0%08Xh\n", $nasm_id;
H. Peter Anvin00edfad2002-05-04 04:10:09 +000076 printf "%%define __NASM_VER__ \"%s\"\n", $line;
H. Peter Anvinf29b1282002-05-21 02:28:51 +000077} elsif ( $what eq 'id' ) {
78 print $nasm_id, "\n"; # Print ID in decimal
79} elsif ( $what eq 'xid' ) {
80 printf "0x%08x\n", $nasm_id; # Print ID in hexadecimal
H. Peter Anvine87613b2002-05-04 03:57:52 +000081} else {
82 die "$0: Unknown output: $what\n";
83}
84
85exit 0;
86