xref: /linux/scripts/Makefile.headersinst (revision 4e420aa94c9e6974533797efd1dd93e779d490c3)
1# ==========================================================================
2# Installing headers
3#
4# header-y files will be installed verbatim
5# unifdef-y are the files where unifdef will be run before installing files
6# objhdr-y are generated files that will be installed verbatim
7#
8# ==========================================================================
9
10UNIFDEF := scripts/unifdef -U__KERNEL__
11
12# Eliminate the contents of (and inclusions of) compiler.h
13HDRSED  := sed 	-e "s/ inline / __inline__ /g" \
14		-e "s/[[:space:]]__user[[:space:]]\{1,\}/ /g" \
15		-e "s/(__user[[:space:]]\{1,\}/ (/g" \
16		-e "s/[[:space:]]__force[[:space:]]\{1,\}/ /g" \
17		-e "s/(__force[[:space:]]\{1,\}/ (/g" \
18		-e "s/[[:space:]]__iomem[[:space:]]\{1,\}/ /g" \
19		-e "s/(__iomem[[:space:]]\{1,\}/ (/g" \
20		-e "s/[[:space:]]__attribute_const__[[:space:]]\{1,\}/\ /g" \
21		-e "s/[[:space:]]__attribute_const__$$//" \
22		-e "/^\#include <linux\/compiler.h>/d"
23
24_dst := $(if $(dst),$(dst),$(obj))
25
26ifeq (,$(patsubst include/asm/%,,$(obj)/))
27# For producing the generated stuff in include/asm for biarch builds, include
28# both sets of Kbuild files; we'll generate anything which is mentioned in
29# _either_ arch, and recurse into subdirectories which are mentioned in either
30# arch. Since some directories may exist in one but not the other, we must
31# use $(wildcard...).
32GENASM := 1
33archasm	   := $(subst include/asm,asm-$(ARCH),$(obj))
34altarchasm := $(subst include/asm,asm-$(ALTARCH),$(obj))
35KBUILDFILES := $(wildcard $(srctree)/include/$(archasm)/Kbuild $(srctree)/include/$(altarchasm)/Kbuild)
36else
37KBUILDFILES := $(srctree)/$(obj)/Kbuild
38endif
39
40include $(KBUILDFILES)
41
42include scripts/Kbuild.include
43
44# If this is include/asm-$(ARCH) and there's no $(ALTARCH), then
45# override $(_dst) so that we install to include/asm directly.
46# Unless $(BIASMDIR) is set, in which case we're probably doing
47# a 'headers_install_all' build and we should keep the -$(ARCH)
48# in the directory name.
49ifeq ($(obj)$(ALTARCH),include/asm-$(ARCH)$(BIASMDIR))
50     _dst := include/asm
51endif
52
53header-y	:= $(sort $(header-y) $(unifdef-y))
54subdir-y	:= $(patsubst %/,%,$(filter %/, $(header-y)))
55header-y	:= $(filter-out %/, $(header-y))
56
57# stamp files for header checks
58check-y		:= $(patsubst %,.check.%,$(header-y) $(objhdr-y))
59
60# Work out what needs to be removed
61oldheaders	:= $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$(wildcard $(INSTALL_HDR_PATH)/$(_dst)/*.h))
62unwanted	:= $(filter-out $(header-y) $(objhdr-y),$(oldheaders))
63
64oldcheckstamps	:= $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$(wildcard $(INSTALL_HDR_PATH)/$(_dst)/.check.*.h))
65unwanted	+= $(filter-out $(check-y),$(oldcheckstamps))
66
67# Prefix them all with full paths to $(INSTALL_HDR_PATH)
68header-y 	:= $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(header-y))
69objhdr-y 	:= $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(objhdr-y))
70check-y 	:= $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(check-y))
71
72
73ifdef ALTARCH
74ifeq ($(obj),include/asm-$(ARCH))
75altarch-y	:= altarch-dir
76endif
77endif
78
79# Make the definitions visible for recursive make invocations
80export ALTARCH
81export ARCHDEF
82export ALTARCHDEF
83
84quiet_cmd_o_hdr_install   = INSTALL $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
85      cmd_o_hdr_install   = cp $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,$(objtree)/$(obj)/%,$@) \
86			    $(INSTALL_HDR_PATH)/$(_dst)
87
88quiet_cmd_unifdef	  = UNIFDEF $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
89      cmd_unifdef	  = $(UNIFDEF) $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,$(srctree)/$(obj)/%,$@) \
90				   | $(HDRSED) > $@ || :
91
92quiet_cmd_check		  = CHECK   $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/.check.%,$(_dst)/%,$@)
93      cmd_check		  = $(CONFIG_SHELL) $(srctree)/scripts/hdrcheck.sh \
94                              $(INSTALL_HDR_PATH)/include $(subst /.check.,/,$@) $@
95
96quiet_cmd_remove	  = REMOVE  $(_dst)/$@
97      cmd_remove	  = rm -f $(INSTALL_HDR_PATH)/$(_dst)/$@
98
99quiet_cmd_mkdir		  = MKDIR   $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
100      cmd_mkdir		  = mkdir -p $@
101
102quiet_cmd_gen		  = GEN     $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
103      cmd_gen		  = \
104FNAME=$(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$@);			\
105STUBDEF=__ASM_STUB_`echo $$FNAME | tr a-z.- A-Z__`;			\
106(echo "/* File autogenerated by 'make headers_install' */" ;		\
107echo "\#ifndef $$STUBDEF" ;						\
108echo "\#define $$STUBDEF" ;						\
109echo "\# if $(ARCHDEF)" ;						\
110if [ -r $(subst /$(_dst)/,/include/$(archasm)/,$@) ]; then		\
111	echo "\#  include <$(archasm)/$$FNAME>" ;			\
112else									\
113	echo "\#  error $(archasm)/$$FNAME does not exist in"		\
114			"the $(ARCH) architecture" ;			\
115fi ;									\
116echo "\# elif $(ALTARCHDEF)" ;						\
117if [ -r $(subst /$(_dst)/,/include/$(altarchasm)/,$@) ]; then		\
118	echo "\#  include <$(altarchasm)/$$FNAME>" ;			\
119else									\
120	echo "\#  error $(altarchasm)/$$FNAME does not exist in"	\
121			"the $(ALTARCH) architecture" ;			\
122fi ;									\
123echo "\# else" ;							\
124echo "\#  warning This machine appears to be"				\
125		 "neither $(ARCH) nor $(ALTARCH)." ;			\
126echo "\# endif" ;							\
127echo "\#endif /* $$STUBDEF */" ;					\
128) > $@
129
130.PHONY: __headersinst __headerscheck
131
132ifdef HDRCHECK
133__headerscheck: $(subdir-y) $(check-y)
134	@true
135
136$(check-y) : $(INSTALL_HDR_PATH)/$(_dst)/.check.%.h : $(INSTALL_HDR_PATH)/$(_dst)/%.h
137	$(call cmd,check)
138
139# Other dependencies for $(check-y)
140include /dev/null $(wildcard $(check-y))
141
142# ... but leave $(check-y) as .PHONY for now until those deps are actually correct.
143.PHONY: $(check-y)
144
145else
146# Rules for installing headers
147__headersinst: $(subdir-y) $(header-y) $(altarch-y) $(objhdr-y)
148	@true
149
150$(objhdr-y) $(subdir-y) $(header-y): | $(INSTALL_HDR_PATH)/$(_dst) $(unwanted)
151
152$(INSTALL_HDR_PATH)/$(_dst):
153	$(call cmd,mkdir)
154
155.PHONY: $(unwanted)
156$(unwanted):
157	$(call cmd,remove)
158
159ifdef GENASM
160$(objhdr-y) $(header-y): $(KBUILDFILES)
161	$(call cmd,gen)
162
163else
164$(objhdr-y): $(INSTALL_HDR_PATH)/$(_dst)/%.h: $(objtree)/$(obj)/%.h $(KBUILDFILES)
165	$(call cmd,o_hdr_install)
166
167$(header-y): $(INSTALL_HDR_PATH)/$(_dst)/%.h: $(srctree)/$(obj)/%.h $(KBUILDFILES)
168	$(call cmd,unifdef)
169
170endif
171endif
172
173hdrinst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
174
175.PHONY: altarch-dir
176# All the files in the normal arch dir must be created first, since we test
177# for their existence.
178altarch-dir: $(subdir-y) $(header-y) $(objhdr-y)
179	$(Q)$(MAKE) $(hdrinst)=include/asm-$(ALTARCH) dst=include/asm-$(ALTARCH)
180	$(Q)$(MAKE) $(hdrinst)=include/asm dst=include/asm$(BIASMDIR)
181
182# Recursion
183.PHONY: $(subdir-y)
184$(subdir-y):
185	$(Q)$(MAKE) $(hdrinst)=$(obj)/$@ dst=$(_dst)/$@ rel=../$(rel)
186