summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2017-11-06 22:37:37 -0800
committerH. Peter Anvin <hpa@zytor.com>2017-11-06 22:37:37 -0800
commitceeaf11e66d7e1b7ad511446f308337981f71a71 (patch)
tree944768624006cd475296e3d7575bcac4ead0e1e7 /tools
parentad4016952d566ca5f95566676b2d4d126da92e54 (diff)
downloadnasm-ceeaf11e66d7e1b7ad511446f308337981f71a71.tar.gz
Make dependency generation a bit more robust
Improve the corner cases where we might end up with bogus dependencies. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/mkdep.pl71
1 files changed, 40 insertions, 31 deletions
diff --git a/tools/mkdep.pl b/tools/mkdep.pl
index eeb044f2..d9373bb5 100755
--- a/tools/mkdep.pl
+++ b/tools/mkdep.pl
@@ -57,8 +57,8 @@ $barrier = "#-- Everything below is generated by mkdep.pl - do not edit --#\n";
sub scandeps($) {
my($file) = @_;
my $line;
- my @xdeps = ();
- my @mdeps = ();
+ my %xdeps;
+ my %mdeps;
open(my $fh, '<', $file)
or return; # If not openable, assume generated
@@ -73,14 +73,14 @@ sub scandeps($) {
die "$0: cannot determine path for dependency: $file -> $nf\n";
}
$nf = $dep_path{$nf};
- push(@mdeps, $nf);
- push(@xdeps, $nf) unless ( defined($deps{$nf}) );
+ $mdeps{$nf}++;
+ $xdeps{$nf}++ unless ( defined($deps{$nf}) );
}
}
close($fh);
- $deps{$file} = [@mdeps];
+ $deps{$file} = [keys(%mdeps)];
- foreach my $xf ( @xdeps ) {
+ foreach my $xf ( keys(%xdeps) ) {
scandeps($xf);
}
}
@@ -104,6 +104,7 @@ sub alldeps($$) {
# This almost certainly works only on relative filenames...
sub convert_file($$) {
my($file,$sep) = @_;
+
my @fspec = (basename($file));
while ( ($file = dirname($file)) ne File::Spec->curdir() &&
$file ne File::Spec->rootdir() ) {
@@ -134,6 +135,8 @@ sub _insert_deps($$) {
my $sep = '/';
my $cont = "\\";
my $include_command = 'include';
+ my $selfrule = 0;
+ my $do_external = 0;
my $maxline = 78; # Seems like a reasonable default
my @exclude = (); # Don't exclude anything
my @genhdrs = ();
@@ -167,12 +170,13 @@ sub _insert_deps($$) {
$include_command = $val;
} elsif ( $parm eq 'external' ) {
# Keep dependencies in an external file
- if ( $force_inline ) {
- next; # Don't output this line
- } else {
- $external = $val;
- }
+ $external = $val;
+ } elsif ( $parm eq 'selfrule' ) {
+ $selfrule = !!$val;
}
+ } elsif ( $line =~ /^(\s*\#?\s*EXTERNAL_DEPENDENCIES\s*=\s*)([01])\s*$/ ) {
+ $is_external = $externalize ? 1 : $force_inline ? 0 : $2+0;
+ $line = $1.$is_external."\n";
} elsif ( $line eq $barrier ) {
$done = 1; # Stop reading input at barrier line
}
@@ -181,20 +185,16 @@ sub _insert_deps($$) {
}
close($in);
- if ( !defined($external) || $externalize ) {
- # Write the existing Makefile content if we are producing
- # inline content. If the Makefile has an
- # EXTERNAL_DEPENDENCIES definition, update it to match.
- map { s/\b(EXTERNAL_DEPENDENCIES\s*=\s*)[0-9]+\b/${1}${externalize}/; }
- @outfile;
+ $is_external = $is_external && defined($external);
+
+ if ( !$is_external || $externalize ) {
print $out @outfile;
} else {
print $out $barrier; # Start generated file with barrier
}
-
if ( $externalize ) {
- if ( defined($external) ) {
+ if ( $is_external ) {
print $out "$include_command $external\n";
}
return undef;
@@ -206,19 +206,25 @@ sub _insert_deps($$) {
$do_exclude{$e} = 1;
}
- my $dfile, $ofile, $str, $sl, $len;
- my @deps, $dep;
+ foreach my $dfile ($external, sort(keys(%deps)) ) {
+ my $ofile;
+ my @deps;
+
+ if ( $selfrule && $dfile eq $external ) {
+ $ofile = convert_file($dfile, $sep).':';
+ @deps = sort(keys(%deps));
+ } elsif ( $dfile =~ /^(.*)\.[Cc]$/ ) {
+ $ofile = convert_file($1, $sep).$obj.':';
+ @deps = ($dfile,alldeps($dfile,1));
+ }
- foreach $dfile ( sort(keys(%deps)) ) {
- if ( $dfile =~ /^(.*)\.[Cc]$/ ) {
- $ofile = $1;
- $str = convert_file($ofile, $sep).$obj.':';
- $len = length($str);
- print $out $str;
- foreach $dep ($dfile, alldeps($dfile,1)) {
+ if (defined($ofile)) {
+ my $len = length($ofile);
+ print $out $ofile;
+ foreach my $dep (@deps) {
unless ($do_exclude{$dep}) {
- $str = convert_file($dep, $sep);
- $sl = length($str)+1;
+ my $str = convert_file($dep, $sep);
+ my $sl = length($str)+1;
if ( $len+$sl > $maxline-2 ) {
print $out ' ', $cont, "\n ", $str;
$len = $sl;
@@ -259,6 +265,7 @@ my @mkfiles = ();
my $mkmode = 0;
$force_inline = 0;
$externalize = 0;
+$debug = 0;
while ( defined(my $arg = shift(@ARGV)) ) {
if ( $arg eq '-m' ) {
@@ -268,6 +275,8 @@ while ( defined(my $arg = shift(@ARGV)) ) {
$force_inline = 1;
} elsif ( $arg eq '-e' ) {
$externalize = 1;
+ } elsif ( $arg eq '-d' ) {
+ $debug++;
} elsif ( $arg eq '-M' ) {
$mkmode = 1; # Futher filenames are output Makefile names
} elsif ( $arg eq '--' && $mkmode ) {
@@ -294,7 +303,7 @@ foreach my $dir ( @files ) {
if ( $file =~ /\.[Cc]$/ ) {
push(@cfiles, $path);
} elsif ( $file =~ /\.[Hh]$/ ) {
- print STDERR "Filesystem: $file -> $path\n";
+ print STDERR "Filesystem: $file -> $path\n" if ( $debug );
$dep_path{$file} = $path; # Allow the blank filename
$dep_path{$path} = $path; # Also allow the full pathname
}