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