Makefile.headersinst 6.4 KB
Newer Older
1 2 3 4 5 6 7 8 9
# ==========================================================================
# Installing headers
#
# header-y files will be installed verbatim
# unifdef-y are the files where unifdef will be run before installing files
# objhdr-y are generated files that will be installed verbatim
#
# ==========================================================================

S
Sam Ravnborg 已提交
10
UNIFDEF := scripts/unifdef -U__KERNEL__
11 12 13

# Eliminate the contents of (and inclusions of) compiler.h
HDRSED  := sed 	-e "s/ inline / __inline__ /g" \
14 15 16 17 18 19 20
		-e "s/[[:space:]]__user[[:space:]]\{1,\}/ /g" \
		-e "s/(__user[[:space:]]\{1,\}/ (/g" \
		-e "s/[[:space:]]__force[[:space:]]\{1,\}/ /g" \
		-e "s/(__force[[:space:]]\{1,\}/ (/g" \
		-e "s/[[:space:]]__iomem[[:space:]]\{1,\}/ /g" \
		-e "s/(__iomem[[:space:]]\{1,\}/ (/g" \
		-e "s/[[:space:]]__attribute_const__[[:space:]]\{1,\}/\ /g" \
21 22 23 24 25 26 27 28 29 30
		-e "s/[[:space:]]__attribute_const__$$//" \
		-e "/^\#include <linux\/compiler.h>/d"

_dst := $(if $(dst),$(dst),$(obj))

ifeq (,$(patsubst include/asm/%,,$(obj)/))
# For producing the generated stuff in include/asm for biarch builds, include
# both sets of Kbuild files; we'll generate anything which is mentioned in
# _either_ arch, and recurse into subdirectories which are mentioned in either
# arch. Since some directories may exist in one but not the other, we must
31
# use $(wildcard...). 
32 33 34
GENASM := 1
archasm	   := $(subst include/asm,asm-$(ARCH),$(obj))
altarchasm := $(subst include/asm,asm-$(ALTARCH),$(obj))
35
KBUILDFILES := $(wildcard $(srctree)/include/$(archasm)/Kbuild $(srctree)/include/$(altarchasm)/Kbuild)
36
else
37
KBUILDFILES := $(srctree)/$(obj)/Kbuild
38 39
endif

40 41 42
include $(KBUILDFILES)

include scripts/Kbuild.include 
43 44 45

# If this is include/asm-$(ARCH) and there's no $(ALTARCH), then
# override $(_dst) so that we install to include/asm directly.
46 47 48 49
# Unless $(BIASMDIR) is set, in which case we're probably doing
# a 'headers_install_all' build and we should keep the -$(ARCH)
# in the directory name.
ifeq ($(obj)$(ALTARCH),include/asm-$(ARCH)$(BIASMDIR))
50 51 52
     _dst := include/asm
endif

53
header-y	:= $(sort $(header-y) $(unifdef-y))
54 55 56
subdir-y	:= $(patsubst %/,%,$(filter %/, $(header-y)))
header-y	:= $(filter-out %/, $(header-y))

57
# stamp files for header checks
58
check-y		:= $(patsubst %,.check.%,$(header-y) $(objhdr-y))
59 60 61

# Work out what needs to be removed
oldheaders	:= $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$(wildcard $(INSTALL_HDR_PATH)/$(_dst)/*.h))
62
unwanted	:= $(filter-out $(header-y) $(objhdr-y),$(oldheaders))
63 64 65 66 67 68 69 70 71 72

oldcheckstamps	:= $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$(wildcard $(INSTALL_HDR_PATH)/$(_dst)/.check.*.h))
unwanted	+= $(filter-out $(check-y),$(oldcheckstamps))

# Prefix them all with full paths to $(INSTALL_HDR_PATH)
header-y 	:= $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(header-y))
objhdr-y 	:= $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(objhdr-y))
check-y 	:= $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(check-y))


73 74 75 76 77 78 79 80 81 82 83
ifdef ALTARCH
ifeq ($(obj),include/asm-$(ARCH))
altarch-y	:= altarch-dir
endif
endif

# Make the definitions visible for recursive make invocations
export ALTARCH
export ARCHDEF
export ALTARCHDEF

84 85 86
quiet_cmd_o_hdr_install   = INSTALL $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
      cmd_o_hdr_install   = cp $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,$(objtree)/$(obj)/%,$@) \
			    $(INSTALL_HDR_PATH)/$(_dst)
87

88 89 90
quiet_cmd_unifdef	  = UNIFDEF $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
      cmd_unifdef	  = $(UNIFDEF) $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,$(srctree)/$(obj)/%,$@) \
				   | $(HDRSED) > $@ || :
91

92
quiet_cmd_check		  = CHECK   $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/.check.%,$(_dst)/%,$@)
A
Andrew Morton 已提交
93
      cmd_check		  = $(CONFIG_SHELL) $(srctree)/scripts/hdrcheck.sh \
94 95 96 97
                              $(INSTALL_HDR_PATH)/include $(subst /.check.,/,$@) $@

quiet_cmd_remove	  = REMOVE  $(_dst)/$@
      cmd_remove	  = rm -f $(INSTALL_HDR_PATH)/$(_dst)/$@
98

99 100
quiet_cmd_mkdir		  = MKDIR   $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
      cmd_mkdir		  = mkdir -p $@
101

102
quiet_cmd_gen		  = GEN     $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
103
      cmd_gen		  = \
D
David Woodhouse 已提交
104
FNAME=$(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$@);			\
105
STUBDEF=__ASM_STUB_`echo $$FNAME | tr a-z.- A-Z__`;			\
106 107 108 109
(echo "/* File autogenerated by 'make headers_install' */" ;		\
echo "\#ifndef $$STUBDEF" ;						\
echo "\#define $$STUBDEF" ;						\
echo "\# if $(ARCHDEF)" ;						\
110 111
if [ -r $(subst /$(_dst)/,/include/$(archasm)/,$@) ]; then		\
	echo "\#  include <$(archasm)/$$FNAME>" ;			\
112
else									\
113
	echo "\#  error $(archasm)/$$FNAME does not exist in"		\
114 115 116
			"the $(ARCH) architecture" ;			\
fi ;									\
echo "\# elif $(ALTARCHDEF)" ;						\
117 118
if [ -r $(subst /$(_dst)/,/include/$(altarchasm)/,$@) ]; then		\
	echo "\#  include <$(altarchasm)/$$FNAME>" ;			\
119
else									\
120
	echo "\#  error $(altarchasm)/$$FNAME does not exist in"	\
121 122 123 124 125 126 127
			"the $(ALTARCH) architecture" ;			\
fi ;									\
echo "\# else" ;							\
echo "\#  warning This machine appears to be"				\
		 "neither $(ARCH) nor $(ALTARCH)." ;			\
echo "\# endif" ;							\
echo "\#endif /* $$STUBDEF */" ;					\
128
) > $@
129

130
.PHONY: __headersinst __headerscheck
131

132
ifdef HDRCHECK
133 134 135 136
__headerscheck: $(subdir-y) $(check-y)
	@true

$(check-y) : $(INSTALL_HDR_PATH)/$(_dst)/.check.%.h : $(INSTALL_HDR_PATH)/$(_dst)/%.h 
137
	$(call cmd,check)
138 139

# Other dependencies for $(check-y)
140
include /dev/null $(wildcard $(check-y))
141 142 143 144

# ... but leave $(check-y) as .PHONY for now until those deps are actually correct.
.PHONY: $(check-y)

145
else
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 154
	$(call cmd,mkdir)

155 156 157 158
.PHONY: $(unwanted)
$(unwanted):
	$(call cmd,remove)

159
ifdef GENASM
160
$(objhdr-y) $(header-y): $(KBUILDFILES)
161 162 163
	$(call cmd,gen)

else
164
$(objhdr-y): $(INSTALL_HDR_PATH)/$(_dst)/%.h: $(objtree)/$(obj)/%.h $(KBUILDFILES)
165 166
	$(call cmd,o_hdr_install)

167
$(header-y): $(INSTALL_HDR_PATH)/$(_dst)/%.h: $(srctree)/$(obj)/%.h $(KBUILDFILES)
168
	$(call cmd,unifdef)
169

170
endif
171
endif
172 173 174 175

hdrinst := -rR -f $(srctree)/scripts/Makefile.headersinst obj

.PHONY: altarch-dir
176 177
# All the files in the normal arch dir must be created first, since we test
# for their existence.
178
altarch-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 185
$(subdir-y):
	$(Q)$(MAKE) $(hdrinst)=$(obj)/$@ dst=$(_dst)/$@ rel=../$(rel)