blob: be2b70c48a3bc068dd5a97c6bfede82749a47a3d [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 Ravnborg283039f2008-06-05 19:19:47 +020017include scripts/Kbuild.include
David Woodhousede789122006-09-24 22:15:14 +010018
Sam Ravnborg77124012008-06-15 21:41:09 +020019install := $(INSTALL_HDR_PATH)/$(_dst)
Sam Ravnborg62284a32008-06-07 13:18:26 +020020
Sam Ravnborg77124012008-06-15 21:41:09 +020021header-y := $(sort $(header-y) $(unifdef-y))
22subdirs := $(patsubst %/,%,$(filter %/, $(header-y)))
23header-y := $(filter-out %/, $(header-y))
David Woodhouse8d730cf2006-06-18 11:58:39 +010024
Sam Ravnborg77124012008-06-15 21:41:09 +020025# files used to track state of install/check
26install-file := $(install)/.install
27check-file := $(install)/.check
28
29# all headers files for this dir
30all-files := $(header-y) $(objhdr-y)
31input-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \
32 $(addprefix $(objtree)/$(obj)/,$(objhdr-y))
33output-files := $(addprefix $(install)/, $(all-files))
David Woodhousede789122006-09-24 22:15:14 +010034
35# Work out what needs to be removed
Sam Ravnborg77124012008-06-15 21:41:09 +020036oldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h))
37unwanted := $(filter-out $(all-files),$(oldheaders))
David Woodhousede789122006-09-24 22:15:14 +010038
Sam Ravnborg77124012008-06-15 21:41:09 +020039# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
40unwanted-file := $(addprefix $(install)/, $(unwanted))
David Woodhousede789122006-09-24 22:15:14 +010041
Sam Ravnborg77124012008-06-15 21:41:09 +020042printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
David Woodhousede789122006-09-24 22:15:14 +010043
Sam Ravnborg77124012008-06-15 21:41:09 +020044quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
45 file$(if $(word 2, $(all-files)),s))
46 cmd_install = $(PERL) $< $(srctree)/$(obj) $(install) $(header-y); \
47 $(PERL) $< $(objtree)/$(obj) $(install) $(objhdr-y); \
48 touch $@
David Woodhouse8d730cf2006-06-18 11:58:39 +010049
Sam Ravnborg77124012008-06-15 21:41:09 +020050quiet_cmd_remove = REMOVE $(unwanted)
51 cmd_remove = rm -f $(unwanted-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010052
Sam Ravnborg77124012008-06-15 21:41:09 +020053quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
54 cmd_check = $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH) \
55 $(addprefix $(install)/, $(all-files)); \
56 touch $@
David Woodhouse68475352006-06-18 12:02:10 +010057
Sam Ravnborg77124012008-06-15 21:41:09 +020058PHONY += __headersinst __headerscheck
David Woodhouse8d730cf2006-06-18 11:58:39 +010059
Sam Ravnborg77124012008-06-15 21:41:09 +020060ifndef HDRCHECK
61# Rules for installing headers
62__headersinst: $(subdirs) $(install-file)
63 @:
David Woodhousede789122006-09-24 22:15:14 +010064
Sam Ravnborg77124012008-06-15 21:41:09 +020065targets += $(install-file)
66$(install-file): scripts/headers_install.pl $(input-files) FORCE
67 $(if $(unwanted),$(call cmd,remove),)
68 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
69 $(call if_changed,install)
David Woodhousede789122006-09-24 22:15:14 +010070
David Woodhouse68475352006-06-18 12:02:10 +010071else
Sam Ravnborg77124012008-06-15 21:41:09 +020072__headerscheck: $(subdirs) $(check-file)
73 @:
David Woodhouse8d730cf2006-06-18 11:58:39 +010074
Sam Ravnborg77124012008-06-15 21:41:09 +020075targets += $(check-file)
76$(check-file): scripts/headers_check.pl $(output-files) FORCE
77 $(call if_changed,check)
Sam Ravnborg4e420aa2008-06-05 16:52:15 +020078
David Woodhouse8d730cf2006-06-18 11:58:39 +010079endif
David Woodhouse8d730cf2006-06-18 11:58:39 +010080
David Woodhouse8d730cf2006-06-18 11:58:39 +010081# Recursion
Sam Ravnborg77124012008-06-15 21:41:09 +020082hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
83.PHONY: $(subdirs)
84$(subdirs):
Sam Ravnborg62284a32008-06-07 13:18:26 +020085 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
Sam Ravnborg77124012008-06-15 21:41:09 +020086
87targets := $(wildcard $(sort $(targets)))
88cmd_files := $(wildcard \
89 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
90
91ifneq ($(cmd_files),)
92 include $(cmd_files)
93endif
94
95.PHONY: $(PHONY)
96PHONY += FORCE
97FORCE: ;