]> err.no Git - util-linux/commitdiff
tools: add checkincludes.pl (from linux kernel)
authorKarel Zak <kzak@redhat.com>
Wed, 26 Nov 2008 11:42:35 +0000 (12:42 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 26 Nov 2008 11:59:29 +0000 (12:59 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
Makefile.am
tools/checkincludes.pl [new file with mode: 0755]

index b78e8a77a582e6180915c6b01dc075c8b3eff05f..fefff76f56ec04893c356a9d18bf303388d1c2ce 100644 (file)
@@ -14,6 +14,10 @@ SUBDIRS = \
        text-utils \
        tests
 
+
+RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o \
+               -name CVS -o -name .pc -o -name .hg -o -name .git \) -prune -o
+
 if LINUX
 SUBDIRS += \
        hwclock \
@@ -42,6 +46,13 @@ distclean-local:
        -find . -name \*~ -o -name \*.orig -o -name \*.rej | xargs rm -f
        rm -rf autom4te.cache
 
+
+checkincludes:
+       -find * $(RCS_FIND_IGNORE) \
+               -name '*.[hcS]' -type f -print | sort -u \
+               | xargs $(top_srcdir)/tools/checkincludes.pl
+
+
 ENABLE_ALL = --enable-static-programs \
  --enable-elvtune --enable-init --enable-kill --enable-last \
  --enable-mesg --enable-partx --enable-raw --enable-rdev --enable-reset \
diff --git a/tools/checkincludes.pl b/tools/checkincludes.pl
new file mode 100755 (executable)
index 0000000..8e6b716
--- /dev/null
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+#
+# checkincludes: Find files included more than once in (other) files.
+# Copyright abandoned, 2000, Niels Kristian Bech Jensen <nkbj@image.dk>.
+
+foreach $file (@ARGV) {
+       open(FILE, $file) or die "Cannot open $file: $!.\n";
+
+       my %includedfiles = ();
+
+       while (<FILE>) {
+               if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
+                       ++$includedfiles{$1};
+               }
+       }
+       
+       foreach $filename (keys %includedfiles) {
+               if ($includedfiles{$filename} > 1) {
+                       print "$file: $filename is included more than once.\n";
+               }
+       }
+
+       close(FILE);
+}