2009-09-01 15:04:40 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use strict;
|
2009-09-01 15:05:11 +00:00
|
|
|
use warnings;
|
2009-09-01 15:04:40 +00:00
|
|
|
|
2009-09-01 15:05:11 +00:00
|
|
|
# This used to be a wrapper around cc -M; however, this is a very slow
|
|
|
|
# operation and we don't conditionally include our own files often enough
|
|
|
|
# to justify the full preprocesor invocation for all ~200 files.
|
2009-09-01 15:04:40 +00:00
|
|
|
|
2009-09-01 15:05:11 +00:00
|
|
|
my %f2dep;
|
2009-09-01 15:04:40 +00:00
|
|
|
|
2009-09-01 15:05:11 +00:00
|
|
|
sub gendep;
|
|
|
|
sub gendep {
|
|
|
|
my $f = shift;
|
|
|
|
my $basedir = $f =~ m#(.*)/# ? $1 : '.';
|
|
|
|
return $f2dep{$f} if exists $f2dep{$f};
|
|
|
|
$f2dep{$f} = '';
|
|
|
|
my %dep;
|
|
|
|
open my $in, '<', $f;
|
|
|
|
while (<$in>) {
|
|
|
|
if (/^\s*#\s*include\s*"([^"]+)"/) {
|
|
|
|
my $inc = $1;
|
|
|
|
for my $loc ("$basedir/$inc", "../include/$inc") {
|
|
|
|
next unless -e $loc;
|
|
|
|
$dep{$loc}++;
|
|
|
|
$dep{$_}++ for split / /, gendep $loc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close $in;
|
|
|
|
$f2dep{$f} = join ' ', sort keys %dep;
|
|
|
|
$f2dep{$f};
|
|
|
|
}
|
2009-09-01 15:04:40 +00:00
|
|
|
|
2009-09-01 15:05:11 +00:00
|
|
|
for my $file (@ARGV) {
|
2009-09-01 15:06:11 +00:00
|
|
|
if (-e $file && $file =~ /cpp$/) {
|
|
|
|
gendep $file;
|
|
|
|
my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp#;
|
|
|
|
my $cmd = "$path.$base.d";
|
|
|
|
my $ext = $path eq 'modules/' || $path eq 'commands/' ? '.so' : '.o';
|
|
|
|
my $out = "$path$base$ext";
|
2009-09-01 15:04:40 +00:00
|
|
|
|
2009-09-01 15:06:11 +00:00
|
|
|
open OUT, '>', $cmd;
|
|
|
|
print OUT "$out: $file $f2dep{$file}\n";
|
|
|
|
print OUT "\t@../make/unit-cc.pl \$(VERBOSE) $file $out\n";
|
|
|
|
print OUT "$cmd: $file $f2dep{$file}\n";
|
|
|
|
print OUT "\t../make/calcdep.pl $file\n";
|
|
|
|
} elsif (-d $file && $file =~ m#^(.*?)([^/]+)/?$#) {
|
|
|
|
my($path,$base) = ($1,$2);
|
|
|
|
my $cmd = "$path.$base.d";
|
|
|
|
my $out = "$path$base.so";
|
|
|
|
opendir DIR, $file;
|
|
|
|
my $ofiles = join ' ', grep s#(.*)\.cpp$#$path$base/$1.o#, readdir DIR;
|
|
|
|
closedir DIR;
|
|
|
|
open OUT, '>', $cmd;
|
2009-09-01 15:06:39 +00:00
|
|
|
print OUT "$out: $ofiles\n\t".'$(RUNCC) $(PICLDFLAGS) -o $@ '
|
2009-09-01 15:06:11 +00:00
|
|
|
.$ofiles."\n";
|
|
|
|
print OUT "$cmd: $file\n\t".'@../make/calcdep.pl '."$path$base\n";
|
|
|
|
} else {
|
|
|
|
print "Cannot generate depencency for $file\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
2009-09-01 15:05:11 +00:00
|
|
|
}
|