From 8317d7ae2f0bf3cf3dd6814eed5a1e3743de8f7f Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin (Intel)" Date: Tue, 7 Jul 2026 14:11:08 -0700 Subject: [PATCH] Mkfiles/msvc.mak: make the docs: target actually work under real nmake The docs: target fed doc/Makefile.in directly to nmake, but that file relies on several GNU make-only constructs nmake cannot parse at all: the $^ automatic variable (not valid nmake macro syntax -- fatal parse error), $< used outside of an inference rule (silently unsupported, since nmake only defines $< within .SUFFIXES-style rules), and the GNU-only "-include *.dep" optional wildcard include directive (nmake only understands the unrelated "!include" directive). Add tools/mkmsvcdocmak.pl, which rewrites just those constructs to their explicit nmake-safe equivalents in a generated copy (doc/Makefile.msvc), leaving doc/Makefile.in itself untouched for the Unix/GNU make build. Verified by rewriting doc/Makefile.in this way and building nasmdoc.pdf through it with GNU make standing in for nmake. Also, doc/Makefile.in expects doc/warnings.src, doc/perlbreq.src and doc/pptok.src to have already been generated -- the Unix "doc" target does this via the top-level Makefile.in before recursing into doc/, but msvc.mak's docs: target had no equivalent step. warnings.src and pptok.src already had msvc.mak rules (just not wired up as prerequisites of docs:); perlbreq.src had no rule at all, since the top-level Makefile.in generates it with a POSIX find/sed pipeline that doesn't translate to Windows. Add tools/genperlbreq.pl, a portable pure-Perl equivalent (using File::Find), and a doc\perlbreq.src rule in msvc.mak that uses it; verified it produces output byte-identical to the existing POSIX pipeline. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Mkfiles/msvc.mak | 20 +++++++++++++-- tools/genperlbreq.pl | 45 ++++++++++++++++++++++++++++++++ tools/mkmsvcdocmak.pl | 60 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 tools/genperlbreq.pl create mode 100644 tools/mkmsvcdocmak.pl diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index c1abe41a5..9716bbe83 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -358,6 +358,9 @@ doc\warnings.src: asm\warnings.pl asm\warnings.dat $(RUNPERL) $(srcdir)\asm\warnings.pl doc doc\warnings.src \ $(srcdir)\asm\warnings.dat +doc\perlbreq.src: tools\genperlbreq.pl $(DIRS) + $(RUNPERL) tools\genperlbreq.pl $(srcdir) doc\perlbreq.src + $(PERLREQ): $(DIRS) perlreq: $(PERLREQ) $(PHONY) @@ -418,6 +421,7 @@ cleaner: clean spotless: distclean cleaner -del /f doc\Makefile + -del /f doc\msvc.mak -del doc\*~ -del doc\*.bak @@ -425,11 +429,23 @@ strip: # Abuse doc/Makefile.in to build nasmdoc.pdf only. # +# doc/Makefile.in expects doc\warnings.src, doc\perlbreq.src and +# doc\pptok.src to already have been generated by the top-level build +# (as the Unix "doc" target does); build them here first. +# +# doc/Makefile.in is written for GNU make and relies on a few +# constructs nmake cannot parse at all ($^, $< outside an inference +# rule, and the GNU-only "-include *.dep" directive); tools/mkmsvcdocmak.pl +# rewrites those to their nmake-safe equivalents in a generated copy, +# doc\msvc.mak, which is what actually gets fed to nmake below. +# # Building the documentation requires Ghostscript and the Roboto / # Roboto Mono fonts to be installed and discoverable; see # doc/source.src ("Optional Build Tools") for details. -docs: - cd doc && $(MAKE) /f Makefile.in srcdir=. top_srcdir=.. \ +docs: doc\warnings.src doc\perlbreq.src doc\pptok.src + $(RUNPERL) $(srcdir)\tools\mkmsvcdocmak.pl \ + $(srcdir)\doc\Makefile.in doc\msvc.mak + cd doc && $(MAKE) /f msvc.mak srcdir=. top_srcdir=.. \ PERL=$(PERL) PDFOPT= nasmdoc.pdf everything: all docs nsis diff --git a/tools/genperlbreq.pl b/tools/genperlbreq.pl new file mode 100644 index 000000000..e96bb5ba4 --- /dev/null +++ b/tools/genperlbreq.pl @@ -0,0 +1,45 @@ +#!/usr/bin/perl +# SPDX-License-Identifier: BSD-2-Clause +# Copyright 1996-2025 The NASM Authors - All Rights Reserved + +# +# Scan the source tree for "use Module;" lines in *.pl/*.ph files and +# produce doc/perlbreq.src, the list of Perl module prerequisites +# included in the documentation. This is a portable (pure Perl) +# equivalent of the find/sed pipeline used by the top-level +# Makefile.in's perlbreq.si/doc/perlbreq.src rules, for use by build +# systems (e.g. Mkfiles/msvc.mak) that cannot rely on POSIX find/sed +# being available. +# + +use strict; +use warnings; +use File::Find; + +my ($srcdir, $outfile) = @ARGV; +die "Usage: $0 \n" unless defined($srcdir) && defined($outfile); + +my %mods; + +find({ + wanted => sub { + return unless /\.p[lh]$/; + open(my $fh, '<', $_) or return; + while (my $line = <$fh>) { + if ($line =~ /^\s*use\s+([[:upper:]][^\s;]*)/) { + my $mod = $1; + next if $mod =~ /^Win32/; + $mods{$mod} = 1; + } + } + close($fh); + }, + no_chdir => 1, +}, $srcdir); + +open(my $out, '>', $outfile) or die "$0: cannot open: $outfile\n"; +foreach my $mod (sort keys %mods) { + print $out "\\c $mod\n"; +} +print $out "\\c Win32 (if building on Windows only)\n"; +close($out); diff --git a/tools/mkmsvcdocmak.pl b/tools/mkmsvcdocmak.pl new file mode 100644 index 000000000..32d212777 --- /dev/null +++ b/tools/mkmsvcdocmak.pl @@ -0,0 +1,60 @@ +#!/usr/bin/perl +# SPDX-License-Identifier: BSD-2-Clause +# Copyright 1996-2025 The NASM Authors - All Rights Reserved + +# +# doc/Makefile.in is written for GNU make (used unmodified, via +# autoconf substitution, on Unix). It relies on a handful of GNU +# make-only constructs -- the $^ automatic variable (not valid nmake +# syntax at all: nmake's parser treats a bare "$^" as an illegal macro +# reference and aborts), the $< automatic variable used outside of an +# inference rule (silently unsupported by nmake, since nmake only +# defines $< within .SUFFIXES-style inference rules), and the +# GNU-only "-include *.dep" optional-include directive (nmake only +# understands the "!include" directive and has no equivalent "ignore +# missing file, glob patterns allowed" form). +# +# Mkfiles/msvc.mak needs to feed doc/Makefile.in directly to nmake (it +# doesn't have its own copy of the doc build rules to maintain in +# parallel), so this script produces an nmake-safe copy of the file by +# rewriting just those constructs to their equivalent explicit form. +# doc/Makefile.in itself is left untouched for the Unix/GNU make +# build; only the copy this script writes is affected. +# + +use strict; +use warnings; + +my ($in, $out) = @ARGV; +die "Usage: $0 \n" unless defined($in) && defined($out); + +open(my $ifh, '<', $in) or die "$0: cannot open: $in\n"; +open(my $ofh, '>', $out) or die "$0: cannot open: $out\n"; + +while (my $line = <$ifh>) { + # insns.src: inslist.pl ../x86/insns.xda + # $(RUNPERL) $^ $@ + if (index($line, '$(RUNPERL) $^ $@') >= 0) { + $line =~ s/\$\(RUNPERL\) \$\^ \$\@/\$(RUNPERL) inslist.pl ..\/x86\/insns.xda \$\@/; + } + + # $(htmltarget)/nasmdoc.dip/nasmdoc.txt: $< is the first prerequisite + # of $(ALLSRCS), i.e. $(SRCS) (nasmdoc.src). + $line =~ s/(\$\(RDSRC\)\s+(?:-ohtml html|dip|txt))\s+\$\s+\$\@)/$1nasmdoc-raw.pdf$2/; + + # GNU make-only optional wildcard include of auto-dependency files; + # not parseable by nmake at all, and unneeded for a one-shot build. + next if $line =~ /^-include\s+\*\.dep\s*$/; + + print $ofh $line; +} + +close($ifh); +close($ofh);