summaryrefslogtreecommitdiff
path: root/source4/script/configure_check_unused.pl
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2005-06-24 00:07:04 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:18:43 -0500
commit3022bfef70f4d76d3a12cfb8ee8cbdc72644b58f (patch)
treeb3b1d9084178dd546e04114b4c67f807b34a11e6 /source4/script/configure_check_unused.pl
parent3e476207765df4387bc89206316b95dfed251dd7 (diff)
downloadsamba-3022bfef70f4d76d3a12cfb8ee8cbdc72644b58f.tar.gz
samba-3022bfef70f4d76d3a12cfb8ee8cbdc72644b58f.tar.bz2
samba-3022bfef70f4d76d3a12cfb8ee8cbdc72644b58f.zip
r7859: Merge a few scripts to one script that checks for the following unused
(used in configure.in, but their output is never used) autoconf macros: - AC_DEFINE - AC_CHECK_FUNC - AC_CHECK_FUNCS - AC_CHECK_HEADER - AC_CHECK_HEADERS (This used to be commit 897d7b7d390815778adea1adf5e73b94f75a3048)
Diffstat (limited to 'source4/script/configure_check_unused.pl')
-rwxr-xr-xsource4/script/configure_check_unused.pl120
1 files changed, 120 insertions, 0 deletions
diff --git a/source4/script/configure_check_unused.pl b/source4/script/configure_check_unused.pl
new file mode 100755
index 0000000000..1b33a9e6b1
--- /dev/null
+++ b/source4/script/configure_check_unused.pl
@@ -0,0 +1,120 @@
+#!/usr/bin/perl
+# Script that finds macros in a configure script that are not
+# used in a set of C files.
+# Copyright Jelmer Vernooij <jelmer@samba.org>, GPL
+#
+# Usage: ./$ARGV[0] configure.in [c-files...]
+
+use strict;
+
+sub autoconf_parse($$$$)
+{
+ my $in = shift;
+ my $defines = shift;
+ my $functions = shift;
+ my $headers = shift;
+
+ open(IN, $in) or die("Can't open $in");
+
+ my $ln = 0;
+
+ foreach(<IN>) {
+ $ln++;
+
+ if(/AC_DEFINE\(([^,]+),/) {
+ $defines->{$1} = "$in:$ln";
+ }
+
+ if(/AC_CHECK_FUNCS\(\[*(.[^],)]+)/) {
+ foreach(split / /, $1) {
+ $functions->{$_} = "$in:$ln";
+ }
+ }
+
+ if(/AC_CHECK_FUNC\(([^,)]+)/) {
+ $functions->{$1} = "$in:$ln";
+ }
+
+ if(/AC_CHECK_HEADERS\(\[*([^],)]+)/) {
+ foreach(split / /, $1) {
+ $headers->{$_} = "$in:$ln";
+ }
+ }
+
+ if(/AC_CHECK_HEADER\(([^,)]+)/) {
+ $headers->{$1} = "$in:$ln";
+ }
+
+ if(/sinclude\(([^,]+)\)/) {
+ autoconf_parse($1, $defines, $functions, $headers);
+ }
+ }
+
+ close IN;
+}
+
+# Return the symbols and headers used by a C file
+sub cfile_parse($$$)
+{
+ my $in = shift;
+ my $symbols = shift;
+ my $headers = shift;
+
+ open(FI, $in) or die("Can't open $in");
+ my $ln = 0;
+ foreach(<FI>) {
+ $ln++;
+ foreach(/\#([ \t]*)include ["<]([^">]+)/g) {
+ $headers->{$2} = "$in:$ln";
+ }
+
+ foreach(/([A-Za-z0-9_]+)/g) {
+ $symbols->{$1} = "$in:$ln";
+ }
+ }
+ close FI;
+}
+
+my %ac_defines = ();
+my %ac_func_checks = ();
+my %ac_headers = ();
+my %symbols = ();
+my %headers = ();
+
+if (scalar(@ARGV) <= 1) {
+ print("Usage: configure_find_unused.pl configure.in [CFILE...]\n");
+ exit 0;
+}
+
+autoconf_parse(shift(@ARGV), \%ac_defines, \%ac_func_checks, \%ac_headers);
+cfile_parse($_, \%symbols, \%headers) foreach(@ARGV);
+
+(keys %ac_defines) or warn("No defines found in configure.in file, parse error?");
+
+foreach (keys %ac_defines) {
+ if (not defined($symbols{$_})) {
+ print "$ac_defines{$_}: Autoconf-defined $_ is unused\n";
+ }
+}
+
+(keys %ac_func_checks) or warn("No function checks found in configure.in file, parse error?");
+
+foreach (keys %ac_func_checks) {
+ if (not defined($symbols{$_})) {
+ print "$ac_func_checks{$_}: Autoconf-checked function $_ is unused\n";
+ } elsif (not defined($symbols{"HAVE_".uc($_)})) {
+ print "$ac_func_checks{$_}: Autoconf-define for function $_ is unused\n";
+ }
+}
+
+(keys %ac_headers) or warn("No headers found in configure.in file, parse error?");
+
+foreach (keys %ac_headers) {
+ my $def = "HAVE_".uc($_);
+ $def =~ s/[\/\.]/_/g;
+ if (not defined($headers{$_})) {
+ print "$ac_headers{$_}: Autoconf-checked header $_ is unused\n";
+ } elsif (not defined($symbols{$def})) {
+ print "$ac_headers{$_}: Autoconf-define for header $_ is unused\n";
+ }
+}