The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/local/bin/perl -w

open(NEED,"<need") || die;
while (<NEED>)
 {
  if (/\b([A-Z])\b\s*_?(.*)$/)
   {
    if ($1 ne 'U')
     {
      $def{$2} = $1;
     }
    else
     {
      $ref{$2} = 1;
     }
   }
 }
close(NEED);

@ARGV = <*.h>;

while (<>)
 {
  if (/(extern|EXTERN|COREXT)\s*(.*)\s(\w+)\s+_ANSI_ARGS_/)
   {
    my $kind = $1;
    if (!exists($def{$3}))
     {
      if ($kind ne 'COREXT')
       {
        print STDERR "$ARGV:$.: $kind $3 not defined\n";
       }
      print "$ARGV:$.: $3 not defined";
      print " - but not referenced" unless (exists($ref{$3}));
      print "\n";
     }
   }
  elsif (/(extern|EXTERN|COREXT)\s*(.*)\s(\w+)\s*;/)
   {
    my $kind = $1;
    if (!exists($def{$3}))
     {
      if ($kind ne 'COREXT')
       {
        print STDERR "$ARGV:$.: $kind $3 not defined\n";
       }
      print "$ARGV:$.: $3 not defined";
      print " - but not referenced" unless (exists($ref{$3}));
      print "\n";
     }
   }
  $. = 0 if (eof);
 }