Update documentation
[platform/upstream/nasm.git] / version.pl
1 #!/usr/bin/perl
2 #
3 # version.pl
4 #
5 # Parse the NASM version file and produce appropriate macros
6 #
7 # The NASM version number is assumed to consist of:
8 #
9 # <major>.<minor>[.<subminor>][pl<patchlevel>]]<tail>
10 #
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
19 # NASM_PATCHLEVEL_VER   -- this is zero is no patchlevel
20 # NASM_VERSION_ID       -- version number encoded
21 # NASM_VER              -- whole version number as a string
22 #
23 # version.mac:
24 # __NASM_MAJOR__
25 # __NASM_MINOR__
26 # __NASM_SUBMINOR__
27 # __NASM_PATCHLEVEL__
28 # __NASM_VERSION_ID__
29 # __NASM_VER__
30 #
31
32 ($what) = @ARGV;
33
34 $line = <STDIN>;
35 chomp $line;
36
37 undef $man, $min, $smin, $plvl, $tail;
38
39 if ( $line =~ /^([0-9]+)\.([0-9]+)/ ) {
40     $maj  = $1;
41     $min  = $2;
42     $tail = $';
43     if ( $tail =~ /^\.([0-9]+)/ ) {
44         $smin = $1;
45         $tail = $';
46     }
47     if ( $tail =~ /^(pl|\.)([0-9]+)/ ) {
48         $plvl = $2;
49         $tail = $';
50     }
51 } else {
52     die "$0: Invalid input format\n";
53 }
54
55 $nmaj = $maj+0;   $nmin = $min+0;
56 $nsmin = $smin+0; $nplvl = $plvl+0;
57
58 $nasm_id = ($nmaj << 24)+($nmin << 16)+($nsmin << 8)+$nplvl;
59
60 if ( $what eq 'h' ) {
61     print  "#ifndef NASM_VERSION_H\n";
62     print  "#define NASM_VERSION_H\n";
63     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;
69     print  "#endif /* NASM_VERSION_H */\n";
70 } elsif ( $what eq 'mac' ) {
71     printf "%%define __NASM_MAJOR__ %d\n", $nmaj;
72     printf "%%define __NASM_MINOR__ %d\n", $nmin;
73     printf "%%define __NASM_SUBMINOR__ %d\n", $nsmin;
74     printf "%%define __NASM_PATCHLEVEL__ %d\n", $nplvl;
75     printf "%%define __NASM_VERSION_ID__ 0%08Xh\n", $nasm_id;
76     printf "%%define __NASM_VER__ \"%s\"\n", $line;
77 } 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
81 } else {
82     die "$0: Unknown output: $what\n";
83 }
84
85 exit 0;
86