blob: 095cfc8b9dbfbddff4cbbbc3437019e8b2996255 [file] [log] [blame]
David Woodhouse8d730cf2006-06-18 11:58:39 +01001# ==========================================================================
2# Installing headers
3#
Sam Ravnborg77124012008-06-15 21:41:09 +02004# 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
David Woodhouse8d730cf2006-06-18 11:58:39 +01008#
9# ==========================================================================
10
Sam Ravnborg77124012008-06-15 21:41:09 +020011# called may set destination dir (when installing to asm/)
David Woodhouse8d730cf2006-06-18 11:58:39 +010012_dst := $(if $(dst),$(dst),$(obj))
13
Sam Ravnborg283039f2008-06-05 19:19:47 +020014kbuild-file := $(srctree)/$(obj)/Kbuild
15include $(kbuild-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010016
Sam Ravnborgc7bb3492009-04-10 08:52:43 +020017_dst := $(if $(destination-y),$(destination-y),$(_dst))
18
Sam Ravnborg283039f2008-06-05 19:19:47 +020019include scripts/Kbuild.include
David Woodhousede789122006-09-24 22:15:14 +010020
Sam Ravnborg77124012008-06-15 21:41:09 +020021install := $(INSTALL_HDR_PATH)/$(_dst)
Sam Ravnborg62284a32008-06-07 13:18:26 +020022
Sam Ravnborg77124012008-06-15 21:41:09 +020023header-y := $(sort $(header-y) $(unifdef-y))
24subdirs := $(patsubst %/,%,$(filter %/, $(header-y)))
25header-y := $(filter-out %/, $(header-y))
David Woodhouse8d730cf2006-06-18 11:58:39 +010026
Sam Ravnborg77124012008-06-15 21:41:09 +020027# files used to track state of install/check
28install-file := $(install)/.install
29check-file := $(install)/.check
30
31# all headers files for this dir
32all-files := $(header-y) $(objhdr-y)
33input-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \
34 $(addprefix $(objtree)/$(obj)/,$(objhdr-y))
35output-files := $(addprefix $(install)/, $(all-files))
David Woodhousede789122006-09-24 22:15:14 +010036
37# Work out what needs to be removed
Sam Ravnborg77124012008-06-15 21:41:09 +020038oldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h))
39unwanted := $(filter-out $(all-files),$(oldheaders))
David Woodhousede789122006-09-24 22:15:14 +010040
Sam Ravnborg77124012008-06-15 21:41:09 +020041# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
42unwanted-file := $(addprefix $(install)/, $(unwanted))
David Woodhousede789122006-09-24 22:15:14 +010043
Sam Ravnborg77124012008-06-15 21:41:09 +020044printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
David Woodhousede789122006-09-24 22:15:14 +010045
Sam Ravnborg77124012008-06-15 21:41:09 +020046quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
47 file$(if $(word 2, $(all-files)),s))
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020048 cmd_install = \
49 $(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \
50 $(PERL) $< $(objtree)/$(obj) $(install) $(SRCARCH) $(objhdr-y); \
51 touch $@
David Woodhouse8d730cf2006-06-18 11:58:39 +010052
Sam Ravnborg77124012008-06-15 21:41:09 +020053quiet_cmd_remove = REMOVE $(unwanted)
54 cmd_remove = rm -f $(unwanted-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010055
Sam Ravnborg77124012008-06-15 21:41:09 +020056quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
57 cmd_check = $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH) \
58 $(addprefix $(install)/, $(all-files)); \
59 touch $@
David Woodhouse68475352006-06-18 12:02:10 +010060
Sam Ravnborg77124012008-06-15 21:41:09 +020061PHONY += __headersinst __headerscheck
David Woodhouse8d730cf2006-06-18 11:58:39 +010062
Sam Ravnborg77124012008-06-15 21:41:09 +020063ifndef HDRCHECK
64# Rules for installing headers
65__headersinst: $(subdirs) $(install-file)
66 @:
David Woodhousede789122006-09-24 22:15:14 +010067
Sam Ravnborg77124012008-06-15 21:41:09 +020068targets += $(install-file)
69$(install-file): scripts/headers_install.pl $(input-files) FORCE
70 $(if $(unwanted),$(call cmd,remove),)
71 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
72 $(call if_changed,install)
David Woodhousede789122006-09-24 22:15:14 +010073
David Woodhouse68475352006-06-18 12:02:10 +010074else
Sam Ravnborg77124012008-06-15 21:41:09 +020075__headerscheck: $(subdirs) $(check-file)
76 @:
David Woodhouse8d730cf2006-06-18 11:58:39 +010077
Sam Ravnborg77124012008-06-15 21:41:09 +020078targets += $(check-file)
79$(check-file): scripts/headers_check.pl $(output-files) FORCE
80 $(call if_changed,check)
Sam Ravnborg4e420aa2008-06-05 16:52:15 +020081
David Woodhouse8d730cf2006-06-18 11:58:39 +010082endif
David Woodhouse8d730cf2006-06-18 11:58:39 +010083
David Woodhouse8d730cf2006-06-18 11:58:39 +010084# Recursion
Sam Ravnborg77124012008-06-15 21:41:09 +020085hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
86.PHONY: $(subdirs)
87$(subdirs):
Sam Ravnborg62284a32008-06-07 13:18:26 +020088 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
Sam Ravnborg77124012008-06-15 21:41:09 +020089
90targets := $(wildcard $(sort $(targets)))
91cmd_files := $(wildcard \
92 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
93
94ifneq ($(cmd_files),)
95 include $(cmd_files)
96endif
97
98.PHONY: $(PHONY)
99PHONY += FORCE
100FORCE: ;