]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - make/calcdep.pl
Re-implement dependency generation in perl to increase speed
[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         next unless $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 }