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 # ==========================================================================
11 # generated header directory
12 gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj)))
14 # Kbuild file is optional
15 kbuild-file := $(srctree)/$(obj)/Kbuild
16 -include $(kbuild-file)
18 # called may set destination dir (when installing to asm/)
19 _dst := $(if $(dst),$(dst),$(obj))
21 old-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild
22 ifneq ($(wildcard $(old-kbuild-file)),)
23 include $(old-kbuild-file)
26 include scripts/Kbuild.include
28 installdir := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst))
30 srcdir := $(srctree)/$(obj)
31 gendir := $(objtree)/$(gen)
32 subdirs := $(patsubst $(srcdir)/%/.,%,$(wildcard $(srcdir)/*/.))
33 header-files := $(notdir $(wildcard $(srcdir)/*.h))
34 header-files += $(notdir $(wildcard $(srcdir)/*.agh))
35 header-files := $(filter-out $(no-export-headers), $(header-files))
36 genhdr-files := $(notdir $(wildcard $(gendir)/*.h))
37 genhdr-files := $(filter-out $(header-files), $(genhdr-files))
39 # files used to track state of install/check
40 install-file := $(installdir)/.install
41 check-file := $(installdir)/.check
43 # generic-y list all files an architecture uses from asm-generic
44 # Use this to build a list of headers which require a wrapper
45 generic-files := $(notdir $(wildcard $(srctree)/include/uapi/asm-generic/*.h))
46 wrapper-files := $(filter $(generic-files), $(generic-y))
47 wrapper-files := $(filter-out $(header-files), $(wrapper-files))
49 # all headers files for this dir
50 all-files := $(header-files) $(genhdr-files) $(wrapper-files)
51 output-files := $(addprefix $(installdir)/, $(all-files))
53 ifneq ($(mandatory-y),)
54 missing := $(filter-out $(all-files),$(mandatory-y))
56 $(error Some mandatory headers ($(missing)) are missing in $(obj))
60 # Work out what needs to be removed
61 oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
62 unwanted := $(filter-out $(all-files),$(oldheaders))
64 # Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
65 unwanted-file := $(addprefix $(installdir)/, $(unwanted))
67 printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
69 quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
70 file$(if $(word 2, $(all-files)),s))
72 $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \
73 $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \
74 for F in $(wrapper-files); do \
75 echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \
79 quiet_cmd_remove = REMOVE $(unwanted)
80 cmd_remove = rm -f $(unwanted-file)
82 quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
83 # Headers list can be pretty long, xargs helps to avoid
84 # the "Argument list too long" error.
85 cmd_check = for f in $(all-files); do \
86 echo "$(installdir)/$${f}"; done \
88 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
91 PHONY += __headersinst __headerscheck
94 # Rules for installing headers
95 __headersinst: $(subdirs) $(install-file)
98 targets += $(install-file)
99 $(install-file): scripts/headers_install.sh \
100 $(addprefix $(srcdir)/,$(header-files)) \
101 $(addprefix $(gendir)/,$(genhdr-files)) FORCE
102 $(if $(unwanted),$(call cmd,remove),)
103 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
104 $(call if_changed,install)
107 __headerscheck: $(subdirs) $(check-file)
110 targets += $(check-file)
111 $(check-file): scripts/headers_check.pl $(output-files) FORCE
112 $(call if_changed,check)
119 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
121 targets := $(wildcard $(sort $(targets)))
122 cmd_files := $(wildcard \
123 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
125 ifneq ($(cmd_files),)