blob: 5bdd9753007a3ae6103bdab7838e94413677cf68 [file] [log] [blame]
Jeremy Huntwork15a2ee72008-10-29 14:20:13 -07001#!/usr/bin/perl -w
Sam Ravnborg77124012008-06-15 21:41:09 +02002#
3# headers_check.pl execute a number of trivial consistency checks
4#
5# Usage: headers_check.pl dir [files...]
6# dir: dir to look for included files
7# arch: architecture
8# files: list of files to check
9#
10# The script reads the supplied files line by line and:
11#
12# 1) for each include statement it checks if the
13# included file actually exists.
14# Only include files located in asm* and linux* are checked.
15# The rest are assumed to be system include files.
16#
Mike Frysinger46b8af52008-12-27 02:43:36 -050017# 2) It is checked that prototypes does not use "extern"
18#
19# 3) TODO: check for leaked CONFIG_ symbols
Sam Ravnborg77124012008-06-15 21:41:09 +020020
21use strict;
Sam Ravnborg77124012008-06-15 21:41:09 +020022
23my ($dir, $arch, @files) = @ARGV;
24
25my $ret = 0;
26my $line;
27my $lineno = 0;
28my $filename;
29
30foreach my $file (@files) {
Jeremy Huntwork15a2ee72008-10-29 14:20:13 -070031 local *FH;
Sam Ravnborg77124012008-06-15 21:41:09 +020032 $filename = $file;
Jeremy Huntwork15a2ee72008-10-29 14:20:13 -070033 open(FH, "<$filename") or die "$filename: $!\n";
Sam Ravnborg77124012008-06-15 21:41:09 +020034 $lineno = 0;
Jeremy Huntwork15a2ee72008-10-29 14:20:13 -070035 while ($line = <FH>) {
Sam Ravnborg77124012008-06-15 21:41:09 +020036 $lineno++;
37 check_include();
Mike Frysinger46b8af52008-12-27 02:43:36 -050038 check_prototypes();
Sam Ravnborg77124012008-06-15 21:41:09 +020039 }
Jeremy Huntwork15a2ee72008-10-29 14:20:13 -070040 close FH;
Sam Ravnborg77124012008-06-15 21:41:09 +020041}
42exit $ret;
43
44sub check_include
45{
46 if ($line =~ m/^\s*#\s*include\s+<((asm|linux).*)>/) {
47 my $inc = $1;
48 my $found;
49 $found = stat($dir . "/" . $inc);
50 if (!$found) {
51 $inc =~ s#asm/#asm-$arch/#;
52 $found = stat($dir . "/" . $inc);
53 }
54 if (!$found) {
55 printf STDERR "$filename:$lineno: included file '$inc' is not exported\n";
56 $ret = 1;
57 }
58 }
59}
Mike Frysinger46b8af52008-12-27 02:43:36 -050060
61sub check_prototypes
62{
63 if ($line =~ m/^\s*extern\b/) {
64 printf STDERR "$filename:$lineno: extern's make no sense in userspace\n";
65 }
66}