MSVC: fix dependency generation and building RDOFF under MSVC

1. The mkdep.pl program didn't handle excluded dependencies correctly,
   causing it to error out due to config/config.h not existing.
2. NMAKE is sensitive to the order suffixes appear in .SUFFIXES,
   causing it to try to use the builtin rule .c.exe instead of
   .c.obj -> .obj.exe.
3. NMAKE doesn't handle the && operator between commands.
4. The !ifdef jungle around dependency generation was wrong.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
H. Peter Anvin 2018-06-18 13:50:25 -07:00
parent ef4e5e209f
commit 5d8193367e
3 changed files with 41 additions and 47 deletions

View File

@ -50,7 +50,7 @@ XMLTO = @XMLTO@
MAKENSIS = makensis MAKENSIS = makensis
MKDIR = mkdir MKDIR = mkdir -p
RM_F = rm -f RM_F = rm -f
RM_RF = rm -rf RM_RF = rm -rf
LN_S = @LN_S@ LN_S = @LN_S@
@ -277,6 +277,13 @@ asm/directbl.c: asm/directiv.dat nasmlib/perfhash.pl perllib/phash.ph
perlreq: $(PERLREQ) perlreq: $(PERLREQ)
# This rule is only used for RDOFF
.$(O)$(X):
$(CC) $(ALL_CFLAGS) -o $@ $< $(LDFLAGS) $(RDFLIB) $(NASMLIB) $(LIBS)
RDFLN = cd rdoff && ln -s
RDFLNPFX =
#-- Begin RDOFF Shared Rules --# #-- Begin RDOFF Shared Rules --#
RDFLIBOBJ = rdoff/rdoff.$(O) rdoff/rdfload.$(O) rdoff/symtab.$(O) \ RDFLIBOBJ = rdoff/rdoff.$(O) rdoff/rdfload.$(O) rdoff/symtab.$(O) \
@ -291,31 +298,23 @@ RDF2BINLINKS = rdoff/rdf2com$(X) rdoff/rdf2ith$(X) \
RDFLIB = rdoff/librdoff.$(A) RDFLIB = rdoff/librdoff.$(A)
RDFLIBS = $(RDFLIB) $(NASMLIB) RDFLIBS = $(RDFLIB) $(NASMLIB)
# This rule is only used for rdoff, to allow common rules
MAKERDF = $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $< $(RDFLIB) $(NASMLIB) $(LIBS)
rdoff/rdfdump$(X): rdoff/rdfdump.$(O) $(RDFLIBS) rdoff/rdfdump$(X): rdoff/rdfdump.$(O) $(RDFLIBS)
$(MAKERDF)
rdoff/ldrdf$(X): rdoff/ldrdf.$(O) $(RDFLIBS) rdoff/ldrdf$(X): rdoff/ldrdf.$(O) $(RDFLIBS)
$(MAKERDF)
rdoff/rdx$(X): rdoff/rdx.$(O) $(RDFLIBS) rdoff/rdx$(X): rdoff/rdx.$(O) $(RDFLIBS)
$(MAKERDF)
rdoff/rdflib$(X): rdoff/rdflib.$(O) $(RDFLIBS) rdoff/rdflib$(X): rdoff/rdflib.$(O) $(RDFLIBS)
$(MAKERDF)
rdoff/rdf2bin$(X): rdoff/rdf2bin.$(O) $(RDFLIBS) rdoff/rdf2bin$(X): rdoff/rdf2bin.$(O) $(RDFLIBS)
$(MAKERDF)
rdoff/rdf2com$(X): rdoff/rdf2bin$(X) rdoff/rdf2com$(X): rdoff/rdf2bin$(X)
$(RM_F) rdoff/rdf2com$(X) $(RM_F) rdoff/rdf2com$(X)
cd rdoff && $(LN_S) rdf2bin$(X) rdf2com$(X) $(RDFLN) $(RDFLNPFX)rdf2bin$(X) $(RDFLNPFX)rdf2com$(X)
rdoff/rdf2ith$(X): rdoff/rdf2bin$(X) rdoff/rdf2ith$(X): rdoff/rdf2bin$(X)
$(RM_F) rdoff/rdf2ith$(X) $(RM_F) rdoff/rdf2ith$(X)
cd rdoff && $(LN_S) rdf2bin$(X) rdf2ith$(X) $(RDFLN) $(RDFLNPFX)rdf2bin$(X) $(RDFLNPFX)rdf2ith$(X)
rdoff/rdf2ihx$(X): rdoff/rdf2bin$(X) rdoff/rdf2ihx$(X): rdoff/rdf2bin$(X)
$(RM_F) rdoff/rdf2ihx$(X) $(RM_F) rdoff/rdf2ihx$(X)
cd rdoff && $(LN_S) rdf2bin$(X) rdf2ihx$(X) $(RDFLN) $(RDFLNPFX)rdf2bin$(X) $(RDFLNPFX)rdf2ihx$(X)
rdoff/rdf2srec$(X): rdoff/rdf2bin$(X) rdoff/rdf2srec$(X): rdoff/rdf2bin$(X)
$(RM_F) rdoff/rdf2srec$(X) $(RM_F) rdoff/rdf2srec$(X)
cd rdoff && $(LN_S) rdf2bin$(X) rdf2srec$(X) $(RDFLN) $(RDFLNPFX)rdf2bin$(X) $(RDFLNPFX)rdf2srec$(X)
#-- End RDOFF Shared Rules --# #-- End RDOFF Shared Rules --#
@ -345,10 +344,10 @@ nsis: nsis/nasm.nsi nsis/arch.nsh nsis/version.nsh
manpages: nasm.1 ndisasm.1 manpages: nasm.1 ndisasm.1
install: nasm$(X) ndisasm$(X) install: nasm$(X) ndisasm$(X)
$(MKDIR) -p $(DESTDIR)$(bindir) $(MKDIR) $(DESTDIR)$(bindir)
$(INSTALL_PROGRAM) nasm$(X) $(DESTDIR)$(bindir)/nasm$(X) $(INSTALL_PROGRAM) nasm$(X) $(DESTDIR)$(bindir)/nasm$(X)
$(INSTALL_PROGRAM) ndisasm$(X) $(DESTDIR)$(bindir)/ndisasm$(X) $(INSTALL_PROGRAM) ndisasm$(X) $(DESTDIR)$(bindir)/ndisasm$(X)
$(MKDIR) -p $(DESTDIR)$(mandir)/man1 $(MKDIR) $(DESTDIR)$(mandir)/man1
$(INSTALL_DATA) $(srcdir)/nasm.1 $(DESTDIR)$(mandir)/man1/nasm.1 $(INSTALL_DATA) $(srcdir)/nasm.1 $(DESTDIR)$(mandir)/man1/nasm.1
$(INSTALL_DATA) $(srcdir)/ndisasm.1 $(DESTDIR)$(mandir)/man1/ndisasm.1 $(INSTALL_DATA) $(srcdir)/ndisasm.1 $(DESTDIR)$(mandir)/man1/ndisasm.1
@ -397,7 +396,7 @@ cscope:
cscope -b -f cscope.out cscope -b -f cscope.out
rdf_install install_rdf install_rdoff: rdf_install install_rdf install_rdoff:
$(MKDIR) -p $(DESTDIR)$(bindir) $(MKDIR) $(DESTDIR)$(bindir)
for f in $(RDFPROGS); do \ for f in $(RDFPROGS); do \
$(INSTALL_PROGRAM) "$$f" '$(DESTDIR)$(bindir)'/ ; \ $(INSTALL_PROGRAM) "$$f" '$(DESTDIR)$(bindir)'/ ; \
done done
@ -406,7 +405,7 @@ rdf_install install_rdf install_rdoff:
bn=`basename "$$f"` && $(RM_F) "$$bn" && \ bn=`basename "$$f"` && $(RM_F) "$$bn" && \
$(LN_S) rdf2bin$(X) "$$bn" ; \ $(LN_S) rdf2bin$(X) "$$bn" ; \
done done
$(MKDIR) -p $(DESTDIR)$(mandir)/man1 $(MKDIR) $(DESTDIR)$(mandir)/man1
$(INSTALL_DATA) $(srcdir)/rdoff/*.1 $(DESTDIR)$(mandir)/man1/ $(INSTALL_DATA) $(srcdir)/rdoff/*.1 $(DESTDIR)$(mandir)/man1/
doc: doc:

View File

@ -46,7 +46,7 @@ RUNPERL = $(PERL) $(PERLFLAGS)
MAKENSIS = makensis MAKENSIS = makensis
RM_F = del /f RM_F = -del /f
LN_S = copy LN_S = copy
# Binary suffixes # Binary suffixes
@ -54,15 +54,11 @@ O = obj
A = lib A = lib
X = .exe X = .exe
.SUFFIXES: .SUFFIXES:
.SUFFIXES: .c .i .s .$(O) .$(A) .exe .1 .man .SUFFIXES: $(X) .$(A) .$(O) .c .i .s .1 .man
.c.obj: .c.obj:
$(CC) /c $(ALL_CFLAGS) /Fo$@ $< $(CC) /c $(ALL_CFLAGS) /Fo$@ $<
# This rule is only used for rdoff
.obj.exe:
$(CC) $(ALL_CFLAGS) /Fe$@ $< $(LDFLAGS) $(RDFLIB) $(NASMLIB) $(LIBS)
#-- Begin File Lists --# #-- Begin File Lists --#
# Edit in Makefile.in, not here! # Edit in Makefile.in, not here!
NASM = asm\nasm.$(O) NASM = asm\nasm.$(O)
@ -252,6 +248,13 @@ asm\directbl.c: asm\directiv.dat nasmlib\perfhash.pl perllib\phash.ph
perlreq: $(PERLREQ) perlreq: $(PERLREQ)
# This rule is only used for RDOFF
.obj.exe:
$(CC) /Fe$@ $< $(LDFLAGS) $(RDFLIB) $(NASMLIB) $(LIBS)
RDFLN = copy
RDFLNPFX = rdoff^\
#-- Begin RDOFF Shared Rules --# #-- Begin RDOFF Shared Rules --#
# Edit in Makefile.in, not here! # Edit in Makefile.in, not here!
@ -267,31 +270,23 @@ RDF2BINLINKS = rdoff\rdf2com$(X) rdoff\rdf2ith$(X) \
RDFLIB = rdoff\librdoff.$(A) RDFLIB = rdoff\librdoff.$(A)
RDFLIBS = $(RDFLIB) $(NASMLIB) RDFLIBS = $(RDFLIB) $(NASMLIB)
# This rule is only used for rdoff, to allow common rules
MAKERDF = $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $< $(RDFLIB) $(NASMLIB) $(LIBS)
rdoff\rdfdump$(X): rdoff\rdfdump.$(O) $(RDFLIBS) rdoff\rdfdump$(X): rdoff\rdfdump.$(O) $(RDFLIBS)
$(MAKERDF)
rdoff\ldrdf$(X): rdoff\ldrdf.$(O) $(RDFLIBS) rdoff\ldrdf$(X): rdoff\ldrdf.$(O) $(RDFLIBS)
$(MAKERDF)
rdoff\rdx$(X): rdoff\rdx.$(O) $(RDFLIBS) rdoff\rdx$(X): rdoff\rdx.$(O) $(RDFLIBS)
$(MAKERDF)
rdoff\rdflib$(X): rdoff\rdflib.$(O) $(RDFLIBS) rdoff\rdflib$(X): rdoff\rdflib.$(O) $(RDFLIBS)
$(MAKERDF)
rdoff\rdf2bin$(X): rdoff\rdf2bin.$(O) $(RDFLIBS) rdoff\rdf2bin$(X): rdoff\rdf2bin.$(O) $(RDFLIBS)
$(MAKERDF)
rdoff\rdf2com$(X): rdoff\rdf2bin$(X) rdoff\rdf2com$(X): rdoff\rdf2bin$(X)
$(RM_F) rdoff\rdf2com$(X) $(RM_F) rdoff\rdf2com$(X)
cd rdoff && $(LN_S) rdf2bin$(X) rdf2com$(X) $(RDFLN) $(RDFLNPFX)rdf2bin$(X) $(RDFLNPFX)rdf2com$(X)
rdoff\rdf2ith$(X): rdoff\rdf2bin$(X) rdoff\rdf2ith$(X): rdoff\rdf2bin$(X)
$(RM_F) rdoff\rdf2ith$(X) $(RM_F) rdoff\rdf2ith$(X)
cd rdoff && $(LN_S) rdf2bin$(X) rdf2ith$(X) $(RDFLN) $(RDFLNPFX)rdf2bin$(X) $(RDFLNPFX)rdf2ith$(X)
rdoff\rdf2ihx$(X): rdoff\rdf2bin$(X) rdoff\rdf2ihx$(X): rdoff\rdf2bin$(X)
$(RM_F) rdoff\rdf2ihx$(X) $(RM_F) rdoff\rdf2ihx$(X)
cd rdoff && $(LN_S) rdf2bin$(X) rdf2ihx$(X) $(RDFLN) $(RDFLNPFX)rdf2bin$(X) $(RDFLNPFX)rdf2ihx$(X)
rdoff\rdf2srec$(X): rdoff\rdf2bin$(X) rdoff\rdf2srec$(X): rdoff\rdf2bin$(X)
$(RM_F) rdoff\rdf2srec$(X) $(RM_F) rdoff\rdf2srec$(X)
cd rdoff && $(LN_S) rdf2bin$(X) rdf2srec$(X) $(RDFLN) $(RDFLNPFX)rdf2bin$(X) $(RDFLNPFX)rdf2srec$(X)
#-- End RDOFF Shared Rules --# #-- End RDOFF Shared Rules --#
@ -384,21 +379,21 @@ dep: msvc.dep
# Include and/or generate msvc.dep as needed. This is too complex to # Include and/or generate msvc.dep as needed. This is too complex to
# use the include-command feature, but we can open-code it here. # use the include-command feature, but we can open-code it here.
!IF $(EXTERNAL_DEPENDENCIES) == 1 MKDEP=0
!IFDEF MKDEP !IF $(EXTERNAL_DEPENDENCIES) == 1 && $(MKDEP) == 0
!IF EXISTS(msvc.dep) !IF EXISTS(msvc.dep)
!INCLUDE msvc.dep !INCLUDE msvc.dep
!ENDIF
!ELSEIF [$(MAKE) /c MKDEP=1 /f Mkfiles\msvc.mak msvc.dep] == 0 !ELSEIF [$(MAKE) /c MKDEP=1 /f Mkfiles\msvc.mak msvc.dep] == 0
!INCLUDE msvc.dep !INCLUDE msvc.dep
!ELSE !ELSE
!ERROR Unable to rebuild dependencies file msvc.dep !ERROR Unable to rebuild dependencies file msvc.dep
!ENDIF !ENDIF
!ENDIF
#-- Magic hints to mkdep.pl --# #-- Magic hints to mkdep.pl --#
# @object-ending: ".$(O)" # @object-ending: ".$(O)"
# @path-separator: "\" # @path-separator: "\"
# @exclude: "config/config.h" # @exclude: "config\config.h"
# @external: "msvc.dep" # @external: "msvc.dep"
# @selfrule: "1" # @selfrule: "1"
#-- Everything below is generated by mkdep.pl - do not edit --# #-- Everything below is generated by mkdep.pl - do not edit --#

View File

@ -51,6 +51,9 @@ $barrier = "#-- Everything below is generated by mkdep.pl - do not edit --#\n";
# This converts from filenames to full pathnames for our dependencies # This converts from filenames to full pathnames for our dependencies
%dep_path = {}; %dep_path = {};
# List of files that cannot be found; these *must* be excluded
@must_exclude = ();
# #
# Scan files for dependencies # Scan files for dependencies
# #
@ -70,7 +73,8 @@ sub scandeps($) {
if ( $line =~ /^\s*\#\s*include\s+\"(.*)\"\s*$/ ) { if ( $line =~ /^\s*\#\s*include\s+\"(.*)\"\s*$/ ) {
my $nf = $1; my $nf = $1;
if (!defined($dep_path{$nf})) { if (!defined($dep_path{$nf})) {
die "$0: cannot determine path for dependency: $file -> $nf\n"; push(@must_exclude, $nf);
next;
} }
$nf = $dep_path{$nf}; $nf = $dep_path{$nf};
$mdeps{$nf}++; $mdeps{$nf}++;
@ -138,7 +142,7 @@ sub _insert_deps($$) {
my $selfrule = 0; my $selfrule = 0;
my $do_external = 0; my $do_external = 0;
my $maxline = 78; # Seems like a reasonable default my $maxline = 78; # Seems like a reasonable default
my @exclude = (); # Don't exclude anything my %exclude = (); # Don't exclude anything
my @genhdrs = (); my @genhdrs = ();
my $external = undef; my $external = undef;
my $raw_output = 0; my $raw_output = 0;
@ -165,7 +169,7 @@ sub _insert_deps($$) {
} elsif ( $parm eq 'continuation' ) { } elsif ( $parm eq 'continuation' ) {
$cont = $val; $cont = $val;
} elsif ( $parm eq 'exclude' ) { } elsif ( $parm eq 'exclude' ) {
@exclude = split(/\,/, $val); $excludes{$val}++;
} elsif ( $parm eq 'include-command' ) { } elsif ( $parm eq 'include-command' ) {
$include_command = $val; $include_command = $val;
} elsif ( $parm eq 'external' ) { } elsif ( $parm eq 'external' ) {
@ -201,10 +205,6 @@ sub _insert_deps($$) {
} }
my $e; my $e;
my %do_exclude = ();
foreach $e (@exclude) {
$do_exclude{$e} = 1;
}
foreach my $dfile ($external, sort(keys(%deps)) ) { foreach my $dfile ($external, sort(keys(%deps)) ) {
my $ofile; my $ofile;
@ -222,7 +222,7 @@ sub _insert_deps($$) {
my $len = length($ofile); my $len = length($ofile);
print $out $ofile; print $out $ofile;
foreach my $dep (@deps) { foreach my $dep (@deps) {
unless ($do_exclude{$dep}) { unless ($excludes{$dep}) {
my $str = convert_file($dep, $sep); my $str = convert_file($dep, $sep);
my $sl = length($str)+1; my $sl = length($str)+1;
if ( $len+$sl > $maxline-2 ) { if ( $len+$sl > $maxline-2 ) {