blob: c583a1e1bd3c16356cf67a772a3e680adec9681a [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)
Richard Genoud2f263d12017-06-15 10:36:22 +020017
18# When make is run under a fakechroot environment, the function
19# $(wildcard $(srcdir)/*/.) doesn't only return directories, but also regular
20# files. So, we are using a combination of sort/dir/wildcard which works
21# with fakechroot.
22subdirs := $(patsubst $(srcdir)/%/,%,\
23 $(filter-out $(srcdir)/,\
24 $(sort $(dir $(wildcard $(srcdir)/*/)))))
25
Masahiro Yamada05d8cba2017-05-16 14:15:03 +090026# caller may set destination dir (when installing to asm/)
27_dst := $(if $(dst),$(dst),$(obj))
28
29# Recursion
30__headers: $(subdirs)
31
32.PHONY: $(subdirs)
33$(subdirs):
34 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
35
36# Skip header install/check for include/uapi and arch/$(hdr-arch)/include/uapi.
37# We have only sub-directories there.
38skip-inst := $(if $(filter %/uapi,$(obj)),1)
39
40ifeq ($(skip-inst),)
41
H. Peter Anvincb979142011-11-11 15:20:34 -080042# generated header directory
43gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj)))
44
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020045# Kbuild file is optional
Sam Ravnborg283039f2008-06-05 19:19:47 +020046kbuild-file := $(srctree)/$(obj)/Kbuild
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020047-include $(kbuild-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010048
David Howells10b63952012-10-02 18:01:57 +010049old-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild
50ifneq ($(wildcard $(old-kbuild-file)),)
51include $(old-kbuild-file)
52endif
Sam Ravnborgc7bb3492009-04-10 08:52:43 +020053
David Howells10b63952012-10-02 18:01:57 +010054installdir := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst))
Sam Ravnborg62284a32008-06-07 13:18:26 +020055
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020056gendir := $(objtree)/$(gen)
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020057header-files := $(notdir $(wildcard $(srcdir)/*.h))
58header-files += $(notdir $(wildcard $(srcdir)/*.agh))
59header-files := $(filter-out $(no-export-headers), $(header-files))
60genhdr-files := $(notdir $(wildcard $(gendir)/*.h))
61genhdr-files := $(filter-out $(header-files), $(genhdr-files))
David Woodhouse8d730cf2006-06-18 11:58:39 +010062
Sam Ravnborg77124012008-06-15 21:41:09 +020063# files used to track state of install/check
David Howells10b63952012-10-02 18:01:57 +010064install-file := $(installdir)/.install
65check-file := $(installdir)/.check
Sam Ravnborg77124012008-06-15 21:41:09 +020066
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020067# generic-y list all files an architecture uses from asm-generic
68# Use this to build a list of headers which require a wrapper
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020069generic-files := $(notdir $(wildcard $(srctree)/include/uapi/asm-generic/*.h))
70wrapper-files := $(filter $(generic-files), $(generic-y))
71wrapper-files := $(filter-out $(header-files), $(wrapper-files))
David Howells10b63952012-10-02 18:01:57 +010072
Sam Ravnborg77124012008-06-15 21:41:09 +020073# all headers files for this dir
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020074all-files := $(header-files) $(genhdr-files) $(wrapper-files)
David Howells10b63952012-10-02 18:01:57 +010075output-files := $(addprefix $(installdir)/, $(all-files))
76
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020077ifneq ($(mandatory-y),)
78missing := $(filter-out $(all-files),$(mandatory-y))
79ifneq ($(missing),)
80$(error Some mandatory headers ($(missing)) are missing in $(obj))
81endif
82endif
David Woodhousede789122006-09-24 22:15:14 +010083
84# Work out what needs to be removed
David Howells10b63952012-10-02 18:01:57 +010085oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
Sam Ravnborg77124012008-06-15 21:41:09 +020086unwanted := $(filter-out $(all-files),$(oldheaders))
David Woodhousede789122006-09-24 22:15:14 +010087
Sam Ravnborg77124012008-06-15 21:41:09 +020088# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
David Howells10b63952012-10-02 18:01:57 +010089unwanted-file := $(addprefix $(installdir)/, $(unwanted))
David Woodhousede789122006-09-24 22:15:14 +010090
Sam Ravnborg77124012008-06-15 21:41:09 +020091printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
David Woodhousede789122006-09-24 22:15:14 +010092
Sam Ravnborg77124012008-06-15 21:41:09 +020093quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
94 file$(if $(word 2, $(all-files)),s))
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020095 cmd_install = \
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020096 $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \
97 $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020098 for F in $(wrapper-files); do \
David Howells10b63952012-10-02 18:01:57 +010099 echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +0200100 done; \
Sam Ravnborgdb1bec42008-06-16 21:29:38 +0200101 touch $@
David Woodhouse8d730cf2006-06-18 11:58:39 +0100102
Sam Ravnborg77124012008-06-15 21:41:09 +0200103quiet_cmd_remove = REMOVE $(unwanted)
104 cmd_remove = rm -f $(unwanted-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +0100105
Sam Ravnborg77124012008-06-15 21:41:09 +0200106quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
Sergei Poselenov7211b8b2009-06-05 16:11:09 +0400107# Headers list can be pretty long, xargs helps to avoid
108# the "Argument list too long" error.
109 cmd_check = for f in $(all-files); do \
David Howells10b63952012-10-02 18:01:57 +0100110 echo "$(installdir)/$${f}"; done \
Sergei Poselenov7211b8b2009-06-05 16:11:09 +0400111 | xargs \
112 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
Sam Ravnborg77124012008-06-15 21:41:09 +0200113 touch $@
David Woodhouse68475352006-06-18 12:02:10 +0100114
Sam Ravnborg77124012008-06-15 21:41:09 +0200115ifndef HDRCHECK
116# Rules for installing headers
Masahiro Yamada05d8cba2017-05-16 14:15:03 +0900117__headers: $(install-file)
Sam Ravnborg77124012008-06-15 21:41:09 +0200118 @:
David Woodhousede789122006-09-24 22:15:14 +0100119
Sam Ravnborg77124012008-06-15 21:41:09 +0200120targets += $(install-file)
Nicolas Dichtel7c025b22017-03-27 14:20:09 +0200121$(install-file): scripts/headers_install.sh \
Nicolas Dichtelfcc84872017-03-27 14:20:15 +0200122 $(addprefix $(srcdir)/,$(header-files)) \
123 $(addprefix $(gendir)/,$(genhdr-files)) FORCE
Sam Ravnborg77124012008-06-15 21:41:09 +0200124 $(if $(unwanted),$(call cmd,remove),)
125 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
126 $(call if_changed,install)
David Woodhousede789122006-09-24 22:15:14 +0100127
David Woodhouse68475352006-06-18 12:02:10 +0100128else
Masahiro Yamada05d8cba2017-05-16 14:15:03 +0900129__headers: $(check-file)
Sam Ravnborg77124012008-06-15 21:41:09 +0200130 @:
David Woodhouse8d730cf2006-06-18 11:58:39 +0100131
Sam Ravnborg77124012008-06-15 21:41:09 +0200132targets += $(check-file)
133$(check-file): scripts/headers_check.pl $(output-files) FORCE
134 $(call if_changed,check)
Sam Ravnborg4e420aa2008-06-05 16:52:15 +0200135
David Woodhouse8d730cf2006-06-18 11:58:39 +0100136endif
David Woodhouse8d730cf2006-06-18 11:58:39 +0100137
Sam Ravnborg77124012008-06-15 21:41:09 +0200138targets := $(wildcard $(sort $(targets)))
139cmd_files := $(wildcard \
140 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
141
142ifneq ($(cmd_files),)
143 include $(cmd_files)
144endif
145
Masahiro Yamada05d8cba2017-05-16 14:15:03 +0900146endif # skip-inst
147
Sam Ravnborg77124012008-06-15 21:41:09 +0200148.PHONY: $(PHONY)
149PHONY += FORCE
150FORCE: ;