build-sys: add check-includes build target and script

This commit is contained in:
Karel Zak 2014-02-10 10:37:11 +01:00 committed by Tom Gundersen
parent 63a1b905d8
commit bfb35cfda1
2 changed files with 31 additions and 0 deletions

View 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

23
tools/check-includes.pl Executable file
View file

@ -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);
}