headers_check.pl 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/perl -w
  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. use strict;
  19. my ($dir, $arch, @files) = @ARGV;
  20. my $ret = 0;
  21. my $line;
  22. my $lineno = 0;
  23. my $filename;
  24. foreach my $file (@files) {
  25. local *FH;
  26. $filename = $file;
  27. open(FH, "<$filename") or die "$filename: $!\n";
  28. $lineno = 0;
  29. while ($line = <FH>) {
  30. $lineno++;
  31. check_include();
  32. }
  33. close FH;
  34. }
  35. exit $ret;
  36. sub check_include
  37. {
  38. if ($line =~ m/^\s*#\s*include\s+<((asm|linux).*)>/) {
  39. my $inc = $1;
  40. my $found;
  41. $found = stat($dir . "/" . $inc);
  42. if (!$found) {
  43. $inc =~ s#asm/#asm-$arch/#;
  44. $found = stat($dir . "/" . $inc);
  45. }
  46. if (!$found) {
  47. printf STDERR "$filename:$lineno: included file '$inc' is not exported\n";
  48. $ret = 1;
  49. }
  50. }
  51. }