Ticket #1213 (closed todo: invalid)

Opened 12 years ago

Last modified 12 years ago

need a tool to check make dependencies

Reported by: coke Owned by:
Priority: normal Milestone:
Component: build Version:
Severity: medium Keywords:
Cc: Language:
Patch status: Platform:


It's quite easy for a developer to add an #include to a generated c file and forget to add the dependency to the makefile.

Here's an extremely rough first pass at complaining about this sort of thing. It is only intended for C #includes.

FYI, NotFound is working on an winxed version as well. Eventually this should be converted into a test that can be run as part of the distro checks. Right now it doesn't deal with any of the INCLUDE variables that refer to other groups of files, and doesn't deal with relative paths 100%. (But if you run it now, it does point out a large number of pmc/pmc_*.h files that are #included but not depended on.)

use Modern::Perl;

use Fatal qw(open);

use File::Spec;

=for comment

A braindead script to check that any .c file depends on its includes.

Run a straight make without -j first to insure all needed c files are


my $files = `ack -fa . | grep '\\.c\$'`;

my %deps;

foreach my $file (split /\n/, $files) {
    open my $fh, '<', $file;
    my $guts;
        local undef $/;
        $guts = <$fh>;
    my @includes = $guts =~ m/#include "(.*)"/g;
    $file =~ s/\.c$//;
    $deps{$file} = [ @includes ];

open my $mf, '<', "Makefile";
my $rules;
    local undef $/;
    $rules = <$mf>;
$rules =~ s/\\\n/ /g;
$rules =~ s/\Q$(SRC_DIR)\E/src/g;
$rules =~ s/\Q$(O)\E//g;

foreach my $file (keys %deps) {
    my ($declared) = ($rules =~ /^$file\s*:\s*(.*)\s*$/m) // "";
    foreach my $inc (@{$deps{$file}}) {
        # incs can be relative, but makefile is from top level
        my ($vol,$dir,$eff) = File::Spec->splitpath($file);
        my $include = File::Spec->catfile($dir,$inc);
        if ($declared !~ /\b\Q$include\E\b/) {
          say "$file includes $inc but makefile doesn't show it.";

Change History

Changed 12 years ago by coke

  • status changed from new to closed
  • resolution set to invalid

rejecting; there's another ticket, and this script needs rework.

Note: See TracTickets for help on using tickets.