headers_check.pl: disallow extern's
[linux-2.6/mini2440.git] / scripts / headers_check.pl
blob5bdd9753007a3ae6103bdab7838e94413677cf68
1 #!/usr/bin/perl -w
3 # headers_check.pl execute a number of trivial consistency checks
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
10 # The script reads the supplied files line by line and:
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.
17 # 2) It is checked that prototypes does not use "extern"
19 # 3) TODO: check for leaked CONFIG_ symbols
21 use strict;
23 my ($dir, $arch, @files) = @ARGV;
25 my $ret = 0;
26 my $line;
27 my $lineno = 0;
28 my $filename;
30 foreach my $file (@files) {
31 local *FH;
32 $filename = $file;
33 open(FH, "<$filename") or die "$filename: $!\n";
34 $lineno = 0;
35 while ($line = <FH>) {
36 $lineno++;
37 check_include();
38 check_prototypes();
40 close FH;
42 exit $ret;
44 sub check_include
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);
54 if (!$found) {
55 printf STDERR "$filename:$lineno: included file '$inc' is not exported\n";
56 $ret = 1;
61 sub check_prototypes
63 if ($line =~ m/^\s*extern\b/) {
64 printf STDERR "$filename:$lineno: extern's make no sense in userspace\n";