kbuild: make missing $DEPMOD a Warning instead of an Error
[GitHub/LineageOS/android_kernel_motorola_exynos9610.git] / scripts / checkversion.pl
CommitLineData
cb77f0d6 1#! /usr/bin/env perl
b2441318 2# SPDX-License-Identifier: GPL-2.0
1da177e4 3#
63104eec
SR
4# checkversion find uses of LINUX_VERSION_CODE or KERNEL_VERSION
5# without including <linux/version.h>, or cases of
1da177e4 6# including <linux/version.h> that don't need it.
f4b09ebc 7# Copyright (C) 2003, Randy Dunlap <rdunlap@xenotime.net>
1da177e4 8
a208868f
SH
9use strict;
10
1da177e4
LT
11$| = 1;
12
a208868f 13my $debugging;
1da177e4 14
a208868f 15foreach my $file (@ARGV) {
6088e9ff 16 next if $file =~ "include/linux/version\.h";
1da177e4 17 # Open this file.
a208868f
SH
18 open( my $f, '<', $file )
19 or die "Can't open $file: $!\n";
1da177e4
LT
20
21 # Initialize variables.
a208868f 22 my ($fInComment, $fInString, $fUseVersion);
1da177e4
LT
23 my $iLinuxVersion = 0;
24
a208868f 25 while (<$f>) {
1da177e4
LT
26 # Strip comments.
27 $fInComment && (s+^.*?\*/+ +o ? ($fInComment = 0) : next);
28 m+/\*+o && (s+/\*.*?\*/+ +go, (s+/\*.*$+ +o && ($fInComment = 1)));
29
30 # Pick up definitions.
31 if ( m/^\s*#/o ) {
32 $iLinuxVersion = $. if m/^\s*#\s*include\s*"linux\/version\.h"/o;
33 }
34
35 # Strip strings.
36 $fInString && (s+^.*?"+ +o ? ($fInString = 0) : next);
37 m+"+o && (s+".*?"+ +go, (s+".*$+ +o && ($fInString = 1)));
38
39 # Pick up definitions.
40 if ( m/^\s*#/o ) {
41 $iLinuxVersion = $. if m/^\s*#\s*include\s*<linux\/version\.h>/o;
42 }
43
44 # Look for uses: LINUX_VERSION_CODE, KERNEL_VERSION, UTS_RELEASE
63104eec 45 if (($_ =~ /LINUX_VERSION_CODE/) || ($_ =~ /\WKERNEL_VERSION/)) {
1da177e4 46 $fUseVersion = 1;
a208868f
SH
47 last if $iLinuxVersion;
48 }
1da177e4
LT
49 }
50
51 # Report used version IDs without include?
52 if ($fUseVersion && ! $iLinuxVersion) {
53 print "$file: $.: need linux/version.h\n";
54 }
55
56 # Report superfluous includes.
57 if ($iLinuxVersion && ! $fUseVersion) {
58 print "$file: $iLinuxVersion linux/version.h not needed.\n";
59 }
60
61 # debug: report OK results:
62 if ($debugging) {
63 if ($iLinuxVersion && $fUseVersion) {
64 print "$file: version use is OK ($iLinuxVersion)\n";
65 }
66 if (! $iLinuxVersion && ! $fUseVersion) {
67 print "$file: version use is OK (none)\n";
68 }
69 }
70
a208868f 71 close($f);
1da177e4 72}