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