summaryrefslogtreecommitdiff
path: root/source4/script/find_unused_makefilevars.pl
blob: 23fc36ef6a5a0c43801253b14e4213361b22d861 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/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 
# Copyright Jelmer Vernooij <jelmer@samba.org>

# Arguments:
#  1: Makefile.in
#

my %references;
my %defines;

# First, make a list of defines in configure
$in = shift;

sub process_file($)
{
	my ($fn) = @_;
	open(IN, $fn);
	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;
		}
		while ($line =~ /^include (.*)/sgm) {
			process_file($1);
		}
	}
	close IN;
}

process_file($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";
		}
	} 
}