Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into registry
[ira/wip.git] / source4 / script / find_unused_makefilevars.pl
1 #!/usr/bin/perl
2 # Script that reads in Makefile.in and outputs the names of all 
3 # used but undefined vars and all defined but unused vars 
4 # Copyright Jelmer Vernooij <jelmer@samba.org>
5
6 # Arguments:
7 #  1: Makefile.in
8 #
9
10 my %references;
11 my %defines;
12
13 # First, make a list of defines in configure
14 $in = shift;
15
16 open(IN, $in);
17 while(<IN>) {
18         my $line = $_;
19         while($line =~ /^\b([a-zA-Z0-9_][a-zA-Z0-9_]*)\b[ \t]*=.*/sgm) {
20                 $defines{$1} = 1;
21         }
22         while($line =~ /\$\(([a-zA-Z0-9_][a-zA-Z0-9_]*)\)/sgm) {
23                 $references{$1} = 1;
24         }
25 }
26 close IN;
27
28 print "##### DEFINED BUT UNUSED: #####\n";
29 foreach(%defines) {
30 #    print $_." defined\n";
31
32         if ($_ != 1) {
33                 if ($references{$_} != 1) {
34                         print $_."\n";
35                 }
36         } 
37 }
38
39 print "##### USED BUT UNDEFINED: #####\n";
40 foreach(%references) {
41         if ($_ != 1) {
42                 if ($defines{$_} != 1) {
43                         print $_."\n";
44                 }
45         } 
46 }