a script which find unused or undefined vars in Makefile or Makefile.in
authorStefan Metzmacher <metze@samba.org>
Tue, 13 Jan 2004 22:24:56 +0000 (22:24 +0000)
committerStefan Metzmacher <metze@samba.org>
Tue, 13 Jan 2004 22:24:56 +0000 (22:24 +0000)
call it like:

script/find_unused_makefilevars.pl Makefile

or

script/find_unused_makefilevars.pl Makefile.in

metze

source/script/find_unused_makefilevars.pl [new file with mode: 0755]

diff --git a/source/script/find_unused_makefilevars.pl b/source/script/find_unused_makefilevars.pl
new file mode 100755 (executable)
index 0000000..697ed54
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/perl
+# Script that reads in Makefile.in and outputs the names of all 
+# used but undefined vars and all defined but unused vars 
+
+# Arguments:
+#  1: Makefile.in
+#
+
+my %references;
+my %defines;
+
+# First, make a list of defines in configure
+$in = shift;
+
+open(IN, $in);
+while(<IN>) {
+       my $line = $_;
+       while($line =~ /^\b([a-zA-Z0-9_][a-zA-Z0-9_]*)\b[ \t]*=.*/sgm) {
+               $defines{$1} = 1;
+       }
+       while($line =~ /\$\(([a-zA-Z0-9_][a-zA-Z0-9_]*)\)/sgm) {
+               $references{$1} = 1;
+       }
+}
+close IN;
+
+print "##### DEFINED BUT UNUSED: #####\n";
+foreach(%defines) {
+#    print $_." defined\n";
+
+       if ($_ != 1) {
+               if ($references{$_} != 1) {
+                       print $_."\n";
+               }
+       } 
+}
+
+print "##### USED BUT UNDEFINED: #####\n";
+foreach(%references) {
+       if ($_ != 1) {
+               if ($defines{$_} != 1) {
+                       print $_."\n";
+               }
+       } 
+}