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