checkversion.pl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #! /usr/bin/perl
  2. #
  3. # checkversion find uses of LINUX_VERSION_CODE, KERNEL_VERSION, or
  4. # UTS_RELEASE 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. ($_ =~ /UTS_RELEASE/)) {
  37. $fUseVersion = 1;
  38. last LINE if $iLinuxVersion;
  39. }
  40. }
  41. # Report used version IDs without include?
  42. if ($fUseVersion && ! $iLinuxVersion) {
  43. print "$file: $.: need linux/version.h\n";
  44. }
  45. # Report superfluous includes.
  46. if ($iLinuxVersion && ! $fUseVersion) {
  47. print "$file: $iLinuxVersion linux/version.h not needed.\n";
  48. }
  49. # debug: report OK results:
  50. if ($debugging) {
  51. if ($iLinuxVersion && $fUseVersion) {
  52. print "$file: version use is OK ($iLinuxVersion)\n";
  53. }
  54. if (! $iLinuxVersion && ! $fUseVersion) {
  55. print "$file: version use is OK (none)\n";
  56. }
  57. }
  58. close(FILE);
  59. }