1 # ==========================================================================
4 # All headers under include/uapi, include/generated/uapi,
5 # arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are
7 # They are preprocessed to remove __KERNEL__ section of the file.
9 # ==========================================================================
14 include scripts/Kbuild.include
16 srcdir := $(srctree)/$(obj)
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
22 subdirs := $(patsubst $(srcdir)/%/,%,\
23 $(filter-out $(srcdir)/,\
24 $(sort $(dir $(wildcard $(srcdir)/*/)))))
26 # caller may set destination dir (when installing to asm/)
27 _dst := $(if $(dst),$(dst),$(obj))
34 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
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)
42 # generated header directory
43 gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj)))
45 # Kbuild file is optional
46 kbuild-file := $(srctree)/$(obj)/Kbuild
47 -include $(kbuild-file)
49 old-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild
50 ifneq ($(wildcard $(old-kbuild-file)),)
51 include $(old-kbuild-file)
54 installdir := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst))
56 gendir := $(objtree)/$(gen)
57 header-files := $(notdir $(wildcard $(srcdir)/*.h))
58 header-files += $(notdir $(wildcard $(srcdir)/*.agh))
59 header-files := $(filter-out $(no-export-headers), $(header-files))
60 genhdr-files := $(notdir $(wildcard $(gendir)/*.h))
61 genhdr-files := $(filter-out $(header-files), $(genhdr-files))
63 # files used to track state of install/check
64 install-file := $(installdir)/.install
65 check-file := $(installdir)/.check
67 # generic-y list all files an architecture uses from asm-generic
68 # Use this to build a list of headers which require a wrapper
69 generic-files := $(notdir $(wildcard $(srctree)/include/uapi/asm-generic/*.h))
70 wrapper-files := $(filter $(generic-files), $(generic-y))
71 wrapper-files := $(filter-out $(header-files), $(wrapper-files))
73 # all headers files for this dir
74 all-files := $(header-files) $(genhdr-files) $(wrapper-files)
75 output-files := $(addprefix $(installdir)/, $(all-files))
77 ifneq ($(mandatory-y),)
78 missing := $(filter-out $(all-files),$(mandatory-y))
80 $(error Some mandatory headers ($(missing)) are missing in $(obj))
84 # Work out what needs to be removed
85 oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
86 unwanted := $(filter-out $(all-files),$(oldheaders))
88 # Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
89 unwanted-file := $(addprefix $(installdir)/, $(unwanted))
91 printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
93 quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
94 file$(if $(word 2, $(all-files)),s))
96 $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \
97 $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \
98 for F in $(wrapper-files); do \
99 echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \
103 quiet_cmd_remove = REMOVE $(unwanted)
104 cmd_remove = rm -f $(unwanted-file)
106 quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
107 # Headers list can be pretty long, xargs helps to avoid
108 # the "Argument list too long" error.
109 cmd_check = for f in $(all-files); do \
110 echo "$(installdir)/$${f}"; done \
112 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
116 # Rules for installing headers
117 __headers: $(install-file)
120 targets += $(install-file)
121 $(install-file): scripts/headers_install.sh \
122 $(addprefix $(srcdir)/,$(header-files)) \
123 $(addprefix $(gendir)/,$(genhdr-files)) FORCE
124 $(if $(unwanted),$(call cmd,remove),)
125 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
126 $(call if_changed,install)
129 __headers: $(check-file)
132 targets += $(check-file)
133 $(check-file): scripts/headers_check.pl $(output-files) FORCE
134 $(call if_changed,check)
138 targets := $(wildcard $(sort $(targets)))
139 cmd_files := $(wildcard \
140 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
142 ifneq ($(cmd_files),)