chiark / gitweb /
build-sys: add check-includes build target and script
authorKarel Zak <kzak@redhat.com>
Mon, 10 Feb 2014 09:37:11 +0000 (10:37 +0100)
committerTom Gundersen <teg@jklm.no>
Mon, 10 Feb 2014 12:00:19 +0000 (13:00 +0100)
Makefile.am
tools/check-includes.pl [new file with mode: 0755]

index 4f5e0369901f3b5a636ae03e3ac32b2173651bbf..3730e71dc2f2bd82f18d8dcfc006fec332a1d3cb 100644 (file)
@@ -4936,6 +4936,14 @@ CLEANFILES += \
 check-api-unused: defined undefined exported
        ( cat exported undefined ) | sort -u  | diff -u - defined | grep ^+ | grep -v ^+++ | cut -c2-
 
+.PHONY: check-includes
+check-includes: $(top_srcdir)/tools/check-includes.pl
+       $(AM_V_GEN) find * -name '*.[hcS]' -type f -print | sort -u \
+               | xargs $(top_srcdir)/tools/check-includes.pl
+
+EXTRA_DIST += \
+       $(top_srcdir)/tools/check-includes.pl
+
 # Stupid test that everything purported to be exported really is
 
 define generate-sym-test
diff --git a/tools/check-includes.pl b/tools/check-includes.pl
new file mode 100755 (executable)
index 0000000..bf23929
--- /dev/null
@@ -0,0 +1,23 @@
+#!/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);
+}