Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1# ==========================================================================
2# Installing headers
3#
4# All headers under include/uapi, include/generated/uapi,
5# arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are
6# exported.
7# They are preprocessed to remove __KERNEL__ section of the file.
8#
9# ==========================================================================
10
11# generated header directory
12gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj)))
13
14# Kbuild file is optional
15kbuild-file := $(srctree)/$(obj)/Kbuild
16-include $(kbuild-file)
17
18# called may set destination dir (when installing to asm/)
19_dst := $(if $(dst),$(dst),$(obj))
20
21old-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild
22ifneq ($(wildcard $(old-kbuild-file)),)
23include $(old-kbuild-file)
24endif
25
26include scripts/Kbuild.include
27
28installdir := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst))
29
30srcdir := $(srctree)/$(obj)
31gendir := $(objtree)/$(gen)
32subdirs := $(patsubst $(srcdir)/%/.,%,$(wildcard $(srcdir)/*/.))
33header-files := $(notdir $(wildcard $(srcdir)/*.h))
34header-files += $(notdir $(wildcard $(srcdir)/*.agh))
35header-files := $(filter-out $(no-export-headers), $(header-files))
36genhdr-files := $(notdir $(wildcard $(gendir)/*.h))
37genhdr-files := $(filter-out $(header-files), $(genhdr-files))
38
39# files used to track state of install/check
40install-file := $(installdir)/.install
41check-file := $(installdir)/.check
42
43# generic-y list all files an architecture uses from asm-generic
44# Use this to build a list of headers which require a wrapper
45generic-files := $(notdir $(wildcard $(srctree)/include/uapi/asm-generic/*.h))
46wrapper-files := $(filter $(generic-files), $(generic-y))
47wrapper-files := $(filter-out $(header-files), $(wrapper-files))
48
49# all headers files for this dir
50all-files := $(header-files) $(genhdr-files) $(wrapper-files)
51output-files := $(addprefix $(installdir)/, $(all-files))
52
53ifneq ($(mandatory-y),)
54missing := $(filter-out $(all-files),$(mandatory-y))
55ifneq ($(missing),)
56$(error Some mandatory headers ($(missing)) are missing in $(obj))
57endif
58endif
59
60# Work out what needs to be removed
61oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
62unwanted := $(filter-out $(all-files),$(oldheaders))
63
64# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
65unwanted-file := $(addprefix $(installdir)/, $(unwanted))
66
67printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
68
69quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
70 file$(if $(word 2, $(all-files)),s))
71 cmd_install = \
72 $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \
73 $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \
74 for F in $(wrapper-files); do \
75 echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \
76 done; \
77 touch $@
78
79quiet_cmd_remove = REMOVE $(unwanted)
80 cmd_remove = rm -f $(unwanted-file)
81
82quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
83# Headers list can be pretty long, xargs helps to avoid
84# the "Argument list too long" error.
85 cmd_check = for f in $(all-files); do \
86 echo "$(installdir)/$${f}"; done \
87 | xargs \
88 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
89 touch $@
90
91PHONY += __headersinst __headerscheck
92
93ifndef HDRCHECK
94# Rules for installing headers
95__headersinst: $(subdirs) $(install-file)
96 @:
97
98targets += $(install-file)
99$(install-file): scripts/headers_install.sh \
100 $(addprefix $(srcdir)/,$(header-files)) \
101 $(addprefix $(gendir)/,$(genhdr-files)) FORCE
102 $(if $(unwanted),$(call cmd,remove),)
103 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
104 $(call if_changed,install)
105
106else
107__headerscheck: $(subdirs) $(check-file)
108 @:
109
110targets += $(check-file)
111$(check-file): scripts/headers_check.pl $(output-files) FORCE
112 $(call if_changed,check)
113
114endif
115
116# Recursion
117.PHONY: $(subdirs)
118$(subdirs):
119 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
120
121targets := $(wildcard $(sort $(targets)))
122cmd_files := $(wildcard \
123 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
124
125ifneq ($(cmd_files),)
126 include $(cmd_files)
127endif
128
129.PHONY: $(PHONY)
130PHONY += FORCE
131FORCE: ;