blob: f89cb87f5c018f24b56e13201530df261379c230 [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
Sam Ravnborg77124012008-06-15 21:41:09 +02006# objhdr-y - Same as header-y but for generated files
David Woodhouse8d730cf2006-06-18 11:58:39 +01007#
8# ==========================================================================
9
Sam Ravnborg77124012008-06-15 21:41:09 +020010# called may set destination dir (when installing to asm/)
David Woodhouse8d730cf2006-06-18 11:58:39 +010011_dst := $(if $(dst),$(dst),$(obj))
12
Sam Ravnborg283039f2008-06-05 19:19:47 +020013kbuild-file := $(srctree)/$(obj)/Kbuild
14include $(kbuild-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010015
Sam Ravnborgc7bb3492009-04-10 08:52:43 +020016_dst := $(if $(destination-y),$(destination-y),$(_dst))
17
Sam Ravnborg283039f2008-06-05 19:19:47 +020018include scripts/Kbuild.include
David Woodhousede789122006-09-24 22:15:14 +010019
Sam Ravnborg77124012008-06-15 21:41:09 +020020install := $(INSTALL_HDR_PATH)/$(_dst)
Sam Ravnborg62284a32008-06-07 13:18:26 +020021
Sam Ravnborg7cfddee2010-08-14 10:22:58 +020022header-y := $(sort $(header-y))
Sam Ravnborg77124012008-06-15 21:41:09 +020023subdirs := $(patsubst %/,%,$(filter %/, $(header-y)))
24header-y := $(filter-out %/, $(header-y))
David Woodhouse8d730cf2006-06-18 11:58:39 +010025
Sam Ravnborg77124012008-06-15 21:41:09 +020026# files used to track state of install/check
27install-file := $(install)/.install
28check-file := $(install)/.check
29
30# all headers files for this dir
31all-files := $(header-y) $(objhdr-y)
32input-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \
33 $(addprefix $(objtree)/$(obj)/,$(objhdr-y))
34output-files := $(addprefix $(install)/, $(all-files))
David Woodhousede789122006-09-24 22:15:14 +010035
36# Work out what needs to be removed
Sam Ravnborg77124012008-06-15 21:41:09 +020037oldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h))
38unwanted := $(filter-out $(all-files),$(oldheaders))
David Woodhousede789122006-09-24 22:15:14 +010039
Sam Ravnborg77124012008-06-15 21:41:09 +020040# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
41unwanted-file := $(addprefix $(install)/, $(unwanted))
David Woodhousede789122006-09-24 22:15:14 +010042
Sam Ravnborg77124012008-06-15 21:41:09 +020043printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
David Woodhousede789122006-09-24 22:15:14 +010044
Sam Ravnborg77124012008-06-15 21:41:09 +020045quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
46 file$(if $(word 2, $(all-files)),s))
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020047 cmd_install = \
48 $(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \
49 $(PERL) $< $(objtree)/$(obj) $(install) $(SRCARCH) $(objhdr-y); \
50 touch $@
David Woodhouse8d730cf2006-06-18 11:58:39 +010051
Sam Ravnborg77124012008-06-15 21:41:09 +020052quiet_cmd_remove = REMOVE $(unwanted)
53 cmd_remove = rm -f $(unwanted-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010054
Sam Ravnborg77124012008-06-15 21:41:09 +020055quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
Sergei Poselenov7211b8b2009-06-05 16:11:09 +040056# Headers list can be pretty long, xargs helps to avoid
57# the "Argument list too long" error.
58 cmd_check = for f in $(all-files); do \
59 echo "$(install)/$${f}"; done \
60 | xargs \
61 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
Sam Ravnborg77124012008-06-15 21:41:09 +020062 touch $@
David Woodhouse68475352006-06-18 12:02:10 +010063
Sam Ravnborg77124012008-06-15 21:41:09 +020064PHONY += __headersinst __headerscheck
David Woodhouse8d730cf2006-06-18 11:58:39 +010065
Sam Ravnborg77124012008-06-15 21:41:09 +020066ifndef HDRCHECK
67# Rules for installing headers
68__headersinst: $(subdirs) $(install-file)
69 @:
David Woodhousede789122006-09-24 22:15:14 +010070
Sam Ravnborg77124012008-06-15 21:41:09 +020071targets += $(install-file)
72$(install-file): scripts/headers_install.pl $(input-files) FORCE
73 $(if $(unwanted),$(call cmd,remove),)
74 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
75 $(call if_changed,install)
David Woodhousede789122006-09-24 22:15:14 +010076
David Woodhouse68475352006-06-18 12:02:10 +010077else
Sam Ravnborg77124012008-06-15 21:41:09 +020078__headerscheck: $(subdirs) $(check-file)
79 @:
David Woodhouse8d730cf2006-06-18 11:58:39 +010080
Sam Ravnborg77124012008-06-15 21:41:09 +020081targets += $(check-file)
82$(check-file): scripts/headers_check.pl $(output-files) FORCE
83 $(call if_changed,check)
Sam Ravnborg4e420aa2008-06-05 16:52:15 +020084
David Woodhouse8d730cf2006-06-18 11:58:39 +010085endif
David Woodhouse8d730cf2006-06-18 11:58:39 +010086
David Woodhouse8d730cf2006-06-18 11:58:39 +010087# Recursion
Sam Ravnborg77124012008-06-15 21:41:09 +020088hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
89.PHONY: $(subdirs)
90$(subdirs):
Sam Ravnborg62284a32008-06-07 13:18:26 +020091 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
Sam Ravnborg77124012008-06-15 21:41:09 +020092
93targets := $(wildcard $(sort $(targets)))
94cmd_files := $(wildcard \
95 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
96
97ifneq ($(cmd_files),)
98 include $(cmd_files)
99endif
100
101.PHONY: $(PHONY)
102PHONY += FORCE
103FORCE: ;