2004-10-07 13:26:23 +04:00
|
|
|
#!/usr/bin/perl -W
|
|
|
|
|
|
|
|
%include = ();
|
|
|
|
|
2007-05-31 02:39:54 +04:00
|
|
|
die "Usage: scandeps object_dirs -- sources" if (@ARGV < 3);
|
2004-10-07 13:26:23 +04:00
|
|
|
|
|
|
|
@objdirs = ();
|
|
|
|
while (($z = shift @ARGV) ne "--") {
|
|
|
|
push @objdirs, $z;
|
|
|
|
}
|
|
|
|
|
|
|
|
# scan all files for relevant #include lines
|
|
|
|
foreach my $file (@ARGV) {
|
|
|
|
open FILE, "<$file" or die "Failed to open $file: $!";
|
|
|
|
while (my $line = <FILE>) {
|
2007-05-31 02:39:54 +04:00
|
|
|
if ($line =~ m|#include "([^"]+)"|) {
|
|
|
|
$include{$file}{$1} = 1 if (-e $1);
|
2004-10-07 13:26:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
close FILE;
|
|
|
|
}
|
|
|
|
|
|
|
|
# output dependencies
|
|
|
|
foreach my $file (@ARGV) {
|
|
|
|
next unless $file =~ m|([^/]+)[.]c$|;
|
|
|
|
%deps = ();
|
|
|
|
search_deps($file);
|
|
|
|
foreach my $z (@objdirs) {
|
|
|
|
print "$z/$1.o ";
|
|
|
|
}
|
|
|
|
print ": $file ";
|
|
|
|
foreach my $z (sort keys %deps) { print "$z " }
|
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub search_deps {
|
|
|
|
my $file = shift;
|
|
|
|
return unless exists $include{$file};
|
|
|
|
foreach my $z (keys %{$include{$file}}) {
|
|
|
|
next if exists $deps{$z};
|
|
|
|
$deps{$z} = 1;
|
|
|
|
search_deps($z);
|
|
|
|
}
|
|
|
|
}
|