blob: 7bd9df6efe2fe3e9d3508a2ca501f264b99d8a0e [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
Sam Ravnborg77124012008-06-15 21:41:09 +020043# all headers files for this dir
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020044header-y := $(filter-out $(generic-y), $(header-y))
David Howells40f1d4c2012-10-02 18:01:56 +010045all-files := $(header-y) $(genhdr-y) $(wrapper-files)
David Howells10b63952012-10-02 18:01:57 +010046output-files := $(addprefix $(installdir)/, $(all-files))
47
Nicolas Dichtel7c025b22017-03-27 14:20:09 +020048# Check that all expected files exist
49$(foreach hdr, $(header-y), \
50 $(if $(wildcard $(srcdir)/$(hdr)),, \
51 $(error Missing UAPI file $(srcdir)/$(hdr)) \
52 ))
53$(foreach hdr, $(genhdr-y), \
54 $(if $(wildcard $(gendir)/$(hdr)),, \
55 $(error Missing generated UAPI file $(gendir)/$(hdr)) \
56 ))
David Woodhousede789122006-09-24 22:15:14 +010057
58# Work out what needs to be removed
David Howells10b63952012-10-02 18:01:57 +010059oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
Sam Ravnborg77124012008-06-15 21:41:09 +020060unwanted := $(filter-out $(all-files),$(oldheaders))
David Woodhousede789122006-09-24 22:15:14 +010061
Sam Ravnborg77124012008-06-15 21:41:09 +020062# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
David Howells10b63952012-10-02 18:01:57 +010063unwanted-file := $(addprefix $(installdir)/, $(unwanted))
David Woodhousede789122006-09-24 22:15:14 +010064
Sam Ravnborg77124012008-06-15 21:41:09 +020065printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
David Woodhousede789122006-09-24 22:15:14 +010066
Sam Ravnborg77124012008-06-15 21:41:09 +020067quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
68 file$(if $(word 2, $(all-files)),s))
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020069 cmd_install = \
Nicolas Dichtel7c025b22017-03-27 14:20:09 +020070 $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-y); \
71 $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-y); \
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020072 for F in $(wrapper-files); do \
David Howells10b63952012-10-02 18:01:57 +010073 echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020074 done; \
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020075 touch $@
David Woodhouse8d730cf2006-06-18 11:58:39 +010076
Sam Ravnborg77124012008-06-15 21:41:09 +020077quiet_cmd_remove = REMOVE $(unwanted)
78 cmd_remove = rm -f $(unwanted-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010079
Sam Ravnborg77124012008-06-15 21:41:09 +020080quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
Sergei Poselenov7211b8b2009-06-05 16:11:09 +040081# Headers list can be pretty long, xargs helps to avoid
82# the "Argument list too long" error.
83 cmd_check = for f in $(all-files); do \
David Howells10b63952012-10-02 18:01:57 +010084 echo "$(installdir)/$${f}"; done \
Sergei Poselenov7211b8b2009-06-05 16:11:09 +040085 | xargs \
86 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
Sam Ravnborg77124012008-06-15 21:41:09 +020087 touch $@
David Woodhouse68475352006-06-18 12:02:10 +010088
Sam Ravnborg77124012008-06-15 21:41:09 +020089PHONY += __headersinst __headerscheck
David Woodhouse8d730cf2006-06-18 11:58:39 +010090
Sam Ravnborg77124012008-06-15 21:41:09 +020091ifndef HDRCHECK
92# Rules for installing headers
93__headersinst: $(subdirs) $(install-file)
94 @:
David Woodhousede789122006-09-24 22:15:14 +010095
Sam Ravnborg77124012008-06-15 21:41:09 +020096targets += $(install-file)
Nicolas Dichtel7c025b22017-03-27 14:20:09 +020097$(install-file): scripts/headers_install.sh \
98 $(addprefix $(srcdir)/,$(header-y)) \
99 $(addprefix $(gendir)/,$(genhdr-y)) FORCE
Sam Ravnborg77124012008-06-15 21:41:09 +0200100 $(if $(unwanted),$(call cmd,remove),)
101 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
102 $(call if_changed,install)
David Woodhousede789122006-09-24 22:15:14 +0100103
David Woodhouse68475352006-06-18 12:02:10 +0100104else
Sam Ravnborg77124012008-06-15 21:41:09 +0200105__headerscheck: $(subdirs) $(check-file)
106 @:
David Woodhouse8d730cf2006-06-18 11:58:39 +0100107
Sam Ravnborg77124012008-06-15 21:41:09 +0200108targets += $(check-file)
109$(check-file): scripts/headers_check.pl $(output-files) FORCE
110 $(call if_changed,check)
Sam Ravnborg4e420aa2008-06-05 16:52:15 +0200111
David Woodhouse8d730cf2006-06-18 11:58:39 +0100112endif
David Woodhouse8d730cf2006-06-18 11:58:39 +0100113
David Woodhouse8d730cf2006-06-18 11:58:39 +0100114# Recursion
Sam Ravnborg77124012008-06-15 21:41:09 +0200115.PHONY: $(subdirs)
116$(subdirs):
Sam Ravnborg62284a32008-06-07 13:18:26 +0200117 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
Sam Ravnborg77124012008-06-15 21:41:09 +0200118
119targets := $(wildcard $(sort $(targets)))
120cmd_files := $(wildcard \
121 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
122
123ifneq ($(cmd_files),)
124 include $(cmd_files)
125endif
126
127.PHONY: $(PHONY)
128PHONY += FORCE
129FORCE: ;