summaryrefslogtreecommitdiffstats
path: root/scripts/Makefile.headersinst
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2019-06-04 06:14:03 -0400
committerMasahiro Yamada <yamada.masahiro@socionext.com>2019-06-15 06:57:02 -0400
commitd5470d14431e9d39ee2131323589afac2a0bfee4 (patch)
tree525d6420912fd5280d8678c09b61e050bce82173 /scripts/Makefile.headersinst
parent59b2bd05f5f4dc62979c2e82ddd384f07e8f10bc (diff)
kbuild: re-implement Makefile.headersinst without recursion
Since commit fcc8487d477a ("uapi: export all headers under uapi directories"), the headers in uapi directories are all exported by default although exceptional cases are still allowed by the syntax 'no-export-headers'. The traditional directory descending has been kept (in a somewhat hacky way), but it is actually unneeded. Get rid of it to simplify the code. Also, handle files one by one instead of the previous per-directory processing. This will emit much more log, but I like it. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Diffstat (limited to 'scripts/Makefile.headersinst')
-rw-r--r--scripts/Makefile.headersinst132
1 files changed, 55 insertions, 77 deletions
diff --git a/scripts/Makefile.headersinst b/scripts/Makefile.headersinst
index 1af6d0b06585..c96c4c26e240 100644
--- a/scripts/Makefile.headersinst
+++ b/scripts/Makefile.headersinst
@@ -14,109 +14,87 @@ __headers:
14 14
15include scripts/Kbuild.include 15include scripts/Kbuild.include
16 16
17srcdir := $(srctree)/$(obj) 17src := $(srctree)/$(obj)
18gen := $(objtree)/$(subst include/,include/generated/,$(obj))
19dst := usr/include
18 20
19# When make is run under a fakechroot environment, the function 21-include $(src)/Kbuild
20# $(wildcard $(srcdir)/*/.) doesn't only return directories, but also regular
21# files. So, we are using a combination of sort/dir/wildcard which works
22# with fakechroot.
23subdirs := $(patsubst $(srcdir)/%/,%,\
24 $(filter-out $(srcdir)/,\
25 $(sort $(dir $(wildcard $(srcdir)/*/)))))
26 22
27# Recursion 23src-subdirs := $(patsubst $(src)/%/,%,$(wildcard $(src)/*/))
28__headers: $(subdirs) 24gen-subdirs := $(patsubst $(gen)/%/,%,$(wildcard $(gen)/*/))
25all-subdirs := $(sort $(src-subdirs) $(gen-subdirs))
29 26
30PHONY += $(subdirs) 27src-headers := $(if $(src-subdirs), $(shell cd $(src) && find $(src-subdirs) -name '*.h'))
31$(subdirs): 28src-headers := $(filter-out $(no-export-headers), $(src-headers))
32 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(dst)/$@ 29gen-headers := $(if $(gen-subdirs), $(shell cd $(gen) && find $(gen-subdirs) -name '*.h'))
30gen-headers := $(filter-out $(no-export-headers), $(gen-headers))
33 31
34# Skip header install/check for include/uapi and arch/$(SRCARCH)/include/uapi. 32# If the same header is exported from source and generated directories,
35# We have only sub-directories there. 33# the former takes precedence, but this should be warned.
36skip-inst := $(if $(filter %/uapi,$(obj)),1) 34duplicated := $(filter $(gen-headers), $(src-headers))
35$(if $(duplicated), $(warning duplicated header export: $(duplicated)))
37 36
38ifeq ($(skip-inst),) 37gen-headers := $(filter-out $(duplicated), $(gen-headers))
39 38
40# Kbuild file is optional 39# Add dst path prefix
41kbuild-file := $(srctree)/$(obj)/Kbuild 40all-subdirs := $(addprefix $(dst)/, $(all-subdirs))
42-include $(kbuild-file) 41src-headers := $(addprefix $(dst)/, $(src-headers))
42gen-headers := $(addprefix $(dst)/, $(gen-headers))
43all-headers := $(src-headers) $(gen-headers)
43 44
44installdir := usr/$(dst) 45# Work out what needs to be removed
45gendir := $(objtree)/$(subst include/,include/generated/,$(obj)) 46old-subdirs := $(wildcard $(all-subdirs))
46header-files := $(notdir $(wildcard $(srcdir)/*.h)) 47old-headers := $(if $(old-subdirs),$(shell find $(old-subdirs) -name '*.h'))
47header-files := $(filter-out $(no-export-headers), $(header-files)) 48unwanted := $(filter-out $(all-headers), $(old-headers))
48genhdr-files := $(notdir $(wildcard $(gendir)/*.h))
49genhdr-files := $(filter-out $(header-files), $(genhdr-files))
50 49
51# files used to track state of install/check 50# Create directories
52install-file := $(installdir)/.install 51existing-dirs := $(sort $(dir $(old-headers)))
53check-file := $(installdir)/.check 52wanted-dirs := $(sort $(dir $(all-headers)))
53new-dirs := $(filter-out $(existing-dirs), $(wanted-dirs))
54$(if $(new-dirs), $(shell mkdir -p $(new-dirs)))
54 55
55# all headers files for this dir 56# Rules
56all-files := $(header-files) $(genhdr-files)
57output-files := $(addprefix $(installdir)/, $(all-files))
58 57
59# Work out what needs to be removed 58ifndef HDRCHECK
60oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
61unwanted := $(filter-out $(all-files),$(oldheaders))
62 59
63# Prefix unwanted with full paths to objtree 60quiet_cmd_install = HDRINST $@
64unwanted-file := $(addprefix $(installdir)/, $(unwanted)) 61 cmd_install = $(CONFIG_SHELL) $(srctree)/scripts/headers_install.sh $(@D) $(<D) $(@F)
65 62
66printdir = $(patsubst %/,%,$(dir $@)) 63$(src-headers): $(dst)/%.h: $(src)/%.h $(srctree)/scripts/headers_install.sh FORCE
64 $(call if_changed,install)
67 65
68quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ 66$(gen-headers): $(dst)/%.h: $(gen)/%.h $(srctree)/scripts/headers_install.sh FORCE
69 file$(if $(word 2, $(all-files)),s)) 67 $(call if_changed,install)
70 cmd_install = \
71 $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \
72 $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \
73 touch $@
74 68
75quiet_cmd_remove = REMOVE $(unwanted) 69quiet_cmd_remove = REMOVE $(unwanted)
76 cmd_remove = rm -f $(unwanted-file) 70 cmd_remove = rm -f $(unwanted)
77
78quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
79# Headers list can be pretty long, xargs helps to avoid
80# the "Argument list too long" error.
81 cmd_check = for f in $(all-files); do \
82 echo "$(installdir)/$${f}"; done \
83 | xargs \
84 $(PERL) $< usr/include $(SRCARCH); \
85 touch $@
86 71
87ifndef HDRCHECK 72__headers: $(all-headers)
88# Rules for installing headers 73ifneq ($(unwanted),)
89__headers: $(install-file) 74 $(call cmd,remove)
75endif
90 @: 76 @:
91 77
92targets += $(install-file) 78existing-headers := $(filter $(old-headers), $(all-headers))
93$(install-file): scripts/headers_install.sh \ 79
94 $(addprefix $(srcdir)/,$(header-files)) \ 80-include $(foreach f,$(existing-headers),$(dir $(f)).$(notdir $(f)).cmd)
95 $(addprefix $(gendir)/,$(genhdr-files)) FORCE
96 $(if $(unwanted),$(call cmd,remove),)
97 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
98 $(call if_changed,install)
99 81
100else 82else
101__headers: $(check-file)
102 @:
103 83
104targets += $(check-file) 84quiet_cmd_check = HDRCHK $<
105$(check-file): scripts/headers_check.pl $(output-files) FORCE 85 cmd_check = $(PERL) $(srctree)/scripts/headers_check.pl $(dst) $(SRCARCH) $<; touch $@
106 $(call if_changed,check)
107 86
108endif 87check-files := $(addsuffix .chk, $(all-headers))
109 88
110cmd_files := $(wildcard \ 89$(check-files): $(dst)/%.chk : $(dst)/% $(srctree)/scripts/headers_check.pl
111 $(foreach f,$(sort $(targets)),$(dir $(f)).$(notdir $(f)).cmd)) 90 $(call cmd,check)
112 91
113ifneq ($(cmd_files),) 92__headers: $(check-files)
114 include $(cmd_files) 93 @:
115endif
116 94
117endif # skip-inst 95endif
118 96
119PHONY += FORCE 97PHONY += FORCE
120FORCE: ; 98FORCE:
121 99
122.PHONY: $(PHONY) 100.PHONY: $(PHONY)