headers_check.pl 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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) It is checked that prototypes does not use "extern"
  18. #
  19. # 3) TODO: check for leaked CONFIG_ symbols
  20. use strict;
  21. my ($dir, $arch, @files) = @ARGV;
  22. my $ret = 0;
  23. my $line;
  24. my $lineno = 0;
  25. my $filename;
  26. foreach my $file (@files) {
  27. local *FH;
  28. $filename = $file;
  29. open(FH, "<$filename") or die "$filename: $!\n";
  30. $lineno = 0;
  31. while ($line = <FH>) {
  32. $lineno++;
  33. check_include();
  34. check_prototypes();
  35. }
  36. close FH;
  37. }
  38. exit $ret;
  39. sub check_include
  40. {
  41. if ($line =~ m/^\s*#\s*include\s+<((asm|linux).*)>/) {
  42. my $inc = $1;
  43. my $found;
  44. $found = stat($dir . "/" . $inc);
  45. if (!$found) {
  46. $inc =~ s#asm/#asm-$arch/#;
  47. $found = stat($dir . "/" . $inc);
  48. }
  49. if (!$found) {
  50. printf STDERR "$filename:$lineno: included file '$inc' is not exported\n";
  51. $ret = 1;
  52. }
  53. }
  54. }
  55. sub check_prototypes
  56. {
  57. if ($line =~ m/^\s*extern\b/) {
  58. printf STDERR "$filename:$lineno: extern's make no sense in userspace\n";
  59. }
  60. }