Commit | Line | Data |
---|---|---|
8d730cfb DW |
1 | # ========================================================================== |
2 | # Installing headers | |
3 | # | |
7712401a SR |
4 | # header-y - list files to be installed. They are preprocessed |
5 | # to remove __KERNEL__ section of the file | |
7712401a | 6 | # objhdr-y - Same as header-y but for generated files |
cb97914b | 7 | # genhdr-y - Same as objhdr-y but in a generated/ directory |
8d730cfb DW |
8 | # |
9 | # ========================================================================== | |
10 | ||
7712401a | 11 | # called may set destination dir (when installing to asm/) |
8d730cfb DW |
12 | _dst := $(if $(dst),$(dst),$(obj)) |
13 | ||
cb97914b PA |
14 | # generated header directory |
15 | gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj))) | |
16 | ||
283039fb SR |
17 | kbuild-file := $(srctree)/$(obj)/Kbuild |
18 | include $(kbuild-file) | |
8d730cfb | 19 | |
c7bb349e SR |
20 | _dst := $(if $(destination-y),$(destination-y),$(_dst)) |
21 | ||
283039fb | 22 | include scripts/Kbuild.include |
de789125 | 23 | |
7712401a | 24 | install := $(INSTALL_HDR_PATH)/$(_dst) |
8d730cfb | 25 | |
7cfddeef | 26 | header-y := $(sort $(header-y)) |
7712401a SR |
27 | subdirs := $(patsubst %/,%,$(filter %/, $(header-y))) |
28 | header-y := $(filter-out %/, $(header-y)) | |
de789125 | 29 | |
7712401a SR |
30 | # files used to track state of install/check |
31 | install-file := $(install)/.install | |
32 | check-file := $(install)/.check | |
de789125 | 33 | |
d8ecc5cd SR |
34 | # generic-y list all files an architecture uses from asm-generic |
35 | # Use this to build a list of headers which require a wrapper | |
36 | wrapper-files := $(filter $(header-y), $(generic-y)) | |
37 | ||
7712401a | 38 | # all headers files for this dir |
d8ecc5cd | 39 | header-y := $(filter-out $(generic-y), $(header-y)) |
cb97914b | 40 | all-files := $(header-y) $(objhdr-y) $(genhdr-y) $(wrapper-files) |
7712401a | 41 | input-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \ |
cb97914b PA |
42 | $(addprefix $(objtree)/$(obj)/,$(objhdr-y)) \ |
43 | $(addprefix $(objtree)/$(gen)/,$(genhdr-y)) | |
7712401a | 44 | output-files := $(addprefix $(install)/, $(all-files)) |
de789125 | 45 | |
7712401a SR |
46 | # Work out what needs to be removed |
47 | oldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h)) | |
48 | unwanted := $(filter-out $(all-files),$(oldheaders)) | |
8d730cfb | 49 | |
7712401a SR |
50 | # Prefix unwanted with full paths to $(INSTALL_HDR_PATH) |
51 | unwanted-file := $(addprefix $(install)/, $(unwanted)) | |
de789125 | 52 | |
7712401a | 53 | printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) |
68475359 | 54 | |
7712401a SR |
55 | quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ |
56 | file$(if $(word 2, $(all-files)),s)) | |
db1bec4f SR |
57 | cmd_install = \ |
58 | $(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \ | |
59 | $(PERL) $< $(objtree)/$(obj) $(install) $(SRCARCH) $(objhdr-y); \ | |
cb97914b | 60 | $(PERL) $< $(objtree)/$(gen) $(install) $(SRCARCH) $(genhdr-y); \ |
d8ecc5cd SR |
61 | for F in $(wrapper-files); do \ |
62 | echo "\#include <asm-generic/$$F>" > $(install)/$$F; \ | |
63 | done; \ | |
db1bec4f | 64 | touch $@ |
8d730cfb | 65 | |
7712401a SR |
66 | quiet_cmd_remove = REMOVE $(unwanted) |
67 | cmd_remove = rm -f $(unwanted-file) | |
8d730cfb | 68 | |
7712401a | 69 | quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) |
7211b8b9 SP |
70 | # Headers list can be pretty long, xargs helps to avoid |
71 | # the "Argument list too long" error. | |
72 | cmd_check = for f in $(all-files); do \ | |
73 | echo "$(install)/$${f}"; done \ | |
74 | | xargs \ | |
75 | $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ | |
7712401a | 76 | touch $@ |
de789125 | 77 | |
7712401a | 78 | PHONY += __headersinst __headerscheck |
de789125 | 79 | |
7712401a SR |
80 | ifndef HDRCHECK |
81 | # Rules for installing headers | |
82 | __headersinst: $(subdirs) $(install-file) | |
83 | @: | |
de789125 | 84 | |
7712401a SR |
85 | targets += $(install-file) |
86 | $(install-file): scripts/headers_install.pl $(input-files) FORCE | |
87 | $(if $(unwanted),$(call cmd,remove),) | |
88 | $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) | |
89 | $(call if_changed,install) | |
de789125 | 90 | |
68475359 | 91 | else |
7712401a SR |
92 | __headerscheck: $(subdirs) $(check-file) |
93 | @: | |
8d730cfb | 94 | |
7712401a SR |
95 | targets += $(check-file) |
96 | $(check-file): scripts/headers_check.pl $(output-files) FORCE | |
97 | $(call if_changed,check) | |
8d730cfb | 98 | |
7712401a | 99 | endif |
de789125 | 100 | |
7712401a SR |
101 | # Recursion |
102 | hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj | |
103 | .PHONY: $(subdirs) | |
104 | $(subdirs): | |
105 | $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@ | |
8d730cfb | 106 | |
7712401a SR |
107 | targets := $(wildcard $(sort $(targets))) |
108 | cmd_files := $(wildcard \ | |
109 | $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) | |
4e420aa9 | 110 | |
7712401a SR |
111 | ifneq ($(cmd_files),) |
112 | include $(cmd_files) | |
8d730cfb DW |
113 | endif |
114 | ||
7712401a SR |
115 | .PHONY: $(PHONY) |
116 | PHONY += FORCE | |
117 | FORCE: ; |