]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - make/calcdep.pl
Use CXXFLAGS rather than nonstandard NICEFLAGS/FLAGS/etc
[user/henk/code/inspircd.git] / make / calcdep.pl
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 # This used to be a wrapper around cc -M; however, this is a very slow
6 # operation and we don't conditionally include our own files often enough
7 # to justify the full preprocesor invocation for all ~200 files.
8
9 my %f2dep;
10
11 sub gendep;
12 sub gendep {
13         my $f = shift;
14         my $basedir = $f =~ m#(.*)/# ? $1 : '.';
15         return $f2dep{$f} if exists $f2dep{$f};
16         $f2dep{$f} = '';
17         my %dep;
18         open my $in, '<', $f;
19         while (<$in>) {
20                 if (/^\s*#\s*include\s*"([^"]+)"/) {
21                         my $inc = $1;
22                         for my $loc ("$basedir/$inc", "../include/$inc") {
23                                 next unless -e $loc;
24                                 $dep{$loc}++;
25                                 $dep{$_}++ for split / /, gendep $loc;
26                         }
27                 }
28         }
29         close $in;
30         $f2dep{$f} = join ' ', sort keys %dep;
31         $f2dep{$f};
32 }
33
34 for my $file (@ARGV) {
35         if (-e $file && $file =~ /cpp$/) {
36                 gendep $file;
37                 my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp#;
38                 my $cmd = "$path.$base.d";
39                 my $ext = $path eq 'modules/' || $path eq 'commands/' ? '.so' : '.o';
40                 my $out = "$path$base$ext";
41
42                 open OUT, '>', $cmd;
43                 print OUT "$out: $file $f2dep{$file}\n";
44                 print OUT "\t@../make/unit-cc.pl \$(VERBOSE) $file $out\n";
45                 print OUT "$cmd: $file $f2dep{$file}\n";
46                 print OUT "\t../make/calcdep.pl $file\n";
47         } elsif (-d $file && $file =~ m#^(.*?)([^/]+)/?$#) {
48                 my($path,$base) = ($1,$2);
49                 my $cmd = "$path.$base.d";
50                 my $out = "$path$base.so";
51                 opendir DIR, $file;
52                 my $ofiles = join ' ', grep s#(.*)\.cpp$#$path$base/$1.o#, readdir DIR;
53                 closedir DIR;
54                 open OUT, '>', $cmd;
55                 print OUT "$out: $ofiles\n\t".'$(RUNCC) $(PICLDFLAGS) -o $@ '
56                         .$ofiles."\n";
57                 print OUT "$cmd: $file\n\t".'@../make/calcdep.pl '."$path$base\n";
58         } else {
59                 print "Cannot generate depencency for $file\n";
60                 exit 1;
61         }
62 }