checkversion.pl 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #! /usr/bin/perl
  2. #
  3. # checkversion find uses of LINUX_VERSION_CODE or KERNEL_VERSION
  4. # without including <linux/version.h>, or cases of
  5. # including <linux/version.h> that don't need it.
  6. # Copyright (C) 2003, Randy Dunlap <rdunlap@xenotime.net>
  7. $| = 1;
  8. my $debugging = 0;
  9. foreach $file (@ARGV)
  10. {
  11. # Open this file.
  12. open(FILE, $file) || die "Can't open $file: $!\n";
  13. # Initialize variables.
  14. my $fInComment = 0;
  15. my $fInString = 0;
  16. my $fUseVersion = 0;
  17. my $iLinuxVersion = 0;
  18. LINE: while ( <FILE> )
  19. {
  20. # Strip comments.
  21. $fInComment && (s+^.*?\*/+ +o ? ($fInComment = 0) : next);
  22. m+/\*+o && (s+/\*.*?\*/+ +go, (s+/\*.*$+ +o && ($fInComment = 1)));
  23. # Pick up definitions.
  24. if ( m/^\s*#/o ) {
  25. $iLinuxVersion = $. if m/^\s*#\s*include\s*"linux\/version\.h"/o;
  26. }
  27. # Strip strings.
  28. $fInString && (s+^.*?"+ +o ? ($fInString = 0) : next);
  29. m+"+o && (s+".*?"+ +go, (s+".*$+ +o && ($fInString = 1)));
  30. # Pick up definitions.
  31. if ( m/^\s*#/o ) {
  32. $iLinuxVersion = $. if m/^\s*#\s*include\s*<linux\/version\.h>/o;
  33. }
  34. # Look for uses: LINUX_VERSION_CODE, KERNEL_VERSION, UTS_RELEASE
  35. if (($_ =~ /LINUX_VERSION_CODE/) || ($_ =~ /\WKERNEL_VERSION/)) {
  36. $fUseVersion = 1;
  37. last LINE if $iLinuxVersion;
  38. }
  39. }
  40. # Report used version IDs without include?
  41. if ($fUseVersion && ! $iLinuxVersion) {
  42. print "$file: $.: need linux/version.h\n";
  43. }
  44. # Report superfluous includes.
  45. if ($iLinuxVersion && ! $fUseVersion) {
  46. print "$file: $iLinuxVersion linux/version.h not needed.\n";
  47. }
  48. # debug: report OK results:
  49. if ($debugging) {
  50. if ($iLinuxVersion && $fUseVersion) {
  51. print "$file: version use is OK ($iLinuxVersion)\n";
  52. }
  53. if (! $iLinuxVersion && ! $fUseVersion) {
  54. print "$file: version use is OK (none)\n";
  55. }
  56. }
  57. close(FILE);
  58. }