checkversion.pl 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. use strict;
  8. $| = 1;
  9. my $debugging;
  10. foreach my $file (@ARGV) {
  11. # Open this file.
  12. open( my $f, '<', $file )
  13. or die "Can't open $file: $!\n";
  14. # Initialize variables.
  15. my ($fInComment, $fInString, $fUseVersion);
  16. my $iLinuxVersion = 0;
  17. while (<$f>) {
  18. # Strip comments.
  19. $fInComment && (s+^.*?\*/+ +o ? ($fInComment = 0) : next);
  20. m+/\*+o && (s+/\*.*?\*/+ +go, (s+/\*.*$+ +o && ($fInComment = 1)));
  21. # Pick up definitions.
  22. if ( m/^\s*#/o ) {
  23. $iLinuxVersion = $. if m/^\s*#\s*include\s*"linux\/version\.h"/o;
  24. }
  25. # Strip strings.
  26. $fInString && (s+^.*?"+ +o ? ($fInString = 0) : next);
  27. m+"+o && (s+".*?"+ +go, (s+".*$+ +o && ($fInString = 1)));
  28. # Pick up definitions.
  29. if ( m/^\s*#/o ) {
  30. $iLinuxVersion = $. if m/^\s*#\s*include\s*<linux\/version\.h>/o;
  31. }
  32. # Look for uses: LINUX_VERSION_CODE, KERNEL_VERSION, UTS_RELEASE
  33. if (($_ =~ /LINUX_VERSION_CODE/) || ($_ =~ /\WKERNEL_VERSION/)) {
  34. $fUseVersion = 1;
  35. last if $iLinuxVersion;
  36. }
  37. }
  38. # Report used version IDs without include?
  39. if ($fUseVersion && ! $iLinuxVersion) {
  40. print "$file: $.: need linux/version.h\n";
  41. }
  42. # Report superfluous includes.
  43. if ($iLinuxVersion && ! $fUseVersion) {
  44. print "$file: $iLinuxVersion linux/version.h not needed.\n";
  45. }
  46. # debug: report OK results:
  47. if ($debugging) {
  48. if ($iLinuxVersion && $fUseVersion) {
  49. print "$file: version use is OK ($iLinuxVersion)\n";
  50. }
  51. if (! $iLinuxVersion && ! $fUseVersion) {
  52. print "$file: version use is OK (none)\n";
  53. }
  54. }
  55. close($f);
  56. }