Jeremy Huntwork | 15a2ee7 | 2008-10-29 14:20:13 -0700 | [diff] [blame] | 1 | #!/usr/bin/perl -w |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 2 | # |
| 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 | # |
| 17 | # 2) TODO: check for leaked CONFIG_ symbols |
| 18 | |
| 19 | use strict; |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 20 | |
| 21 | my ($dir, $arch, @files) = @ARGV; |
| 22 | |
| 23 | my $ret = 0; |
| 24 | my $line; |
| 25 | my $lineno = 0; |
| 26 | my $filename; |
| 27 | |
| 28 | foreach my $file (@files) { |
Jeremy Huntwork | 15a2ee7 | 2008-10-29 14:20:13 -0700 | [diff] [blame] | 29 | local *FH; |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 30 | $filename = $file; |
Jeremy Huntwork | 15a2ee7 | 2008-10-29 14:20:13 -0700 | [diff] [blame] | 31 | open(FH, "<$filename") or die "$filename: $!\n"; |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 32 | $lineno = 0; |
Jeremy Huntwork | 15a2ee7 | 2008-10-29 14:20:13 -0700 | [diff] [blame] | 33 | while ($line = <FH>) { |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 34 | $lineno++; |
| 35 | check_include(); |
| 36 | } |
Jeremy Huntwork | 15a2ee7 | 2008-10-29 14:20:13 -0700 | [diff] [blame] | 37 | close FH; |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 38 | } |
| 39 | exit $ret; |
| 40 | |
| 41 | sub check_include |
| 42 | { |
| 43 | if ($line =~ m/^\s*#\s*include\s+<((asm|linux).*)>/) { |
| 44 | my $inc = $1; |
| 45 | my $found; |
| 46 | $found = stat($dir . "/" . $inc); |
| 47 | if (!$found) { |
| 48 | $inc =~ s#asm/#asm-$arch/#; |
| 49 | $found = stat($dir . "/" . $inc); |
| 50 | } |
| 51 | if (!$found) { |
| 52 | printf STDERR "$filename:$lineno: included file '$inc' is not exported\n"; |
| 53 | $ret = 1; |
| 54 | } |
| 55 | } |
| 56 | } |