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