aboutsummaryrefslogtreecommitdiffstats
path: root/asm
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2020-08-18 15:07:51 -0700
committerH. Peter Anvin <hpa@zytor.com>2020-08-18 15:07:51 -0700
commitf3a3f9925c510c8668f9d2289403681bea8ebd3b (patch)
treef75a1d9938fc1a018bec84d664e102cbba5f69e7 /asm
parentfb95a2ef7a24c63cbfc17461e1dc05cf01ab80a4 (diff)
downloadnasm-f3a3f9925c510c8668f9d2289403681bea8ebd3b.tar.gz
nasm-f3a3f9925c510c8668f9d2289403681bea8ebd3b.tar.xz
nasm-f3a3f9925c510c8668f9d2289403681bea8ebd3b.zip
Auto-make the warning files
The warning files are generated by a script, but the scripts is fast enough run every time a C file is updated. To prevent having to rebuild every file, however, make the generation script only actually modify the file if it has changed. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Diffstat (limited to 'asm')
-rwxr-xr-xasm/warnings.pl23
1 files changed, 21 insertions, 2 deletions
diff --git a/asm/warnings.pl b/asm/warnings.pl
index 8a79568a..6660d17a 100755
--- a/asm/warnings.pl
+++ b/asm/warnings.pl
@@ -1,6 +1,7 @@
#!/usr/bin/perl
use strict;
+use Fcntl qw(:seek);
use File::Find;
use File::Basename;
@@ -134,8 +135,9 @@ sub sort_warnings {
my @warn_noall = @warnings;
pop @warn_noall if ($warn_noall[$#warn_noall]->{name} eq 'all');
-open(my $out, '>', $outfile)
- or die "$0: cannot open output file $outfile: $!\n";
+my $outdata;
+open(my $out, '>', \$outdata)
+ or die "$0: cannot create memory file: $!\n";
if ($what eq 'c') {
print $out "#include \"error.h\"\n\n";
@@ -273,4 +275,21 @@ if ($what eq 'c') {
print $out "\\b \\i\\c{", $pfx, "} ", @doc, "\n";
}
}
+
+close($out);
+
+# Write data to file if and only if it has changed
+# Windows requires append mode here
+open($out, '+>>', $outfile)
+ or die "$0: cannot open output file $outfile: $!\n";
+my $datalen = length($outdata);
+my $oldlen = read($out, my $oldoutdata, $datalen+1);
+if (!defined($oldlen) || $oldlen != $datalen ||
+ !($oldoutdata eq $outdata)) {
+ # Data changed, must rewrite
+ truncate($out, 0);
+ seek($out, 0, SEEK_SET)
+ or die "$0: cannot rewind output file $outfile: $!\n";
+ print $out $outdata;
+}
close($out);