s4:provision - Some rework
[Samba/ekacnet.git] / source4 / script / configure_check_unused.pl
blob52d8deeb27f9e48bff254984397b6d0e083e51f6
1 #!/usr/bin/perl
2 # Script that finds macros in a configure script that are not
3 # used in a set of C files.
4 # Copyright Jelmer Vernooij <jelmer@samba.org>, GPL
6 # Usage: ./$ARGV[0] configure.in [c-files...]
8 use strict;
10 sub autoconf_parse($$$$)
12 my $in = shift;
13 my $defines = shift;
14 my $functions = shift;
15 my $headers = shift;
17 open(IN, $in) or die("Can't open $in");
19 my $ln = 0;
21 foreach(<IN>) {
22 $ln++;
24 if(/AC_DEFINE\(([^,]+),/) {
25 $defines->{$1} = "$in:$ln";
28 if(/AC_CHECK_FUNCS\(\[*(.[^],)]+)/) {
29 foreach(split / /, $1) {
30 $functions->{$_} = "$in:$ln";
34 if(/AC_CHECK_FUNC\(([^,)]+)/) {
35 $functions->{$1} = "$in:$ln";
38 if(/AC_CHECK_HEADERS\(\[*([^],)]+)/) {
39 foreach(split / /, $1) {
40 $headers->{$_} = "$in:$ln";
44 if(/AC_CHECK_HEADER\(([^,)]+)/) {
45 $headers->{$1} = "$in:$ln";
48 if(/sinclude\(([^,]+)\)/) {
49 autoconf_parse($1, $defines, $functions, $headers);
53 close IN;
56 # Return the symbols and headers used by a C file
57 sub cfile_parse($$$)
59 my $in = shift;
60 my $symbols = shift;
61 my $headers = shift;
63 open(FI, $in) or die("Can't open $in");
64 my $ln = 0;
65 my $line;
66 while($line = <FI>) {
67 $ln++;
68 $_ = $line;
69 if (/\#([ \t]*)include ["<]([^">]+)/) {
70 $headers->{$2} = "$in:$ln";
73 $_ = $line;
74 while(/([A-Za-z0-9_]+)/g) {
75 $symbols->{$1} = "$in:$ln";
78 close FI;
81 my %ac_defines = ();
82 my %ac_func_checks = ();
83 my %ac_headers = ();
84 my %symbols = ();
85 my %headers = ();
87 if (scalar(@ARGV) <= 1) {
88 print("Usage: configure_find_unused.pl configure.in [CFILE...]\n");
89 exit 0;
92 autoconf_parse(shift(@ARGV), \%ac_defines, \%ac_func_checks, \%ac_headers);
93 cfile_parse($_, \%symbols, \%headers) foreach(@ARGV);
95 (keys %ac_defines) or warn("No defines found in configure.in file, parse error?");
97 foreach (keys %ac_defines) {
98 if (not defined($symbols{$_})) {
99 print "$ac_defines{$_}: Autoconf-defined $_ is unused\n";
103 (keys %ac_func_checks) or warn("No function checks found in configure.in file, parse error?");
105 foreach (keys %ac_func_checks) {
106 my $def = "HAVE_".uc($_);
107 if (not defined($symbols{$_})) {
108 print "$ac_func_checks{$_}: Autoconf-checked function `$_' is unused\n";
109 } elsif (not defined($symbols{$def})) {
110 print "$ac_func_checks{$_}: Autoconf-define `$def' for function `$_' is unused\n";
114 (keys %ac_headers) or warn("No headers found in configure.in file, parse error?");
116 foreach (keys %ac_headers) {
117 my $def = "HAVE_".uc($_);
118 $def =~ s/[\/\.]/_/g;
119 if (not defined($headers{$_})) {
120 print "$ac_headers{$_}: Autoconf-checked header `$_' is unused\n";
121 } elsif (not defined($symbols{$def})) {
122 print "$ac_headers{$_}: Autoconf-define `$def' for header `$_' is unused\n";