1 # ==========================================================================
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
8 # ==========================================================================
10 UNIFDEF := scripts/unifdef -U__KERNEL__
12 # Eliminate the contents of (and inclusions of) compiler.h
13 HDRSED := sed -e "s/ inline / __inline__ /g" \
14 -e "s/[[:space:]]__user[[:space:]]\+/ /g" \
15 -e "s/(__user[[:space:]]\+/ (/g" \
16 -e "s/[[:space:]]__force[[:space:]]\+/ /g" \
17 -e "s/(__force[[:space:]]\+/ (/g" \
18 -e "s/[[:space:]]__iomem[[:space:]]\+/ /g" \
19 -e "s/(__iomem[[:space:]]\+/ (/g" \
20 -e "s/[[:space:]]__attribute_const__[[:space:]]\+/\ /g" \
21 -e "s/[[:space:]]__attribute_const__$$//" \
22 -e "/^\#include <linux\/compiler.h>/d"
24 _dst := $(if $(dst),$(dst),$(obj))
26 ifeq (,$(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
33 archasm := $(subst include/asm,asm-$(ARCH),$(obj))
34 altarchasm := $(subst include/asm,asm-$(ALTARCH),$(obj))
35 KBUILDFILES := $(wildcard $(srctree)/include/$(archasm)/Kbuild $(srctree)/include/$(altarchasm)/Kbuild)
37 KBUILDFILES := $(srctree)/$(obj)/Kbuild
40 include $(KBUILDFILES)
42 include scripts/Kbuild.include
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.
49 ifeq ($(obj)$(ALTARCH),include/asm-$(ARCH)$(BIASMDIR))
53 header-y := $(sort $(header-y))
54 unifdef-y := $(sort $(unifdef-y))
55 subdir-y := $(patsubst %/,%,$(filter %/, $(header-y)))
56 header-y := $(filter-out %/, $(header-y))
57 header-y := $(filter-out $(unifdef-y),$(header-y))
59 # stamp files for header checks
60 check-y := $(patsubst %,.check.%,$(header-y) $(unifdef-y) $(objhdr-y))
62 # Work out what needs to be removed
63 oldheaders := $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$(wildcard $(INSTALL_HDR_PATH)/$(_dst)/*.h))
64 unwanted := $(filter-out $(header-y) $(unifdef-y) $(objhdr-y),$(oldheaders))
66 oldcheckstamps := $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$(wildcard $(INSTALL_HDR_PATH)/$(_dst)/.check.*.h))
67 unwanted += $(filter-out $(check-y),$(oldcheckstamps))
69 # Prefix them all with full paths to $(INSTALL_HDR_PATH)
70 header-y := $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(header-y))
71 unifdef-y := $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(unifdef-y))
72 objhdr-y := $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(objhdr-y))
73 check-y := $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(check-y))
77 ifeq ($(obj),include/asm-$(ARCH))
78 altarch-y := altarch-dir
82 # Make the definitions visible for recursive make invocations
87 quiet_cmd_o_hdr_install = INSTALL $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
88 cmd_o_hdr_install = cp $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,$(objtree)/$(obj)/%,$@) \
89 $(INSTALL_HDR_PATH)/$(_dst)
91 quiet_cmd_headers_install = INSTALL $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
92 cmd_headers_install = $(HDRSED) $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,$(srctree)/$(obj)/%,$@) \
95 quiet_cmd_unifdef = UNIFDEF $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
96 cmd_unifdef = $(UNIFDEF) $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,$(srctree)/$(obj)/%,$@) \
99 quiet_cmd_check = CHECK $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/.check.%,$(_dst)/%,$@)
100 cmd_check = $(CONFIG_SHELL) $(srctree)/scripts/hdrcheck.sh \
101 $(INSTALL_HDR_PATH)/include $(subst /.check.,/,$@) $@
103 quiet_cmd_remove = REMOVE $(_dst)/$@
104 cmd_remove = rm -f $(INSTALL_HDR_PATH)/$(_dst)/$@
106 quiet_cmd_mkdir = MKDIR $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
107 cmd_mkdir = mkdir -p $@
109 quiet_cmd_gen = GEN $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
111 FNAME=$(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$@) \
112 STUBDEF=__ASM_STUB_`echo $$FNAME | tr a-z. A-Z_`; \
113 (echo "/* File autogenerated by 'make headers_install' */" ; \
114 echo "\#ifndef $$STUBDEF" ; \
115 echo "\#define $$STUBDEF" ; \
116 echo "\# if $(ARCHDEF)" ; \
117 if [ -r $(subst /$(_dst)/,/include/$(archasm)/,$@) ]; then \
118 echo "\# include <$(archasm)/$$FNAME>" ; \
120 echo "\# error $(archasm)/$$FNAME does not exist in" \
121 "the $(ARCH) architecture" ; \
123 echo "\# elif $(ALTARCHDEF)" ; \
124 if [ -r $(subst /$(_dst)/,/include/$(altarchasm)/,$@) ]; then \
125 echo "\# include <$(altarchasm)/$$FNAME>" ; \
127 echo "\# error $(altarchasm)/$$FNAME does not exist in" \
128 "the $(ALTARCH) architecture" ; \
131 echo "\# warning This machine appears to be" \
132 "neither $(ARCH) nor $(ALTARCH)." ; \
134 echo "\#endif /* $$STUBDEF */" ; \
137 .PHONY: __headersinst __headerscheck
140 __headerscheck: $(subdir-y) $(check-y)
143 $(check-y) : $(INSTALL_HDR_PATH)/$(_dst)/.check.%.h : $(INSTALL_HDR_PATH)/$(_dst)/%.h
146 # Other dependencies for $(check-y)
147 -include /dev/null $(check-y)
149 # ... but leave $(check-y) as .PHONY for now until those deps are actually correct.
153 # Rules for installing headers
154 __headersinst: $(subdir-y) $(header-y) $(unifdef-y) $(altarch-y) $(objhdr-y)
157 $(objhdr-y) $(subdir-y) $(header-y) $(unifdef-y): | $(INSTALL_HDR_PATH)/$(_dst) $(unwanted)
159 $(INSTALL_HDR_PATH)/$(_dst):
167 $(objhdr-y) $(header-y) $(unifdef-y): $(KBUILDFILES)
171 $(objhdr-y) : $(INSTALL_HDR_PATH)/$(_dst)/%.h: $(srctree)/$(obj)/%.h $(KBUILDFILES)
172 $(call cmd,o_hdr_install)
174 $(header-y) : $(INSTALL_HDR_PATH)/$(_dst)/%.h: $(srctree)/$(obj)/%.h $(KBUILDFILES)
175 $(call cmd,headers_install)
177 $(unifdef-y) : $(INSTALL_HDR_PATH)/$(_dst)/%.h: $(srctree)/$(obj)/%.h $(KBUILDFILES)
182 hdrinst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
185 # All the files in the normal arch dir must be created first, since we test
186 # for their existence.
187 altarch-dir: $(subdir-y) $(header-y) $(unifdef-y) $(objhdr-y)
188 $(Q)$(MAKE) $(hdrinst)=include/asm-$(ALTARCH) dst=include/asm-$(ALTARCH)
189 $(Q)$(MAKE) $(hdrinst)=include/asm dst=include/asm$(BIASMDIR)
194 $(Q)$(MAKE) $(hdrinst)=$(obj)/$@ dst=$(_dst)/$@ rel=../$(rel)