11.138Schristos#	$NetBSD: Makefile.rump,v 1.138 2024/05/20 04:16:48 christos Exp $
21.1Spooka#
31.1Spooka
41.95Spooka.if !defined(_RUMP_MK)
51.95Spooka_RUMP_MK= #defined
61.95Spooka
71.33SlukemWARNS?=		3	# XXX: src/sys won't compile with -Wsign-compare yet
81.10SpookaNOLINT=		# kernel code
91.1Spooka
101.20Spooka.include <bsd.own.mk>
111.20Spooka
121.90Spooka# Use NetBSD kernel ABI by default on x86 archs.  Performance-related
131.90Spooka# compile-time options may override this at a later date.
141.92Spooka.if (${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64")
151.90Spooka_RUMP_NATIVEABI= yes
161.90Spooka.else
171.90Spooka_RUMP_NATIVEABI= no
181.18SpookaCPPFLAGS:=	-I${RUMPTOP}/include ${CPPFLAGS}
191.92SpookaCPPFLAGS+=	-D_RUMPKERNEL -I${RUMPTOP}/librump/rumpkern
201.18Spooka.endif
211.18Spooka
221.124Schristos# We are compiling the kernel code with no-delete-null-pointer-checks,
231.124Schristos# and compiling without it, causes issues at least on sh3 by adding
241.124Schristos# aborts after kern_assert on NULL pointer checks.
251.127SkamilCFLAGS+=    ${${ACTIVE_CC} == "gcc":? -fno-delete-null-pointer-checks :}
261.124Schristos
271.133Smartin.if ${RUMP_SANITIZE:Uno} != "no"
281.133SmartinCFLAGS+=	-fsanitize=${RUMP_SANITIZE}
291.133SmartinLDFLAGS+=	-fsanitize=${RUMP_SANITIZE}
301.133Smartin.endif
311.133Smartin
321.128Skamil# NULL + 0 arithmetic raises LLVM UBSan warnings, specially in sys/pslist.h
331.128Skamil# in the type-safe macros _PSLIST_VALIDATE_PTRS and _PSLIST_VALIDATE_CONTAINER.
341.128Skamil.if ${MKSANITIZER:Uno} == "yes" || ${MKLIBCSANITIZER:Uno} == "yes"
351.128SkamilCFLAGS+=    ${${ACTIVE_CC} == "clang":? -fno-delete-null-pointer-checks :}
361.128Skamil.endif
371.128Skamil
381.99Salnsn# Define baseline cpu for mips ports, required for
391.99Salnsn# rumpcomp_sync_icache() hypercall.
401.99Salnsn.if !empty(MACHINE_ARCH:Mmips*)
411.132Schristos.if ${MACHINE_MIPS64}
421.99SalnsnCPPFLAGS+=	-DMIPS64=1
431.99Salnsn.else
441.99SalnsnCPPFLAGS+=	-DMIPS1=1
451.99Salnsn.endif
461.99Salnsn.endif
471.99Salnsn
481.112Spooka# which NetBSD compat to build
491.113SpookaRUMP_NBCOMPAT?=default
501.113Spooka.if ${RUMP_NBCOMPAT} == "all" || ${RUMP_NBCOMPAT} == "default"
511.137SchristosRUMP_NBCOMPAT=	50 60 70 80 90 100 110
521.112Spooka.endif
531.112Spooka.if ${RUMP_NBCOMPAT} == "none"
541.112SpookaRUMP_NBCOMPAT=
551.112Spooka.endif
561.110SpookaRUMP_NBCOMPAT:=	${RUMP_NBCOMPAT:S/,/ /g}
571.138SchristosCPPFLAGS+=	${RUMP_NBCOMPAT:C/^[1-9][0-9]*/-DCOMPAT_&/g}
581.104Spooka
591.66SpookaCPPFLAGS+=	-nostdinc
601.22SpookaCFLAGS+=	-ffreestanding -fno-strict-aliasing
611.66Spooka
621.50SpookaCWARNFLAGS+=	-Wno-format-zero-length -Wno-pointer-sign
631.114Spooka
641.131SchristosCPPIFLAGS+=	-imacros ${RUMPTOP}/include/opt/opt_rumpkernel.h
651.115Spooka.ifdef BUILDRUMP_IMACROS
661.131SchristosCPPIFLAGS+=	-imacros ${BUILDRUMP_IMACROS}
671.115Spooka.endif
681.114Spooka
691.15SpookaCPPFLAGS+=	-I${.CURDIR} -I.
701.65SpookaCPPFLAGS+=	-I${RUMPTOP}/../../common/include
711.18SpookaCPPFLAGS+=	-I${RUMPTOP}/include
721.117SpookaCPPFLAGS+=	-I${RUMPTOP}/include/opt
731.65Spooka
741.103SpookaSHLIB_MAJOR?=	0
751.103SpookaSHLIB_MINOR?=	0
761.103Spooka
771.65Spooka.ifdef NEED_ISYSTEM
781.131SchristosCPPIFLAGS+=	-isystem ${RUMPTOP}/../arch
791.131SchristosCPPIFLAGS+=	-isystem ${RUMPTOP}/..
801.65Spooka.else
811.65SpookaCPPFLAGS+=	-I${RUMPTOP}/../arch
821.65SpookaCPPFLAGS+=	-I${RUMPTOP}/..
831.65Spooka.endif
841.65Spooka
851.93SpookaRUMP_LDSCRIPT?=	GNU
861.79Spooka.if ${RUMP_LDSCRIPT} != "no"
871.72Spooka# my ld or yours?
881.97Spooka.if ${RUMP_LDSCRIPT} == "sun"
891.72SpookaLDFLAGS+=	-Wl,-M ${RUMPTOP}/ldscript_sun.rump
901.72SpookaSRCS+=		linksyms_sun.c
911.74Spooka.PATH:		${RUMPTOP}
921.93Spooka.elif ${RUMP_LDSCRIPT} == "GNU"
931.93SpookaLDFLAGS+=	-Wl,-T,${RUMPTOP}/ldscript.rump
941.96Spooka.elif ${RUMP_LDSCRIPT} == "ctor"
951.96SpookaCPPFLAGS+=	-DRUMP_USE_CTOR
961.72Spooka.else
971.93Spooka.error Unknown ldscript ${RUMP_LDSCRIPT}
981.73Spooka.endif
991.79Spooka.endif
1001.62Spooka
1011.94Spooka.if defined(RUMP_CURLWP)
1021.94Spooka.if   ${RUMP_CURLWP} == "hypercall"
1031.94SpookaCPPFLAGS+=	-DRUMP_CURLWP=RUMP_CURLWP_HYPERCALL
1041.94Spooka.elif ${RUMP_CURLWP} == "__thread"
1051.94SpookaCPPFLAGS+=	-DRUMP_CURLWP=RUMP_CURLWP___THREAD
1061.94Spooka.elif ${RUMP_CURLWP} == "register"
1071.94SpookaCPPFLAGS+=	-DRUMP_CURLWP=RUMP_CURLWP_REGISTER
1081.94Spooka.else
1091.94Spooka.error Unsupported curlwp scheme: ${RUMP_CURLWP}
1101.94Spooka.endif
1111.94Spooka.endif
1121.94Spooka
1131.62SpookaRUMP_DIAGNOSTIC?=yes
1141.62Spooka.if ${RUMP_DIAGNOSTIC} == "yes"
1151.62SpookaCPPFLAGS+=	-DDIAGNOSTIC
1161.62Spooka.endif
1171.62Spooka
1181.62Spooka.ifdef RUMP_DEBUG
1191.62SpookaCPPFLAGS+=	-DDEBUG
1201.62Spooka.endif
1211.1Spooka
1221.59Spooka.ifdef RUMP_LOCKDEBUG
1231.59SpookaCPPFLAGS+=	-DLOCKDEBUG
1241.59Spooka.endif
1251.59Spooka
1261.134Shannken.ifdef RUMP_VNODE_LOCKDEBUG
1271.134ShannkenCPPFLAGS+=	-DVNODE_LOCKDEBUG
1281.134Shannken.endif
1291.134Shannken
1301.89SpookaRUMP_KTRACE?=yes
1311.89Spooka.if ${RUMP_KTRACE} == "yes"
1321.89SpookaCPPFLAGS+=	-DKTRACE
1331.89Spooka.endif
1341.89Spooka
1351.42Spooka# kernel libs should not get linked against libc
1361.43Spooka# XXX: actually, we would like to enable this but cannot, since it
1371.43Spooka# also leaves out libgcc, it causes problems on some platforms.
1381.43Spooka# revisit some day.
1391.43Spooka#LDFLAGS+=	-nodefaultlibs
1401.42Spooka
1411.39Spooka# make sure __NetBSD__ gets defined (for builds on non-NetBSD)
1421.67Spooka# also, give those builds a way to undef the local compiler's macros
1431.114SpookaCPPFLAGS+=	${RUMPKERN_UNDEF}
1441.39Spooka
1451.11SpookaRUMPKERNEL=	This is NetBSD and I am the rump.  Good evening.
1461.11Spooka
1471.13Spooka# workaround: evbppc is not a well-defined arch
1481.130Srin.if ${MACHINE} == "evbppc"
1491.130Srin.  if ${MACHINE_ARCH} == "powerpc"
1501.16SpookaCPPFLAGS+=	-DPPC_OEA
1511.130Srin.  else
1521.130SrinCPPFLAGS+=	-DPPC_OEA64
1531.130Srin.  endif
1541.13Spooka.endif
1551.13Spooka
1561.114Spooka# If any of these files change, we need a full rebuild
1571.25SpookaDPSRCS+=	${RUMPTOP}/Makefile.rump
1581.24Spooka
1591.24Spooka#
1601.69Spooka# Support for component-specific hypercalls
1611.69Spooka#
1621.69Spooka
1631.101Spooka# no easy way to get WARNS out of bsd.sys.mk
1641.102SpookaRUMPCOMP_USER_WARNFLAGS=	-Wall -Wextra -Wno-unused-parameter
1651.102SpookaRUMPCOMP_USER_WARNFLAGS+=	-Wstrict-prototypes -Wmissing-prototypes
1661.75Schristos
1671.91Spooka.ifdef RUMPCOMP_USER_SRCS && !defined(RUMPKERN_ONLY)
1681.75Schristos.if empty(DESTDIR)
1691.75SchristosDESTDIR=/
1701.75Schristos.endif
1711.75SchristosBUILDRUMP_CPPFLAGS ?= -isysroot ${DESTDIR}
1721.82SpookaRUMPCOMP_USER_WERROR = ${${_NOWERROR} == "no" :?-Werror:}
1731.91Spooka.for rcusrc in ${RUMPCOMP_USER_SRCS:R}
1741.91Spooka${rcusrc}.d: ${rcusrc}.c
1751.69Spooka	${_MKTARGET_CREATE}
1761.122Sjoerg	${MKDEP} -f ${.TARGET} -- ${MKDEPFLAGS} ${CPUFLAGS} ${REPROFLAGS} ${BUILDRUMP_CPPFLAGS} ${RUMPCOMP_USER_CPPFLAGS} ${.ALLSRC:O:u:M*${rcusrc}.c}
1771.69Spooka
1781.91Spooka${rcusrc}.o: ${rcusrc}.c
1791.69Spooka	${_MKTARGET_COMPILE}
1801.122Sjoerg	${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}
1811.69Spooka
1821.91Spooka${rcusrc}.pico: ${rcusrc}.c
1831.69Spooka	${_MKTARGET_COMPILE}
1841.122Sjoerg	${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}
1851.69Spooka
1861.91Spooka${rcusrc}.po: ${rcusrc}.c
1871.69Spooka	${_MKTARGET_COMPILE}
1881.122Sjoerg	${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}
1891.69Spooka
1901.91SpookaRUMPOBJ_NORENAME+=${rcusrc}.o ${rcusrc}.pico ${rcusrc}.po
1911.91SpookaSRCS+=${rcusrc}.c
1921.91Spooka.endfor
1931.69Spooka.endif
1941.69Spooka
1951.69Spooka#
1961.24Spooka# Rename library symbols before use.  If a symbol does not already belong
1971.24Spooka# to a rump namespace ("rump" or "RUMP"), prefix it with "rumpns".  This
1981.24Spooka# avoids accidentally linking any kernel symbol against host platform
1991.24Spooka# libraries.  The only non-renamed symbols are linkset delimiters and
2001.24Spooka# the GOT, which are more a property of the compiler than the kernel.
2011.24Spooka#
2021.29Spooka# Some toolchains generate unresolved symbols which are supposed to be
2031.29Spooka# satisfied by the toolchain itself when the program is linked.
2041.29Spooka# Unfortunately, we do not know which of the symbols are generated by
2051.29Spooka# the toolchain.  Worse, they vary from platform to platform and
2061.29Spooka# toolchain to toolchain.  The good news, however, is that this will
2071.29Spooka# be detected by a compile-time failure, so we can fairly easily manage
2081.29Spooka# a quirktable here.
2091.46Spooka#
2101.46Spooka# We also allow calling ourselves externally with e.g.:
2111.46Spooka# make -f /sys/rump/Makefile.rump RUMP_SYMREN=ffs.kobj
2121.46Spooka#
2131.29Spooka.if ${MACHINE_CPU} == "mips"
2141.29Spooka_SYMQUIRK='|_gp_disp'
2151.29Spooka.elif ${MACHINE_CPU} == "hppa"
2161.29Spooka_SYMQUIRK='|\$$\$$'
2171.54Smrg.elif ${MACHINE_ARCH} == "powerpc64"
2181.55Smrg_SYMQUIRK="|PF_funcs"
2191.55Smrg.endif
2201.55Smrg
2211.55Smrg#
2221.55Smrg# Prefix quirks.  At least one toolchain generates global
2231.55Smrg# symbols with prefixes which really need to remain as prefixes
2241.55Smrg# (i.e. the '.' on the front of some ppc64 globals).  The
2251.55Smrg# way to know if you have the problem is if you get later
2261.55Smrg# complaints about symbols like 'rumpns_XrumpBLAH' or 'XrumpBLAH';
2271.55Smrg# the 'X' part was added by the toolchain and will need to
2281.55Smrg# be mentioned here.
2291.55Smrg# 
2301.55Smrg.if ${MACHINE_ARCH} == "powerpc64"
2311.55Smrg_PQ="\.?"
2321.55Smrg.else
2331.55Smrg_PQ=
2341.29Spooka.endif
2351.46Spooka
2361.46Spookarump_symren: __archivebuild
2371.46Spooka.if !defined(RUMP_SYMREN)
2381.46Spooka	@echo "Must supply RUMP_SYMREN for target rump_symren"
2391.46Spooka	@false
2401.46Spooka.endif
2411.46Spooka
2421.46Spooka# if we are called from lib build (RUMP_SYMREN is not specified),
2431.136Sandvar# build the archive.  otherwise just rename symbols.
2441.24Spooka__archivebuild: .USE
2451.46Spooka.if defined(RUMP_SYMREN) && defined(RUMPTOP)
2461.46Spooka	@echo "ERROR: RUMP_SYMREN can only be used standalone"
2471.46Spooka	@false
2481.46Spooka.endif
2491.46Spooka.if defined(RUMP_SYMREN)
2501.46Spooka	${_MKMSG} " symbol rename " ${RUMP_SYMREN}
2511.46Spooka.else
2521.24Spooka	${_MKTARGET_BUILD}
2531.24Spooka	rm -f ${.TARGET}
2541.46Spooka.endif
2551.91Spooka	for renameobj in ${RUMP_SYMREN:U${.ALLSRC:C/(${RUMPOBJ_NORENAME:ts|})//g}}; do \
2561.91Spooka		${NM} -go $${renameobj} | ${TOOL_AWK} ' \
2571.125Sjoerg		    $$NF!~/^'${_PQ}'(rump|RUMP|__|_GLOBAL_OFFSET_TABLE|\.TOC\.'${_SYMQUIRK}'${RUMP_SYM_NORENAME:D|${RUMP_SYM_NORENAME}})/ \
2581.69Spooka		      {s=$$NF;sub(/^'${_PQ}'/, "&rumpns_", s); print $$NF, s}'\
2591.91Spooka		    | sort | uniq  > renametab.$${renameobj}; \
2601.69Spooka		${OBJCOPY} --preserve-dates --redefine-syms \
2611.91Spooka		    renametab.$${renameobj} $${renameobj}; \
2621.91Spooka		rm -f renametab.$${renameobj}; \
2631.69Spooka	done
2641.46Spooka.if !defined(RUMP_SYMREN)
2651.69Spooka	${AR} ${_ARFL} ${.TARGET} \
2661.69Spooka	    `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
2671.46Spooka.endif
2681.47Spooka
2691.119SpookaCOMMENT?=	(no description)
2701.120Spookarumpdescribe: .PHONY
2711.119Spooka	@printf '%-24s %s\n' '${LIB}' '${COMMENT}'
2721.119Spooka
2731.131SchristosCPPFLAGS+=	${CPPIFLAGS}
2741.131SchristosLINTFLAGS+=	${CPPIFLAGS:S/^/-Z /}
2751.131Schristos
2761.53Spooka_BSD_IOCONF_MK_USER_=1
2771.53Spooka.include <bsd.ioconf.mk>
2781.47Spooka
2791.44Spooka.-include "${NETBSDSRCDIR}/sys/arch/${MACHINE_CPU}/include/Makefile.inc"
2801.44Spooka.-include "${NETBSDSRCDIR}/sys/arch/${MACHINE}/include/Makefile.inc"
2811.95Spooka
2821.95Spooka.endif # _RUMP_MK
283