]>
Commit | Line | Data |
---|---|---|
8d730cfb DW |
1 | # ========================================================================== |
2 | # Installing headers | |
3 | # | |
fcc8487d | 4 | # All headers under include/uapi, include/generated/uapi, |
61562f98 | 5 | # arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are |
fcc8487d ND |
6 | # exported. |
7 | # They are preprocessed to remove __KERNEL__ section of the file. | |
8d730cfb DW |
8 | # |
9 | # ========================================================================== | |
10 | ||
05d8cba4 MY |
11 | PHONY := __headers |
12 | __headers: | |
13 | ||
14 | include scripts/Kbuild.include | |
15 | ||
16 | srcdir := $(srctree)/$(obj) | |
2f263d14 RG |
17 | |
18 | # When make is run under a fakechroot environment, the function | |
19 | # $(wildcard $(srcdir)/*/.) doesn't only return directories, but also regular | |
20 | # files. So, we are using a combination of sort/dir/wildcard which works | |
21 | # with fakechroot. | |
22 | subdirs := $(patsubst $(srcdir)/%/,%,\ | |
23 | $(filter-out $(srcdir)/,\ | |
24 | $(sort $(dir $(wildcard $(srcdir)/*/))))) | |
25 | ||
05d8cba4 MY |
26 | # caller may set destination dir (when installing to asm/) |
27 | _dst := $(if $(dst),$(dst),$(obj)) | |
28 | ||
29 | # Recursion | |
30 | __headers: $(subdirs) | |
31 | ||
32 | .PHONY: $(subdirs) | |
33 | $(subdirs): | |
34 | $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@ | |
35 | ||
36 | # Skip header install/check for include/uapi and arch/$(hdr-arch)/include/uapi. | |
37 | # We have only sub-directories there. | |
38 | skip-inst := $(if $(filter %/uapi,$(obj)),1) | |
39 | ||
40 | ifeq ($(skip-inst),) | |
41 | ||
fcc8487d | 42 | # Kbuild file is optional |
283039fb | 43 | kbuild-file := $(srctree)/$(obj)/Kbuild |
fcc8487d | 44 | -include $(kbuild-file) |
8d730cfb | 45 | |
10b63956 DH |
46 | old-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild |
47 | ifneq ($(wildcard $(old-kbuild-file)),) | |
48 | include $(old-kbuild-file) | |
49 | endif | |
c7bb349e | 50 | |
10b63956 | 51 | installdir := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst)) |
8d730cfb | 52 | |
87ebb94e | 53 | gendir := $(objtree)/$(subst include/,include/generated/,$(obj)) |
fcc8487d ND |
54 | header-files := $(notdir $(wildcard $(srcdir)/*.h)) |
55 | header-files += $(notdir $(wildcard $(srcdir)/*.agh)) | |
56 | header-files := $(filter-out $(no-export-headers), $(header-files)) | |
57 | genhdr-files := $(notdir $(wildcard $(gendir)/*.h)) | |
58 | genhdr-files := $(filter-out $(header-files), $(genhdr-files)) | |
de789125 | 59 | |
7712401a | 60 | # files used to track state of install/check |
10b63956 DH |
61 | install-file := $(installdir)/.install |
62 | check-file := $(installdir)/.check | |
de789125 | 63 | |
d8ecc5cd SR |
64 | # generic-y list all files an architecture uses from asm-generic |
65 | # Use this to build a list of headers which require a wrapper | |
fcc8487d ND |
66 | generic-files := $(notdir $(wildcard $(srctree)/include/uapi/asm-generic/*.h)) |
67 | wrapper-files := $(filter $(generic-files), $(generic-y)) | |
68 | wrapper-files := $(filter-out $(header-files), $(wrapper-files)) | |
10b63956 | 69 | |
7712401a | 70 | # all headers files for this dir |
fcc8487d | 71 | all-files := $(header-files) $(genhdr-files) $(wrapper-files) |
10b63956 DH |
72 | output-files := $(addprefix $(installdir)/, $(all-files)) |
73 | ||
fcc8487d ND |
74 | ifneq ($(mandatory-y),) |
75 | missing := $(filter-out $(all-files),$(mandatory-y)) | |
76 | ifneq ($(missing),) | |
77 | $(error Some mandatory headers ($(missing)) are missing in $(obj)) | |
78 | endif | |
79 | endif | |
de789125 | 80 | |
7712401a | 81 | # Work out what needs to be removed |
10b63956 | 82 | oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h)) |
7712401a | 83 | unwanted := $(filter-out $(all-files),$(oldheaders)) |
8d730cfb | 84 | |
7712401a | 85 | # Prefix unwanted with full paths to $(INSTALL_HDR_PATH) |
10b63956 | 86 | unwanted-file := $(addprefix $(installdir)/, $(unwanted)) |
de789125 | 87 | |
7712401a | 88 | printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) |
68475359 | 89 | |
7712401a SR |
90 | quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ |
91 | file$(if $(word 2, $(all-files)),s)) | |
db1bec4f | 92 | cmd_install = \ |
fcc8487d ND |
93 | $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \ |
94 | $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \ | |
d8ecc5cd | 95 | for F in $(wrapper-files); do \ |
10b63956 | 96 | echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \ |
d8ecc5cd | 97 | done; \ |
db1bec4f | 98 | touch $@ |
8d730cfb | 99 | |
7712401a SR |
100 | quiet_cmd_remove = REMOVE $(unwanted) |
101 | cmd_remove = rm -f $(unwanted-file) | |
8d730cfb | 102 | |
7712401a | 103 | quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) |
7211b8b9 SP |
104 | # Headers list can be pretty long, xargs helps to avoid |
105 | # the "Argument list too long" error. | |
106 | cmd_check = for f in $(all-files); do \ | |
10b63956 | 107 | echo "$(installdir)/$${f}"; done \ |
7211b8b9 SP |
108 | | xargs \ |
109 | $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ | |
7712401a | 110 | touch $@ |
de789125 | 111 | |
7712401a SR |
112 | ifndef HDRCHECK |
113 | # Rules for installing headers | |
05d8cba4 | 114 | __headers: $(install-file) |
7712401a | 115 | @: |
de789125 | 116 | |
7712401a | 117 | targets += $(install-file) |
7c025b2a | 118 | $(install-file): scripts/headers_install.sh \ |
fcc8487d ND |
119 | $(addprefix $(srcdir)/,$(header-files)) \ |
120 | $(addprefix $(gendir)/,$(genhdr-files)) FORCE | |
7712401a SR |
121 | $(if $(unwanted),$(call cmd,remove),) |
122 | $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) | |
123 | $(call if_changed,install) | |
de789125 | 124 | |
68475359 | 125 | else |
05d8cba4 | 126 | __headers: $(check-file) |
7712401a | 127 | @: |
8d730cfb | 128 | |
7712401a SR |
129 | targets += $(check-file) |
130 | $(check-file): scripts/headers_check.pl $(output-files) FORCE | |
131 | $(call if_changed,check) | |
8d730cfb | 132 | |
7712401a | 133 | endif |
de789125 | 134 | |
7712401a SR |
135 | targets := $(wildcard $(sort $(targets))) |
136 | cmd_files := $(wildcard \ | |
137 | $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) | |
4e420aa9 | 138 | |
7712401a SR |
139 | ifneq ($(cmd_files),) |
140 | include $(cmd_files) | |
8d730cfb DW |
141 | endif |
142 | ||
05d8cba4 MY |
143 | endif # skip-inst |
144 | ||
7712401a SR |
145 | .PHONY: $(PHONY) |
146 | PHONY += FORCE | |
147 | FORCE: ; |