6 my $basesrc = "$ENV{SOURCEPATH}/src";
7 my $baseinc = "$ENV{SOURCEPATH}/include";
17 my $basedir = $f =~ m#(.*)/# ? $1 : '.';
18 return $f2dep{$f} if exists $f2dep{$f};
21 my $link = readlink $f;
23 $link = "$basedir/$link" unless $link =~ m#^/#;
26 open my $in, '<', $f or die "Could not read $f";
28 if (/^\s*#\s*include\s*"([^"]+)"/) {
30 next if $inc eq 'inspircd_version.h' && $f eq $baseinc.'/inspircd.h';
32 for my $loc ("$basedir/$inc", "$baseinc/$inc") {
36 $dep{$_}++ for split / /, gendep $loc;
38 if ($found == 0 && $inc ne 'inspircd_win32wrapper.h') {
39 print STDERR "WARNING: could not find header $inc for $f\n";
40 } elsif ($found > 1 && $basedir ne $baseinc) {
41 print STDERR "WARNING: ambiguous include $inc in $f\n";
46 $f2dep{$f} = join ' ', sort keys %dep;
51 my($file, $dfile) = @_;
53 my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file";
54 my $ext = $path eq 'modules/' || $path eq 'commands/' ? '.so' : '.o';
55 my $out = "$path$base$ext";
56 $dfile = "$baseout/$path.$base.d" unless defined $dfile;
58 open OUT, '>', "$dfile" or die "Could not write $dfile: $!";
59 print OUT "$out: $file $f2dep{$file}\n";
60 print OUT "\t@\$(SOURCEPATH)/make/unit-cc.pl \$(VERBOSE) \$< $out\n";
64 my($dir, $dfile) = @_;
65 if ($dir =~ m#^(.*?)([^/]+)/?$#) {
66 my($path,$base) = ($1,$2);
67 my $out = "$path$base.so";
68 $dfile = "$baseout/$path.$base.d" unless defined $dfile;
69 opendir DIR, "$basesrc/$dir";
70 my $ofiles = join ' ', grep s/(.*)\.cpp$/$path$base\/$1.o/, readdir DIR;
72 open OUT, '>', "$dfile" or die "Could not write $dfile: $!";
73 print OUT "$out: $ofiles\n\t\$(RUNCC) \$(PICLDFLAGS) -o \$\@ \$^\n";
76 print STDERR "Cannot generate depencency for $dir\n";
81 my($all,$quiet, $file);
88 if (!$all && !defined $file) {
89 print "Use: $0 {-all|-file src dest} [-quiet]\n";
94 my $dfile = shift or die "Syntax: -file <in> <out>";
95 $dfile = "$baseout/$dfile" unless $dfile =~ m#^/#;
97 dep_cpp $file, $dfile;
99 dep_dir $file, $dfile;
101 print STDERR "Can't generate dependencies for $file\n";
105 my @files = (<*.cpp>, <commands/*.cpp>, <modes/*.cpp>, <modules/*.cpp>, <modules/m_*/*.cpp>);
106 push @files, "socketengines/$ENV{SOCKETENGINE}.cpp", "threadengines/threadengine_pthread.cpp";
107 my @dirs = grep -d, <modules/m_*>;
108 mkdir "$baseout/$_" for qw(commands modes modules socketengines threadengines), @dirs;
110 for my $file (@files) {
114 for my $dir (@dirs) {
118 s#([^/]+)\.cpp#.$1.d# for @files;
119 s#([^/]+)/?$#.$1.d# for @dirs;
120 print join ' ', @files, @dirs;