| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #! /usr/bin/perl | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2006-07-03 23:30:54 +02:00
										 |  |  | # checkversion find uses of LINUX_VERSION_CODE or KERNEL_VERSION | 
					
						
							|  |  |  | # without including <linux/version.h>, or cases of | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | # including <linux/version.h> that don't need it. | 
					
						
							| 
									
										
										
										
											2006-01-03 13:37:51 +01:00
										 |  |  | # Copyright (C) 2003, Randy Dunlap <rdunlap@xenotime.net> | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-22 15:17:14 -08:00
										 |  |  | use strict; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | $| = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-22 15:17:14 -08:00
										 |  |  | my $debugging; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-22 15:17:14 -08:00
										 |  |  | foreach my $file (@ARGV) { | 
					
						
							| 
									
										
										
										
											2011-04-26 19:07:56 -04:00
										 |  |  |     next if $file =~ "include/linux/version\.h"; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |     # Open this file. | 
					
						
							| 
									
										
										
										
											2010-02-22 15:17:14 -08:00
										 |  |  |     open( my $f, '<', $file ) | 
					
						
							|  |  |  |       or die "Can't open $file: $!\n"; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Initialize variables. | 
					
						
							| 
									
										
										
										
											2010-02-22 15:17:14 -08:00
										 |  |  |     my ($fInComment, $fInString, $fUseVersion); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |     my $iLinuxVersion = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-22 15:17:14 -08:00
										 |  |  |     while (<$f>) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	# Strip comments. | 
					
						
							|  |  |  | 	$fInComment && (s+^.*?\*/+ +o ? ($fInComment = 0) : next); | 
					
						
							|  |  |  | 	m+/\*+o && (s+/\*.*?\*/+ +go, (s+/\*.*$+ +o && ($fInComment = 1))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# Pick up definitions. | 
					
						
							|  |  |  | 	if ( m/^\s*#/o ) { | 
					
						
							|  |  |  | 	    $iLinuxVersion      = $. if m/^\s*#\s*include\s*"linux\/version\.h"/o; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# Strip strings. | 
					
						
							|  |  |  | 	$fInString && (s+^.*?"+ +o ? ($fInString = 0) : next); | 
					
						
							|  |  |  | 	m+"+o && (s+".*?"+ +go, (s+".*$+ +o && ($fInString = 1))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# Pick up definitions. | 
					
						
							|  |  |  | 	if ( m/^\s*#/o ) { | 
					
						
							|  |  |  | 	    $iLinuxVersion      = $. if m/^\s*#\s*include\s*<linux\/version\.h>/o; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# Look for uses: LINUX_VERSION_CODE, KERNEL_VERSION, UTS_RELEASE | 
					
						
							| 
									
										
										
										
											2006-07-03 23:30:54 +02:00
										 |  |  | 	if (($_ =~ /LINUX_VERSION_CODE/) || ($_ =~ /\WKERNEL_VERSION/)) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	    $fUseVersion = 1; | 
					
						
							| 
									
										
										
										
											2010-02-22 15:17:14 -08:00
										 |  |  |             last if $iLinuxVersion; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Report used version IDs without include? | 
					
						
							|  |  |  |     if ($fUseVersion && ! $iLinuxVersion) { | 
					
						
							|  |  |  | 	print "$file: $.: need linux/version.h\n"; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Report superfluous includes. | 
					
						
							|  |  |  |     if ($iLinuxVersion && ! $fUseVersion) { | 
					
						
							|  |  |  | 	print "$file: $iLinuxVersion linux/version.h not needed.\n"; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # debug: report OK results: | 
					
						
							|  |  |  |     if ($debugging) { | 
					
						
							|  |  |  |         if ($iLinuxVersion && $fUseVersion) { | 
					
						
							|  |  |  | 	    print "$file: version use is OK ($iLinuxVersion)\n"; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (! $iLinuxVersion && ! $fUseVersion) { | 
					
						
							|  |  |  | 	    print "$file: version use is OK (none)\n"; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-22 15:17:14 -08:00
										 |  |  |     close($f); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } |