[nasm:nasm-2.15.xx] Auto-make the warning files

nasm-bot for H. Peter Anvin hpa at zytor.com
Tue Aug 18 15:21:03 PDT 2020


Commit-ID:  f3a3f9925c510c8668f9d2289403681bea8ebd3b
Gitweb:     http://repo.or.cz/w/nasm.git?a=commitdiff;h=f3a3f9925c510c8668f9d2289403681bea8ebd3b
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Tue, 18 Aug 2020 15:07:51 -0700
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Tue, 18 Aug 2020 15:07:51 -0700

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 at zytor.com>


---
 Makefile.in          | 29 +++++++++++++++++++----------
 Mkfiles/msvc.mak     | 21 +++++++++++++++------
 Mkfiles/openwcom.mak | 21 +++++++++++++++------
 asm/warnings.pl      | 23 +++++++++++++++++++++--
 4 files changed, 70 insertions(+), 24 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index bb023d02..baca4396 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -65,8 +65,8 @@ LN_S		= @LN_S@
 FIND		= find
 
 # Binary suffixes
-O               = @OBJEXT@
-X               = @EXEEXT@
+O              	= @OBJEXT@
+X              	= @EXEEXT@
 A		= @LIBEXT@
 
 # Debug stuff
@@ -97,7 +97,7 @@ endif
 	$(XMLTO) man --skip-validation $< 2>/dev/null
 
 #-- Begin File Lists --#
-NASM =	asm/nasm.$(O)
+NASM    = asm/nasm.$(O)
 NDISASM = disasm/ndisasm.$(O)
 
 LIBOBJ = stdlib/snprintf.$(O) stdlib/vsnprintf.$(O) stdlib/strlcpy.$(O) \
@@ -147,6 +147,8 @@ LIBOBJ = stdlib/snprintf.$(O) stdlib/vsnprintf.$(O) stdlib/strlcpy.$(O) \
 	\
 	disasm/disasm.$(O) disasm/sync.$(O)
 
+ALLOBJ = $(NASM) $(NDISASM) $(LIBOBJ)
+
 SUBDIRS  = stdlib nasmlib output asm disasm x86 common macros
 XSUBDIRS = test doc nsis rdoff
 DEPDIRS  = . include config x86 rdoff $(SUBDIRS)
@@ -258,21 +260,28 @@ x86/regs.h: x86/regs.dat x86/regs.pl
 	$(RUNPERL) $(srcdir)/x86/regs.pl h \
 		$(srcdir)/x86/regs.dat > x86/regs.h
 
-# Extract warnings from source code. Since this depends on
-# ALL the source files, this is only done on demand.
+# Extract warnings from source code. This is done automatically if any
+# C files have changed; the script is fast enough that that is
+# reasonable, but doesn't update the time stamp if the files aren't
+# changed, to avoid rebuilding everything every time. Track the actual
+# dependency by the empty file asm/warnings.time.
 WARNFILES = asm/warnings.c include/warnings.h doc/warnings.src
 
 warnings:
 	$(RM_F) $(WARNFILES)
+	$(MAKE) asm/warnings.time
+
+asm/warnings.time: $(ALLOBJ:. at OBJEXT@=.c)
+	: > asm/warnings.time
 	$(MAKE) $(WARNFILES)
 
-asm/warnings.c: asm/warnings.pl
+asm/warnings.c: asm/warnings.pl asm/warnings.time
 	$(RUNPERL) $(srcdir)/asm/warnings.pl c asm/warnings.c $(srcdir)
 
-include/warnings.h: asm/warnings.pl
+include/warnings.h: asm/warnings.pl asm/warnings.time
 	$(RUNPERL) $(srcdir)/asm/warnings.pl h include/warnings.h $(srcdir)
 
-doc/warnings.src: asm/warnings.pl
+doc/warnings.src: asm/warnings.pl asm/warnings.time
 	$(RUNPERL) $(srcdir)/asm/warnings.pl doc doc/warnings.src $(srcdir)
 
 # Assembler token hash
@@ -403,12 +412,12 @@ distclean: clean
 	done
 	$(RM_F) test/*.$(O)
 	$(RM_RF) autom4te*.cache
-	$(RM_F) Makefile *.dep
+	$(RM_F) Makefile *.dep asm/warnings.time
 
 cleaner: clean
 	$(RM_F) $(PERLREQ) *.1 nasm.spec
 	$(MAKE) -C doc clean
-	$(RM_F) *.dep
+	$(RM_F) *.dep asm/warnings.time
 
 spotless: distclean cleaner
 	$(RM_F) doc/Makefile
diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak
index 9346c293..ee2022d3 100644
--- a/Mkfiles/msvc.mak
+++ b/Mkfiles/msvc.mak
@@ -61,7 +61,7 @@ X               = .exe
 
 #-- Begin File Lists --#
 # Edit in Makefile.in, not here!
-NASM =	asm\nasm.$(O)
+NASM    = asm\nasm.$(O)
 NDISASM = disasm\ndisasm.$(O)
 
 LIBOBJ = stdlib\snprintf.$(O) stdlib\vsnprintf.$(O) stdlib\strlcpy.$(O) \
@@ -111,6 +111,8 @@ LIBOBJ = stdlib\snprintf.$(O) stdlib\vsnprintf.$(O) stdlib\strlcpy.$(O) \
 	\
 	disasm\disasm.$(O) disasm\sync.$(O)
 
+ALLOBJ = $(NASM) $(NDISASM) $(LIBOBJ)
+
 SUBDIRS  = stdlib nasmlib output asm disasm x86 common macros
 XSUBDIRS = test doc nsis rdoff
 DEPDIRS  = . include config x86 rdoff $(SUBDIRS)
@@ -217,21 +219,28 @@ x86\regs.h: x86\regs.dat x86\regs.pl
 	$(RUNPERL) $(srcdir)\x86\regs.pl h \
 		$(srcdir)\x86\regs.dat > x86\regs.h
 
-# Extract warnings from source code. Since this depends on
-# ALL the source files, this is only done on demand.
+# Extract warnings from source code. This is done automatically if any
+# C files have changed; the script is fast enough that that is
+# reasonable, but doesn't update the time stamp if the files aren't
+# changed, to avoid rebuilding everything every time. Track the actual
+# dependency by the empty file asm\warnings.time.
 WARNFILES = asm\warnings.c include\warnings.h doc\warnings.src
 
 warnings:
 	$(RM_F) $(WARNFILES)
+	$(MAKE) asm\warnings.time
+
+asm\warnings.time: $(ALLOBJ:. at OBJEXT@=.c)
+	: > asm\warnings.time
 	$(MAKE) $(WARNFILES)
 
-asm\warnings.c: asm\warnings.pl
+asm\warnings.c: asm\warnings.pl asm\warnings.time
 	$(RUNPERL) $(srcdir)\asm\warnings.pl c asm\warnings.c $(srcdir)
 
-include\warnings.h: asm\warnings.pl
+include\warnings.h: asm\warnings.pl asm\warnings.time
 	$(RUNPERL) $(srcdir)\asm\warnings.pl h include\warnings.h $(srcdir)
 
-doc\warnings.src: asm\warnings.pl
+doc\warnings.src: asm\warnings.pl asm\warnings.time
 	$(RUNPERL) $(srcdir)\asm\warnings.pl doc doc\warnings.src $(srcdir)
 
 # Assembler token hash
diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak
index 262a0419..9d080290 100644
--- a/Mkfiles/openwcom.mak
+++ b/Mkfiles/openwcom.mak
@@ -50,7 +50,7 @@ X               = .exe
 
 #-- Begin File Lists --#
 # Edit in Makefile.in, not here!
-NASM =	asm\nasm.$(O)
+NASM    = asm\nasm.$(O)
 NDISASM = disasm\ndisasm.$(O)
 
 LIBOBJ = stdlib\snprintf.$(O) stdlib\vsnprintf.$(O) stdlib\strlcpy.$(O) &
@@ -100,6 +100,8 @@ LIBOBJ = stdlib\snprintf.$(O) stdlib\vsnprintf.$(O) stdlib\strlcpy.$(O) &
 	&
 	disasm\disasm.$(O) disasm\sync.$(O)
 
+ALLOBJ = $(NASM) $(NDISASM) $(LIBOBJ)
+
 SUBDIRS  = stdlib nasmlib output asm disasm x86 common macros
 XSUBDIRS = test doc nsis rdoff
 DEPDIRS  = . include config x86 rdoff $(SUBDIRS)
@@ -230,21 +232,28 @@ x86\regs.h: x86\regs.dat x86\regs.pl
 	$(RUNPERL) $(srcdir)\x86\regs.pl h &
 		$(srcdir)\x86\regs.dat > x86\regs.h
 
-# Extract warnings from source code. Since this depends on
-# ALL the source files, this is only done on demand.
+# Extract warnings from source code. This is done automatically if any
+# C files have changed; the script is fast enough that that is
+# reasonable, but doesn't update the time stamp if the files aren't
+# changed, to avoid rebuilding everything every time. Track the actual
+# dependency by the empty file asm\warnings.time.
 WARNFILES = asm\warnings.c include\warnings.h doc\warnings.src
 
 warnings:
 	$(RM_F) $(WARNFILES)
+	$(MAKE) asm\warnings.time
+
+asm\warnings.time: $(ALLOBJ:. at OBJEXT@=.c)
+	: > asm\warnings.time
 	$(MAKE) $(WARNFILES)
 
-asm\warnings.c: asm\warnings.pl
+asm\warnings.c: asm\warnings.pl asm\warnings.time
 	$(RUNPERL) $(srcdir)\asm\warnings.pl c asm\warnings.c $(srcdir)
 
-include\warnings.h: asm\warnings.pl
+include\warnings.h: asm\warnings.pl asm\warnings.time
 	$(RUNPERL) $(srcdir)\asm\warnings.pl h include\warnings.h $(srcdir)
 
-doc\warnings.src: asm\warnings.pl
+doc\warnings.src: asm\warnings.pl asm\warnings.time
 	$(RUNPERL) $(srcdir)\asm\warnings.pl doc doc\warnings.src $(srcdir)
 
 # Assembler token hash
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);


More information about the Nasm-commits mailing list