blob: 99967948d764259228b50b7e8af8110eda5126a2 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
David Woodhouse8d730cf2006-06-18 11:58:39 +01002# ==========================================================================
3# Installing headers
4#
Nicolas Dichtelfcc84872017-03-27 14:20:15 +02005# All headers under include/uapi, include/generated/uapi,
Nicolas Dichtel61562f92017-03-27 14:20:16 +02006# arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are
Nicolas Dichtelfcc84872017-03-27 14:20:15 +02007# exported.
8# They are preprocessed to remove __KERNEL__ section of the file.
David Woodhouse8d730cf2006-06-18 11:58:39 +01009#
10# ==========================================================================
11
Masahiro Yamada05d8cba2017-05-16 14:15:03 +090012PHONY := __headers
13__headers:
14
15include scripts/Kbuild.include
16
17srcdir := $(srctree)/$(obj)
Richard Genoud2f263d12017-06-15 10:36:22 +020018
19# When make is run under a fakechroot environment, the function
20# $(wildcard $(srcdir)/*/.) doesn't only return directories, but also regular
21# files. So, we are using a combination of sort/dir/wildcard which works
22# with fakechroot.
23subdirs := $(patsubst $(srcdir)/%/,%,\
24 $(filter-out $(srcdir)/,\
25 $(sort $(dir $(wildcard $(srcdir)/*/)))))
26
Masahiro Yamada05d8cba2017-05-16 14:15:03 +090027# Recursion
28__headers: $(subdirs)
29
30.PHONY: $(subdirs)
31$(subdirs):
Masahiro Yamadaa8ff49a2017-07-10 03:32:35 +090032 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(dst)/$@
Masahiro Yamada05d8cba2017-05-16 14:15:03 +090033
34# Skip header install/check for include/uapi and arch/$(hdr-arch)/include/uapi.
35# We have only sub-directories there.
36skip-inst := $(if $(filter %/uapi,$(obj)),1)
37
38ifeq ($(skip-inst),)
39
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020040# Kbuild file is optional
Sam Ravnborg283039f2008-06-05 19:19:47 +020041kbuild-file := $(srctree)/$(obj)/Kbuild
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020042-include $(kbuild-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010043
Masahiro Yamadaa8ff49a2017-07-10 03:32:35 +090044installdir := $(INSTALL_HDR_PATH)/$(dst)
Masahiro Yamada87ebb942017-07-10 03:32:33 +090045gendir := $(objtree)/$(subst include/,include/generated/,$(obj))
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020046header-files := $(notdir $(wildcard $(srcdir)/*.h))
47header-files += $(notdir $(wildcard $(srcdir)/*.agh))
48header-files := $(filter-out $(no-export-headers), $(header-files))
49genhdr-files := $(notdir $(wildcard $(gendir)/*.h))
50genhdr-files := $(filter-out $(header-files), $(genhdr-files))
David Woodhouse8d730cf2006-06-18 11:58:39 +010051
Sam Ravnborg77124012008-06-15 21:41:09 +020052# files used to track state of install/check
David Howells10b63952012-10-02 18:01:57 +010053install-file := $(installdir)/.install
54check-file := $(installdir)/.check
Sam Ravnborg77124012008-06-15 21:41:09 +020055
56# all headers files for this dir
Masahiro Yamada09c37762017-07-10 03:33:00 +090057all-files := $(header-files) $(genhdr-files)
David Howells10b63952012-10-02 18:01:57 +010058output-files := $(addprefix $(installdir)/, $(all-files))
59
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020060ifneq ($(mandatory-y),)
61missing := $(filter-out $(all-files),$(mandatory-y))
62ifneq ($(missing),)
63$(error Some mandatory headers ($(missing)) are missing in $(obj))
64endif
65endif
David Woodhousede789122006-09-24 22:15:14 +010066
67# Work out what needs to be removed
David Howells10b63952012-10-02 18:01:57 +010068oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
Sam Ravnborg77124012008-06-15 21:41:09 +020069unwanted := $(filter-out $(all-files),$(oldheaders))
David Woodhousede789122006-09-24 22:15:14 +010070
Sam Ravnborg77124012008-06-15 21:41:09 +020071# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
David Howells10b63952012-10-02 18:01:57 +010072unwanted-file := $(addprefix $(installdir)/, $(unwanted))
David Woodhousede789122006-09-24 22:15:14 +010073
Sam Ravnborg77124012008-06-15 21:41:09 +020074printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
David Woodhousede789122006-09-24 22:15:14 +010075
Sam Ravnborg77124012008-06-15 21:41:09 +020076quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
77 file$(if $(word 2, $(all-files)),s))
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020078 cmd_install = \
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020079 $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \
80 $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020081 touch $@
David Woodhouse8d730cf2006-06-18 11:58:39 +010082
Sam Ravnborg77124012008-06-15 21:41:09 +020083quiet_cmd_remove = REMOVE $(unwanted)
84 cmd_remove = rm -f $(unwanted-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010085
Sam Ravnborg77124012008-06-15 21:41:09 +020086quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
Sergei Poselenov7211b8b2009-06-05 16:11:09 +040087# Headers list can be pretty long, xargs helps to avoid
88# the "Argument list too long" error.
89 cmd_check = for f in $(all-files); do \
David Howells10b63952012-10-02 18:01:57 +010090 echo "$(installdir)/$${f}"; done \
Sergei Poselenov7211b8b2009-06-05 16:11:09 +040091 | xargs \
92 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
Sam Ravnborg77124012008-06-15 21:41:09 +020093 touch $@
David Woodhouse68475352006-06-18 12:02:10 +010094
Sam Ravnborg77124012008-06-15 21:41:09 +020095ifndef HDRCHECK
96# Rules for installing headers
Masahiro Yamada05d8cba2017-05-16 14:15:03 +090097__headers: $(install-file)
Sam Ravnborg77124012008-06-15 21:41:09 +020098 @:
David Woodhousede789122006-09-24 22:15:14 +010099
Sam Ravnborg77124012008-06-15 21:41:09 +0200100targets += $(install-file)
Nicolas Dichtel7c025b22017-03-27 14:20:09 +0200101$(install-file): scripts/headers_install.sh \
Nicolas Dichtelfcc84872017-03-27 14:20:15 +0200102 $(addprefix $(srcdir)/,$(header-files)) \
103 $(addprefix $(gendir)/,$(genhdr-files)) FORCE
Sam Ravnborg77124012008-06-15 21:41:09 +0200104 $(if $(unwanted),$(call cmd,remove),)
105 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
106 $(call if_changed,install)
David Woodhousede789122006-09-24 22:15:14 +0100107
David Woodhouse68475352006-06-18 12:02:10 +0100108else
Masahiro Yamada05d8cba2017-05-16 14:15:03 +0900109__headers: $(check-file)
Sam Ravnborg77124012008-06-15 21:41:09 +0200110 @:
David Woodhouse8d730cf2006-06-18 11:58:39 +0100111
Sam Ravnborg77124012008-06-15 21:41:09 +0200112targets += $(check-file)
113$(check-file): scripts/headers_check.pl $(output-files) FORCE
114 $(call if_changed,check)
Sam Ravnborg4e420aa2008-06-05 16:52:15 +0200115
David Woodhouse8d730cf2006-06-18 11:58:39 +0100116endif
David Woodhouse8d730cf2006-06-18 11:58:39 +0100117
Sam Ravnborg77124012008-06-15 21:41:09 +0200118targets := $(wildcard $(sort $(targets)))
119cmd_files := $(wildcard \
120 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
121
122ifneq ($(cmd_files),)
123 include $(cmd_files)
124endif
125
Masahiro Yamada05d8cba2017-05-16 14:15:03 +0900126endif # skip-inst
127
Sam Ravnborg77124012008-06-15 21:41:09 +0200128.PHONY: $(PHONY)
129PHONY += FORCE
130FORCE: ;