blob: 82abf5a09e5dce680e0d10c8d331fbc1e5e91ea1 [file] [log] [blame]
David Woodhouse8d730cf2006-06-18 11:58:39 +01001# ==========================================================================
2# Installing headers
3#
Nicolas Dichtel3b0fe0b2017-03-27 14:20:15 +02004# All headers under include/uapi, include/generated/uapi,
Nicolas Dichtel365052f2017-03-27 14:20:16 +02005# arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are
Nicolas Dichtel3b0fe0b2017-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
Masahiro Yamada59b85962017-05-16 14:15:03 +090011PHONY := __headers
12__headers:
13
14include scripts/Kbuild.include
15
16srcdir := $(srctree)/$(obj)
17subdirs := $(patsubst $(srcdir)/%/.,%,$(wildcard $(srcdir)/*/.))
18# caller may set destination dir (when installing to asm/)
19_dst := $(if $(dst),$(dst),$(obj))
20
21# Recursion
22__headers: $(subdirs)
23
24.PHONY: $(subdirs)
25$(subdirs):
26 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
27
28# Skip header install/check for include/uapi and arch/$(hdr-arch)/include/uapi.
29# We have only sub-directories there.
30skip-inst := $(if $(filter %/uapi,$(obj)),1)
31
32ifeq ($(skip-inst),)
33
H. Peter Anvincb979142011-11-11 15:20:34 -080034# generated header directory
35gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj)))
36
Nicolas Dichtel3b0fe0b2017-03-27 14:20:15 +020037# Kbuild file is optional
Sam Ravnborg283039f2008-06-05 19:19:47 +020038kbuild-file := $(srctree)/$(obj)/Kbuild
Nicolas Dichtel3b0fe0b2017-03-27 14:20:15 +020039-include $(kbuild-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010040
David Howells10b63952012-10-02 18:01:57 +010041old-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild
42ifneq ($(wildcard $(old-kbuild-file)),)
43include $(old-kbuild-file)
44endif
Sam Ravnborgc7bb3492009-04-10 08:52:43 +020045
David Howells10b63952012-10-02 18:01:57 +010046installdir := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst))
Sam Ravnborg62284a32008-06-07 13:18:26 +020047
Nicolas Dichtel3b0fe0b2017-03-27 14:20:15 +020048gendir := $(objtree)/$(gen)
Nicolas Dichtel3b0fe0b2017-03-27 14:20:15 +020049header-files := $(notdir $(wildcard $(srcdir)/*.h))
50header-files += $(notdir $(wildcard $(srcdir)/*.agh))
51header-files := $(filter-out $(no-export-headers), $(header-files))
52genhdr-files := $(notdir $(wildcard $(gendir)/*.h))
53genhdr-files := $(filter-out $(header-files), $(genhdr-files))
David Woodhouse8d730cf2006-06-18 11:58:39 +010054
Sam Ravnborg77124012008-06-15 21:41:09 +020055# files used to track state of install/check
David Howells10b63952012-10-02 18:01:57 +010056install-file := $(installdir)/.install
57check-file := $(installdir)/.check
Sam Ravnborg77124012008-06-15 21:41:09 +020058
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020059# generic-y list all files an architecture uses from asm-generic
60# Use this to build a list of headers which require a wrapper
Nicolas Dichtel3b0fe0b2017-03-27 14:20:15 +020061generic-files := $(notdir $(wildcard $(srctree)/include/uapi/asm-generic/*.h))
62wrapper-files := $(filter $(generic-files), $(generic-y))
63wrapper-files := $(filter-out $(header-files), $(wrapper-files))
David Howells10b63952012-10-02 18:01:57 +010064
65oldsrcdir := $(srctree)/$(subst /uapi,,$(obj))
66
Sam Ravnborg77124012008-06-15 21:41:09 +020067# all headers files for this dir
Nicolas Dichtel3b0fe0b2017-03-27 14:20:15 +020068all-files := $(header-files) $(genhdr-files) $(wrapper-files)
David Howells10b63952012-10-02 18:01:57 +010069output-files := $(addprefix $(installdir)/, $(all-files))
70
Nicolas Dichtel3b0fe0b2017-03-27 14:20:15 +020071ifneq ($(mandatory-y),)
72missing := $(filter-out $(all-files),$(mandatory-y))
73ifneq ($(missing),)
74$(error Some mandatory headers ($(missing)) are missing in $(obj))
75endif
76endif
David Woodhousede789122006-09-24 22:15:14 +010077
78# Work out what needs to be removed
David Howells10b63952012-10-02 18:01:57 +010079oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
Sam Ravnborg77124012008-06-15 21:41:09 +020080unwanted := $(filter-out $(all-files),$(oldheaders))
David Woodhousede789122006-09-24 22:15:14 +010081
Sam Ravnborg77124012008-06-15 21:41:09 +020082# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
David Howells10b63952012-10-02 18:01:57 +010083unwanted-file := $(addprefix $(installdir)/, $(unwanted))
David Woodhousede789122006-09-24 22:15:14 +010084
Sam Ravnborg77124012008-06-15 21:41:09 +020085printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
David Woodhousede789122006-09-24 22:15:14 +010086
Sam Ravnborg77124012008-06-15 21:41:09 +020087quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
88 file$(if $(word 2, $(all-files)),s))
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020089 cmd_install = \
Nicolas Dichtel3b0fe0b2017-03-27 14:20:15 +020090 $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \
91 $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020092 for F in $(wrapper-files); do \
David Howells10b63952012-10-02 18:01:57 +010093 echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020094 done; \
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020095 touch $@
David Woodhouse8d730cf2006-06-18 11:58:39 +010096
Sam Ravnborg77124012008-06-15 21:41:09 +020097quiet_cmd_remove = REMOVE $(unwanted)
98 cmd_remove = rm -f $(unwanted-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010099
Sam Ravnborg77124012008-06-15 21:41:09 +0200100quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
Sergei Poselenov7211b8b2009-06-05 16:11:09 +0400101# Headers list can be pretty long, xargs helps to avoid
102# the "Argument list too long" error.
103 cmd_check = for f in $(all-files); do \
David Howells10b63952012-10-02 18:01:57 +0100104 echo "$(installdir)/$${f}"; done \
Sergei Poselenov7211b8b2009-06-05 16:11:09 +0400105 | xargs \
106 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
Sam Ravnborg77124012008-06-15 21:41:09 +0200107 touch $@
David Woodhouse68475352006-06-18 12:02:10 +0100108
Sam Ravnborg77124012008-06-15 21:41:09 +0200109ifndef HDRCHECK
110# Rules for installing headers
Masahiro Yamada59b85962017-05-16 14:15:03 +0900111__headers: $(install-file)
Sam Ravnborg77124012008-06-15 21:41:09 +0200112 @:
David Woodhousede789122006-09-24 22:15:14 +0100113
Sam Ravnborg77124012008-06-15 21:41:09 +0200114targets += $(install-file)
Nicolas Dichtel3b0fe0b2017-03-27 14:20:15 +0200115$(install-file): scripts/headers_install.sh \
116 $(addprefix $(srcdir)/,$(header-files)) \
117 $(addprefix $(gendir)/,$(genhdr-files)) FORCE
Sam Ravnborg77124012008-06-15 21:41:09 +0200118 $(if $(unwanted),$(call cmd,remove),)
119 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
120 $(call if_changed,install)
David Woodhousede789122006-09-24 22:15:14 +0100121
David Woodhouse68475352006-06-18 12:02:10 +0100122else
Masahiro Yamada59b85962017-05-16 14:15:03 +0900123__headers: $(check-file)
Sam Ravnborg77124012008-06-15 21:41:09 +0200124 @:
David Woodhouse8d730cf2006-06-18 11:58:39 +0100125
Sam Ravnborg77124012008-06-15 21:41:09 +0200126targets += $(check-file)
127$(check-file): scripts/headers_check.pl $(output-files) FORCE
128 $(call if_changed,check)
Sam Ravnborg4e420aa2008-06-05 16:52:15 +0200129
David Woodhouse8d730cf2006-06-18 11:58:39 +0100130endif
David Woodhouse8d730cf2006-06-18 11:58:39 +0100131
Sam Ravnborg77124012008-06-15 21:41:09 +0200132targets := $(wildcard $(sort $(targets)))
133cmd_files := $(wildcard \
134 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
135
136ifneq ($(cmd_files),)
137 include $(cmd_files)
138endif
139
Masahiro Yamada59b85962017-05-16 14:15:03 +0900140endif # skip-inst
141
Sam Ravnborg77124012008-06-15 21:41:09 +0200142.PHONY: $(PHONY)
143PHONY += FORCE
144FORCE: ;