Makefile.headersinst 6.8 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 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

# Eliminate the contents of (and inclusions of) compiler.h
HDRSED  := sed 	-e "s/ inline / __inline__ /g" \
		-e "s/[[:space:]]__user[[:space:]]\+/ /g" \
		-e "s/(__user[[:space:]]\+/ (/g" \
		-e "s/[[:space:]]__force[[:space:]]\+/ /g" \
		-e "s/(__force[[:space:]]\+/ (/g" \
		-e "s/[[:space:]]__iomem[[:space:]]\+/ /g" \
		-e "s/(__iomem[[:space:]]\+/ (/g" \
		-e "s/[[:space:]]__attribute_const__[[:space:]]\+/\ /g" \
		-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 53 54 55 56 57 58
     _dst := include/asm
endif

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

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
# stamp files for header checks
check-y		:= $(patsubst %,.check.%,$(header-y) $(unifdef-y) $(objhdr-y))

# Work out what needs to be removed
oldheaders	:= $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$(wildcard $(INSTALL_HDR_PATH)/$(_dst)/*.h))
unwanted	:= $(filter-out $(header-y) $(unifdef-y) $(objhdr-y),$(oldheaders))

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))
unifdef-y 	:= $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(unifdef-y))
objhdr-y 	:= $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(objhdr-y))
check-y 	:= $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(check-y))


76 77 78 79 80 81 82 83 84 85 86
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

87 88 89
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)
90

91 92 93
quiet_cmd_headers_install = INSTALL $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
      cmd_headers_install = $(HDRSED) $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,$(srctree)/$(obj)/%,$@)	\
			    > $@
94

95 96 97
quiet_cmd_unifdef	  = UNIFDEF $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
      cmd_unifdef	  = $(UNIFDEF) $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,$(srctree)/$(obj)/%,$@) \
				   | $(HDRSED) > $@ || :
98

99
quiet_cmd_check		  = CHECK   $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/.check.%,$(_dst)/%,$@)
100
      cmd_check		  = $(srctree)/scripts/hdrcheck.sh		\
101 102 103 104
                              $(INSTALL_HDR_PATH)/include $(subst /.check.,/,$@) $@

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

106 107
quiet_cmd_mkdir		  = MKDIR   $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
      cmd_mkdir		  = mkdir -p $@
108

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

137
.PHONY: __headersinst __headerscheck
138

139
ifdef HDRCHECK
140 141 142 143
__headerscheck: $(subdir-y) $(check-y)
	@true

$(check-y) : $(INSTALL_HDR_PATH)/$(_dst)/.check.%.h : $(INSTALL_HDR_PATH)/$(_dst)/%.h 
144
	$(call cmd,check)
145 146 147 148 149 150 151

# Other dependencies for $(check-y)
-include /dev/null $(check-y)

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

152
else
153
# Rules for installing headers
154 155
__headersinst: $(subdir-y) $(header-y) $(unifdef-y) $(altarch-y) $(objhdr-y)
	@true
156

157
$(objhdr-y) $(subdir-y) $(header-y) $(unifdef-y): | $(INSTALL_HDR_PATH)/$(_dst) $(unwanted)
158

159
$(INSTALL_HDR_PATH)/$(_dst):
160 161
	$(call cmd,mkdir)

162 163 164 165
.PHONY: $(unwanted)
$(unwanted):
	$(call cmd,remove)

166
ifdef GENASM
167
$(objhdr-y) $(header-y) $(unifdef-y): $(KBUILDFILES)
168 169 170
	$(call cmd,gen)

else
171
$(objhdr-y) :		$(INSTALL_HDR_PATH)/$(_dst)/%.h: $(srctree)/$(obj)/%.h $(KBUILDFILES)
172 173
	$(call cmd,o_hdr_install)

174
$(header-y) :		$(INSTALL_HDR_PATH)/$(_dst)/%.h: $(srctree)/$(obj)/%.h $(KBUILDFILES)
175 176
	$(call cmd,headers_install)

177
$(unifdef-y) :		$(INSTALL_HDR_PATH)/$(_dst)/%.h: $(srctree)/$(obj)/%.h $(KBUILDFILES)
178 179
	$(call cmd,unifdef)
endif
180
endif
181 182 183 184

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

.PHONY: altarch-dir
185 186 187
# All the files in the normal arch dir must be created first, since we test
# for their existence.
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)
190 191

# Recursion
192
.PHONY: $(subdir-y)
193 194
$(subdir-y):
	$(Q)$(MAKE) $(hdrinst)=$(obj)/$@ dst=$(_dst)/$@ rel=../$(rel)