blob: 20be1fbc19cc8e9a33842288f2c9ffced3397595 [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,
5# arch/<arch>/include/uapi/asm and arch/<arch>/include/generated/uapi/asm are
6# 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)/*/.))
33subdirs += $(subdir-y)
34header-files := $(notdir $(wildcard $(srcdir)/*.h))
35header-files += $(notdir $(wildcard $(srcdir)/*.agh))
36header-files := $(filter-out $(no-export-headers), $(header-files))
37genhdr-files := $(notdir $(wildcard $(gendir)/*.h))
38genhdr-files := $(filter-out $(header-files), $(genhdr-files))
David Woodhouse8d730cf2006-06-18 11:58:39 +010039
Sam Ravnborg77124012008-06-15 21:41:09 +020040# files used to track state of install/check
David Howells10b63952012-10-02 18:01:57 +010041install-file := $(installdir)/.install
42check-file := $(installdir)/.check
Sam Ravnborg77124012008-06-15 21:41:09 +020043
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020044# generic-y list all files an architecture uses from asm-generic
45# Use this to build a list of headers which require a wrapper
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020046generic-files := $(notdir $(wildcard $(srctree)/include/uapi/asm-generic/*.h))
47wrapper-files := $(filter $(generic-files), $(generic-y))
48wrapper-files := $(filter-out $(header-files), $(wrapper-files))
David Howells10b63952012-10-02 18:01:57 +010049
Sam Ravnborg77124012008-06-15 21:41:09 +020050# all headers files for this dir
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020051all-files := $(header-files) $(genhdr-files) $(wrapper-files)
David Howells10b63952012-10-02 18:01:57 +010052output-files := $(addprefix $(installdir)/, $(all-files))
53
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020054ifneq ($(mandatory-y),)
55missing := $(filter-out $(all-files),$(mandatory-y))
56ifneq ($(missing),)
57$(error Some mandatory headers ($(missing)) are missing in $(obj))
58endif
59endif
David Woodhousede789122006-09-24 22:15:14 +010060
61# Work out what needs to be removed
David Howells10b63952012-10-02 18:01:57 +010062oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
Sam Ravnborg77124012008-06-15 21:41:09 +020063unwanted := $(filter-out $(all-files),$(oldheaders))
David Woodhousede789122006-09-24 22:15:14 +010064
Sam Ravnborg77124012008-06-15 21:41:09 +020065# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
David Howells10b63952012-10-02 18:01:57 +010066unwanted-file := $(addprefix $(installdir)/, $(unwanted))
David Woodhousede789122006-09-24 22:15:14 +010067
Sam Ravnborg77124012008-06-15 21:41:09 +020068printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
David Woodhousede789122006-09-24 22:15:14 +010069
Sam Ravnborg77124012008-06-15 21:41:09 +020070quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
71 file$(if $(word 2, $(all-files)),s))
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020072 cmd_install = \
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020073 $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \
74 $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-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)
Nicolas Dichtel7c025b22017-03-27 14:20:09 +0200100$(install-file): scripts/headers_install.sh \
Nicolas Dichtelfcc84872017-03-27 14:20:15 +0200101 $(addprefix $(srcdir)/,$(header-files)) \
102 $(addprefix $(gendir)/,$(genhdr-files)) FORCE
Sam Ravnborg77124012008-06-15 21:41:09 +0200103 $(if $(unwanted),$(call cmd,remove),)
104 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
105 $(call if_changed,install)
David Woodhousede789122006-09-24 22:15:14 +0100106
David Woodhouse68475352006-06-18 12:02:10 +0100107else
Sam Ravnborg77124012008-06-15 21:41:09 +0200108__headerscheck: $(subdirs) $(check-file)
109 @:
David Woodhouse8d730cf2006-06-18 11:58:39 +0100110
Sam Ravnborg77124012008-06-15 21:41:09 +0200111targets += $(check-file)
112$(check-file): scripts/headers_check.pl $(output-files) FORCE
113 $(call if_changed,check)
Sam Ravnborg4e420aa2008-06-05 16:52:15 +0200114
David Woodhouse8d730cf2006-06-18 11:58:39 +0100115endif
David Woodhouse8d730cf2006-06-18 11:58:39 +0100116
David Woodhouse8d730cf2006-06-18 11:58:39 +0100117# Recursion
Sam Ravnborg77124012008-06-15 21:41:09 +0200118.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: ;