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