blob: 06ba4a70bd4d0db666a4b50b90b73f33e7c6b81e [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 Howells10b63952012-10-02 18:01:57 +010011_dst := $(or $(destination-y),$(dst),$(obj))
David Woodhouse8d730cf2006-06-18 11:58:39 +010012
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
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), \
51 $(or \
52 $(wildcard $(srcdir)/$(hdr)), \
53 $(wildcard $(oldsrcdir)/$(hdr)), \
54 $(error Missing UAPI file $(srcdir)/$(hdr)) \
55 )) \
56 $(foreach hdr, $(genhdr-y), \
57 $(or \
58 $(wildcard $(gendir)/$(hdr)), \
59 $(error Missing generated UAPI file $(gendir)/$(hdr)) \
60 ))
David Woodhousede789122006-09-24 22:15:14 +010061
62# Work out what needs to be removed
David Howells10b63952012-10-02 18:01:57 +010063oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
Sam Ravnborg77124012008-06-15 21:41:09 +020064unwanted := $(filter-out $(all-files),$(oldheaders))
David Woodhousede789122006-09-24 22:15:14 +010065
Sam Ravnborg77124012008-06-15 21:41:09 +020066# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
David Howells10b63952012-10-02 18:01:57 +010067unwanted-file := $(addprefix $(installdir)/, $(unwanted))
David Woodhousede789122006-09-24 22:15:14 +010068
Sam Ravnborg77124012008-06-15 21:41:09 +020069printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
David Woodhousede789122006-09-24 22:15:14 +010070
Sam Ravnborg77124012008-06-15 21:41:09 +020071quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
72 file$(if $(word 2, $(all-files)),s))
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020073 cmd_install = \
David Howells10b63952012-10-02 18:01:57 +010074 $(PERL) $< $(installdir) $(SRCARCH) $(input-files); \
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020075 for F in $(wrapper-files); do \
David Howells10b63952012-10-02 18:01:57 +010076 echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020077 done; \
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020078 touch $@
David Woodhouse8d730cf2006-06-18 11:58:39 +010079
Sam Ravnborg77124012008-06-15 21:41:09 +020080quiet_cmd_remove = REMOVE $(unwanted)
81 cmd_remove = rm -f $(unwanted-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010082
Sam Ravnborg77124012008-06-15 21:41:09 +020083quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
Sergei Poselenov7211b8b2009-06-05 16:11:09 +040084# Headers list can be pretty long, xargs helps to avoid
85# the "Argument list too long" error.
86 cmd_check = for f in $(all-files); do \
David Howells10b63952012-10-02 18:01:57 +010087 echo "$(installdir)/$${f}"; done \
Sergei Poselenov7211b8b2009-06-05 16:11:09 +040088 | xargs \
89 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
Sam Ravnborg77124012008-06-15 21:41:09 +020090 touch $@
David Woodhouse68475352006-06-18 12:02:10 +010091
Sam Ravnborg77124012008-06-15 21:41:09 +020092PHONY += __headersinst __headerscheck
David Woodhouse8d730cf2006-06-18 11:58:39 +010093
Sam Ravnborg77124012008-06-15 21:41:09 +020094ifndef HDRCHECK
95# Rules for installing headers
96__headersinst: $(subdirs) $(install-file)
97 @:
David Woodhousede789122006-09-24 22:15:14 +010098
Sam Ravnborg77124012008-06-15 21:41:09 +020099targets += $(install-file)
100$(install-file): scripts/headers_install.pl $(input-files) FORCE
101 $(if $(unwanted),$(call cmd,remove),)
102 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
103 $(call if_changed,install)
David Woodhousede789122006-09-24 22:15:14 +0100104
David Woodhouse68475352006-06-18 12:02:10 +0100105else
Sam Ravnborg77124012008-06-15 21:41:09 +0200106__headerscheck: $(subdirs) $(check-file)
107 @:
David Woodhouse8d730cf2006-06-18 11:58:39 +0100108
Sam Ravnborg77124012008-06-15 21:41:09 +0200109targets += $(check-file)
110$(check-file): scripts/headers_check.pl $(output-files) FORCE
111 $(call if_changed,check)
Sam Ravnborg4e420aa2008-06-05 16:52:15 +0200112
David Woodhouse8d730cf2006-06-18 11:58:39 +0100113endif
David Woodhouse8d730cf2006-06-18 11:58:39 +0100114
David Woodhouse8d730cf2006-06-18 11:58:39 +0100115# Recursion
Sam Ravnborg77124012008-06-15 21:41:09 +0200116hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
117.PHONY: $(subdirs)
118$(subdirs):
Sam Ravnborg62284a32008-06-07 13:18:26 +0200119 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
Sam Ravnborg77124012008-06-15 21:41:09 +0200120
121targets := $(wildcard $(sort $(targets)))
122cmd_files := $(wildcard \
123 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
124
125ifneq ($(cmd_files),)
126 include $(cmd_files)
127endif
128
129.PHONY: $(PHONY)
130PHONY += FORCE
131FORCE: ;