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