Makefile.rump revision 1.125
11.125Sjoerg#	$NetBSD: Makefile.rump,v 1.125 2020/02/20 22:52:10 joerg 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.124SchristosCFLAGS+=    ${${ACTIVE_CC} == "gcc":? -fno-delete-null-pointer-checks :}
261.124Schristos
271.99Salnsn# Define baseline cpu for mips ports, required for
281.99Salnsn# rumpcomp_sync_icache() hypercall.
291.99Salnsn.if !empty(MACHINE_ARCH:Mmips*)
301.99Salnsn.if !empty(MACHINE_ARCH:Mmips64*)
311.99SalnsnCPPFLAGS+=	-DMIPS64=1
321.99Salnsn.else
331.99SalnsnCPPFLAGS+=	-DMIPS1=1
341.99Salnsn.endif
351.99Salnsn.endif
361.99Salnsn
371.112Spooka# which NetBSD compat to build
381.113SpookaRUMP_NBCOMPAT?=default
391.113Spooka.if ${RUMP_NBCOMPAT} == "all" || ${RUMP_NBCOMPAT} == "default"
401.123SmrgRUMP_NBCOMPAT=	50 60 70 80
411.112Spooka.endif
421.112Spooka.if ${RUMP_NBCOMPAT} == "none"
431.112SpookaRUMP_NBCOMPAT=
441.112Spooka.endif
451.110SpookaRUMP_NBCOMPAT:=	${RUMP_NBCOMPAT:S/,/ /g}
461.110SpookaCPPFLAGS+=	${RUMP_NBCOMPAT:C/[1-9]0/-DCOMPAT_&/g}
471.104Spooka
481.66SpookaCPPFLAGS+=	-nostdinc
491.22SpookaCFLAGS+=	-ffreestanding -fno-strict-aliasing
501.66Spooka
511.50SpookaCWARNFLAGS+=	-Wno-format-zero-length -Wno-pointer-sign
521.114Spooka
531.114SpookaCPPFLAGS+=	-imacros ${RUMPTOP}/include/opt/opt_rumpkernel.h
541.115Spooka.ifdef BUILDRUMP_IMACROS
551.115SpookaCPPFLAGS+=	-imacros ${BUILDRUMP_IMACROS}
561.115Spooka.endif
571.114Spooka
581.15SpookaCPPFLAGS+=	-I${.CURDIR} -I.
591.65SpookaCPPFLAGS+=	-I${RUMPTOP}/../../common/include
601.18SpookaCPPFLAGS+=	-I${RUMPTOP}/include
611.117SpookaCPPFLAGS+=	-I${RUMPTOP}/include/opt
621.65Spooka
631.103SpookaSHLIB_MAJOR?=	0
641.103SpookaSHLIB_MINOR?=	0
651.103Spooka
661.65Spooka.ifdef NEED_ISYSTEM
671.65SpookaCPPFLAGS+=	-isystem ${RUMPTOP}/../arch
681.65SpookaCPPFLAGS+=	-isystem ${RUMPTOP}/..
691.65Spooka.else
701.65SpookaCPPFLAGS+=	-I${RUMPTOP}/../arch
711.65SpookaCPPFLAGS+=	-I${RUMPTOP}/..
721.65Spooka.endif
731.65Spooka
741.93SpookaRUMP_LDSCRIPT?=	GNU
751.79Spooka.if ${RUMP_LDSCRIPT} != "no"
761.72Spooka# my ld or yours?
771.97Spooka.if ${RUMP_LDSCRIPT} == "sun"
781.72SpookaLDFLAGS+=	-Wl,-M ${RUMPTOP}/ldscript_sun.rump
791.72SpookaSRCS+=		linksyms_sun.c
801.74Spooka.PATH:		${RUMPTOP}
811.93Spooka.elif ${RUMP_LDSCRIPT} == "GNU"
821.93SpookaLDFLAGS+=	-Wl,-T,${RUMPTOP}/ldscript.rump
831.96Spooka.elif ${RUMP_LDSCRIPT} == "ctor"
841.96SpookaCPPFLAGS+=	-DRUMP_USE_CTOR
851.72Spooka.else
861.93Spooka.error Unknown ldscript ${RUMP_LDSCRIPT}
871.73Spooka.endif
881.79Spooka.endif
891.62Spooka
901.94Spooka.if defined(RUMP_CURLWP)
911.94Spooka.if   ${RUMP_CURLWP} == "hypercall"
921.94SpookaCPPFLAGS+=	-DRUMP_CURLWP=RUMP_CURLWP_HYPERCALL
931.94Spooka.elif ${RUMP_CURLWP} == "__thread"
941.94SpookaCPPFLAGS+=	-DRUMP_CURLWP=RUMP_CURLWP___THREAD
951.94Spooka.elif ${RUMP_CURLWP} == "register"
961.94SpookaCPPFLAGS+=	-DRUMP_CURLWP=RUMP_CURLWP_REGISTER
971.94Spooka.else
981.94Spooka.error Unsupported curlwp scheme: ${RUMP_CURLWP}
991.94Spooka.endif
1001.94Spooka.endif
1011.94Spooka
1021.62SpookaRUMP_DIAGNOSTIC?=yes
1031.62Spooka.if ${RUMP_DIAGNOSTIC} == "yes"
1041.62SpookaCPPFLAGS+=	-DDIAGNOSTIC
1051.62Spooka.endif
1061.62Spooka
1071.62Spooka.ifdef RUMP_DEBUG
1081.62SpookaCPPFLAGS+=	-DDEBUG
1091.62Spooka.endif
1101.1Spooka
1111.59Spooka.ifdef RUMP_LOCKDEBUG
1121.59SpookaCPPFLAGS+=	-DLOCKDEBUG
1131.59Spooka.endif
1141.59Spooka
1151.89SpookaRUMP_KTRACE?=yes
1161.89Spooka.if ${RUMP_KTRACE} == "yes"
1171.89SpookaCPPFLAGS+=	-DKTRACE
1181.89Spooka.endif
1191.89Spooka
1201.42Spooka# kernel libs should not get linked against libc
1211.43Spooka# XXX: actually, we would like to enable this but cannot, since it
1221.43Spooka# also leaves out libgcc, it causes problems on some platforms.
1231.43Spooka# revisit some day.
1241.43Spooka#LDFLAGS+=	-nodefaultlibs
1251.42Spooka
1261.39Spooka# make sure __NetBSD__ gets defined (for builds on non-NetBSD)
1271.67Spooka# also, give those builds a way to undef the local compiler's macros
1281.114SpookaCPPFLAGS+=	${RUMPKERN_UNDEF}
1291.39Spooka
1301.11SpookaRUMPKERNEL=	This is NetBSD and I am the rump.  Good evening.
1311.11Spooka
1321.13Spooka# workaround: evbppc is not a well-defined arch
1331.13Spooka.if (${MACHINE} == "evbppc")
1341.16SpookaCPPFLAGS+=	-DPPC_OEA
1351.13Spooka.endif
1361.13Spooka
1371.114Spooka# If any of these files change, we need a full rebuild
1381.25SpookaDPSRCS+=	${RUMPTOP}/Makefile.rump
1391.24Spooka
1401.24Spooka#
1411.69Spooka# Support for component-specific hypercalls
1421.69Spooka#
1431.69Spooka
1441.101Spooka# no easy way to get WARNS out of bsd.sys.mk
1451.102SpookaRUMPCOMP_USER_WARNFLAGS=	-Wall -Wextra -Wno-unused-parameter
1461.102SpookaRUMPCOMP_USER_WARNFLAGS+=	-Wstrict-prototypes -Wmissing-prototypes
1471.75Schristos
1481.91Spooka.ifdef RUMPCOMP_USER_SRCS && !defined(RUMPKERN_ONLY)
1491.75Schristos.if empty(DESTDIR)
1501.75SchristosDESTDIR=/
1511.75Schristos.endif
1521.75SchristosBUILDRUMP_CPPFLAGS ?= -isysroot ${DESTDIR}
1531.82SpookaRUMPCOMP_USER_WERROR = ${${_NOWERROR} == "no" :?-Werror:}
1541.91Spooka.for rcusrc in ${RUMPCOMP_USER_SRCS:R}
1551.91Spooka${rcusrc}.d: ${rcusrc}.c
1561.69Spooka	${_MKTARGET_CREATE}
1571.122Sjoerg	${MKDEP} -f ${.TARGET} -- ${MKDEPFLAGS} ${CPUFLAGS} ${REPROFLAGS} ${BUILDRUMP_CPPFLAGS} ${RUMPCOMP_USER_CPPFLAGS} ${.ALLSRC:O:u:M*${rcusrc}.c}
1581.69Spooka
1591.91Spooka${rcusrc}.o: ${rcusrc}.c
1601.69Spooka	${_MKTARGET_COMPILE}
1611.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}
1621.69Spooka
1631.91Spooka${rcusrc}.pico: ${rcusrc}.c
1641.69Spooka	${_MKTARGET_COMPILE}
1651.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}
1661.69Spooka
1671.91Spooka${rcusrc}.po: ${rcusrc}.c
1681.69Spooka	${_MKTARGET_COMPILE}
1691.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}
1701.69Spooka
1711.91SpookaRUMPOBJ_NORENAME+=${rcusrc}.o ${rcusrc}.pico ${rcusrc}.po
1721.91SpookaSRCS+=${rcusrc}.c
1731.91Spooka.endfor
1741.69Spooka.endif
1751.69Spooka
1761.69Spooka#
1771.24Spooka# Rename library symbols before use.  If a symbol does not already belong
1781.24Spooka# to a rump namespace ("rump" or "RUMP"), prefix it with "rumpns".  This
1791.24Spooka# avoids accidentally linking any kernel symbol against host platform
1801.24Spooka# libraries.  The only non-renamed symbols are linkset delimiters and
1811.24Spooka# the GOT, which are more a property of the compiler than the kernel.
1821.24Spooka#
1831.29Spooka# Some toolchains generate unresolved symbols which are supposed to be
1841.29Spooka# satisfied by the toolchain itself when the program is linked.
1851.29Spooka# Unfortunately, we do not know which of the symbols are generated by
1861.29Spooka# the toolchain.  Worse, they vary from platform to platform and
1871.29Spooka# toolchain to toolchain.  The good news, however, is that this will
1881.29Spooka# be detected by a compile-time failure, so we can fairly easily manage
1891.29Spooka# a quirktable here.
1901.46Spooka#
1911.46Spooka# We also allow calling ourselves externally with e.g.:
1921.46Spooka# make -f /sys/rump/Makefile.rump RUMP_SYMREN=ffs.kobj
1931.46Spooka#
1941.29Spooka.if ${MACHINE_CPU} == "mips"
1951.29Spooka_SYMQUIRK='|_gp_disp'
1961.29Spooka.elif ${MACHINE_CPU} == "hppa"
1971.29Spooka_SYMQUIRK='|\$$\$$'
1981.54Smrg.elif ${MACHINE_ARCH} == "powerpc64"
1991.55Smrg_SYMQUIRK="|PF_funcs"
2001.55Smrg.endif
2011.55Smrg
2021.55Smrg#
2031.55Smrg# Prefix quirks.  At least one toolchain generates global
2041.55Smrg# symbols with prefixes which really need to remain as prefixes
2051.55Smrg# (i.e. the '.' on the front of some ppc64 globals).  The
2061.55Smrg# way to know if you have the problem is if you get later
2071.55Smrg# complaints about symbols like 'rumpns_XrumpBLAH' or 'XrumpBLAH';
2081.55Smrg# the 'X' part was added by the toolchain and will need to
2091.55Smrg# be mentioned here.
2101.55Smrg# 
2111.55Smrg.if ${MACHINE_ARCH} == "powerpc64"
2121.55Smrg_PQ="\.?"
2131.55Smrg.else
2141.55Smrg_PQ=
2151.29Spooka.endif
2161.46Spooka
2171.46Spookarump_symren: __archivebuild
2181.46Spooka.if !defined(RUMP_SYMREN)
2191.46Spooka	@echo "Must supply RUMP_SYMREN for target rump_symren"
2201.46Spooka	@false
2211.46Spooka.endif
2221.46Spooka
2231.46Spooka# if we are called from lib build (RUMP_SYMREN is not specified),
2241.46Spooka# build the arrrrchive.  otherwise just rename symbols.
2251.24Spooka__archivebuild: .USE
2261.46Spooka.if defined(RUMP_SYMREN) && defined(RUMPTOP)
2271.46Spooka	@echo "ERROR: RUMP_SYMREN can only be used standalone"
2281.46Spooka	@false
2291.46Spooka.endif
2301.46Spooka.if defined(RUMP_SYMREN)
2311.46Spooka	${_MKMSG} " symbol rename " ${RUMP_SYMREN}
2321.46Spooka.else
2331.24Spooka	${_MKTARGET_BUILD}
2341.24Spooka	rm -f ${.TARGET}
2351.46Spooka.endif
2361.91Spooka	for renameobj in ${RUMP_SYMREN:U${.ALLSRC:C/(${RUMPOBJ_NORENAME:ts|})//g}}; do \
2371.91Spooka		${NM} -go $${renameobj} | ${TOOL_AWK} ' \
2381.125Sjoerg		    $$NF!~/^'${_PQ}'(rump|RUMP|__|_GLOBAL_OFFSET_TABLE|\.TOC\.'${_SYMQUIRK}'${RUMP_SYM_NORENAME:D|${RUMP_SYM_NORENAME}})/ \
2391.69Spooka		      {s=$$NF;sub(/^'${_PQ}'/, "&rumpns_", s); print $$NF, s}'\
2401.91Spooka		    | sort | uniq  > renametab.$${renameobj}; \
2411.69Spooka		${OBJCOPY} --preserve-dates --redefine-syms \
2421.91Spooka		    renametab.$${renameobj} $${renameobj}; \
2431.91Spooka		rm -f renametab.$${renameobj}; \
2441.69Spooka	done
2451.46Spooka.if !defined(RUMP_SYMREN)
2461.69Spooka	${AR} ${_ARFL} ${.TARGET} \
2471.69Spooka	    `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
2481.46Spooka.endif
2491.47Spooka
2501.119SpookaCOMMENT?=	(no description)
2511.120Spookarumpdescribe: .PHONY
2521.119Spooka	@printf '%-24s %s\n' '${LIB}' '${COMMENT}'
2531.119Spooka
2541.53Spooka_BSD_IOCONF_MK_USER_=1
2551.53Spooka.include <bsd.ioconf.mk>
2561.47Spooka
2571.44Spooka.-include "${NETBSDSRCDIR}/sys/arch/${MACHINE_CPU}/include/Makefile.inc"
2581.44Spooka.-include "${NETBSDSRCDIR}/sys/arch/${MACHINE}/include/Makefile.inc"
2591.95Spooka
2601.95Spooka.endif # _RUMP_MK
261