use lib '.';
use configdata;
-use File::Spec::Functions qw(canonpath rel2abs);
+use File::Spec::Functions qw(:DEFAULT rel2abs);
use File::Compare qw(compare_text);
+use feature 'state';
# When using stat() on Windows, we can get it to perform better by avoid some
# data. This doesn't affect the mtime field, so we're not losing anything...
# Ok, primary checks are done, time to do some real work
-my $abs_srcdir = rel2abs($config{sourcedir});
-my $abs_blddir = rel2abs($config{builddir});
-
my $producer = shift @ARGV;
die "Producer not given\n" unless $producer;
+my $srcdir = $config{sourcedir};
+my $blddir = $config{builddir};
+my $abs_srcdir = rel2abs($srcdir);
+my $abs_blddir = rel2abs($blddir);
+
+# Convenient cache of absolute to relative map. We start with filling it
+# with mappings for the known generated header files. They are relative to
+# the current working directory, so that's an easy task.
+# NOTE: there's more than C header files that are generated. They will also
+# generate entries in this map. We could of course deal with C header files
+# only, but in case we decide to handle more than just C files in the future,
+# we already have the mechanism in place here.
+# NOTE2: we lower case the index to make it searchable without regard for
+# character case. That could seem dangerous, but as long as we don't have
+# files we depend on in the same directory that only differ by character case,
+# we're fine.
+my %depconv_cache =
+ map { catfile($abs_blddir, $_) => $_ }
+ keys %{$unified_info{generate}};
+
my %procedures = (
'gcc' => undef, # gcc style dependency files needs no mods
'makedepend' =>
},
'VMS C' =>
sub {
+ state $abs_srcdir_shaved = undef;
+ state $srcdir_shaved = undef;
+
+ unless (defined $abs_srcdir_shaved) {
+ ($abs_srcdir_shaved = $abs_srcdir) =~ s|[>\]]$||;
+ ($srcdir_shaved = $srcdir) =~ s|[>\]]$||;
+ }
+
# current versions of DEC / Compaq / HP / VSI C strips away all
# directory information from the object file, so we must insert it
# back. To make life simpler, we simply replace it with the
# All we got now is a dependency, just shave off surrounding spaces
$line =~ s/^\s+//;
$line =~ s/\s+$//;
- return ($objfile, $line);
+
+ # VMS C gives us absolute paths, always. Let's see if we can
+ # make them relative instead.
+ $line = canonpath($line);
+
+ unless (defined $depconv_cache{$line}) {
+ my $dep = $line;
+ # Since we have already pre-populated the cache with
+ # mappings for generated headers, we only need to deal
+ # with the source tree.
+ if ($dep =~ s|^\Q$abs_srcdir_shaved\E([\.>\]])?|$srcdir_shaved$1|i) {
+ $depconv_cache{$line} = $dep;
+ }
+ }
+ return ($objfile, $depconv_cache{$line})
+ if defined $depconv_cache{$line};
+ print STDERR "DEBUG[VMS C]: ignoring $objfile <- $line\n"
+ if $debug;
+
+ return undef;
},
'VC' =>
sub {
# VC gives us absolute paths for all include files, so to
# remove system header dependencies, we need to check that
- # they don't match $abs_srcdir or $abs_blddir
+ # they don't match $abs_srcdir or $abs_blddir.
$tail = canonpath($tail);
- if ($tail =~ m|^\Q$abs_srcdir\E|i
- || $tail =~ m|^\Q$abs_blddir\E|i) {
- return ($objfile, "\"$tail\"");
+
+ unless (defined $depconv_cache{$tail}) {
+ my $dep = $tail;
+ # Since we have already pre-populated the cache with
+ # mappings for generated headers, we only need to deal
+ # with the source tree.
+ if ($dep =~ s|^\Q$abs_srcdir\E\\|\$(SRCDIR)\\|i) {
+ $depconv_cache{$tail} = $dep;
+ }
}
+ return ($objfile, '"'.$depconv_cache{$tail}.'"')
+ if defined $depconv_cache{$tail};
+ print STDERR "DEBUG[VC]: ignoring $objfile <- $tail\n"
+ if $debug;
}
return undef;