summaryrefslogtreecommitdiff
path: root/make/calcdep.pl
diff options
context:
space:
mode:
Diffstat (limited to 'make/calcdep.pl')
-rwxr-xr-xmake/calcdep.pl47
1 files changed, 27 insertions, 20 deletions
diff --git a/make/calcdep.pl b/make/calcdep.pl
index a4bb7f4d6..261b6ec18 100755
--- a/make/calcdep.pl
+++ b/make/calcdep.pl
@@ -3,6 +3,12 @@ use strict;
use warnings;
use Getopt::Long;
+my $basesrc = "$ENV{SOURCEPATH}/src";
+my $baseinc = "$ENV{SOURCEPATH}/include";
+my $baseout = `pwd`;
+chomp $baseout;
+chdir $basesrc;
+
my %f2dep;
sub gendep;
@@ -21,9 +27,9 @@ sub gendep {
while (<$in>) {
if (/^\s*#\s*include\s*"([^"]+)"/) {
my $inc = $1;
- next if $inc eq 'inspircd_version.h' && $f eq '../include/inspircd.h';
+ next if $inc eq 'inspircd_version.h' && $f eq $baseinc.'/inspircd.h';
my $found = 0;
- for my $loc ("$basedir/$inc", "../include/$inc") {
+ for my $loc ("$basedir/$inc", "$baseinc/$inc") {
next unless -e $loc;
$found++;
$dep{$loc}++;
@@ -31,7 +37,7 @@ sub gendep {
}
if ($found == 0 && $inc ne 'inspircd_win32wrapper.h') {
print STDERR "WARNING: could not find header $inc for $f\n";
- } elsif ($found > 1 && $basedir ne '../include') {
+ } elsif ($found > 1 && $basedir ne $baseinc) {
print STDERR "WARNING: ambiguous include $inc in $f\n";
}
}
@@ -42,33 +48,30 @@ sub gendep {
}
sub dep_cpp {
- my $file = shift;
+ my($file, $dfile) = @_;
gendep $file;
my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file";
- my $cmd = "$path.$base.d";
my $ext = $path eq 'modules/' || $path eq 'commands/' ? '.so' : '.o';
my $out = "$path$base$ext";
+ $dfile = "$baseout/$path.$base.d" unless defined $dfile;
- open OUT, '>', $cmd;
+ open OUT, '>', "$dfile" or die "Could not write $dfile: $!";
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 $file\n";
+ print OUT "\t@\$(SOURCEPATH)/make/unit-cc.pl \$(VERBOSE) \$< $out\n";
}
sub dep_dir {
- my $dir = shift;
+ my($dir, $dfile) = @_;
if ($dir =~ m#^(.*?)([^/]+)/?$#) {
my($path,$base) = ($1,$2);
- my $cmd = "$path.$base.d";
my $out = "$path$base.so";
- opendir DIR, $dir;
+ $dfile = "$baseout/$path.$base.d" unless defined $dfile;
+ opendir DIR, "$basesrc/$dir";
my $ofiles = join ' ', grep s/(.*)\.cpp$/$path$base\/$1.o/, readdir DIR;
closedir DIR;
- open OUT, '>', $cmd;
- print OUT "$out: $ofiles\n\t".'$(RUNCC) $(PICLDFLAGS) -o $@ '
- .$ofiles."\n";
- print OUT "$cmd: $dir\n\t".'@../make/calcdep.pl -file '."$path$base\n";
+ open OUT, '>', "$dfile" or die "Could not write $dfile: $!";
+ print OUT "$out: $ofiles\n\t\$(RUNCC) \$(PICLDFLAGS) -o \$\@ \$^\n";
+ close OUT;
} else {
print STDERR "Cannot generate depencency for $dir\n";
exit 1;
@@ -83,15 +86,17 @@ GetOptions(
);
if (!$all && !defined $file) {
- print "Use: $0 {-all|-file filename} [-quiet]\n";
+ print "Use: $0 {-all|-file src dest} [-quiet]\n";
exit 1;
}
if (defined $file) {
+ my $dfile = shift or die "Syntax: -file <in> <out>";
+ $dfile = "$baseout/$dfile" unless $dfile =~ m#^/#;
if (-f $file) {
- dep_cpp $file;
+ dep_cpp $file, $dfile;
} elsif (-d $file) {
- dep_dir $file;
+ dep_dir $file, $dfile;
} else {
print STDERR "Can't generate dependencies for $file\n";
exit 1;
@@ -99,11 +104,13 @@ if (defined $file) {
} else {
my @files = (<*.cpp>, <commands/*.cpp>, <modes/*.cpp>, <modules/*.cpp>, <modules/m_*/*.cpp>);
push @files, "socketengines/$ENV{SOCKETENGINE}.cpp", "threadengines/threadengine_pthread.cpp";
+ my @dirs = grep -d, <modules/m_*>;
+ mkdir "$baseout/$_" for qw(commands modes modules socketengines threadengines), @dirs;
+
for my $file (@files) {
dep_cpp $file;
}
- my @dirs = grep -d, <modules/m_*>;
for my $dir (@dirs) {
dep_dir $dir;
}