blob: 6ba97a1f9c5a26304abdf0f043211efe6c273ffc [file] [log] [blame]
David Woodhouse8d730cf2006-06-18 11:58:39 +01001# ==========================================================================
2# Installing headers
3#
Nicolas Dichtelfcc84872017-03-27 14:20:15 +02004# All headers under include/uapi, include/generated/uapi,
Nicolas Dichtel61562f92017-03-27 14:20:16 +02005# arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are
Nicolas Dichtelfcc84872017-03-27 14:20:15 +02006# exported.
7# They are preprocessed to remove __KERNEL__ section of the file.
David Woodhouse8d730cf2006-06-18 11:58:39 +01008#
9# ==========================================================================
10
H. Peter Anvincb979142011-11-11 15:20:34 -080011# generated header directory
12gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj)))
13
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020014# Kbuild file is optional
Sam Ravnborg283039f2008-06-05 19:19:47 +020015kbuild-file := $(srctree)/$(obj)/Kbuild
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020016-include $(kbuild-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010017
Jesper Nilsson9b58b922013-02-02 11:18:35 +010018# called may set destination dir (when installing to asm/)
Nicolas Dichtelbd73a322017-03-27 14:20:10 +020019_dst := $(if $(dst),$(dst),$(obj))
Jesper Nilsson9b58b922013-02-02 11:18:35 +010020
David Howells10b63952012-10-02 18:01:57 +010021old-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild
22ifneq ($(wildcard $(old-kbuild-file)),)
23include $(old-kbuild-file)
24endif
Sam Ravnborgc7bb3492009-04-10 08:52:43 +020025
Sam Ravnborg283039f2008-06-05 19:19:47 +020026include scripts/Kbuild.include
David Woodhousede789122006-09-24 22:15:14 +010027
David Howells10b63952012-10-02 18:01:57 +010028installdir := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst))
Sam Ravnborg62284a32008-06-07 13:18:26 +020029
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020030srcdir := $(srctree)/$(obj)
31gendir := $(objtree)/$(gen)
32subdirs := $(patsubst $(srcdir)/%/.,%,$(wildcard $(srcdir)/*/.))
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020033header-files := $(notdir $(wildcard $(srcdir)/*.h))
34header-files += $(notdir $(wildcard $(srcdir)/*.agh))
35header-files := $(filter-out $(no-export-headers), $(header-files))
36genhdr-files := $(notdir $(wildcard $(gendir)/*.h))
37genhdr-files := $(filter-out $(header-files), $(genhdr-files))
David Woodhouse8d730cf2006-06-18 11:58:39 +010038
Sam Ravnborg77124012008-06-15 21:41:09 +020039# files used to track state of install/check
David Howells10b63952012-10-02 18:01:57 +010040install-file := $(installdir)/.install
41check-file := $(installdir)/.check
Sam Ravnborg77124012008-06-15 21:41:09 +020042
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020043# generic-y list all files an architecture uses from asm-generic
44# Use this to build a list of headers which require a wrapper
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020045generic-files := $(notdir $(wildcard $(srctree)/include/uapi/asm-generic/*.h))
46wrapper-files := $(filter $(generic-files), $(generic-y))
47wrapper-files := $(filter-out $(header-files), $(wrapper-files))
David Howells10b63952012-10-02 18:01:57 +010048
Sam Ravnborg77124012008-06-15 21:41:09 +020049# all headers files for this dir
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020050all-files := $(header-files) $(genhdr-files) $(wrapper-files)
David Howells10b63952012-10-02 18:01:57 +010051output-files := $(addprefix $(installdir)/, $(all-files))
52
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020053ifneq ($(mandatory-y),)
54missing := $(filter-out $(all-files),$(mandatory-y))
55ifneq ($(missing),)
56$(error Some mandatory headers ($(missing)) are missing in $(obj))
57endif
58endif
David Woodhousede789122006-09-24 22:15:14 +010059
60# Work out what needs to be removed
David Howells10b63952012-10-02 18:01:57 +010061oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
Sam Ravnborg77124012008-06-15 21:41:09 +020062unwanted := $(filter-out $(all-files),$(oldheaders))
David Woodhousede789122006-09-24 22:15:14 +010063
Sam Ravnborg77124012008-06-15 21:41:09 +020064# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
David Howells10b63952012-10-02 18:01:57 +010065unwanted-file := $(addprefix $(installdir)/, $(unwanted))
David Woodhousede789122006-09-24 22:15:14 +010066
Sam Ravnborg77124012008-06-15 21:41:09 +020067printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
David Woodhousede789122006-09-24 22:15:14 +010068
Sam Ravnborg77124012008-06-15 21:41:09 +020069quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
70 file$(if $(word 2, $(all-files)),s))
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020071 cmd_install = \
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020072 $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \
73 $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020074 for F in $(wrapper-files); do \
David Howells10b63952012-10-02 18:01:57 +010075 echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020076 done; \
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020077 touch $@
David Woodhouse8d730cf2006-06-18 11:58:39 +010078
Sam Ravnborg77124012008-06-15 21:41:09 +020079quiet_cmd_remove = REMOVE $(unwanted)
80 cmd_remove = rm -f $(unwanted-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010081
Sam Ravnborg77124012008-06-15 21:41:09 +020082quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
Sergei Poselenov7211b8b2009-06-05 16:11:09 +040083# Headers list can be pretty long, xargs helps to avoid
84# the "Argument list too long" error.
85 cmd_check = for f in $(all-files); do \
David Howells10b63952012-10-02 18:01:57 +010086 echo "$(installdir)/$${f}"; done \
Sergei Poselenov7211b8b2009-06-05 16:11:09 +040087 | xargs \
88 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
Sam Ravnborg77124012008-06-15 21:41:09 +020089 touch $@
David Woodhouse68475352006-06-18 12:02:10 +010090
Sam Ravnborg77124012008-06-15 21:41:09 +020091PHONY += __headersinst __headerscheck
David Woodhouse8d730cf2006-06-18 11:58:39 +010092
Sam Ravnborg77124012008-06-15 21:41:09 +020093ifndef HDRCHECK
94# Rules for installing headers
95__headersinst: $(subdirs) $(install-file)
96 @:
David Woodhousede789122006-09-24 22:15:14 +010097
Sam Ravnborg77124012008-06-15 21:41:09 +020098targets += $(install-file)
Nicolas Dichtel7c025b22017-03-27 14:20:09 +020099$(install-file): scripts/headers_install.sh \
Nicolas Dichtelfcc84872017-03-27 14:20:15 +0200100 $(addprefix $(srcdir)/,$(header-files)) \
101 $(addprefix $(gendir)/,$(genhdr-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 +0200117.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: ;