diff options
author | Masahiro Yamada <yamada.masahiro@socionext.com> | 2019-06-04 06:14:03 -0400 |
---|---|---|
committer | Masahiro Yamada <yamada.masahiro@socionext.com> | 2019-06-15 06:57:02 -0400 |
commit | d5470d14431e9d39ee2131323589afac2a0bfee4 (patch) | |
tree | 525d6420912fd5280d8678c09b61e050bce82173 /scripts/Makefile.headersinst | |
parent | 59b2bd05f5f4dc62979c2e82ddd384f07e8f10bc (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.headersinst | 132 |
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 | ||
15 | include scripts/Kbuild.include | 15 | include scripts/Kbuild.include |
16 | 16 | ||
17 | srcdir := $(srctree)/$(obj) | 17 | src := $(srctree)/$(obj) |
18 | gen := $(objtree)/$(subst include/,include/generated/,$(obj)) | ||
19 | dst := 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. | ||
23 | subdirs := $(patsubst $(srcdir)/%/,%,\ | ||
24 | $(filter-out $(srcdir)/,\ | ||
25 | $(sort $(dir $(wildcard $(srcdir)/*/))))) | ||
26 | 22 | ||
27 | # Recursion | 23 | src-subdirs := $(patsubst $(src)/%/,%,$(wildcard $(src)/*/)) |
28 | __headers: $(subdirs) | 24 | gen-subdirs := $(patsubst $(gen)/%/,%,$(wildcard $(gen)/*/)) |
25 | all-subdirs := $(sort $(src-subdirs) $(gen-subdirs)) | ||
29 | 26 | ||
30 | PHONY += $(subdirs) | 27 | src-headers := $(if $(src-subdirs), $(shell cd $(src) && find $(src-subdirs) -name '*.h')) |
31 | $(subdirs): | 28 | src-headers := $(filter-out $(no-export-headers), $(src-headers)) |
32 | $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(dst)/$@ | 29 | gen-headers := $(if $(gen-subdirs), $(shell cd $(gen) && find $(gen-subdirs) -name '*.h')) |
30 | gen-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. |
36 | skip-inst := $(if $(filter %/uapi,$(obj)),1) | 34 | duplicated := $(filter $(gen-headers), $(src-headers)) |
35 | $(if $(duplicated), $(warning duplicated header export: $(duplicated))) | ||
37 | 36 | ||
38 | ifeq ($(skip-inst),) | 37 | gen-headers := $(filter-out $(duplicated), $(gen-headers)) |
39 | 38 | ||
40 | # Kbuild file is optional | 39 | # Add dst path prefix |
41 | kbuild-file := $(srctree)/$(obj)/Kbuild | 40 | all-subdirs := $(addprefix $(dst)/, $(all-subdirs)) |
42 | -include $(kbuild-file) | 41 | src-headers := $(addprefix $(dst)/, $(src-headers)) |
42 | gen-headers := $(addprefix $(dst)/, $(gen-headers)) | ||
43 | all-headers := $(src-headers) $(gen-headers) | ||
43 | 44 | ||
44 | installdir := usr/$(dst) | 45 | # Work out what needs to be removed |
45 | gendir := $(objtree)/$(subst include/,include/generated/,$(obj)) | 46 | old-subdirs := $(wildcard $(all-subdirs)) |
46 | header-files := $(notdir $(wildcard $(srcdir)/*.h)) | 47 | old-headers := $(if $(old-subdirs),$(shell find $(old-subdirs) -name '*.h')) |
47 | header-files := $(filter-out $(no-export-headers), $(header-files)) | 48 | unwanted := $(filter-out $(all-headers), $(old-headers)) |
48 | genhdr-files := $(notdir $(wildcard $(gendir)/*.h)) | ||
49 | genhdr-files := $(filter-out $(header-files), $(genhdr-files)) | ||
50 | 49 | ||
51 | # files used to track state of install/check | 50 | # Create directories |
52 | install-file := $(installdir)/.install | 51 | existing-dirs := $(sort $(dir $(old-headers))) |
53 | check-file := $(installdir)/.check | 52 | wanted-dirs := $(sort $(dir $(all-headers))) |
53 | new-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 |
56 | all-files := $(header-files) $(genhdr-files) | ||
57 | output-files := $(addprefix $(installdir)/, $(all-files)) | ||
58 | 57 | ||
59 | # Work out what needs to be removed | 58 | ifndef HDRCHECK |
60 | oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h)) | ||
61 | unwanted := $(filter-out $(all-files),$(oldheaders)) | ||
62 | 59 | ||
63 | # Prefix unwanted with full paths to objtree | 60 | quiet_cmd_install = HDRINST $@ |
64 | unwanted-file := $(addprefix $(installdir)/, $(unwanted)) | 61 | cmd_install = $(CONFIG_SHELL) $(srctree)/scripts/headers_install.sh $(@D) $(<D) $(@F) |
65 | 62 | ||
66 | printdir = $(patsubst %/,%,$(dir $@)) | 63 | $(src-headers): $(dst)/%.h: $(src)/%.h $(srctree)/scripts/headers_install.sh FORCE |
64 | $(call if_changed,install) | ||
67 | 65 | ||
68 | quiet_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 | ||
75 | quiet_cmd_remove = REMOVE $(unwanted) | 69 | quiet_cmd_remove = REMOVE $(unwanted) |
76 | cmd_remove = rm -f $(unwanted-file) | 70 | cmd_remove = rm -f $(unwanted) |
77 | |||
78 | quiet_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 | ||
87 | ifndef HDRCHECK | 72 | __headers: $(all-headers) |
88 | # Rules for installing headers | 73 | ifneq ($(unwanted),) |
89 | __headers: $(install-file) | 74 | $(call cmd,remove) |
75 | endif | ||
90 | @: | 76 | @: |
91 | 77 | ||
92 | targets += $(install-file) | 78 | existing-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 | ||
100 | else | 82 | else |
101 | __headers: $(check-file) | ||
102 | @: | ||
103 | 83 | ||
104 | targets += $(check-file) | 84 | quiet_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 | ||
108 | endif | 87 | check-files := $(addsuffix .chk, $(all-headers)) |
109 | 88 | ||
110 | cmd_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 | ||
113 | ifneq ($(cmd_files),) | 92 | __headers: $(check-files) |
114 | include $(cmd_files) | 93 | @: |
115 | endif | ||
116 | 94 | ||
117 | endif # skip-inst | 95 | endif |
118 | 96 | ||
119 | PHONY += FORCE | 97 | PHONY += FORCE |
120 | FORCE: ; | 98 | FORCE: |
121 | 99 | ||
122 | .PHONY: $(PHONY) | 100 | .PHONY: $(PHONY) |