summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2017-11-01 13:48:17 -0700
committerH. Peter Anvin <hpa@linux.intel.com>2017-11-01 14:00:34 -0700
commitad4016952d566ca5f95566676b2d4d126da92e54 (patch)
tree0bc87709590f9e9c254965d03d332c951d9dc526 /tools
parentd428e983feb31a829781f6087076423f670d3c64 (diff)
downloadnasm-ad4016952d566ca5f95566676b2d4d126da92e54.tar.gz
Makefile: don't store dependency information in git
Make it possible to keep dependency information separate from the Makefiles, so we don't have to deal with it noisifying the git logs. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/mkdep.pl98
1 files changed, 74 insertions, 24 deletions
diff --git a/tools/mkdep.pl b/tools/mkdep.pl
index cf8bf979..eeb044f2 100755
--- a/tools/mkdep.pl
+++ b/tools/mkdep.pl
@@ -1,7 +1,7 @@
#!/usr/bin/perl
## --------------------------------------------------------------------------
-##
-## Copyright 1996-2016 The NASM Authors - All Rights Reserved
+##
+## Copyright 1996-2017 The NASM Authors - All Rights Reserved
## See the file AUTHORS included with the NASM distribution for
## the specific copyright holders.
##
@@ -15,7 +15,7 @@
## copyright notice, this list of conditions and the following
## disclaimer in the documentation and/or other materials provided
## with the distribution.
-##
+##
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
## CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -35,11 +35,15 @@
#
# Script to create Makefile-style dependencies.
#
-# Usage: perl mkdep.pl [-s path-separator] [-o obj-ext] dir... > deps
+# Usage:
+# perl mkdep.pl [-s path-separator][-o obj-ext] dir... > deps
+# perl mkdep.pl [-i][-e][-m makefile]...[-M makefile... --] dir...
#
use File::Spec;
use File::Basename;
+use File::Copy;
+use File::Temp;
use Fcntl;
$barrier = "#-- Everything below is generated by mkdep.pl - do not edit --#\n";
@@ -119,25 +123,26 @@ sub convert_file($$) {
#
# Insert dependencies into a Makefile
#
-sub insert_deps($) {
- my($file) = @_;
- $nexttemp++; # Unique serial number for each temp file
- my $tmp = File::Spec->catfile(dirname($file), 'tmp.'.$nexttemp);
+sub _insert_deps($$) {
+ my($file, $out) = @_;
open(my $in, '<', $file)
or die "$0: Cannot open input: $file\n";
- open(my $out, '>', $tmp)
- or die "$0: Cannot open output: $tmp\n";
-
- my($line,$parm,$val);
- my($obj) = '.o'; # Defaults
- my($sep) = '/';
- my($cont) = "\\";
- my($maxline) = 78; # Seems like a reasonable default
+
+ my $line, $parm, $val;
+ my $obj = '.o'; # Defaults
+ my $sep = '/';
+ my $cont = "\\";
+ my $include_command = 'include';
+ my $maxline = 78; # Seems like a reasonable default
my @exclude = (); # Don't exclude anything
my @genhdrs = ();
+ my $external = undef;
+ my $raw_output = 0;
+ my @outfile = ();
+ my $done = 0;
- while ( defined($line = <$in>) ) {
+ while ( defined($line = <$in>) && !$done ) {
if ( $line =~ /^([^\s\#\$\:]+\.h):/ ) {
# Note: we trust the first Makefile given best
my $fpath = $1;
@@ -158,14 +163,43 @@ sub insert_deps($) {
$cont = $val;
} elsif ( $parm eq 'exclude' ) {
@exclude = split(/\,/, $val);
+ } elsif ( $parm eq 'include-command' ) {
+ $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;
+ }
}
} elsif ( $line eq $barrier ) {
- last; # Stop reading input at barrier line
+ $done = 1; # Stop reading input at barrier line
}
- print $out $line;
+
+ push @outfile, $line;
}
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;
+ print $out @outfile;
+ } else {
+ print $out $barrier; # Start generated file with barrier
+ }
+
+
+ if ( $externalize ) {
+ if ( defined($external) ) {
+ print $out "$include_command $external\n";
+ }
+ return undef;
+ }
+
my $e;
my %do_exclude = ();
foreach $e (@exclude) {
@@ -175,8 +209,6 @@ sub insert_deps($) {
my $dfile, $ofile, $str, $sl, $len;
my @deps, $dep;
- print $out $barrier;
-
foreach $dfile ( sort(keys(%deps)) ) {
if ( $dfile =~ /^(.*)\.[Cc]$/ ) {
$ofile = $1;
@@ -199,10 +231,22 @@ sub insert_deps($) {
print $out "\n";
}
}
- close($out);
- (unlink($file) && rename($tmp, $file))
- or die "$0: Failed to change $tmp -> $file\n";
+ return $external;
+}
+
+sub insert_deps($)
+{
+ my($mkfile) = @_;
+ my $tmp = File::Temp->new(DIR => dirname($mkfile));
+ my $tmpname = $tmp->filename;
+
+ my $newname = _insert_deps($mkfile, $tmp);
+ close($tmp);
+
+ $newname = $mkfile unless(defined($newname));
+
+ move($tmpname, $newname);
}
#
@@ -213,11 +257,17 @@ my %deps = ();
my @files = ();
my @mkfiles = ();
my $mkmode = 0;
+$force_inline = 0;
+$externalize = 0;
while ( defined(my $arg = shift(@ARGV)) ) {
if ( $arg eq '-m' ) {
$arg = shift(@ARGV);
push(@mkfiles, $arg);
+ } elsif ( $arg eq '-i' ) {
+ $force_inline = 1;
+ } elsif ( $arg eq '-e' ) {
+ $externalize = 1;
} elsif ( $arg eq '-M' ) {
$mkmode = 1; # Futher filenames are output Makefile names
} elsif ( $arg eq '--' && $mkmode ) {