blob: 463b95acc15bbd1ffec991913e67908dfc3f7e4a [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
David Howells40f1d4c2012-10-02 18:01:56 +01006# genhdr-y - Same as header-y but in a generated/ directory
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
H. Peter Anvincb979142011-11-11 15:20:34 -080013# generated header directory
14gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj)))
15
Sam Ravnborg283039f2008-06-05 19:19:47 +020016kbuild-file := $(srctree)/$(obj)/Kbuild
17include $(kbuild-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010018
Sam Ravnborgc7bb3492009-04-10 08:52:43 +020019_dst := $(if $(destination-y),$(destination-y),$(_dst))
20
Sam Ravnborg283039f2008-06-05 19:19:47 +020021include scripts/Kbuild.include
David Woodhousede789122006-09-24 22:15:14 +010022
Sam Ravnborg77124012008-06-15 21:41:09 +020023install := $(INSTALL_HDR_PATH)/$(_dst)
Sam Ravnborg62284a32008-06-07 13:18:26 +020024
Sam Ravnborg7cfddee2010-08-14 10:22:58 +020025header-y := $(sort $(header-y))
Sam Ravnborg77124012008-06-15 21:41:09 +020026subdirs := $(patsubst %/,%,$(filter %/, $(header-y)))
27header-y := $(filter-out %/, $(header-y))
David Woodhouse8d730cf2006-06-18 11:58:39 +010028
Sam Ravnborg77124012008-06-15 21:41:09 +020029# files used to track state of install/check
30install-file := $(install)/.install
31check-file := $(install)/.check
32
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020033# generic-y list all files an architecture uses from asm-generic
34# Use this to build a list of headers which require a wrapper
35wrapper-files := $(filter $(header-y), $(generic-y))
36
Sam Ravnborg77124012008-06-15 21:41:09 +020037# all headers files for this dir
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020038header-y := $(filter-out $(generic-y), $(header-y))
David Howells40f1d4c2012-10-02 18:01:56 +010039all-files := $(header-y) $(genhdr-y) $(wrapper-files)
Sam Ravnborg77124012008-06-15 21:41:09 +020040input-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \
H. Peter Anvincb979142011-11-11 15:20:34 -080041 $(addprefix $(objtree)/$(gen)/,$(genhdr-y))
Sam Ravnborg77124012008-06-15 21:41:09 +020042output-files := $(addprefix $(install)/, $(all-files))
David Woodhousede789122006-09-24 22:15:14 +010043
44# Work out what needs to be removed
Sam Ravnborg77124012008-06-15 21:41:09 +020045oldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h))
46unwanted := $(filter-out $(all-files),$(oldheaders))
David Woodhousede789122006-09-24 22:15:14 +010047
Sam Ravnborg77124012008-06-15 21:41:09 +020048# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
49unwanted-file := $(addprefix $(install)/, $(unwanted))
David Woodhousede789122006-09-24 22:15:14 +010050
Sam Ravnborg77124012008-06-15 21:41:09 +020051printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
David Woodhousede789122006-09-24 22:15:14 +010052
Sam Ravnborg77124012008-06-15 21:41:09 +020053quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
54 file$(if $(word 2, $(all-files)),s))
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020055 cmd_install = \
56 $(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \
H. Peter Anvincb979142011-11-11 15:20:34 -080057 $(PERL) $< $(objtree)/$(gen) $(install) $(SRCARCH) $(genhdr-y); \
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020058 for F in $(wrapper-files); do \
59 echo "\#include <asm-generic/$$F>" > $(install)/$$F; \
60 done; \
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020061 touch $@
David Woodhouse8d730cf2006-06-18 11:58:39 +010062
Sam Ravnborg77124012008-06-15 21:41:09 +020063quiet_cmd_remove = REMOVE $(unwanted)
64 cmd_remove = rm -f $(unwanted-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010065
Sam Ravnborg77124012008-06-15 21:41:09 +020066quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
Sergei Poselenov7211b8b2009-06-05 16:11:09 +040067# Headers list can be pretty long, xargs helps to avoid
68# the "Argument list too long" error.
69 cmd_check = for f in $(all-files); do \
70 echo "$(install)/$${f}"; done \
71 | xargs \
72 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
Sam Ravnborg77124012008-06-15 21:41:09 +020073 touch $@
David Woodhouse68475352006-06-18 12:02:10 +010074
Sam Ravnborg77124012008-06-15 21:41:09 +020075PHONY += __headersinst __headerscheck
David Woodhouse8d730cf2006-06-18 11:58:39 +010076
Sam Ravnborg77124012008-06-15 21:41:09 +020077ifndef HDRCHECK
78# Rules for installing headers
79__headersinst: $(subdirs) $(install-file)
80 @:
David Woodhousede789122006-09-24 22:15:14 +010081
Sam Ravnborg77124012008-06-15 21:41:09 +020082targets += $(install-file)
83$(install-file): scripts/headers_install.pl $(input-files) FORCE
84 $(if $(unwanted),$(call cmd,remove),)
85 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
86 $(call if_changed,install)
David Woodhousede789122006-09-24 22:15:14 +010087
David Woodhouse68475352006-06-18 12:02:10 +010088else
Sam Ravnborg77124012008-06-15 21:41:09 +020089__headerscheck: $(subdirs) $(check-file)
90 @:
David Woodhouse8d730cf2006-06-18 11:58:39 +010091
Sam Ravnborg77124012008-06-15 21:41:09 +020092targets += $(check-file)
93$(check-file): scripts/headers_check.pl $(output-files) FORCE
94 $(call if_changed,check)
Sam Ravnborg4e420aa2008-06-05 16:52:15 +020095
David Woodhouse8d730cf2006-06-18 11:58:39 +010096endif
David Woodhouse8d730cf2006-06-18 11:58:39 +010097
David Woodhouse8d730cf2006-06-18 11:58:39 +010098# Recursion
Sam Ravnborg77124012008-06-15 21:41:09 +020099hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
100.PHONY: $(subdirs)
101$(subdirs):
Sam Ravnborg62284a32008-06-07 13:18:26 +0200102 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
Sam Ravnborg77124012008-06-15 21:41:09 +0200103
104targets := $(wildcard $(sort $(targets)))
105cmd_files := $(wildcard \
106 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
107
108ifneq ($(cmd_files),)
109 include $(cmd_files)
110endif
111
112.PHONY: $(PHONY)
113PHONY += FORCE
114FORCE: ;