blob: 22b17af0902f271e2c28c8486921b4b96aaf99b8 [file] [log] [blame]
David Woodhouse8d730cf2006-06-18 11:58:39 +01001# ==========================================================================
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
Sam Ravnborg07aea3a2006-07-23 20:47:50 +020010UNIFDEF := scripts/unifdef -U__KERNEL__
David Woodhouse8d730cf2006-06-18 11:58:39 +010011
12# Eliminate the contents of (and inclusions of) compiler.h
13HDRSED := sed -e "s/ inline / __inline__ /g" \
Mike Frysingerc0519032007-07-09 11:43:55 -070014 -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" \
David Woodhouse8d730cf2006-06-18 11:58:39 +010021 -e "s/[[:space:]]__attribute_const__$$//" \
22 -e "/^\#include <linux\/compiler.h>/d"
23
24_dst := $(if $(dst),$(dst),$(obj))
25
David Woodhouse8d730cf2006-06-18 11:58:39 +010026ifeq (,$(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
David Woodhousede789122006-09-24 22:15:14 +010031# use $(wildcard...).
David Woodhouse8d730cf2006-06-18 11:58:39 +010032GENASM := 1
33archasm := $(subst include/asm,asm-$(ARCH),$(obj))
34altarchasm := $(subst include/asm,asm-$(ALTARCH),$(obj))
David Woodhousede789122006-09-24 22:15:14 +010035KBUILDFILES := $(wildcard $(srctree)/include/$(archasm)/Kbuild $(srctree)/include/$(altarchasm)/Kbuild)
David Woodhouse8d730cf2006-06-18 11:58:39 +010036else
David Woodhousede789122006-09-24 22:15:14 +010037KBUILDFILES := $(srctree)/$(obj)/Kbuild
David Woodhouse8d730cf2006-06-18 11:58:39 +010038endif
39
David Woodhousede789122006-09-24 22:15:14 +010040include $(KBUILDFILES)
41
42include scripts/Kbuild.include
David Woodhouse8d730cf2006-06-18 11:58:39 +010043
44# If this is include/asm-$(ARCH) and there's no $(ALTARCH), then
45# override $(_dst) so that we install to include/asm directly.
David Woodhousede789122006-09-24 22:15:14 +010046# 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))
David Woodhouse8d730cf2006-06-18 11:58:39 +010050 _dst := include/asm
51endif
52
Sam Ravnborg4e420aa2008-06-05 16:52:15 +020053header-y := $(sort $(header-y) $(unifdef-y))
David Woodhouse8d730cf2006-06-18 11:58:39 +010054subdir-y := $(patsubst %/,%,$(filter %/, $(header-y)))
55header-y := $(filter-out %/, $(header-y))
David Woodhouse8d730cf2006-06-18 11:58:39 +010056
David Woodhousede789122006-09-24 22:15:14 +010057# stamp files for header checks
Sam Ravnborg4e420aa2008-06-05 16:52:15 +020058check-y := $(patsubst %,.check.%,$(header-y) $(objhdr-y))
David Woodhousede789122006-09-24 22:15:14 +010059
60# Work out what needs to be removed
61oldheaders := $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$(wildcard $(INSTALL_HDR_PATH)/$(_dst)/*.h))
Sam Ravnborg4e420aa2008-06-05 16:52:15 +020062unwanted := $(filter-out $(header-y) $(objhdr-y),$(oldheaders))
David Woodhousede789122006-09-24 22:15:14 +010063
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))
David Woodhousede789122006-09-24 22:15:14 +010069objhdr-y := $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(objhdr-y))
70check-y := $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(check-y))
71
72
David Woodhouse8d730cf2006-06-18 11:58:39 +010073ifdef 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
David Woodhousede789122006-09-24 22:15:14 +010084quiet_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)
David Woodhouse8d730cf2006-06-18 11:58:39 +010087
David Woodhousede789122006-09-24 22:15:14 +010088quiet_cmd_unifdef = UNIFDEF $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
89 cmd_unifdef = $(UNIFDEF) $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,$(srctree)/$(obj)/%,$@) \
90 | $(HDRSED) > $@ || :
David Woodhouse8d730cf2006-06-18 11:58:39 +010091
David Woodhousede789122006-09-24 22:15:14 +010092quiet_cmd_check = CHECK $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/.check.%,$(_dst)/%,$@)
Andrew Morton4e776b12006-10-04 02:15:20 -070093 cmd_check = $(CONFIG_SHELL) $(srctree)/scripts/hdrcheck.sh \
David Woodhousede789122006-09-24 22:15:14 +010094 $(INSTALL_HDR_PATH)/include $(subst /.check.,/,$@) $@
David Woodhouse68475352006-06-18 12:02:10 +010095
David Woodhousede789122006-09-24 22:15:14 +010096quiet_cmd_remove = REMOVE $(_dst)/$@
97 cmd_remove = rm -f $(INSTALL_HDR_PATH)/$(_dst)/$@
David Woodhouse8d730cf2006-06-18 11:58:39 +010098
David Woodhousede789122006-09-24 22:15:14 +010099quiet_cmd_mkdir = MKDIR $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
100 cmd_mkdir = mkdir -p $@
101
102quiet_cmd_gen = GEN $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
David Woodhouse8d730cf2006-06-18 11:58:39 +0100103 cmd_gen = \
David Woodhouse0db19c42007-07-06 02:39:52 -0700104FNAME=$(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$@); \
Mike Frysingerec268be2007-01-30 14:35:55 -0800105STUBDEF=__ASM_STUB_`echo $$FNAME | tr a-z.- A-Z__`; \
David Woodhouse8d730cf2006-06-18 11:58:39 +0100106(echo "/* File autogenerated by 'make headers_install' */" ; \
107echo "\#ifndef $$STUBDEF" ; \
108echo "\#define $$STUBDEF" ; \
109echo "\# if $(ARCHDEF)" ; \
David Woodhousede789122006-09-24 22:15:14 +0100110if [ -r $(subst /$(_dst)/,/include/$(archasm)/,$@) ]; then \
111 echo "\# include <$(archasm)/$$FNAME>" ; \
David Woodhouse8d730cf2006-06-18 11:58:39 +0100112else \
David Woodhousede789122006-09-24 22:15:14 +0100113 echo "\# error $(archasm)/$$FNAME does not exist in" \
David Woodhouse8d730cf2006-06-18 11:58:39 +0100114 "the $(ARCH) architecture" ; \
115fi ; \
116echo "\# elif $(ALTARCHDEF)" ; \
David Woodhousede789122006-09-24 22:15:14 +0100117if [ -r $(subst /$(_dst)/,/include/$(altarchasm)/,$@) ]; then \
118 echo "\# include <$(altarchasm)/$$FNAME>" ; \
David Woodhouse8d730cf2006-06-18 11:58:39 +0100119else \
David Woodhousede789122006-09-24 22:15:14 +0100120 echo "\# error $(altarchasm)/$$FNAME does not exist in" \
David Woodhouse8d730cf2006-06-18 11:58:39 +0100121 "the $(ALTARCH) architecture" ; \
122fi ; \
123echo "\# else" ; \
124echo "\# warning This machine appears to be" \
125 "neither $(ARCH) nor $(ALTARCH)." ; \
126echo "\# endif" ; \
127echo "\#endif /* $$STUBDEF */" ; \
David Woodhousede789122006-09-24 22:15:14 +0100128) > $@
David Woodhouse8d730cf2006-06-18 11:58:39 +0100129
David Woodhousede789122006-09-24 22:15:14 +0100130.PHONY: __headersinst __headerscheck
David Woodhouse8d730cf2006-06-18 11:58:39 +0100131
David Woodhouse68475352006-06-18 12:02:10 +0100132ifdef HDRCHECK
David Woodhousede789122006-09-24 22:15:14 +0100133__headerscheck: $(subdir-y) $(check-y)
134 @true
135
136$(check-y) : $(INSTALL_HDR_PATH)/$(_dst)/.check.%.h : $(INSTALL_HDR_PATH)/$(_dst)/%.h
David Woodhouse68475352006-06-18 12:02:10 +0100137 $(call cmd,check)
David Woodhousede789122006-09-24 22:15:14 +0100138
139# Other dependencies for $(check-y)
David Woodhousedf5f6312007-05-21 19:53:35 -0400140include /dev/null $(wildcard $(check-y))
David Woodhousede789122006-09-24 22:15:14 +0100141
142# ... but leave $(check-y) as .PHONY for now until those deps are actually correct.
143.PHONY: $(check-y)
144
David Woodhouse68475352006-06-18 12:02:10 +0100145else
David Woodhouse8d730cf2006-06-18 11:58:39 +0100146# Rules for installing headers
Sam Ravnborg4e420aa2008-06-05 16:52:15 +0200147__headersinst: $(subdir-y) $(header-y) $(altarch-y) $(objhdr-y)
David Woodhousede789122006-09-24 22:15:14 +0100148 @true
David Woodhouse8d730cf2006-06-18 11:58:39 +0100149
Sam Ravnborg4e420aa2008-06-05 16:52:15 +0200150$(objhdr-y) $(subdir-y) $(header-y): | $(INSTALL_HDR_PATH)/$(_dst) $(unwanted)
David Woodhouse8d730cf2006-06-18 11:58:39 +0100151
David Woodhousede789122006-09-24 22:15:14 +0100152$(INSTALL_HDR_PATH)/$(_dst):
David Woodhouse8d730cf2006-06-18 11:58:39 +0100153 $(call cmd,mkdir)
154
David Woodhousede789122006-09-24 22:15:14 +0100155.PHONY: $(unwanted)
156$(unwanted):
157 $(call cmd,remove)
158
David Woodhouse8d730cf2006-06-18 11:58:39 +0100159ifdef GENASM
Sam Ravnborg4e420aa2008-06-05 16:52:15 +0200160$(objhdr-y) $(header-y): $(KBUILDFILES)
David Woodhouse8d730cf2006-06-18 11:58:39 +0100161 $(call cmd,gen)
162
163else
Sam Ravnborg4e420aa2008-06-05 16:52:15 +0200164$(objhdr-y): $(INSTALL_HDR_PATH)/$(_dst)/%.h: $(objtree)/$(obj)/%.h $(KBUILDFILES)
David Woodhouse8d730cf2006-06-18 11:58:39 +0100165 $(call cmd,o_hdr_install)
166
Sam Ravnborg4e420aa2008-06-05 16:52:15 +0200167$(header-y): $(INSTALL_HDR_PATH)/$(_dst)/%.h: $(srctree)/$(obj)/%.h $(KBUILDFILES)
David Woodhouse8d730cf2006-06-18 11:58:39 +0100168 $(call cmd,unifdef)
Sam Ravnborg4e420aa2008-06-05 16:52:15 +0200169
David Woodhouse8d730cf2006-06-18 11:58:39 +0100170endif
David Woodhouse68475352006-06-18 12:02:10 +0100171endif
David Woodhouse8d730cf2006-06-18 11:58:39 +0100172
173hdrinst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
174
175.PHONY: altarch-dir
David Woodhouseb5122172006-09-16 12:15:45 -0700176# All the files in the normal arch dir must be created first, since we test
177# for their existence.
Sam Ravnborg4e420aa2008-06-05 16:52:15 +0200178altarch-dir: $(subdir-y) $(header-y) $(objhdr-y)
David Woodhouse8d730cf2006-06-18 11:58:39 +0100179 $(Q)$(MAKE) $(hdrinst)=include/asm-$(ALTARCH) dst=include/asm-$(ALTARCH)
David Woodhousede789122006-09-24 22:15:14 +0100180 $(Q)$(MAKE) $(hdrinst)=include/asm dst=include/asm$(BIASMDIR)
David Woodhouse8d730cf2006-06-18 11:58:39 +0100181
182# Recursion
David Woodhousede789122006-09-24 22:15:14 +0100183.PHONY: $(subdir-y)
David Woodhouse8d730cf2006-06-18 11:58:39 +0100184$(subdir-y):
185 $(Q)$(MAKE) $(hdrinst)=$(obj)/$@ dst=$(_dst)/$@ rel=../$(rel)