Skip to content

Commit 699684b

Browse files
author
H. Peter Anvin
committed
Merge remote-tracking branch 'github/nasm-2.16.xx'
2 parents 49640ed + 8ef2fa2 commit 699684b

File tree

1 file changed

+44
-20
lines changed

1 file changed

+44
-20
lines changed

tools/mkdep.pl

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"#-- Everything below is generated by mkdep.pl - do not edit --#\n";
5353

5454
# This converts from filenames to full pathnames for our dependencies
55+
# These are arrays of [full path, Makefile path]
5556
my %dep_path = ();
5657

5758
# List of files that cannot be found; these *must* be excluded
@@ -73,52 +74,68 @@
7374

7475
#
7576
# Scan files for dependencies
77+
# $path is the full filesystem path, $file Makefile name
7678
#
7779
sub scandeps {
78-
# path is the filesystem path, file what the output should call it
7980
my($path, $file) = @_;
8081
my $line;
8182
my %xdeps;
8283
my %mdeps;
8384

84-
open(my $fh, '<', $path)
85-
or return; # If not openable, assume generated
85+
print STDERR "mkdep: scanning file: $path\n" if ( $debug );
86+
87+
my $fh;
88+
if (!open($fh, '<', $path)) {
89+
print STDERR " -> missing, assume generated\n" if ( $debug );
90+
return;
91+
}
8692

8793
while ( defined($line = <$fh>) ) {
8894
chomp $line;
8995
$line =~ s:/\*.*\*/::g;
9096
$line =~ s://.*$::;
9197
if ( $line =~ /^\s*\#\s*include\s+\"(.*)\"\s*$/ ) {
9298
my $nf = $1;
93-
if (!defined($dep_path{$nf})) {
99+
my $dp = $dep_path{$nf};
100+
if (!defined($dp)) {
94101
push(@must_exclude, $nf);
102+
print STDERR " -> $nf [missing]\n" if ( $debug );
95103
next;
96104
}
97-
$nf = $dep_path{$nf};
98-
$mdeps{$nf}++;
99-
$xdeps{$nf}++ unless ( defined($deps{$nf}) );
105+
my $dn = $dp->[1];
106+
$mdeps{$dn}++;
107+
$xdeps{$dn} = $dp unless ( defined($deps{$dn}) );
108+
printf STDERR " -> %s (%s)\n", $nf, $dn if ( $debug );
100109
}
101110
}
102111
close($fh);
103112
$deps{$file} = [keys(%mdeps)];
104113

105114
foreach my $xf ( keys(%xdeps) ) {
106-
scandeps($xf);
115+
scandeps(@{$xdeps{$xf}});
107116
}
108117
}
109118

110119
# %deps contains direct dependencies. This subroutine resolves
111120
# indirect dependencies that result.
112-
sub alldeps($$) {
113-
my($file, $level) = @_;
114-
my %adeps;
121+
sub _alldeps($$$) {
122+
my($file, $level, $adeps) = @_;
123+
124+
return if ($adeps->{$file});
125+
126+
printf STDERR " %s-> %s\n", (' ' x $level), $file;
127+
$adeps->{$file}++;
115128

116129
foreach my $dep ( @{$deps{$file}} ) {
117-
$adeps{$dep} = 1;
118-
foreach my $idep ( alldeps($dep, $level+1) ) {
119-
$adeps{$idep} = 1;
120-
}
130+
_alldeps($dep, $level+1, $adeps);
121131
}
132+
}
133+
134+
sub alldeps($) {
135+
my($file) = @_;
136+
137+
my %adeps;
138+
_alldeps($file, 1, \%adeps);
122139
return sort(keys(%adeps));
123140
}
124141

@@ -177,7 +194,7 @@ ($)
177194
my $fpath = $1;
178195
my $fbase = basename($fpath);
179196
if (!defined($dep_path{$fbase})) {
180-
$dep_path{$fbase} = $fpath;
197+
$dep_path{$fbase} = [$fpath, $fpath];
181198
print STDERR "Makefile: $fbase -> $fpath\n";
182199
}
183200
} elsif ( $line =~ /^\s*\#\s*@([a-z0-9-]+):\s*\"([^\"]*)\"/ ) {
@@ -249,7 +266,8 @@ ($)
249266
@deps = sort(keys(%deps));
250267
} elsif ( $dfile =~ /^(.*)\.[Cc]$/ ) {
251268
$ofile = convert_file($1, $sep).$obj.':';
252-
@deps = ($dfile,alldeps($dfile,1));
269+
print STDERR "mkdep: dependencies for: $dfile\n";
270+
@deps = alldeps($dfile);
253271
}
254272

255273
if (defined($ofile)) {
@@ -332,12 +350,15 @@ ($$)
332350

333351
foreach my $sdir ( @searchdirs ) {
334352
my $dir = mycatdir($sdir, $fdir);
353+
335354
if ($scanned{$dir}) {
336355
# Have already been here
337356
$found = 1;
338357
next;
339358
}
340359

360+
print STDERR "mkdep: scanning directory $dir\n" if ( $debug );
361+
341362
opendir(DIR, $dir) or next;
342363
$scanned{$dir}++;
343364
$found++;
@@ -351,9 +372,12 @@ ($$)
351372
if ( $file =~ /\.[Cc]$/ ) {
352373
push(@cfiles, [$fullpath, $path]);
353374
} elsif ( $file =~ /\.[Hh]$/ ) {
354-
print STDERR "Filesystem: $file -> $path\n" if ( $debug );
355-
$dep_path{$file} = $path; # Allow the blank filename
356-
$dep_path{$path} = $path; # Also allow the full pathname
375+
print STDERR "mkdep: filesystem: $file -> $path\n" if ( $debug );
376+
if (defined($dep_path{$file})) {
377+
print STDERR "mkdep: warning: more than one instance of filename $file!\n";
378+
}
379+
$dep_path{$file} = [$fullpath, $path];
380+
$dep_path{$path} = [$fullpath, $path];
357381
}
358382
}
359383
closedir(DIR);

0 commit comments

Comments
 (0)