2002-05-04 11:57:52 +08:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
|
|
|
# version.pl
|
|
|
|
#
|
|
|
|
# Parse the NASM version file and produce appropriate macros
|
|
|
|
#
|
|
|
|
# The NASM version number is assumed to consist of:
|
|
|
|
#
|
2002-05-21 10:28:51 +08:00
|
|
|
# <major>.<minor>[.<subminor>][pl<patchlevel>]]<tail>
|
2002-05-04 11:57:52 +08:00
|
|
|
#
|
|
|
|
# ... where <tail> is not necessarily numeric.
|
|
|
|
#
|
|
|
|
# This defines the following macros:
|
|
|
|
#
|
|
|
|
# version.h:
|
|
|
|
# NASM_MAJOR_VER
|
|
|
|
# NASM_MINOR_VER
|
|
|
|
# NASM_SUBMINOR_VER -- this is zero if no subminor
|
2002-05-20 09:04:34 +08:00
|
|
|
# NASM_PATCHLEVEL_VER -- this is zero is no patchlevel
|
|
|
|
# NASM_VERSION_ID -- version number encoded
|
2002-05-04 11:57:52 +08:00
|
|
|
# NASM_VER -- whole version number as a string
|
|
|
|
#
|
|
|
|
# version.mac:
|
|
|
|
# __NASM_MAJOR__
|
|
|
|
# __NASM_MINOR__
|
|
|
|
# __NASM_SUBMINOR__
|
2002-05-20 09:04:34 +08:00
|
|
|
# __NASM_PATCHLEVEL__
|
|
|
|
# __NASM_VERSION_ID__
|
2002-05-04 11:57:52 +08:00
|
|
|
# __NASM_VER__
|
|
|
|
#
|
|
|
|
|
|
|
|
($what) = @ARGV;
|
|
|
|
|
|
|
|
$line = <STDIN>;
|
|
|
|
chomp $line;
|
|
|
|
|
2002-05-21 10:28:51 +08:00
|
|
|
undef $man, $min, $smin, $plvl, $tail;
|
2007-09-23 07:19:19 +08:00
|
|
|
$is_rc = 0;
|
2002-05-21 10:28:51 +08:00
|
|
|
|
2007-09-23 07:19:19 +08:00
|
|
|
if ( $line =~ /^([0-9]+)\.([0-9]+)(.*)$/ ) {
|
2002-05-21 10:28:51 +08:00
|
|
|
$maj = $1;
|
|
|
|
$min = $2;
|
2007-09-23 07:19:19 +08:00
|
|
|
$tail = $3;
|
|
|
|
if ( $tail =~ /^\.([0-9]+)(.*)$/ ) {
|
2002-05-21 10:28:51 +08:00
|
|
|
$smin = $1;
|
2007-09-23 07:19:19 +08:00
|
|
|
$tail = $2;
|
2002-05-21 10:28:51 +08:00
|
|
|
}
|
2007-09-23 07:19:19 +08:00
|
|
|
if ( $tail =~ /^(pl|\.)([0-9]+)(.*)$/ ) {
|
2002-05-21 10:28:51 +08:00
|
|
|
$plvl = $2;
|
2007-09-23 07:19:19 +08:00
|
|
|
$tail = $3;
|
|
|
|
} elsif ( $tail =~ /^rc([0-9]+)(.*)$/ ) {
|
|
|
|
$is_rc = 1;
|
|
|
|
$plvl = $1;
|
|
|
|
$tail = $2;
|
2002-05-21 10:28:51 +08:00
|
|
|
}
|
2002-05-04 11:57:52 +08:00
|
|
|
} else {
|
|
|
|
die "$0: Invalid input format\n";
|
|
|
|
}
|
|
|
|
|
2002-05-21 10:28:51 +08:00
|
|
|
$nmaj = $maj+0; $nmin = $min+0;
|
|
|
|
$nsmin = $smin+0; $nplvl = $plvl+0;
|
|
|
|
|
2007-09-23 07:19:19 +08:00
|
|
|
if ($is_rc) {
|
|
|
|
$nplvl += 90;
|
|
|
|
if ($nsmin > 0) {
|
|
|
|
$nsmin--;
|
|
|
|
} else {
|
|
|
|
$nsmin = 99;
|
|
|
|
if ($nmin > 0) {
|
|
|
|
$nmin--;
|
|
|
|
} else {
|
|
|
|
$nmin = 99;
|
|
|
|
$nmaj--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-20 09:04:34 +08:00
|
|
|
$nasm_id = ($nmaj << 24)+($nmin << 16)+($nsmin << 8)+$nplvl;
|
|
|
|
|
2007-09-23 07:35:11 +08:00
|
|
|
$mangled_ver = sprintf("%d.%02d.%02d", $nmaj, $nmin, $nsmin);
|
|
|
|
$mangled_ver .= '.'.$nplvl if ($nplvl != 0);
|
|
|
|
|
2002-05-04 11:57:52 +08:00
|
|
|
if ( $what eq 'h' ) {
|
|
|
|
print "#ifndef NASM_VERSION_H\n";
|
|
|
|
print "#define NASM_VERSION_H\n";
|
2002-05-20 09:04:34 +08:00
|
|
|
printf "#define NASM_MAJOR_VER %d\n", $nmaj;
|
|
|
|
printf "#define NASM_MINOR_VER %d\n", $nmin;
|
|
|
|
printf "#define NASM_SUBMINOR_VER %d\n", $nsmin;
|
|
|
|
printf "#define NASM_PATCHLEVEL_VER %d\n", $nplvl;
|
|
|
|
printf "#define NASM_VERSION_ID 0x%08x\n", $nasm_id;
|
|
|
|
printf "#define NASM_VER \"%s\"\n", $line;
|
2002-05-04 11:57:52 +08:00
|
|
|
print "#endif /* NASM_VERSION_H */\n";
|
|
|
|
} elsif ( $what eq 'mac' ) {
|
2002-05-04 12:10:09 +08:00
|
|
|
printf "%%define __NASM_MAJOR__ %d\n", $nmaj;
|
|
|
|
printf "%%define __NASM_MINOR__ %d\n", $nmin;
|
2002-05-04 11:57:52 +08:00
|
|
|
printf "%%define __NASM_SUBMINOR__ %d\n", $nsmin;
|
2002-05-20 09:04:34 +08:00
|
|
|
printf "%%define __NASM_PATCHLEVEL__ %d\n", $nplvl;
|
|
|
|
printf "%%define __NASM_VERSION_ID__ 0%08Xh\n", $nasm_id;
|
2002-05-04 12:10:09 +08:00
|
|
|
printf "%%define __NASM_VER__ \"%s\"\n", $line;
|
2007-09-23 07:35:11 +08:00
|
|
|
} elsif ( $what eq 'sed' ) {
|
|
|
|
printf "s/\@\@NASM_MAJOR\@\@/%d/g\n", $nmaj;
|
|
|
|
printf "s/\@\@NASM_MINOR\@\@/%d/g\n", $nmin;
|
|
|
|
printf "s/\@\@NASM_SUBMINOR\@\@/%d/g\n", $nsmin;
|
|
|
|
printf "s/\@\@NASM_PATCHLEVEL\@\@/%d/g\n", $nplvl;
|
|
|
|
printf "s/\@\@NASM_VERSION_ID\@\@/%d/g\n", $nasm_id;
|
|
|
|
printf "s/\@\@NASM_VERSION_XID\@\@/0x%08x/g\n", $nasm_id;
|
|
|
|
printf "s/\@\@NASM_VER\@\@/%s/g\n", $line;
|
|
|
|
printf "s/\@\@NASM_MANGLED_VER\@\@/%s/g\n", $mangled_ver;
|
2002-05-21 10:28:51 +08:00
|
|
|
} elsif ( $what eq 'id' ) {
|
|
|
|
print $nasm_id, "\n"; # Print ID in decimal
|
|
|
|
} elsif ( $what eq 'xid' ) {
|
|
|
|
printf "0x%08x\n", $nasm_id; # Print ID in hexadecimal
|
2002-05-04 11:57:52 +08:00
|
|
|
} else {
|
|
|
|
die "$0: Unknown output: $what\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
|