1 # ==========================================================================
4 # header-y - list files to be installed. They are preprocessed
5 # to remove __KERNEL__ section of the file
6 # unifdef-y - Same as header-y. Obsolete
7 # objhdr-y - Same as header-y but for generated files
9 # ==========================================================================
11 # called may set destination dir (when installing to asm/)
12 _dst := $(if $(dst),$(dst),$(obj))
14 kbuild-file := $(srctree)/$(obj)/Kbuild
15 include $(kbuild-file)
17 include scripts/Kbuild.include
19 install := $(INSTALL_HDR_PATH)/$(_dst)
21 header-y := $(sort $(header-y) $(unifdef-y))
22 subdirs := $(patsubst %/,%,$(filter %/, $(header-y)))
23 header-y := $(filter-out %/, $(header-y))
25 # files used to track state of install/check
26 install-file := $(install)/.install
27 check-file := $(install)/.check
29 # all headers files for this dir
30 all-files := $(header-y) $(objhdr-y)
31 input-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \
32 $(addprefix $(objtree)/$(obj)/,$(objhdr-y))
33 output-files := $(addprefix $(install)/, $(all-files))
35 # Work out what needs to be removed
36 oldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h))
37 unwanted := $(filter-out $(all-files),$(oldheaders))
39 # Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
40 unwanted-file := $(addprefix $(install)/, $(unwanted))
42 printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
44 quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
45 file$(if $(word 2, $(all-files)),s))
47 $(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \
48 $(PERL) $< $(objtree)/$(obj) $(install) $(SRCARCH) $(objhdr-y); \
51 quiet_cmd_remove = REMOVE $(unwanted)
52 cmd_remove = rm -f $(unwanted-file)
54 quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
55 cmd_check = $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH) \
56 $(addprefix $(install)/, $(all-files)); \
59 PHONY += __headersinst __headerscheck
62 # Rules for installing headers
63 __headersinst: $(subdirs) $(install-file)
66 targets += $(install-file)
67 $(install-file): scripts/headers_install.pl $(input-files) FORCE
68 $(if $(unwanted),$(call cmd,remove),)
69 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
70 $(call if_changed,install)
73 __headerscheck: $(subdirs) $(check-file)
76 targets += $(check-file)
77 $(check-file): scripts/headers_check.pl $(output-files) FORCE
78 $(call if_changed,check)
83 hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
86 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
88 targets := $(wildcard $(sort $(targets)))
89 cmd_files := $(wildcard \
90 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))