blob: c6fb2b75d81308abc67143470d3d77ab429e8383 [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# Recursion
27__headers: $(subdirs)
28
29.PHONY: $(subdirs)
30$(subdirs):
Masahiro Yamadaa8ff49a2017-07-10 03:32:35 +090031 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(dst)/$@
Masahiro Yamada05d8cba2017-05-16 14:15:03 +090032
Masahiro Yamada9d022c52017-10-04 12:56:04 +090033# Skip header install/check for include/uapi and arch/$(SRCARCH)/include/uapi.
Masahiro Yamada05d8cba2017-05-16 14:15:03 +090034# We have only sub-directories there.
35skip-inst := $(if $(filter %/uapi,$(obj)),1)
36
37ifeq ($(skip-inst),)
38
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020039# Kbuild file is optional
Sam Ravnborg283039f2008-06-05 19:19:47 +020040kbuild-file := $(srctree)/$(obj)/Kbuild
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020041-include $(kbuild-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010042
Masahiro Yamadaa8ff49a2017-07-10 03:32:35 +090043installdir := $(INSTALL_HDR_PATH)/$(dst)
Masahiro Yamada87ebb942017-07-10 03:32:33 +090044gendir := $(objtree)/$(subst include/,include/generated/,$(obj))
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020045header-files := $(notdir $(wildcard $(srcdir)/*.h))
46header-files += $(notdir $(wildcard $(srcdir)/*.agh))
47header-files := $(filter-out $(no-export-headers), $(header-files))
48genhdr-files := $(notdir $(wildcard $(gendir)/*.h))
49genhdr-files := $(filter-out $(header-files), $(genhdr-files))
David Woodhouse8d730cf2006-06-18 11:58:39 +010050
Sam Ravnborg77124012008-06-15 21:41:09 +020051# files used to track state of install/check
David Howells10b63952012-10-02 18:01:57 +010052install-file := $(installdir)/.install
53check-file := $(installdir)/.check
Sam Ravnborg77124012008-06-15 21:41:09 +020054
55# all headers files for this dir
Masahiro Yamada09c37762017-07-10 03:33:00 +090056all-files := $(header-files) $(genhdr-files)
David Howells10b63952012-10-02 18:01:57 +010057output-files := $(addprefix $(installdir)/, $(all-files))
58
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020059ifneq ($(mandatory-y),)
60missing := $(filter-out $(all-files),$(mandatory-y))
61ifneq ($(missing),)
62$(error Some mandatory headers ($(missing)) are missing in $(obj))
63endif
64endif
David Woodhousede789122006-09-24 22:15:14 +010065
66# Work out what needs to be removed
David Howells10b63952012-10-02 18:01:57 +010067oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
Sam Ravnborg77124012008-06-15 21:41:09 +020068unwanted := $(filter-out $(all-files),$(oldheaders))
David Woodhousede789122006-09-24 22:15:14 +010069
Sam Ravnborg77124012008-06-15 21:41:09 +020070# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
David Howells10b63952012-10-02 18:01:57 +010071unwanted-file := $(addprefix $(installdir)/, $(unwanted))
David Woodhousede789122006-09-24 22:15:14 +010072
Sam Ravnborg77124012008-06-15 21:41:09 +020073printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
David Woodhousede789122006-09-24 22:15:14 +010074
Sam Ravnborg77124012008-06-15 21:41:09 +020075quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
76 file$(if $(word 2, $(all-files)),s))
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020077 cmd_install = \
Nicolas Dichtelfcc84872017-03-27 14:20:15 +020078 $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \
79 $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020080 touch $@
David Woodhouse8d730cf2006-06-18 11:58:39 +010081
Sam Ravnborg77124012008-06-15 21:41:09 +020082quiet_cmd_remove = REMOVE $(unwanted)
83 cmd_remove = rm -f $(unwanted-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010084
Sam Ravnborg77124012008-06-15 21:41:09 +020085quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
Sergei Poselenov7211b8b2009-06-05 16:11:09 +040086# Headers list can be pretty long, xargs helps to avoid
87# the "Argument list too long" error.
88 cmd_check = for f in $(all-files); do \
David Howells10b63952012-10-02 18:01:57 +010089 echo "$(installdir)/$${f}"; done \
Sergei Poselenov7211b8b2009-06-05 16:11:09 +040090 | xargs \
91 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
Sam Ravnborg77124012008-06-15 21:41:09 +020092 touch $@
David Woodhouse68475352006-06-18 12:02:10 +010093
Sam Ravnborg77124012008-06-15 21:41:09 +020094ifndef HDRCHECK
95# Rules for installing headers
Masahiro Yamada05d8cba2017-05-16 14:15:03 +090096__headers: $(install-file)
Sam Ravnborg77124012008-06-15 21:41:09 +020097 @:
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
Masahiro Yamada05d8cba2017-05-16 14:15:03 +0900108__headers: $(check-file)
Sam Ravnborg77124012008-06-15 21:41:09 +0200109 @:
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
Sam Ravnborg77124012008-06-15 21:41:09 +0200117cmd_files := $(wildcard \
Masahiro Yamada2982c952017-11-13 19:29:35 +0900118 $(foreach f,$(sort $(targets)),$(dir $(f)).$(notdir $(f)).cmd))
Sam Ravnborg77124012008-06-15 21:41:09 +0200119
120ifneq ($(cmd_files),)
121 include $(cmd_files)
122endif
123
Masahiro Yamada05d8cba2017-05-16 14:15:03 +0900124endif # skip-inst
125
Sam Ravnborg77124012008-06-15 21:41:09 +0200126.PHONY: $(PHONY)
127PHONY += FORCE
128FORCE: ;