2002-05-04 11:57:52 +08:00
|
|
|
#!/usr/bin/perl
|
2009-06-29 07:52:56 +08:00
|
|
|
## --------------------------------------------------------------------------
|
|
|
|
##
|
2016-05-17 11:30:09 +08:00
|
|
|
## Copyright 1996-2016 The NASM Authors - All Rights Reserved
|
2009-06-29 07:52:56 +08:00
|
|
|
## See the file AUTHORS included with the NASM distribution for
|
|
|
|
## the specific copyright holders.
|
|
|
|
##
|
|
|
|
## Redistribution and use in source and binary forms, with or without
|
|
|
|
## modification, are permitted provided that the following
|
|
|
|
## conditions are met:
|
|
|
|
##
|
|
|
|
## * Redistributions of source code must retain the above copyright
|
|
|
|
## notice, this list of conditions and the following disclaimer.
|
|
|
|
## * Redistributions in binary form must reproduce the above
|
|
|
|
## copyright notice, this list of conditions and the following
|
|
|
|
## disclaimer in the documentation and/or other materials provided
|
|
|
|
## with the distribution.
|
|
|
|
##
|
|
|
|
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
## CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
## DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
|
|
## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
## NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
## OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
|
|
## EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
##
|
|
|
|
## --------------------------------------------------------------------------
|
|
|
|
|
2002-05-04 11:57:52 +08:00
|
|
|
#
|
|
|
|
# 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
|
|
|
#
|
2007-09-28 12:12:17 +08:00
|
|
|
# ... where <tail> is not necessarily numeric, but if it is of the form
|
|
|
|
# -<digits> it is assumed to be a snapshot release.
|
2002-05-04 11:57:52 +08:00
|
|
|
#
|
|
|
|
# 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
|
2007-09-28 12:12:17 +08:00
|
|
|
# NASM_SNAPSHOT -- if snapshot
|
2002-05-20 09:04:34 +08:00
|
|
|
# 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__
|
2007-09-28 12:12:17 +08:00
|
|
|
# __NASM_SNAPSHOT__
|
2002-05-20 09:04:34 +08:00
|
|
|
# __NASM_VERSION_ID__
|
2002-05-04 11:57:52 +08:00
|
|
|
# __NASM_VER__
|
|
|
|
#
|
|
|
|
|
|
|
|
($what) = @ARGV;
|
|
|
|
|
|
|
|
$line = <STDIN>;
|
|
|
|
chomp $line;
|
|
|
|
|
2019-08-10 04:30:19 +08:00
|
|
|
undef $maj;
|
|
|
|
undef $min;
|
|
|
|
undef $smin;
|
|
|
|
undef $plvl;
|
|
|
|
undef $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";
|
|
|
|
}
|
|
|
|
|
2008-11-02 03:57:05 +08:00
|
|
|
if ($tail =~ /^\-([0-9]+)$/) {
|
2007-09-28 12:12:17 +08:00
|
|
|
$snapshot = $1;
|
|
|
|
} else {
|
|
|
|
undef $snapshot;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2008-10-25 01:10:32 +08:00
|
|
|
$mangled_ver = sprintf("%d.%02d", $nmaj, $nmin);
|
2008-10-26 03:41:29 +08:00
|
|
|
if ($nsmin || $nplvl || defined($snapshot)) {
|
|
|
|
$mangled_ver .= sprintf(".%02d", $nsmin);
|
|
|
|
if ($nplvl || defined($snapshot)) {
|
|
|
|
$mangled_ver .= '.'.$nplvl;
|
|
|
|
}
|
|
|
|
}
|
2007-09-28 12:12:17 +08:00
|
|
|
($mtail = $tail) =~ tr/-/./;
|
|
|
|
$mangled_ver .= $mtail;
|
2007-09-23 07:35:11 +08:00
|
|
|
|
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;
|
2007-09-28 12:12:17 +08:00
|
|
|
if (defined($snapshot)) {
|
|
|
|
printf "#define NASM_SNAPSHOT %d\n", $snapshot;
|
|
|
|
}
|
2002-05-20 09:04:34 +08:00
|
|
|
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' ) {
|
2016-07-14 05:23:48 +08:00
|
|
|
print "STD: version\n";
|
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;
|
2007-09-28 12:12:17 +08:00
|
|
|
if (defined($snapshot)) {
|
|
|
|
printf "%%define __NASM_SNAPSHOT__ %d\n", $snapshot;
|
|
|
|
}
|
2002-05-20 09:04:34 +08:00
|
|
|
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;
|
2007-09-28 12:12:17 +08:00
|
|
|
printf "s/\@\@NASM_SNAPSHOT\@\@/%d/g\n", $snapshot; # Possibly empty
|
2007-09-23 07:35:11 +08:00
|
|
|
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;
|
2008-02-06 13:29:32 +08:00
|
|
|
} elsif ( $what eq 'make' ) {
|
|
|
|
printf "NASM_VER=%s\n", $line;
|
|
|
|
printf "NASM_MAJOR_VER=%d\n", $nmaj;
|
|
|
|
printf "NASM_MINOR_VER=%d\n", $nmin;
|
|
|
|
printf "NASM_SUBMINOR_VER=%d\n", $nsmin;
|
|
|
|
printf "NASM_PATCHLEVEL_VER=%d\n", $nplvl;
|
2009-04-07 10:12:34 +08:00
|
|
|
} elsif ( $what eq 'nsis' ) {
|
|
|
|
printf "!define VERSION \"%s\"\n", $line;
|
|
|
|
printf "!define MAJOR_VER %d\n", $nmin;
|
|
|
|
printf "!define MINOR_VER %d\n", $nmin;
|
|
|
|
printf "!define SUBMINOR_VER %d\n", $nsmin;
|
|
|
|
printf "!define PATCHLEVEL_VER %d\n", $nplvl;
|
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
|
2016-05-17 11:30:09 +08:00
|
|
|
} elsif ( $what eq 'docsrc' ) {
|
|
|
|
printf "\\M{version}{%s}\n", $line;
|
|
|
|
printf "\\M{subtitle}{version %s}\n", $line;
|
2002-05-04 11:57:52 +08:00
|
|
|
} else {
|
|
|
|
die "$0: Unknown output: $what\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
exit 0;
|