aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/Makefile.headersinst
diff options
context:
space:
mode:
authorDavid Woodhouse <dwmw2@infradead.org>2006-06-18 06:58:39 -0400
committerDavid Woodhouse <dwmw2@infradead.org>2006-06-18 06:58:39 -0400
commit8d730cfb50cc77da6d00f941daef440918a1922f (patch)
tree9679a9ba79e3c496058d351417a058432c42257d /scripts/Makefile.headersinst
parent9348f0de2d2b541b4ba64fb1f4efee9710a3d731 (diff)
Basic implementation of 'make headers_install'
This adds a make target which exports a subset of headers which contain definitions which are useful for system libraries and tools. It uses the BSD 'unifdef' tool to remove instances of #ifdef __KERNEL__, and uses sed to remove markers like __user. Based on an original implementation by Arnd Bergmann <arnd@arndb.de> Hacked about by David Woodhouse <dwmw2@infradead.org> Reviewed and cleaned up by Sam Ravnborg <sam@ravnborg.org> Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Diffstat (limited to 'scripts/Makefile.headersinst')
-rw-r--r--scripts/Makefile.headersinst147
1 files changed, 147 insertions, 0 deletions
diff --git a/scripts/Makefile.headersinst b/scripts/Makefile.headersinst
new file mode 100644
index 000000000000..688f8cb081d9
--- /dev/null
+++ b/scripts/Makefile.headersinst
@@ -0,0 +1,147 @@
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 := 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:]]\+/ /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"
23
24_dst := $(if $(dst),$(dst),$(obj))
25
26.PHONY: __headersinst
27__headersinst:
28
29
30ifeq (,$(patsubst include/asm/%,,$(obj)/))
31# For producing the generated stuff in include/asm for biarch builds, include
32# both sets of Kbuild files; we'll generate anything which is mentioned in
33# _either_ arch, and recurse into subdirectories which are mentioned in either
34# arch. Since some directories may exist in one but not the other, we must
35# use '-include'.
36GENASM := 1
37archasm := $(subst include/asm,asm-$(ARCH),$(obj))
38altarchasm := $(subst include/asm,asm-$(ALTARCH),$(obj))
39-include $(srctree)/include/$(archasm)/Kbuild
40-include $(srctree)/include/$(altarchasm)/Kbuild
41else
42include $(srctree)/$(obj)/Kbuild
43endif
44
45include scripts/Kbuild.include
46
47# If this is include/asm-$(ARCH) and there's no $(ALTARCH), then
48# override $(_dst) so that we install to include/asm directly.
49ifeq ($(obj)$(ALTARCH),include/asm-$(ARCH))
50 _dst := include/asm
51endif
52
53header-y := $(sort $(header-y))
54unifdef-y := $(sort $(unifdef-y))
55subdir-y := $(patsubst %/,%,$(filter %/, $(header-y)))
56header-y := $(filter-out %/, $(header-y))
57header-y := $(filter-out $(unifdef-y),$(header-y))
58
59ifdef ALTARCH
60ifeq ($(obj),include/asm-$(ARCH))
61altarch-y := altarch-dir
62endif
63endif
64
65# Make the definitions visible for recursive make invocations
66export ALTARCH
67export ARCHDEF
68export ALTARCHDEF
69
70quiet_cmd_o_hdr_install = INSTALL $(_dst)/$@
71 cmd_o_hdr_install = cp $(objtree)/$(obj)/$@ $(INSTALL_HDR_PATH)/$(_dst)
72
73quiet_cmd_headers_install = INSTALL $(_dst)/$@
74 cmd_headers_install = $(HDRSED) $(srctree)/$(obj)/$@ \
75 > $(INSTALL_HDR_PATH)/$(_dst)/$@
76
77quiet_cmd_unifdef = UNIFDEF $(_dst)/$@
78 cmd_unifdef = $(UNIFDEF) $(srctree)/$(obj)/$@ | $(HDRSED) \
79 > $(INSTALL_HDR_PATH)/$(_dst)/$@ || :
80
81quiet_cmd_mkdir = MKDIR $@
82 cmd_mkdir = mkdir -p $(INSTALL_HDR_PATH)/$@
83
84quiet_cmd_gen = GEN $(_dst)/$@
85 cmd_gen = \
86STUBDEF=__ASM_STUB_`echo $@ | tr a-z. A-Z_`; \
87(echo "/* File autogenerated by 'make headers_install' */" ; \
88echo "\#ifndef $$STUBDEF" ; \
89echo "\#define $$STUBDEF" ; \
90echo "\# if $(ARCHDEF)" ; \
91if [ -r $(srctree)/include/$(archasm)/$@ ]; then \
92 echo "\# include <$(archasm)/$@>" ; \
93else \
94 echo "\# error $(archasm)/$@ does not exist in" \
95 "the $(ARCH) architecture" ; \
96fi ; \
97echo "\# elif $(ALTARCHDEF)" ; \
98if [ -r $(srctree)/include/$(altarchasm)/$@ ]; then \
99 echo "\# include <$(altarchasm)/$@>" ; \
100else \
101 echo "\# error $(altarchasm)/$@ does not exist in" \
102 "the $(ALTARCH) architecture" ; \
103fi ; \
104echo "\# else" ; \
105echo "\# warning This machine appears to be" \
106 "neither $(ARCH) nor $(ALTARCH)." ; \
107echo "\# endif" ; \
108echo "\#endif /* $$STUBDEF */" ; \
109) > $(INSTALL_HDR_PATH)/$(_dst)/$@
110
111__headersinst: $(subdir-y) $(header-y) $(unifdef-y) $(altarch-y) $(objhdr-y)
112
113.PHONY: $(header-y) $(unifdef-y) $(subdir-y)
114
115# Rules for installing headers
116
117$(objhdr-y) $(subdir-y) $(header-y) $(unifdef-y): $(_dst)
118
119.PHONY: $(_dst)
120$(_dst):
121 $(call cmd,mkdir)
122
123ifdef GENASM
124$(objhdr-y) $(header-y) $(unifdef-y):
125 $(call cmd,gen)
126
127else
128$(objhdr-y):
129 $(call cmd,o_hdr_install)
130
131$(header-y):
132 $(call cmd,headers_install)
133
134$(unifdef-y):
135 $(call cmd,unifdef)
136endif
137
138hdrinst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
139
140.PHONY: altarch-dir
141altarch-dir:
142 $(Q)$(MAKE) $(hdrinst)=include/asm-$(ALTARCH) dst=include/asm-$(ALTARCH)
143 $(Q)$(MAKE) $(hdrinst)=include/asm dst=include/asm
144
145# Recursion
146$(subdir-y):
147 $(Q)$(MAKE) $(hdrinst)=$(obj)/$@ dst=$(_dst)/$@ rel=../$(rel)