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);