blob: 0fcd838387719d4638e960d77108b761af86eb9d [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)
Sergei Poselenov7211b8b2009-06-05 16:11:09 +040057# Headers list can be pretty long, xargs helps to avoid
58# the "Argument list too long" error.
59 cmd_check = for f in $(all-files); do \
60 echo "$(install)/$${f}"; done \
61 | xargs \
62 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
Sam Ravnborg77124012008-06-15 21:41:09 +020063 touch $@
David Woodhouse68475352006-06-18 12:02:10 +010064
Sam Ravnborg77124012008-06-15 21:41:09 +020065PHONY += __headersinst __headerscheck
David Woodhouse8d730cf2006-06-18 11:58:39 +010066
Sam Ravnborg77124012008-06-15 21:41:09 +020067ifndef HDRCHECK
68# Rules for installing headers
69__headersinst: $(subdirs) $(install-file)
70 @:
David Woodhousede789122006-09-24 22:15:14 +010071
Sam Ravnborg77124012008-06-15 21:41:09 +020072targets += $(install-file)
73$(install-file): scripts/headers_install.pl $(input-files) FORCE
74 $(if $(unwanted),$(call cmd,remove),)
75 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
76 $(call if_changed,install)
David Woodhousede789122006-09-24 22:15:14 +010077
David Woodhouse68475352006-06-18 12:02:10 +010078else
Sam Ravnborg77124012008-06-15 21:41:09 +020079__headerscheck: $(subdirs) $(check-file)
80 @:
David Woodhouse8d730cf2006-06-18 11:58:39 +010081
Sam Ravnborg77124012008-06-15 21:41:09 +020082targets += $(check-file)
83$(check-file): scripts/headers_check.pl $(output-files) FORCE
84 $(call if_changed,check)
Sam Ravnborg4e420aa2008-06-05 16:52:15 +020085
David Woodhouse8d730cf2006-06-18 11:58:39 +010086endif
David Woodhouse8d730cf2006-06-18 11:58:39 +010087
David Woodhouse8d730cf2006-06-18 11:58:39 +010088# Recursion
Sam Ravnborg77124012008-06-15 21:41:09 +020089hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
90.PHONY: $(subdirs)
91$(subdirs):
Sam Ravnborg62284a32008-06-07 13:18:26 +020092 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
Sam Ravnborg77124012008-06-15 21:41:09 +020093
94targets := $(wildcard $(sort $(targets)))
95cmd_files := $(wildcard \
96 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
97
98ifneq ($(cmd_files),)
99 include $(cmd_files)
100endif
101
102.PHONY: $(PHONY)
103PHONY += FORCE
104FORCE: ;