blob: ce753a408c56823dbd1c4b5d4fb5cfe88e7054c4 [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
Masahiro Yamada05d8cba2017-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 Dichtelfcc84872017-03-27 14:20:15 +020037# Kbuild file is optional
Sam Ravnborg283039f2008-06-05 19:19:47 +020038kbuild-file := $(srctree)/$(obj)/Kbuild
Nicolas Dichtelfcc84872017-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 Dichtelfcc84872017-03-27 14:20:15 +020048gendir := $(objtree)/$(gen)
Nicolas Dichtelfcc84872017-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 Dichtelfcc84872017-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
Sam Ravnborg77124012008-06-15 21:41:09 +020065# all headers files for this dir
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020066all-files := $(header-files) $(genhdr-files) $(wrapper-files)
David Howells10b63952012-10-02 18:01:57 +010067output-files := $(addprefix $(installdir)/, $(all-files))
68
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020069ifneq ($(mandatory-y),)
70missing := $(filter-out $(all-files),$(mandatory-y))
71ifneq ($(missing),)
72$(error Some mandatory headers ($(missing)) are missing in $(obj))
73endif
74endif
David Woodhousede789122006-09-24 22:15:14 +010075
76# Work out what needs to be removed
David Howells10b63952012-10-02 18:01:57 +010077oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
Sam Ravnborg77124012008-06-15 21:41:09 +020078unwanted := $(filter-out $(all-files),$(oldheaders))
David Woodhousede789122006-09-24 22:15:14 +010079
Sam Ravnborg77124012008-06-15 21:41:09 +020080# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
David Howells10b63952012-10-02 18:01:57 +010081unwanted-file := $(addprefix $(installdir)/, $(unwanted))
David Woodhousede789122006-09-24 22:15:14 +010082
Sam Ravnborg77124012008-06-15 21:41:09 +020083printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
David Woodhousede789122006-09-24 22:15:14 +010084
Sam Ravnborg77124012008-06-15 21:41:09 +020085quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
86 file$(if $(word 2, $(all-files)),s))
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020087 cmd_install = \
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020088 $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \
89 $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020090 for F in $(wrapper-files); do \
David Howells10b63952012-10-02 18:01:57 +010091 echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020092 done; \
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020093 touch $@
David Woodhouse8d730cf2006-06-18 11:58:39 +010094
Sam Ravnborg77124012008-06-15 21:41:09 +020095quiet_cmd_remove = REMOVE $(unwanted)
96 cmd_remove = rm -f $(unwanted-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010097
Sam Ravnborg77124012008-06-15 21:41:09 +020098quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
Sergei Poselenov7211b8b2009-06-05 16:11:09 +040099# Headers list can be pretty long, xargs helps to avoid
100# the "Argument list too long" error.
101 cmd_check = for f in $(all-files); do \
David Howells10b63952012-10-02 18:01:57 +0100102 echo "$(installdir)/$${f}"; done \
Sergei Poselenov7211b8b2009-06-05 16:11:09 +0400103 | xargs \
104 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
Sam Ravnborg77124012008-06-15 21:41:09 +0200105 touch $@
David Woodhouse68475352006-06-18 12:02:10 +0100106
Sam Ravnborg77124012008-06-15 21:41:09 +0200107ifndef HDRCHECK
108# Rules for installing headers
Masahiro Yamada05d8cba2017-05-16 14:15:03 +0900109__headers: $(install-file)
Sam Ravnborg77124012008-06-15 21:41:09 +0200110 @:
David Woodhousede789122006-09-24 22:15:14 +0100111
Sam Ravnborg77124012008-06-15 21:41:09 +0200112targets += $(install-file)
Nicolas Dichtel7c025b22017-03-27 14:20:09 +0200113$(install-file): scripts/headers_install.sh \
Nicolas Dichtelfcc84872017-03-27 14:20:15 +0200114 $(addprefix $(srcdir)/,$(header-files)) \
115 $(addprefix $(gendir)/,$(genhdr-files)) FORCE
Sam Ravnborg77124012008-06-15 21:41:09 +0200116 $(if $(unwanted),$(call cmd,remove),)
117 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
118 $(call if_changed,install)
David Woodhousede789122006-09-24 22:15:14 +0100119
David Woodhouse68475352006-06-18 12:02:10 +0100120else
Masahiro Yamada05d8cba2017-05-16 14:15:03 +0900121__headers: $(check-file)
Sam Ravnborg77124012008-06-15 21:41:09 +0200122 @:
David Woodhouse8d730cf2006-06-18 11:58:39 +0100123
Sam Ravnborg77124012008-06-15 21:41:09 +0200124targets += $(check-file)
125$(check-file): scripts/headers_check.pl $(output-files) FORCE
126 $(call if_changed,check)
Sam Ravnborg4e420aa2008-06-05 16:52:15 +0200127
David Woodhouse8d730cf2006-06-18 11:58:39 +0100128endif
David Woodhouse8d730cf2006-06-18 11:58:39 +0100129
Sam Ravnborg77124012008-06-15 21:41:09 +0200130targets := $(wildcard $(sort $(targets)))
131cmd_files := $(wildcard \
132 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
133
134ifneq ($(cmd_files),)
135 include $(cmd_files)
136endif
137
Masahiro Yamada05d8cba2017-05-16 14:15:03 +0900138endif # skip-inst
139
Sam Ravnborg77124012008-06-15 21:41:09 +0200140.PHONY: $(PHONY)
141PHONY += FORCE
142FORCE: ;