Makefile.rump revision 1.111
1#	$NetBSD: Makefile.rump,v 1.111 2015/04/24 06:29:56 pooka Exp $
2#
3
4.if !defined(_RUMP_MK)
5_RUMP_MK= #defined
6
7WARNS?=		3	# XXX: src/sys won't compile with -Wsign-compare yet
8NOLINT=		# kernel code
9
10.include <bsd.own.mk>
11
12# Use NetBSD kernel ABI by default on x86 archs.  Performance-related
13# compile-time options may override this at a later date.
14.if (${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64")
15_RUMP_NATIVEABI= yes
16.else
17_RUMP_NATIVEABI= no
18CPPFLAGS:=	-I${RUMPTOP}/include ${CPPFLAGS}
19CPPFLAGS+=	-D_RUMPKERNEL -I${RUMPTOP}/librump/rumpkern
20.endif
21
22# Define baseline cpu for mips ports, required for
23# rumpcomp_sync_icache() hypercall.
24.if !empty(MACHINE_ARCH:Mmips*)
25.if !empty(MACHINE_ARCH:Mmips64*)
26CPPFLAGS+=	-DMIPS64=1
27.else
28CPPFLAGS+=	-DMIPS1=1
29.endif
30.endif
31
32RUMP_NBCOMPAT?=	50 60 70
33# normalize alternatively accepted comma-separated list
34RUMP_NBCOMPAT:=	${RUMP_NBCOMPAT:S/,/ /g}
35CPPFLAGS+=	${RUMP_NBCOMPAT:C/[1-9]0/-DCOMPAT_&/g}
36
37CPPFLAGS+=	-DMAXUSERS=32
38
39CPPFLAGS+=	-nostdinc
40CFLAGS+=	-ffreestanding -fno-strict-aliasing
41
42CWARNFLAGS+=	-Wno-format-zero-length -Wno-pointer-sign
43CPPFLAGS+=	-D_KERNEL -DMULTIPROCESSOR -D_MODULE -DMODULAR
44CPPFLAGS+=	-DDEBUGPRINT
45CPPFLAGS+=	-I${.CURDIR} -I.
46CPPFLAGS+=	-I${RUMPTOP}/../../common/include
47CPPFLAGS+=	-I${RUMPTOP}/include
48CPPFLAGS+=	-I${RUMPTOP}/librump/rumpkern/opt
49
50SHLIB_MAJOR?=	0
51SHLIB_MINOR?=	0
52
53.ifdef NEED_ISYSTEM
54CPPFLAGS+=	-isystem ${RUMPTOP}/../arch
55CPPFLAGS+=	-isystem ${RUMPTOP}/..
56.else
57CPPFLAGS+=	-I${RUMPTOP}/../arch
58CPPFLAGS+=	-I${RUMPTOP}/..
59.endif
60
61RUMP_LDSCRIPT?=	GNU
62.if ${RUMP_LDSCRIPT} != "no"
63# my ld or yours?
64.if ${RUMP_LDSCRIPT} == "sun"
65LDFLAGS+=	-Wl,-M ${RUMPTOP}/ldscript_sun.rump
66SRCS+=		linksyms_sun.c
67.PATH:		${RUMPTOP}
68.elif ${RUMP_LDSCRIPT} == "GNU"
69LDFLAGS+=	-Wl,-T,${RUMPTOP}/ldscript.rump
70.elif ${RUMP_LDSCRIPT} == "ctor"
71CPPFLAGS+=	-DRUMP_USE_CTOR
72.else
73.error Unknown ldscript ${RUMP_LDSCRIPT}
74.endif
75.endif
76
77.if defined(RUMP_CURLWP)
78.if   ${RUMP_CURLWP} == "hypercall"
79CPPFLAGS+=	-DRUMP_CURLWP=RUMP_CURLWP_HYPERCALL
80.elif ${RUMP_CURLWP} == "__thread"
81CPPFLAGS+=	-DRUMP_CURLWP=RUMP_CURLWP___THREAD
82.elif ${RUMP_CURLWP} == "register"
83CPPFLAGS+=	-DRUMP_CURLWP=RUMP_CURLWP_REGISTER
84.else
85.error Unsupported curlwp scheme: ${RUMP_CURLWP}
86.endif
87.endif
88
89RUMP_DIAGNOSTIC?=yes
90.if ${RUMP_DIAGNOSTIC} == "yes"
91CPPFLAGS+=	-DDIAGNOSTIC
92.endif
93
94.ifdef RUMP_DEBUG
95CPPFLAGS+=	-DDEBUG
96.endif
97
98.ifdef RUMP_LOCKDEBUG
99CPPFLAGS+=	-DLOCKDEBUG
100.endif
101
102RUMP_KTRACE?=yes
103.if ${RUMP_KTRACE} == "yes"
104CPPFLAGS+=	-DKTRACE
105.endif
106
107# kernel libs should not get linked against libc
108# XXX: actually, we would like to enable this but cannot, since it
109# also leaves out libgcc, it causes problems on some platforms.
110# revisit some day.
111#LDFLAGS+=	-nodefaultlibs
112
113# make sure __NetBSD__ gets defined (for builds on non-NetBSD)
114# also, give those builds a way to undef the local compiler's macros
115CPPFLAGS+=	-D__NetBSD__ ${RUMPKERN_UNDEF}
116
117RUMPKERNEL=	This is NetBSD and I am the rump.  Good evening.
118
119# workaround: evbppc is not a well-defined arch
120.if (${MACHINE} == "evbppc")
121CPPFLAGS+=	-DPPC_OEA
122.endif
123
124# If this file changes, we need a full rebuild
125DPSRCS+=	${RUMPTOP}/Makefile.rump
126
127#
128# Support for component-specific hypercalls
129#
130
131# no easy way to get WARNS out of bsd.sys.mk
132RUMPCOMP_USER_WARNFLAGS=	-Wall -Wextra -Wno-unused-parameter
133RUMPCOMP_USER_WARNFLAGS+=	-Wstrict-prototypes -Wmissing-prototypes
134
135.ifdef RUMPCOMP_USER_SRCS && !defined(RUMPKERN_ONLY)
136.if empty(DESTDIR)
137DESTDIR=/
138.endif
139BUILDRUMP_CPPFLAGS ?= -isysroot ${DESTDIR}
140RUMPCOMP_USER_WERROR = ${${_NOWERROR} == "no" :?-Werror:}
141.for rcusrc in ${RUMPCOMP_USER_SRCS:R}
142${rcusrc}.d: ${rcusrc}.c
143	${_MKTARGET_CREATE}
144	${MKDEP} -f ${.TARGET} -- ${MKDEPFLAGS} ${BUILDRUMP_CPPFLAGS} ${RUMPCOMP_USER_CPPFLAGS} ${.ALLSRC:O:u:M*${rcusrc}.c}
145
146${rcusrc}.o: ${rcusrc}.c
147	${_MKTARGET_COMPILE}
148	${CC} -o ${.TARGET} ${DBG} ${CWARNFLAGS} ${RUMPCOMP_USER_WERROR} ${RUMPCOMP_USER_WARNFLAGS} ${BUILDRUMP_CPPFLAGS} ${BUILDRUMP_CFLAGS} ${RUMPCOMP_USER_CPPFLAGS} ${RUMPCOMP_USER_CFLAGS} -c ${.ALLSRC:O:u:M*${rcusrc}.c}
149
150${rcusrc}.pico: ${rcusrc}.c
151	${_MKTARGET_COMPILE}
152	${CC} -o ${.TARGET} -fPIC -DPIC ${DBG} ${CWARNFLAGS} ${RUMPCOMP_USER_WERROR} ${RUMPCOMP_USER_WARNFLAGS} ${BUILDRUMP_CPPFLAGS} ${BUILDRUMP_CFLAGS} ${RUMPCOMP_USER_CPPFLAGS} ${RUMPCOMP_USER_CFLAGS} -c ${.ALLSRC:O:u:M*${rcusrc}.c}
153
154${rcusrc}.po: ${rcusrc}.c
155	${_MKTARGET_COMPILE}
156	${CC} -o ${.TARGET} ${PROFFLAGS} -pg ${DBG} ${CWARNFLAGS} ${RUMPCOMP_USER_WERROR} ${RUMPCOMP_USER_WARNFLAGS} ${BUILDRUMP_CPPFLAGS} ${BUILDRUMP_CFLAGS} ${RUMPCOMP_USER_CPPFLAGS} ${RUMPCOMP_USER_CFLAGS} -c ${.ALLSRC:O:u:M*${rcusrc}.c}
157
158RUMPOBJ_NORENAME+=${rcusrc}.o ${rcusrc}.pico ${rcusrc}.po
159SRCS+=${rcusrc}.c
160.endfor
161.endif
162
163#
164# Rename library symbols before use.  If a symbol does not already belong
165# to a rump namespace ("rump" or "RUMP"), prefix it with "rumpns".  This
166# avoids accidentally linking any kernel symbol against host platform
167# libraries.  The only non-renamed symbols are linkset delimiters and
168# the GOT, which are more a property of the compiler than the kernel.
169#
170# Some toolchains generate unresolved symbols which are supposed to be
171# satisfied by the toolchain itself when the program is linked.
172# Unfortunately, we do not know which of the symbols are generated by
173# the toolchain.  Worse, they vary from platform to platform and
174# toolchain to toolchain.  The good news, however, is that this will
175# be detected by a compile-time failure, so we can fairly easily manage
176# a quirktable here.
177#
178# We also allow calling ourselves externally with e.g.:
179# make -f /sys/rump/Makefile.rump RUMP_SYMREN=ffs.kobj
180#
181.if ${MACHINE_CPU} == "mips"
182_SYMQUIRK='|_gp_disp'
183.elif ${MACHINE_CPU} == "hppa"
184_SYMQUIRK='|\$$\$$'
185.elif ${MACHINE_ARCH} == "powerpc64"
186_SYMQUIRK="|PF_funcs"
187.endif
188
189#
190# Prefix quirks.  At least one toolchain generates global
191# symbols with prefixes which really need to remain as prefixes
192# (i.e. the '.' on the front of some ppc64 globals).  The
193# way to know if you have the problem is if you get later
194# complaints about symbols like 'rumpns_XrumpBLAH' or 'XrumpBLAH';
195# the 'X' part was added by the toolchain and will need to
196# be mentioned here.
197# 
198.if ${MACHINE_ARCH} == "powerpc64"
199_PQ="\.?"
200.else
201_PQ=
202.endif
203
204rump_symren: __archivebuild
205.if !defined(RUMP_SYMREN)
206	@echo "Must supply RUMP_SYMREN for target rump_symren"
207	@false
208.endif
209
210# if we are called from lib build (RUMP_SYMREN is not specified),
211# build the arrrrchive.  otherwise just rename symbols.
212__archivebuild: .USE
213.if defined(RUMP_SYMREN) && defined(RUMPTOP)
214	@echo "ERROR: RUMP_SYMREN can only be used standalone"
215	@false
216.endif
217.if defined(RUMP_SYMREN)
218	${_MKMSG} " symbol rename " ${RUMP_SYMREN}
219.else
220	${_MKTARGET_BUILD}
221	rm -f ${.TARGET}
222.endif
223	for renameobj in ${RUMP_SYMREN:U${.ALLSRC:C/(${RUMPOBJ_NORENAME:ts|})//g}}; do \
224		${NM} -go $${renameobj} | ${TOOL_AWK} ' \
225		    $$NF!~/^'${_PQ}'(rump|RUMP|__|_GLOBAL_OFFSET_TABLE'${_SYMQUIRK}'${RUMP_SYM_NORENAME:D|${RUMP_SYM_NORENAME}})/ \
226		      {s=$$NF;sub(/^'${_PQ}'/, "&rumpns_", s); print $$NF, s}'\
227		    | sort | uniq  > renametab.$${renameobj}; \
228		${OBJCOPY} --preserve-dates --redefine-syms \
229		    renametab.$${renameobj} $${renameobj}; \
230		rm -f renametab.$${renameobj}; \
231	done
232.if !defined(RUMP_SYMREN)
233	${AR} ${_ARFL} ${.TARGET} \
234	    `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
235.endif
236
237_BSD_IOCONF_MK_USER_=1
238.include <bsd.ioconf.mk>
239
240.-include "${NETBSDSRCDIR}/sys/arch/${MACHINE_CPU}/include/Makefile.inc"
241.-include "${NETBSDSRCDIR}/sys/arch/${MACHINE}/include/Makefile.inc"
242
243.endif # _RUMP_MK
244