blob: 182084d728c82d29b69170e642b3e978a8266f6e [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
50input-files := $(foreach hdr, $(header-y), \
Sam Ravnborgc4619bc2013-03-04 21:36:24 +010051 $(if $(wildcard $(srcdir)/$(hdr)), \
David Howells10b63952012-10-02 18:01:57 +010052 $(wildcard $(srcdir)/$(hdr)), \
Sam Ravnborgc4619bc2013-03-04 21:36:24 +010053 $(if $(wildcard $(oldsrcdir)/$(hdr)), \
54 $(wildcard $(oldsrcdir)/$(hdr)), \
55 $(error Missing UAPI file $(srcdir)/$(hdr))) \
David Howells10b63952012-10-02 18:01:57 +010056 )) \
57 $(foreach hdr, $(genhdr-y), \
Sam Ravnborgc4619bc2013-03-04 21:36:24 +010058 $(if $(wildcard $(gendir)/$(hdr)), \
David Howells10b63952012-10-02 18:01:57 +010059 $(wildcard $(gendir)/$(hdr)), \
60 $(error Missing generated UAPI file $(gendir)/$(hdr)) \
61 ))
David Woodhousede789122006-09-24 22:15:14 +010062
63# Work out what needs to be removed
David Howells10b63952012-10-02 18:01:57 +010064oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
Sam Ravnborg77124012008-06-15 21:41:09 +020065unwanted := $(filter-out $(all-files),$(oldheaders))
David Woodhousede789122006-09-24 22:15:14 +010066
Sam Ravnborg77124012008-06-15 21:41:09 +020067# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
David Howells10b63952012-10-02 18:01:57 +010068unwanted-file := $(addprefix $(installdir)/, $(unwanted))
David Woodhousede789122006-09-24 22:15:14 +010069
Sam Ravnborg77124012008-06-15 21:41:09 +020070printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
David Woodhousede789122006-09-24 22:15:14 +010071
Sam Ravnborg77124012008-06-15 21:41:09 +020072quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
73 file$(if $(word 2, $(all-files)),s))
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020074 cmd_install = \
Rob Landleye0e2fa42013-03-27 10:24:11 +110075 $(CONFIG_SHELL) $< $(installdir) $(input-files); \
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020076 for F in $(wrapper-files); do \
David Howells10b63952012-10-02 18:01:57 +010077 echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020078 done; \
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020079 touch $@
David Woodhouse8d730cf2006-06-18 11:58:39 +010080
Sam Ravnborg77124012008-06-15 21:41:09 +020081quiet_cmd_remove = REMOVE $(unwanted)
82 cmd_remove = rm -f $(unwanted-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010083
Sam Ravnborg77124012008-06-15 21:41:09 +020084quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
Sergei Poselenov7211b8b2009-06-05 16:11:09 +040085# Headers list can be pretty long, xargs helps to avoid
86# the "Argument list too long" error.
87 cmd_check = for f in $(all-files); do \
David Howells10b63952012-10-02 18:01:57 +010088 echo "$(installdir)/$${f}"; done \
Sergei Poselenov7211b8b2009-06-05 16:11:09 +040089 | xargs \
90 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
Sam Ravnborg77124012008-06-15 21:41:09 +020091 touch $@
David Woodhouse68475352006-06-18 12:02:10 +010092
Sam Ravnborg77124012008-06-15 21:41:09 +020093PHONY += __headersinst __headerscheck
David Woodhouse8d730cf2006-06-18 11:58:39 +010094
Sam Ravnborg77124012008-06-15 21:41:09 +020095ifndef HDRCHECK
96# Rules for installing headers
97__headersinst: $(subdirs) $(install-file)
98 @:
David Woodhousede789122006-09-24 22:15:14 +010099
Sam Ravnborg77124012008-06-15 21:41:09 +0200100targets += $(install-file)
Rob Landleye0e2fa42013-03-27 10:24:11 +1100101$(install-file): scripts/headers_install.sh $(input-files) FORCE
Sam Ravnborg77124012008-06-15 21:41:09 +0200102 $(if $(unwanted),$(call cmd,remove),)
103 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
104 $(call if_changed,install)
David Woodhousede789122006-09-24 22:15:14 +0100105
David Woodhouse68475352006-06-18 12:02:10 +0100106else
Sam Ravnborg77124012008-06-15 21:41:09 +0200107__headerscheck: $(subdirs) $(check-file)
108 @:
David Woodhouse8d730cf2006-06-18 11:58:39 +0100109
Sam Ravnborg77124012008-06-15 21:41:09 +0200110targets += $(check-file)
111$(check-file): scripts/headers_check.pl $(output-files) FORCE
112 $(call if_changed,check)
Sam Ravnborg4e420aa2008-06-05 16:52:15 +0200113
David Woodhouse8d730cf2006-06-18 11:58:39 +0100114endif
David Woodhouse8d730cf2006-06-18 11:58:39 +0100115
David Woodhouse8d730cf2006-06-18 11:58:39 +0100116# Recursion
Sam Ravnborg77124012008-06-15 21:41:09 +0200117hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
118.PHONY: $(subdirs)
119$(subdirs):
Sam Ravnborg62284a32008-06-07 13:18:26 +0200120 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
Sam Ravnborg77124012008-06-15 21:41:09 +0200121
122targets := $(wildcard $(sort $(targets)))
123cmd_files := $(wildcard \
124 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
125
126ifneq ($(cmd_files),)
127 include $(cmd_files)
128endif
129
130.PHONY: $(PHONY)
131PHONY += FORCE
132FORCE: ;