aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/checkincludes.pl
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-09-23 18:37:02 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-09-23 18:37:02 -0400
commitc37efa932598de5e30330a1414e34d9e082e0d9e (patch)
tree1e3b782d257fa39a54f583af3dc7c32d7cffc67d /scripts/checkincludes.pl
parent9e12a7e7d89ad813d01092890010cf67d0f914bd (diff)
parentabe1ee3a221d53778c3e58747bbec6e518e5471b (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/sam/kbuild-next
* git://git.kernel.org/pub/scm/linux/kernel/git/sam/kbuild-next: (30 commits) Use macros for .data.page_aligned section. Use macros for .bss.page_aligned section. Use new __init_task_data macro in arch init_task.c files. kbuild: Don't define ALIGN and ENTRY when preprocessing linker scripts. arm, cris, mips, sparc, powerpc, um, xtensa: fix build with bash 4.0 kbuild: add static to prototypes kbuild: fail build if recordmcount.pl fails kbuild: set -fconserve-stack option for gcc 4.5 kbuild: echo the record_mcount command gconfig: disable "typeahead find" search in treeviews kbuild: fix cc1 options check to ensure we do not use -fPIC when compiling checkincludes.pl: add option to remove duplicates in place markup_oops: use modinfo to avoid confusion with underscored module names checkincludes.pl: provide usage helper checkincludes.pl: close file as soon as we're done with it ctags: usability fix kernel hacking: move STRIP_ASM_SYMS from General gitignore usr/initramfs_data.cpio.bz2 and usr/initramfs_data.cpio.lzma kbuild: Check if linker supports the -X option kbuild: introduce ld-option ... Fix trivial conflict in scripts/basic/fixdep.c
Diffstat (limited to 'scripts/checkincludes.pl')
-rwxr-xr-xscripts/checkincludes.pl71
1 files changed, 66 insertions, 5 deletions
diff --git a/scripts/checkincludes.pl b/scripts/checkincludes.pl
index 8e6b716c191c..676ddc07d6fa 100755
--- a/scripts/checkincludes.pl
+++ b/scripts/checkincludes.pl
@@ -1,24 +1,85 @@
1#!/usr/bin/perl 1#!/usr/bin/perl
2# 2#
3# checkincludes: Find files included more than once in (other) files. 3# checkincludes: find/remove files included more than once
4#
4# Copyright abandoned, 2000, Niels Kristian Bech Jensen <nkbj@image.dk>. 5# Copyright abandoned, 2000, Niels Kristian Bech Jensen <nkbj@image.dk>.
6# Copyright 2009 Luis R. Rodriguez <mcgrof@gmail.com>
7#
8# This script checks for duplicate includes. It also has support
9# to remove them in place. Note that this will not take into
10# consideration macros so you should run this only if you know
11# you do have real dups and do not have them under #ifdef's. You
12# could also just review the results.
13
14sub usage {
15 print "Usage: checkincludes.pl [-r]\n";
16 print "By default we just warn of duplicates\n";
17 print "To remove duplicated includes in place use -r\n";
18 exit 1;
19}
20
21my $remove = 0;
22
23if ($#ARGV < 0) {
24 usage();
25}
26
27if ($#ARGV >= 1) {
28 if ($ARGV[0] =~ /^-/) {
29 if ($ARGV[0] eq "-r") {
30 $remove = 1;
31 shift;
32 } else {
33 usage();
34 }
35 }
36}
5 37
6foreach $file (@ARGV) { 38foreach $file (@ARGV) {
7 open(FILE, $file) or die "Cannot open $file: $!.\n"; 39 open(FILE, $file) or die "Cannot open $file: $!.\n";
8 40
9 my %includedfiles = (); 41 my %includedfiles = ();
42 my @file_lines = ();
10 43
11 while (<FILE>) { 44 while (<FILE>) {
12 if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) { 45 if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
13 ++$includedfiles{$1}; 46 ++$includedfiles{$1};
14 } 47 }
48 push(@file_lines, $_);
15 } 49 }
16 50
17 foreach $filename (keys %includedfiles) { 51 close(FILE);
18 if ($includedfiles{$filename} > 1) { 52
19 print "$file: $filename is included more than once.\n"; 53 if (!$remove) {
54 foreach $filename (keys %includedfiles) {
55 if ($includedfiles{$filename} > 1) {
56 print "$file: $filename is included more than once.\n";
57 }
20 } 58 }
59 next;
21 } 60 }
22 61
62 open(FILE,">$file") || die("Cannot write to $file: $!");
63
64 my $dups = 0;
65 foreach (@file_lines) {
66 if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
67 foreach $filename (keys %includedfiles) {
68 if ($1 eq $filename) {
69 if ($includedfiles{$filename} > 1) {
70 $includedfiles{$filename}--;
71 $dups++;
72 } else {
73 print FILE $_;
74 }
75 }
76 }
77 } else {
78 print FILE $_;
79 }
80 }
81 if ($dups > 0) {
82 print "$file: removed $dups duplicate includes\n";
83 }
23 close(FILE); 84 close(FILE);
24} 85}