blob: 612dc13ddd85fcda58d327ea688746f887ad02db [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))
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020046 cmd_install = \
47 $(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \
48 $(PERL) $< $(objtree)/$(obj) $(install) $(SRCARCH) $(objhdr-y); \
49 touch $@
David Woodhouse8d730cf2006-06-18 11:58:39 +010050
Sam Ravnborg77124012008-06-15 21:41:09 +020051quiet_cmd_remove = REMOVE $(unwanted)
52 cmd_remove = rm -f $(unwanted-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010053
Sam Ravnborg77124012008-06-15 21:41:09 +020054quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
55 cmd_check = $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH) \
56 $(addprefix $(install)/, $(all-files)); \
57 touch $@
David Woodhouse68475352006-06-18 12:02:10 +010058
Sam Ravnborg77124012008-06-15 21:41:09 +020059PHONY += __headersinst __headerscheck
David Woodhouse8d730cf2006-06-18 11:58:39 +010060
Sam Ravnborg77124012008-06-15 21:41:09 +020061ifndef HDRCHECK
62# Rules for installing headers
63__headersinst: $(subdirs) $(install-file)
64 @:
David Woodhousede789122006-09-24 22:15:14 +010065
Sam Ravnborg77124012008-06-15 21:41:09 +020066targets += $(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)
David Woodhousede789122006-09-24 22:15:14 +010071
David Woodhouse68475352006-06-18 12:02:10 +010072else
Sam Ravnborg77124012008-06-15 21:41:09 +020073__headerscheck: $(subdirs) $(check-file)
74 @:
David Woodhouse8d730cf2006-06-18 11:58:39 +010075
Sam Ravnborg77124012008-06-15 21:41:09 +020076targets += $(check-file)
77$(check-file): scripts/headers_check.pl $(output-files) FORCE
78 $(call if_changed,check)
Sam Ravnborg4e420aa2008-06-05 16:52:15 +020079
David Woodhouse8d730cf2006-06-18 11:58:39 +010080endif
David Woodhouse8d730cf2006-06-18 11:58:39 +010081
David Woodhouse8d730cf2006-06-18 11:58:39 +010082# Recursion
Sam Ravnborg77124012008-06-15 21:41:09 +020083hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
84.PHONY: $(subdirs)
85$(subdirs):
Sam Ravnborg62284a32008-06-07 13:18:26 +020086 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
Sam Ravnborg77124012008-06-15 21:41:09 +020087
88targets := $(wildcard $(sort $(targets)))
89cmd_files := $(wildcard \
90 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
91
92ifneq ($(cmd_files),)
93 include $(cmd_files)
94endif
95
96.PHONY: $(PHONY)
97PHONY += FORCE
98FORCE: ;