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