blob: a57f5bd5a13d5b8f14a90b03bf23115e925b4a0a [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
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020030# generic-y list all files an architecture uses from asm-generic
31# Use this to build a list of headers which require a wrapper
32wrapper-files := $(filter $(header-y), $(generic-y))
33
Sam Ravnborg77124012008-06-15 21:41:09 +020034# all headers files for this dir
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020035header-y := $(filter-out $(generic-y), $(header-y))
36all-files := $(header-y) $(objhdr-y) $(wrapper-files)
Sam Ravnborg77124012008-06-15 21:41:09 +020037input-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \
38 $(addprefix $(objtree)/$(obj)/,$(objhdr-y))
39output-files := $(addprefix $(install)/, $(all-files))
David Woodhousede789122006-09-24 22:15:14 +010040
41# Work out what needs to be removed
Sam Ravnborg77124012008-06-15 21:41:09 +020042oldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h))
43unwanted := $(filter-out $(all-files),$(oldheaders))
David Woodhousede789122006-09-24 22:15:14 +010044
Sam Ravnborg77124012008-06-15 21:41:09 +020045# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
46unwanted-file := $(addprefix $(install)/, $(unwanted))
David Woodhousede789122006-09-24 22:15:14 +010047
Sam Ravnborg77124012008-06-15 21:41:09 +020048printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
David Woodhousede789122006-09-24 22:15:14 +010049
Sam Ravnborg77124012008-06-15 21:41:09 +020050quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
51 file$(if $(word 2, $(all-files)),s))
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020052 cmd_install = \
53 $(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \
54 $(PERL) $< $(objtree)/$(obj) $(install) $(SRCARCH) $(objhdr-y); \
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020055 for F in $(wrapper-files); do \
56 echo "\#include <asm-generic/$$F>" > $(install)/$$F; \
57 done; \
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020058 touch $@
David Woodhouse8d730cf2006-06-18 11:58:39 +010059
Sam Ravnborg77124012008-06-15 21:41:09 +020060quiet_cmd_remove = REMOVE $(unwanted)
61 cmd_remove = rm -f $(unwanted-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010062
Sam Ravnborg77124012008-06-15 21:41:09 +020063quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
Sergei Poselenov7211b8b2009-06-05 16:11:09 +040064# Headers list can be pretty long, xargs helps to avoid
65# the "Argument list too long" error.
66 cmd_check = for f in $(all-files); do \
67 echo "$(install)/$${f}"; done \
68 | xargs \
69 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
Sam Ravnborg77124012008-06-15 21:41:09 +020070 touch $@
David Woodhouse68475352006-06-18 12:02:10 +010071
Sam Ravnborg77124012008-06-15 21:41:09 +020072PHONY += __headersinst __headerscheck
David Woodhouse8d730cf2006-06-18 11:58:39 +010073
Sam Ravnborg77124012008-06-15 21:41:09 +020074ifndef HDRCHECK
75# Rules for installing headers
76__headersinst: $(subdirs) $(install-file)
77 @:
David Woodhousede789122006-09-24 22:15:14 +010078
Sam Ravnborg77124012008-06-15 21:41:09 +020079targets += $(install-file)
80$(install-file): scripts/headers_install.pl $(input-files) FORCE
81 $(if $(unwanted),$(call cmd,remove),)
82 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
83 $(call if_changed,install)
David Woodhousede789122006-09-24 22:15:14 +010084
David Woodhouse68475352006-06-18 12:02:10 +010085else
Sam Ravnborg77124012008-06-15 21:41:09 +020086__headerscheck: $(subdirs) $(check-file)
87 @:
David Woodhouse8d730cf2006-06-18 11:58:39 +010088
Sam Ravnborg77124012008-06-15 21:41:09 +020089targets += $(check-file)
90$(check-file): scripts/headers_check.pl $(output-files) FORCE
91 $(call if_changed,check)
Sam Ravnborg4e420aa2008-06-05 16:52:15 +020092
David Woodhouse8d730cf2006-06-18 11:58:39 +010093endif
David Woodhouse8d730cf2006-06-18 11:58:39 +010094
David Woodhouse8d730cf2006-06-18 11:58:39 +010095# Recursion
Sam Ravnborg77124012008-06-15 21:41:09 +020096hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
97.PHONY: $(subdirs)
98$(subdirs):
Sam Ravnborg62284a32008-06-07 13:18:26 +020099 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
Sam Ravnborg77124012008-06-15 21:41:09 +0200100
101targets := $(wildcard $(sort $(targets)))
102cmd_files := $(wildcard \
103 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
104
105ifneq ($(cmd_files),)
106 include $(cmd_files)
107endif
108
109.PHONY: $(PHONY)
110PHONY += FORCE
111FORCE: ;