Makefile.rump revision 1.126
11.126Skamil#	$NetBSD: Makefile.rump,v 1.126 2020/03/09 00:03:00 kamil 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.126Skamil# no-delete-null-pointer-checks is required in Clang/LLVM at least for
261.126Skamil# NULL + 0 operations that trigger LLVM UBSan and could be miscompiled.
271.126SkamilCFLAGS+=    -fno-delete-null-pointer-checks
281.124Schristos
291.99Salnsn# Define baseline cpu for mips ports, required for
301.99Salnsn# rumpcomp_sync_icache() hypercall.
311.99Salnsn.if !empty(MACHINE_ARCH:Mmips*)
321.99Salnsn.if !empty(MACHINE_ARCH:Mmips64*)
331.99SalnsnCPPFLAGS+=	-DMIPS64=1
341.99Salnsn.else
351.99SalnsnCPPFLAGS+=	-DMIPS1=1
361.99Salnsn.endif
371.99Salnsn.endif
381.99Salnsn
391.112Spooka# which NetBSD compat to build
401.113SpookaRUMP_NBCOMPAT?=default
411.113Spooka.if ${RUMP_NBCOMPAT} == "all" || ${RUMP_NBCOMPAT} == "default"
421.123SmrgRUMP_NBCOMPAT=	50 60 70 80
431.112Spooka.endif
441.112Spooka.if ${RUMP_NBCOMPAT} == "none"
451.112SpookaRUMP_NBCOMPAT=
461.112Spooka.endif
471.110SpookaRUMP_NBCOMPAT:=	${RUMP_NBCOMPAT:S/,/ /g}
481.110SpookaCPPFLAGS+=	${RUMP_NBCOMPAT:C/[1-9]0/-DCOMPAT_&/g}
491.104Spooka
501.66SpookaCPPFLAGS+=	-nostdinc
511.22SpookaCFLAGS+=	-ffreestanding -fno-strict-aliasing
521.66Spooka
531.50SpookaCWARNFLAGS+=	-Wno-format-zero-length -Wno-pointer-sign
541.114Spooka
551.114SpookaCPPFLAGS+=	-imacros ${RUMPTOP}/include/opt/opt_rumpkernel.h
561.115Spooka.ifdef BUILDRUMP_IMACROS
571.115SpookaCPPFLAGS+=	-imacros ${BUILDRUMP_IMACROS}
581.115Spooka.endif
591.114Spooka
601.15SpookaCPPFLAGS+=	-I${.CURDIR} -I.
611.65SpookaCPPFLAGS+=	-I${RUMPTOP}/../../common/include
621.18SpookaCPPFLAGS+=	-I${RUMPTOP}/include
631.117SpookaCPPFLAGS+=	-I${RUMPTOP}/include/opt
641.65Spooka
651.103SpookaSHLIB_MAJOR?=	0
661.103SpookaSHLIB_MINOR?=	0
671.103Spooka
681.65Spooka.ifdef NEED_ISYSTEM
691.65SpookaCPPFLAGS+=	-isystem ${RUMPTOP}/../arch
701.65SpookaCPPFLAGS+=	-isystem ${RUMPTOP}/..
711.65Spooka.else
721.65SpookaCPPFLAGS+=	-I${RUMPTOP}/../arch
731.65SpookaCPPFLAGS+=	-I${RUMPTOP}/..
741.65Spooka.endif
751.65Spooka
761.93SpookaRUMP_LDSCRIPT?=	GNU
771.79Spooka.if ${RUMP_LDSCRIPT} != "no"
781.72Spooka# my ld or yours?
791.97Spooka.if ${RUMP_LDSCRIPT} == "sun"
801.72SpookaLDFLAGS+=	-Wl,-M ${RUMPTOP}/ldscript_sun.rump
811.72SpookaSRCS+=		linksyms_sun.c
821.74Spooka.PATH:		${RUMPTOP}
831.93Spooka.elif ${RUMP_LDSCRIPT} == "GNU"
841.93SpookaLDFLAGS+=	-Wl,-T,${RUMPTOP}/ldscript.rump
851.96Spooka.elif ${RUMP_LDSCRIPT} == "ctor"
861.96SpookaCPPFLAGS+=	-DRUMP_USE_CTOR
871.72Spooka.else
881.93Spooka.error Unknown ldscript ${RUMP_LDSCRIPT}
891.73Spooka.endif
901.79Spooka.endif
911.62Spooka
921.94Spooka.if defined(RUMP_CURLWP)
931.94Spooka.if   ${RUMP_CURLWP} == "hypercall"
941.94SpookaCPPFLAGS+=	-DRUMP_CURLWP=RUMP_CURLWP_HYPERCALL
951.94Spooka.elif ${RUMP_CURLWP} == "__thread"
961.94SpookaCPPFLAGS+=	-DRUMP_CURLWP=RUMP_CURLWP___THREAD
971.94Spooka.elif ${RUMP_CURLWP} == "register"
981.94SpookaCPPFLAGS+=	-DRUMP_CURLWP=RUMP_CURLWP_REGISTER
991.94Spooka.else
1001.94Spooka.error Unsupported curlwp scheme: ${RUMP_CURLWP}
1011.94Spooka.endif
1021.94Spooka.endif
1031.94Spooka
1041.62SpookaRUMP_DIAGNOSTIC?=yes
1051.62Spooka.if ${RUMP_DIAGNOSTIC} == "yes"
1061.62SpookaCPPFLAGS+=	-DDIAGNOSTIC
1071.62Spooka.endif
1081.62Spooka
1091.62Spooka.ifdef RUMP_DEBUG
1101.62SpookaCPPFLAGS+=	-DDEBUG
1111.62Spooka.endif
1121.1Spooka
1131.59Spooka.ifdef RUMP_LOCKDEBUG
1141.59SpookaCPPFLAGS+=	-DLOCKDEBUG
1151.59Spooka.endif
1161.59Spooka
1171.89SpookaRUMP_KTRACE?=yes
1181.89Spooka.if ${RUMP_KTRACE} == "yes"
1191.89SpookaCPPFLAGS+=	-DKTRACE
1201.89Spooka.endif
1211.89Spooka
1221.42Spooka# kernel libs should not get linked against libc
1231.43Spooka# XXX: actually, we would like to enable this but cannot, since it
1241.43Spooka# also leaves out libgcc, it causes problems on some platforms.
1251.43Spooka# revisit some day.
1261.43Spooka#LDFLAGS+=	-nodefaultlibs
1271.42Spooka
1281.39Spooka# make sure __NetBSD__ gets defined (for builds on non-NetBSD)
1291.67Spooka# also, give those builds a way to undef the local compiler's macros
1301.114SpookaCPPFLAGS+=	${RUMPKERN_UNDEF}
1311.39Spooka
1321.11SpookaRUMPKERNEL=	This is NetBSD and I am the rump.  Good evening.
1331.11Spooka
1341.13Spooka# workaround: evbppc is not a well-defined arch
1351.13Spooka.if (${MACHINE} == "evbppc")
1361.16SpookaCPPFLAGS+=	-DPPC_OEA
1371.13Spooka.endif
1381.13Spooka
1391.114Spooka# If any of these files change, we need a full rebuild
1401.25SpookaDPSRCS+=	${RUMPTOP}/Makefile.rump
1411.24Spooka
1421.24Spooka#
1431.69Spooka# Support for component-specific hypercalls
1441.69Spooka#
1451.69Spooka
1461.101Spooka# no easy way to get WARNS out of bsd.sys.mk
1471.102SpookaRUMPCOMP_USER_WARNFLAGS=	-Wall -Wextra -Wno-unused-parameter
1481.102SpookaRUMPCOMP_USER_WARNFLAGS+=	-Wstrict-prototypes -Wmissing-prototypes
1491.75Schristos
1501.91Spooka.ifdef RUMPCOMP_USER_SRCS && !defined(RUMPKERN_ONLY)
1511.75Schristos.if empty(DESTDIR)
1521.75SchristosDESTDIR=/
1531.75Schristos.endif
1541.75SchristosBUILDRUMP_CPPFLAGS ?= -isysroot ${DESTDIR}
1551.82SpookaRUMPCOMP_USER_WERROR = ${${_NOWERROR} == "no" :?-Werror:}
1561.91Spooka.for rcusrc in ${RUMPCOMP_USER_SRCS:R}
1571.91Spooka${rcusrc}.d: ${rcusrc}.c
1581.69Spooka	${_MKTARGET_CREATE}
1591.122Sjoerg	${MKDEP} -f ${.TARGET} -- ${MKDEPFLAGS} ${CPUFLAGS} ${REPROFLAGS} ${BUILDRUMP_CPPFLAGS} ${RUMPCOMP_USER_CPPFLAGS} ${.ALLSRC:O:u:M*${rcusrc}.c}
1601.69Spooka
1611.91Spooka${rcusrc}.o: ${rcusrc}.c
1621.69Spooka	${_MKTARGET_COMPILE}
1631.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}
1641.69Spooka
1651.91Spooka${rcusrc}.pico: ${rcusrc}.c
1661.69Spooka	${_MKTARGET_COMPILE}
1671.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}
1681.69Spooka
1691.91Spooka${rcusrc}.po: ${rcusrc}.c
1701.69Spooka	${_MKTARGET_COMPILE}
1711.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}
1721.69Spooka
1731.91SpookaRUMPOBJ_NORENAME+=${rcusrc}.o ${rcusrc}.pico ${rcusrc}.po
1741.91SpookaSRCS+=${rcusrc}.c
1751.91Spooka.endfor
1761.69Spooka.endif
1771.69Spooka
1781.69Spooka#
1791.24Spooka# Rename library symbols before use.  If a symbol does not already belong
1801.24Spooka# to a rump namespace ("rump" or "RUMP"), prefix it with "rumpns".  This
1811.24Spooka# avoids accidentally linking any kernel symbol against host platform
1821.24Spooka# libraries.  The only non-renamed symbols are linkset delimiters and
1831.24Spooka# the GOT, which are more a property of the compiler than the kernel.
1841.24Spooka#
1851.29Spooka# Some toolchains generate unresolved symbols which are supposed to be
1861.29Spooka# satisfied by the toolchain itself when the program is linked.
1871.29Spooka# Unfortunately, we do not know which of the symbols are generated by
1881.29Spooka# the toolchain.  Worse, they vary from platform to platform and
1891.29Spooka# toolchain to toolchain.  The good news, however, is that this will
1901.29Spooka# be detected by a compile-time failure, so we can fairly easily manage
1911.29Spooka# a quirktable here.
1921.46Spooka#
1931.46Spooka# We also allow calling ourselves externally with e.g.:
1941.46Spooka# make -f /sys/rump/Makefile.rump RUMP_SYMREN=ffs.kobj
1951.46Spooka#
1961.29Spooka.if ${MACHINE_CPU} == "mips"
1971.29Spooka_SYMQUIRK='|_gp_disp'
1981.29Spooka.elif ${MACHINE_CPU} == "hppa"
1991.29Spooka_SYMQUIRK='|\$$\$$'
2001.54Smrg.elif ${MACHINE_ARCH} == "powerpc64"
2011.55Smrg_SYMQUIRK="|PF_funcs"
2021.55Smrg.endif
2031.55Smrg
2041.55Smrg#
2051.55Smrg# Prefix quirks.  At least one toolchain generates global
2061.55Smrg# symbols with prefixes which really need to remain as prefixes
2071.55Smrg# (i.e. the '.' on the front of some ppc64 globals).  The
2081.55Smrg# way to know if you have the problem is if you get later
2091.55Smrg# complaints about symbols like 'rumpns_XrumpBLAH' or 'XrumpBLAH';
2101.55Smrg# the 'X' part was added by the toolchain and will need to
2111.55Smrg# be mentioned here.
2121.55Smrg# 
2131.55Smrg.if ${MACHINE_ARCH} == "powerpc64"
2141.55Smrg_PQ="\.?"
2151.55Smrg.else
2161.55Smrg_PQ=
2171.29Spooka.endif
2181.46Spooka
2191.46Spookarump_symren: __archivebuild
2201.46Spooka.if !defined(RUMP_SYMREN)
2211.46Spooka	@echo "Must supply RUMP_SYMREN for target rump_symren"
2221.46Spooka	@false
2231.46Spooka.endif
2241.46Spooka
2251.46Spooka# if we are called from lib build (RUMP_SYMREN is not specified),
2261.46Spooka# build the arrrrchive.  otherwise just rename symbols.
2271.24Spooka__archivebuild: .USE
2281.46Spooka.if defined(RUMP_SYMREN) && defined(RUMPTOP)
2291.46Spooka	@echo "ERROR: RUMP_SYMREN can only be used standalone"
2301.46Spooka	@false
2311.46Spooka.endif
2321.46Spooka.if defined(RUMP_SYMREN)
2331.46Spooka	${_MKMSG} " symbol rename " ${RUMP_SYMREN}
2341.46Spooka.else
2351.24Spooka	${_MKTARGET_BUILD}
2361.24Spooka	rm -f ${.TARGET}
2371.46Spooka.endif
2381.91Spooka	for renameobj in ${RUMP_SYMREN:U${.ALLSRC:C/(${RUMPOBJ_NORENAME:ts|})//g}}; do \
2391.91Spooka		${NM} -go $${renameobj} | ${TOOL_AWK} ' \
2401.125Sjoerg		    $$NF!~/^'${_PQ}'(rump|RUMP|__|_GLOBAL_OFFSET_TABLE|\.TOC\.'${_SYMQUIRK}'${RUMP_SYM_NORENAME:D|${RUMP_SYM_NORENAME}})/ \
2411.69Spooka		      {s=$$NF;sub(/^'${_PQ}'/, "&rumpns_", s); print $$NF, s}'\
2421.91Spooka		    | sort | uniq  > renametab.$${renameobj}; \
2431.69Spooka		${OBJCOPY} --preserve-dates --redefine-syms \
2441.91Spooka		    renametab.$${renameobj} $${renameobj}; \
2451.91Spooka		rm -f renametab.$${renameobj}; \
2461.69Spooka	done
2471.46Spooka.if !defined(RUMP_SYMREN)
2481.69Spooka	${AR} ${_ARFL} ${.TARGET} \
2491.69Spooka	    `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
2501.46Spooka.endif
2511.47Spooka
2521.119SpookaCOMMENT?=	(no description)
2531.120Spookarumpdescribe: .PHONY
2541.119Spooka	@printf '%-24s %s\n' '${LIB}' '${COMMENT}'
2551.119Spooka
2561.53Spooka_BSD_IOCONF_MK_USER_=1
2571.53Spooka.include <bsd.ioconf.mk>
2581.47Spooka
2591.44Spooka.-include "${NETBSDSRCDIR}/sys/arch/${MACHINE_CPU}/include/Makefile.inc"
2601.44Spooka.-include "${NETBSDSRCDIR}/sys/arch/${MACHINE}/include/Makefile.inc"
2611.95Spooka
2621.95Spooka.endif # _RUMP_MK
263