blob: 8ccf83056a7ab6b260a028a9ee9a422e6949525e [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
H. Peter Anvincb979142011-11-11 15:20:34 -080010# generated header directory
11gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(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
Jesper Nilsson9b58b922013-02-02 11:18:35 +010016# called may set destination dir (when installing to asm/)
Sam Ravnborgc4619bc2013-03-04 21:36:24 +010017_dst := $(if $(destination-y),$(destination-y),$(if $(dst),$(dst),$(obj)))
Jesper Nilsson9b58b922013-02-02 11:18:35 +010018
David Howells10b63952012-10-02 18:01:57 +010019old-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild
20ifneq ($(wildcard $(old-kbuild-file)),)
21include $(old-kbuild-file)
22endif
Sam Ravnborgc7bb3492009-04-10 08:52:43 +020023
Sam Ravnborg283039f2008-06-05 19:19:47 +020024include scripts/Kbuild.include
David Woodhousede789122006-09-24 22:15:14 +010025
David Howells10b63952012-10-02 18:01:57 +010026installdir := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst))
Sam Ravnborg62284a32008-06-07 13:18:26 +020027
Sam Ravnborg7cfddee2010-08-14 10:22:58 +020028header-y := $(sort $(header-y))
Sam Ravnborg77124012008-06-15 21:41:09 +020029subdirs := $(patsubst %/,%,$(filter %/, $(header-y)))
30header-y := $(filter-out %/, $(header-y))
David Woodhouse8d730cf2006-06-18 11:58:39 +010031
Sam Ravnborg77124012008-06-15 21:41:09 +020032# files used to track state of install/check
David Howells10b63952012-10-02 18:01:57 +010033install-file := $(installdir)/.install
34check-file := $(installdir)/.check
Sam Ravnborg77124012008-06-15 21:41:09 +020035
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020036# generic-y list all files an architecture uses from asm-generic
37# Use this to build a list of headers which require a wrapper
38wrapper-files := $(filter $(header-y), $(generic-y))
39
David Howells10b63952012-10-02 18:01:57 +010040srcdir := $(srctree)/$(obj)
41gendir := $(objtree)/$(gen)
42
43oldsrcdir := $(srctree)/$(subst /uapi,,$(obj))
44
Sam Ravnborg77124012008-06-15 21:41:09 +020045# all headers files for this dir
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020046header-y := $(filter-out $(generic-y), $(header-y))
David Howells40f1d4c2012-10-02 18:01:56 +010047all-files := $(header-y) $(genhdr-y) $(wrapper-files)
David Howells10b63952012-10-02 18:01:57 +010048output-files := $(addprefix $(installdir)/, $(all-files))
49
Nicolas Dichtelc0ff68f2013-04-29 14:15:51 +020050input-files1 := $(foreach hdr, $(header-y), \
Sam Ravnborgc4619bc2013-03-04 21:36:24 +010051 $(if $(wildcard $(srcdir)/$(hdr)), \
Nicolas Dichtelc0ff68f2013-04-29 14:15:51 +020052 $(wildcard $(srcdir)/$(hdr))) \
53 )
54input-files1-name := $(notdir $(input-files1))
55input-files2 := $(foreach hdr, $(header-y), \
56 $(if $(wildcard $(srcdir)/$(hdr)),, \
Sam Ravnborgc4619bc2013-03-04 21:36:24 +010057 $(if $(wildcard $(oldsrcdir)/$(hdr)), \
58 $(wildcard $(oldsrcdir)/$(hdr)), \
59 $(error Missing UAPI file $(srcdir)/$(hdr))) \
Nicolas Dichtelc0ff68f2013-04-29 14:15:51 +020060 ))
61input-files2-name := $(notdir $(input-files2))
62input-files3 := $(foreach hdr, $(genhdr-y), \
Sam Ravnborgc4619bc2013-03-04 21:36:24 +010063 $(if $(wildcard $(gendir)/$(hdr)), \
David Howells10b63952012-10-02 18:01:57 +010064 $(wildcard $(gendir)/$(hdr)), \
65 $(error Missing generated UAPI file $(gendir)/$(hdr)) \
66 ))
Nicolas Dichtelc0ff68f2013-04-29 14:15:51 +020067input-files3-name := $(notdir $(input-files3))
David Woodhousede789122006-09-24 22:15:14 +010068
69# Work out what needs to be removed
David Howells10b63952012-10-02 18:01:57 +010070oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
Sam Ravnborg77124012008-06-15 21:41:09 +020071unwanted := $(filter-out $(all-files),$(oldheaders))
David Woodhousede789122006-09-24 22:15:14 +010072
Sam Ravnborg77124012008-06-15 21:41:09 +020073# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
David Howells10b63952012-10-02 18:01:57 +010074unwanted-file := $(addprefix $(installdir)/, $(unwanted))
David Woodhousede789122006-09-24 22:15:14 +010075
Sam Ravnborg77124012008-06-15 21:41:09 +020076printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
David Woodhousede789122006-09-24 22:15:14 +010077
Sam Ravnborg77124012008-06-15 21:41:09 +020078quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
79 file$(if $(word 2, $(all-files)),s))
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020080 cmd_install = \
Nicolas Dichtelc0ff68f2013-04-29 14:15:51 +020081 $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(input-files1-name); \
82 $(CONFIG_SHELL) $< $(installdir) $(oldsrcdir) $(input-files2-name); \
83 $(CONFIG_SHELL) $< $(installdir) $(gendir) $(input-files3-name); \
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020084 for F in $(wrapper-files); do \
David Howells10b63952012-10-02 18:01:57 +010085 echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020086 done; \
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020087 touch $@
David Woodhouse8d730cf2006-06-18 11:58:39 +010088
Sam Ravnborg77124012008-06-15 21:41:09 +020089quiet_cmd_remove = REMOVE $(unwanted)
90 cmd_remove = rm -f $(unwanted-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010091
Sam Ravnborg77124012008-06-15 21:41:09 +020092quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
Sergei Poselenov7211b8b2009-06-05 16:11:09 +040093# Headers list can be pretty long, xargs helps to avoid
94# the "Argument list too long" error.
95 cmd_check = for f in $(all-files); do \
David Howells10b63952012-10-02 18:01:57 +010096 echo "$(installdir)/$${f}"; done \
Sergei Poselenov7211b8b2009-06-05 16:11:09 +040097 | xargs \
98 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
Sam Ravnborg77124012008-06-15 21:41:09 +020099 touch $@
David Woodhouse68475352006-06-18 12:02:10 +0100100
Sam Ravnborg77124012008-06-15 21:41:09 +0200101PHONY += __headersinst __headerscheck
David Woodhouse8d730cf2006-06-18 11:58:39 +0100102
Sam Ravnborg77124012008-06-15 21:41:09 +0200103ifndef HDRCHECK
104# Rules for installing headers
105__headersinst: $(subdirs) $(install-file)
106 @:
David Woodhousede789122006-09-24 22:15:14 +0100107
Sam Ravnborg77124012008-06-15 21:41:09 +0200108targets += $(install-file)
Nicolas Dichtelc0ff68f2013-04-29 14:15:51 +0200109$(install-file): scripts/headers_install.sh $(input-files1) $(input-files2) $(input-files3) FORCE
Sam Ravnborg77124012008-06-15 21:41:09 +0200110 $(if $(unwanted),$(call cmd,remove),)
111 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
112 $(call if_changed,install)
David Woodhousede789122006-09-24 22:15:14 +0100113
David Woodhouse68475352006-06-18 12:02:10 +0100114else
Sam Ravnborg77124012008-06-15 21:41:09 +0200115__headerscheck: $(subdirs) $(check-file)
116 @:
David Woodhouse8d730cf2006-06-18 11:58:39 +0100117
Sam Ravnborg77124012008-06-15 21:41:09 +0200118targets += $(check-file)
119$(check-file): scripts/headers_check.pl $(output-files) FORCE
120 $(call if_changed,check)
Sam Ravnborg4e420aa2008-06-05 16:52:15 +0200121
David Woodhouse8d730cf2006-06-18 11:58:39 +0100122endif
David Woodhouse8d730cf2006-06-18 11:58:39 +0100123
David Woodhouse8d730cf2006-06-18 11:58:39 +0100124# Recursion
Sam Ravnborg77124012008-06-15 21:41:09 +0200125hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
126.PHONY: $(subdirs)
127$(subdirs):
Sam Ravnborg62284a32008-06-07 13:18:26 +0200128 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
Sam Ravnborg77124012008-06-15 21:41:09 +0200129
130targets := $(wildcard $(sort $(targets)))
131cmd_files := $(wildcard \
132 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
133
134ifneq ($(cmd_files),)
135 include $(cmd_files)
136endif
137
138.PHONY: $(PHONY)
139PHONY += FORCE
140FORCE: ;