Makefile.rump revision 1.129
1#	$NetBSD: Makefile.rump,v 1.129 2020/06/12 11:04:45 roy 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")
140CPPFLAGS+=	-DPPC_OEA
141.endif
142
143# If any of these files change, we need a full rebuild
144DPSRCS+=	${RUMPTOP}/Makefile.rump
145
146#
147# Support for component-specific hypercalls
148#
149
150# no easy way to get WARNS out of bsd.sys.mk
151RUMPCOMP_USER_WARNFLAGS=	-Wall -Wextra -Wno-unused-parameter
152RUMPCOMP_USER_WARNFLAGS+=	-Wstrict-prototypes -Wmissing-prototypes
153
154.ifdef RUMPCOMP_USER_SRCS && !defined(RUMPKERN_ONLY)
155.if empty(DESTDIR)
156DESTDIR=/
157.endif
158BUILDRUMP_CPPFLAGS ?= -isysroot ${DESTDIR}
159RUMPCOMP_USER_WERROR = ${${_NOWERROR} == "no" :?-Werror:}
160.for rcusrc in ${RUMPCOMP_USER_SRCS:R}
161${rcusrc}.d: ${rcusrc}.c
162	${_MKTARGET_CREATE}
163	${MKDEP} -f ${.TARGET} -- ${MKDEPFLAGS} ${CPUFLAGS} ${REPROFLAGS} ${BUILDRUMP_CPPFLAGS} ${RUMPCOMP_USER_CPPFLAGS} ${.ALLSRC:O:u:M*${rcusrc}.c}
164
165${rcusrc}.o: ${rcusrc}.c
166	${_MKTARGET_COMPILE}
167	${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}
168
169${rcusrc}.pico: ${rcusrc}.c
170	${_MKTARGET_COMPILE}
171	${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}
172
173${rcusrc}.po: ${rcusrc}.c
174	${_MKTARGET_COMPILE}
175	${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}
176
177RUMPOBJ_NORENAME+=${rcusrc}.o ${rcusrc}.pico ${rcusrc}.po
178SRCS+=${rcusrc}.c
179.endfor
180.endif
181
182#
183# Rename library symbols before use.  If a symbol does not already belong
184# to a rump namespace ("rump" or "RUMP"), prefix it with "rumpns".  This
185# avoids accidentally linking any kernel symbol against host platform
186# libraries.  The only non-renamed symbols are linkset delimiters and
187# the GOT, which are more a property of the compiler than the kernel.
188#
189# Some toolchains generate unresolved symbols which are supposed to be
190# satisfied by the toolchain itself when the program is linked.
191# Unfortunately, we do not know which of the symbols are generated by
192# the toolchain.  Worse, they vary from platform to platform and
193# toolchain to toolchain.  The good news, however, is that this will
194# be detected by a compile-time failure, so we can fairly easily manage
195# a quirktable here.
196#
197# We also allow calling ourselves externally with e.g.:
198# make -f /sys/rump/Makefile.rump RUMP_SYMREN=ffs.kobj
199#
200.if ${MACHINE_CPU} == "mips"
201_SYMQUIRK='|_gp_disp'
202.elif ${MACHINE_CPU} == "hppa"
203_SYMQUIRK='|\$$\$$'
204.elif ${MACHINE_ARCH} == "powerpc64"
205_SYMQUIRK="|PF_funcs"
206.endif
207
208#
209# Prefix quirks.  At least one toolchain generates global
210# symbols with prefixes which really need to remain as prefixes
211# (i.e. the '.' on the front of some ppc64 globals).  The
212# way to know if you have the problem is if you get later
213# complaints about symbols like 'rumpns_XrumpBLAH' or 'XrumpBLAH';
214# the 'X' part was added by the toolchain and will need to
215# be mentioned here.
216# 
217.if ${MACHINE_ARCH} == "powerpc64"
218_PQ="\.?"
219.else
220_PQ=
221.endif
222
223rump_symren: __archivebuild
224.if !defined(RUMP_SYMREN)
225	@echo "Must supply RUMP_SYMREN for target rump_symren"
226	@false
227.endif
228
229# if we are called from lib build (RUMP_SYMREN is not specified),
230# build the arrrrchive.  otherwise just rename symbols.
231__archivebuild: .USE
232.if defined(RUMP_SYMREN) && defined(RUMPTOP)
233	@echo "ERROR: RUMP_SYMREN can only be used standalone"
234	@false
235.endif
236.if defined(RUMP_SYMREN)
237	${_MKMSG} " symbol rename " ${RUMP_SYMREN}
238.else
239	${_MKTARGET_BUILD}
240	rm -f ${.TARGET}
241.endif
242	for renameobj in ${RUMP_SYMREN:U${.ALLSRC:C/(${RUMPOBJ_NORENAME:ts|})//g}}; do \
243		${NM} -go $${renameobj} | ${TOOL_AWK} ' \
244		    $$NF!~/^'${_PQ}'(rump|RUMP|__|_GLOBAL_OFFSET_TABLE|\.TOC\.'${_SYMQUIRK}'${RUMP_SYM_NORENAME:D|${RUMP_SYM_NORENAME}})/ \
245		      {s=$$NF;sub(/^'${_PQ}'/, "&rumpns_", s); print $$NF, s}'\
246		    | sort | uniq  > renametab.$${renameobj}; \
247		${OBJCOPY} --preserve-dates --redefine-syms \
248		    renametab.$${renameobj} $${renameobj}; \
249		rm -f renametab.$${renameobj}; \
250	done
251.if !defined(RUMP_SYMREN)
252	${AR} ${_ARFL} ${.TARGET} \
253	    `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
254.endif
255
256COMMENT?=	(no description)
257rumpdescribe: .PHONY
258	@printf '%-24s %s\n' '${LIB}' '${COMMENT}'
259
260_BSD_IOCONF_MK_USER_=1
261.include <bsd.ioconf.mk>
262
263.-include "${NETBSDSRCDIR}/sys/arch/${MACHINE_CPU}/include/Makefile.inc"
264.-include "${NETBSDSRCDIR}/sys/arch/${MACHINE}/include/Makefile.inc"
265
266.endif # _RUMP_MK
267