aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSam Ravnborg <sam@ravnborg.org>2008-06-15 15:41:09 -0400
committerSam Ravnborg <sam@ravnborg.org>2008-07-25 16:12:16 -0400
commit7712401ae9006fc9d9b9a3e7861dc73781429a89 (patch)
treecb0989cc5a1db8b7e4f490eef8e33225a2e40e93 /scripts
parent88181ec30f58a28cd78b26aaac38bef4062b23dc (diff)
kbuild: optimize headers_* targets
Move the core functionality of headers_install and headers_check to two small perl scripts. The makefile is adapted to use the perl scrip and changed to operate on all files in a directory. So if one file is changed then all files in the directory is processed. perl were chosen for the helper scripts because this is pure text processing which perl is good at and especially the headers_check.pl script are expected to see changes / new checks implmented. The speed is ~300% faster on this box. And the output generated to the screen is now down to two lines per directory (one for install, one for check) so it is easier to scroll back after a kernel build. The perl scripts has been brought to sanity by patient feedback from: Vegard Nossum <vegard.nossum@gmail.com> Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Makefile.headersinst145
-rwxr-xr-xscripts/hdrcheck.sh10
-rw-r--r--scripts/headers_check.pl56
-rw-r--r--scripts/headers_install.pl42
4 files changed, 161 insertions, 92 deletions
diff --git a/scripts/Makefile.headersinst b/scripts/Makefile.headersinst
index 599503f0e5f2..be2b70c48a3b 100644
--- a/scripts/Makefile.headersinst
+++ b/scripts/Makefile.headersinst
@@ -1,26 +1,14 @@
1# ========================================================================== 1# ==========================================================================
2# Installing headers 2# Installing headers
3# 3#
4# header-y files will be installed verbatim 4# header-y - list files to be installed. They are preprocessed
5# unifdef-y are the files where unifdef will be run before installing files 5# to remove __KERNEL__ section of the file
6# objhdr-y are generated files that will be installed verbatim 6# unifdef-y - Same as header-y. Obsolete
7# objhdr-y - Same as header-y but for generated files
7# 8#
8# ========================================================================== 9# ==========================================================================
9 10
10UNIFDEF := scripts/unifdef -U__KERNEL__ 11# called may set destination dir (when installing to asm/)
11
12# Eliminate the contents of (and inclusions of) compiler.h
13HDRSED := sed -e "s/ inline / __inline__ /g" \
14 -e "s/[[:space:]]__user[[:space:]]\{1,\}/ /g" \
15 -e "s/(__user[[:space:]]\{1,\}/ (/g" \
16 -e "s/[[:space:]]__force[[:space:]]\{1,\}/ /g" \
17 -e "s/(__force[[:space:]]\{1,\}/ (/g" \
18 -e "s/[[:space:]]__iomem[[:space:]]\{1,\}/ /g" \
19 -e "s/(__iomem[[:space:]]\{1,\}/ (/g" \
20 -e "s/[[:space:]]__attribute_const__[[:space:]]\{1,\}/\ /g" \
21 -e "s/[[:space:]]__attribute_const__$$//" \
22 -e "/^\#include <linux\/compiler.h>/d"
23
24_dst := $(if $(dst),$(dst),$(obj)) 12_dst := $(if $(dst),$(dst),$(obj))
25 13
26kbuild-file := $(srctree)/$(obj)/Kbuild 14kbuild-file := $(srctree)/$(obj)/Kbuild
@@ -28,89 +16,82 @@ include $(kbuild-file)
28 16
29include scripts/Kbuild.include 17include scripts/Kbuild.include
30 18
31install := $(INSTALL_HDR_PATH)/$(_dst) 19install := $(INSTALL_HDR_PATH)/$(_dst)
32
33header-y := $(sort $(header-y) $(unifdef-y))
34subdir-y := $(patsubst %/,%,$(filter %/, $(header-y)))
35header-y := $(filter-out %/, $(header-y))
36 20
37# stamp files for header checks 21header-y := $(sort $(header-y) $(unifdef-y))
38check-y := $(patsubst %,.check.%,$(header-y) $(objhdr-y)) 22subdirs := $(patsubst %/,%,$(filter %/, $(header-y)))
39 23header-y := $(filter-out %/, $(header-y))
40# Work out what needs to be removed
41oldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h))
42unwanted := $(filter-out $(header-y) $(objhdr-y),$(oldheaders))
43 24
44oldcheckstamps := $(patsubst $(install)/%,%,$(wildcard $(install)/.check.*.h)) 25# files used to track state of install/check
45unwanted += $(filter-out $(check-y),$(oldcheckstamps)) 26install-file := $(install)/.install
27check-file := $(install)/.check
46 28
47# Prefix them all with full paths to $(INSTALL_HDR_PATH) 29# all headers files for this dir
48header-y := $(patsubst %,$(install)/%,$(header-y)) 30all-files := $(header-y) $(objhdr-y)
49objhdr-y := $(patsubst %,$(install)/%,$(objhdr-y)) 31input-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \
50check-y := $(patsubst %,$(install)/%,$(check-y)) 32 $(addprefix $(objtree)/$(obj)/,$(objhdr-y))
33output-files := $(addprefix $(install)/, $(all-files))
51 34
52quiet_cmd_o_hdr_install = INSTALL $(patsubst $(INSTALL_HDR_PATH)/%,%,$@) 35# Work out what needs to be removed
53 cmd_o_hdr_install = cp $(patsubst $(install)/%,$(objtree)/$(obj)/%,$@) \ 36oldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h))
54 $(install) 37unwanted := $(filter-out $(all-files),$(oldheaders))
55
56quiet_cmd_unifdef = UNIFDEF $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
57 cmd_unifdef = $(UNIFDEF) $(patsubst $(install)/%,$(srctree)/$(obj)/%,$@)\
58 | $(HDRSED) > $@ || :
59 38
60quiet_cmd_check = CHECK $(patsubst $(install)/.check.%,$(_dst)/%,$@) 39# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
61 cmd_check = $(CONFIG_SHELL) $(srctree)/scripts/hdrcheck.sh \ 40unwanted-file := $(addprefix $(install)/, $(unwanted))
62 $(INSTALL_HDR_PATH)/include $(subst /.check.,/,$@) $@
63 41
64quiet_cmd_remove = REMOVE $(_dst)/$@ 42printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
65 cmd_remove = rm -f $(install)/$@
66 43
67quiet_cmd_mkdir = MKDIR $(patsubst $(INSTALL_HDR_PATH)/%,%,$@) 44quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
68 cmd_mkdir = mkdir -p $@ 45 file$(if $(word 2, $(all-files)),s))
46 cmd_install = $(PERL) $< $(srctree)/$(obj) $(install) $(header-y); \
47 $(PERL) $< $(objtree)/$(obj) $(install) $(objhdr-y); \
48 touch $@
69 49
70.PHONY: __headersinst __headerscheck 50quiet_cmd_remove = REMOVE $(unwanted)
51 cmd_remove = rm -f $(unwanted-file)
71 52
72ifdef HDRCHECK 53quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
73__headerscheck: $(subdir-y) $(check-y) 54 cmd_check = $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH) \
74 @true 55 $(addprefix $(install)/, $(all-files)); \
56 touch $@
75 57
76$(check-y) : $(install)/.check.%.h : $(install)/%.h 58PHONY += __headersinst __headerscheck
77 $(call cmd,check)
78 59
79# Other dependencies for $(check-y) 60ifndef HDRCHECK
80include /dev/null $(wildcard $(check-y)) 61# Rules for installing headers
62__headersinst: $(subdirs) $(install-file)
63 @:
81 64
82# but leave $(check-y) as .PHONY for now until those 65targets += $(install-file)
83# deps are actually correct. 66$(install-file): scripts/headers_install.pl $(input-files) FORCE
84.PHONY: $(check-y) 67 $(if $(unwanted),$(call cmd,remove),)
68 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
69 $(call if_changed,install)
85 70
86else 71else
87# Rules for installing headers 72__headerscheck: $(subdirs) $(check-file)
88__headersinst: $(subdir-y) $(header-y) $(objhdr-y) 73 @:
89 @true
90 74
91$(objhdr-y) $(subdir-y) $(header-y): | $(install) $(unwanted) 75targets += $(check-file)
76$(check-file): scripts/headers_check.pl $(output-files) FORCE
77 $(call if_changed,check)
92 78
93$(install): 79endif
94 $(call cmd,mkdir)
95
96# Rules for removing unwanted header files
97.PHONY: $(unwanted)
98$(unwanted):
99 $(call cmd,remove)
100 80
101# Install generated files 81# Recursion
102$(objhdr-y): $(install)/%.h: $(objtree)/$(obj)/%.h $(kbuild-file) 82hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
103 $(call cmd,o_hdr_install) 83.PHONY: $(subdirs)
84$(subdirs):
85 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
104 86
105# Unifdef header files and install them 87targets := $(wildcard $(sort $(targets)))
106$(header-y): $(install)/%.h: $(srctree)/$(obj)/%.h $(kbuild-file) 88cmd_files := $(wildcard \
107 $(call cmd,unifdef) 89 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
108 90
91ifneq ($(cmd_files),)
92 include $(cmd_files)
109endif 93endif
110 94
111hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj 95.PHONY: $(PHONY)
112 96PHONY += FORCE
113# Recursion 97FORCE: ;
114.PHONY: $(subdir-y)
115$(subdir-y):
116 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
diff --git a/scripts/hdrcheck.sh b/scripts/hdrcheck.sh
deleted file mode 100755
index 31598584f871..000000000000
--- a/scripts/hdrcheck.sh
+++ /dev/null
@@ -1,10 +0,0 @@
1#!/bin/sh
2
3for FILE in `grep '^[ \t]*#[ \t]*include[ \t]*<' $2 | cut -f2 -d\< | cut -f1 -d\> | egrep ^linux\|^asm` ; do
4 if [ ! -r $1/$FILE ]; then
5 echo $2 requires $FILE, which does not exist in exported headers
6 exit 1
7 fi
8done
9# FIXME: List dependencies into $3
10touch $3
diff --git a/scripts/headers_check.pl b/scripts/headers_check.pl
new file mode 100644
index 000000000000..15d53a6b1a1f
--- /dev/null
+++ b/scripts/headers_check.pl
@@ -0,0 +1,56 @@
1#!/usr/bin/perl
2#
3# headers_check.pl execute a number of trivial consistency checks
4#
5# Usage: headers_check.pl dir [files...]
6# dir: dir to look for included files
7# arch: architecture
8# files: list of files to check
9#
10# The script reads the supplied files line by line and:
11#
12# 1) for each include statement it checks if the
13# included file actually exists.
14# Only include files located in asm* and linux* are checked.
15# The rest are assumed to be system include files.
16#
17# 2) TODO: check for leaked CONFIG_ symbols
18
19use strict;
20use warnings;
21
22my ($dir, $arch, @files) = @ARGV;
23
24my $ret = 0;
25my $line;
26my $lineno = 0;
27my $filename;
28
29foreach my $file (@files) {
30 $filename = $file;
31 open(my $fh, '<', "$filename") or die "$filename: $!\n";
32 $lineno = 0;
33 while ($line = <$fh>) {
34 $lineno++;
35 check_include();
36 }
37 close $fh;
38}
39exit $ret;
40
41sub check_include
42{
43 if ($line =~ m/^\s*#\s*include\s+<((asm|linux).*)>/) {
44 my $inc = $1;
45 my $found;
46 $found = stat($dir . "/" . $inc);
47 if (!$found) {
48 $inc =~ s#asm/#asm-$arch/#;
49 $found = stat($dir . "/" . $inc);
50 }
51 if (!$found) {
52 printf STDERR "$filename:$lineno: included file '$inc' is not exported\n";
53 $ret = 1;
54 }
55 }
56}
diff --git a/scripts/headers_install.pl b/scripts/headers_install.pl
new file mode 100644
index 000000000000..f0ff9a35acd0
--- /dev/null
+++ b/scripts/headers_install.pl
@@ -0,0 +1,42 @@
1#!/usr/bin/perl
2#
3# headers_install prepare the listed header files for use in
4# user space and copy the files to their destination.
5#
6# Usage: headers_install.pl odir installdir [files...]
7# odir: dir to open files
8# install: dir to install the files
9# files: list of files to check
10#
11# Step in preparation for users space:
12# 1) Drop all use of compiler.h definitions
13# 2) Drop include of compiler.h
14# 3) Drop all sections defined out by __KERNEL__ (using unifdef)
15
16use strict;
17use warnings;
18
19my ($readdir, $installdir, @files) = @ARGV;
20
21my $unifdef = "scripts/unifdef -U__KERNEL__";
22
23foreach my $file (@files) {
24 my $tmpfile = "$installdir/$file.tmp";
25 open(my $infile, '<', "$readdir/$file")
26 or die "$readdir/$file: $!\n";
27 open(my $outfile, '>', "$tmpfile") or die "$tmpfile: $!\n";
28 while (my $line = <$infile>) {
29 $line =~ s/([\s(])__user\s/$1/g;
30 $line =~ s/([\s(])__force\s/$1/g;
31 $line =~ s/([\s(])__iomem\s/$1/g;
32 $line =~ s/\s__attribute_const__\s/ /g;
33 $line =~ s/\s__attribute_const__$//g;
34 $line =~ s/^#include <linux\/compiler.h>//;
35 printf $outfile "%s", $line;
36 }
37 close $outfile;
38 close $infile;
39 system $unifdef . " $tmpfile > $installdir/$file";
40 unlink $tmpfile;
41}
42exit 0;