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