Makefile.rump revision 1.65
11.65Spooka#	$NetBSD: Makefile.rump,v 1.65 2012/11/21 17:48:05 pooka Exp $
21.1Spooka#
31.1Spooka
41.33SlukemWARNS?=		3	# XXX: src/sys won't compile with -Wsign-compare yet
51.10SpookaNOLINT=		# kernel code
61.1Spooka
71.20Spooka.include <bsd.own.mk>
81.20Spooka
91.51Spooka# If RUMPKMOD is _not_ set (only on capable archs, from bsd.own.mk),
101.51Spooka# use rump ABI instead of the NetBSD kernel ABI.
111.31She.ifndef RUMPKMOD
121.18SpookaCPPFLAGS:=	-I${RUMPTOP}/include ${CPPFLAGS}
131.57SpookaCPPFLAGS+=	-D_RUMPKERNEL
141.56Spooka.else
151.56SpookaCPPFLAGS+=	-D_RUMP_NATIVE_ABI
161.18Spooka.endif
171.18Spooka
181.22SpookaCFLAGS+=	-ffreestanding -fno-strict-aliasing
191.63Sjoerg.if (defined(HAVE_GCC) && ${HAVE_GCC} >= 3) || defined(HAVE_LLVM)
201.61SmattCFLAGS+=	-Wsign-compare
211.61SmattCFLAGS+=	-Wno-pointer-sign -Wno-attributes
221.61SmattCFLAGS+=	-std=gnu99
231.61Smatt.endif
241.50SpookaCWARNFLAGS+=	-Wno-format-zero-length -Wno-pointer-sign
251.23SpookaCPPFLAGS+=	-D_KERNEL -DMULTIPROCESSOR -D_MODULE -DMODULAR
261.21SpookaCPPFLAGS+=	-DMAXUSERS=32
271.60SmattCPPFLAGS+=	-DCOMPAT_50=1
281.38SpookaCPPFLAGS+=	-DDEBUGPRINT
291.15SpookaCPPFLAGS+=	-I${.CURDIR} -I.
301.65SpookaCPPFLAGS+=	-I${RUMPTOP}/../../common/include
311.18SpookaCPPFLAGS+=	-I${RUMPTOP}/include
321.21SpookaCPPFLAGS+=	-I${RUMPTOP}/librump/rumpkern/opt
331.65SpookaCPPFLAGS+=	-nostdinc
341.65Spooka
351.65Spooka.ifdef NEED_ISYSTEM
361.65SpookaCPPFLAGS+=	-isystem ${RUMPTOP}/../arch
371.65SpookaCPPFLAGS+=	-isystem ${RUMPTOP}/..
381.65Spooka.else
391.65SpookaCPPFLAGS+=	-I${RUMPTOP}/../arch
401.65SpookaCPPFLAGS+=	-I${RUMPTOP}/..
411.65Spooka.endif
421.65Spooka
431.45SpookaLDFLAGS+=	-T ${RUMPTOP}/ldscript.rump
441.62Spooka
451.62SpookaRUMP_DIAGNOSTIC?=yes
461.62Spooka.if ${RUMP_DIAGNOSTIC} == "yes"
471.62SpookaCPPFLAGS+=	-DDIAGNOSTIC
481.62Spooka.endif
491.62Spooka
501.62Spooka.ifdef RUMP_DEBUG
511.62SpookaCPPFLAGS+=	-DDEBUG
521.62Spooka.endif
531.1Spooka
541.59Spooka.ifdef RUMP_LOCKDEBUG
551.59SpookaCPPFLAGS+=	-DLOCKDEBUG
561.59Spooka.endif
571.59Spooka
581.42Spooka# kernel libs should not get linked against libc
591.43Spooka# XXX: actually, we would like to enable this but cannot, since it
601.43Spooka# also leaves out libgcc, it causes problems on some platforms.
611.43Spooka# revisit some day.
621.43Spooka#LDFLAGS+=	-nodefaultlibs
631.42Spooka
641.39Spooka# make sure __NetBSD__ gets defined (for builds on non-NetBSD)
651.64Spooka# aaand make sure cc doesn't source files any wild ideas
661.39SpookaCPPFLAGS+=	-D__NetBSD__
671.64SpookaCPPFLAGS+=	-Ulinux -U__linux -U__linux__ -U__gnu_linux__
681.39Spooka
691.11SpookaRUMPKERNEL=	This is NetBSD and I am the rump.  Good evening.
701.11Spooka
711.13Spooka# workaround: evbppc is not a well-defined arch
721.13Spooka.if (${MACHINE} == "evbppc")
731.16SpookaCPPFLAGS+=	-DPPC_OEA
741.13Spooka.endif
751.13Spooka
761.25Spooka# If this file changes, we need a full rebuild
771.25SpookaDPSRCS+=	${RUMPTOP}/Makefile.rump
781.24Spooka
791.24Spooka#
801.24Spooka# Rename library symbols before use.  If a symbol does not already belong
811.24Spooka# to a rump namespace ("rump" or "RUMP"), prefix it with "rumpns".  This
821.24Spooka# avoids accidentally linking any kernel symbol against host platform
831.24Spooka# libraries.  The only non-renamed symbols are linkset delimiters and
841.24Spooka# the GOT, which are more a property of the compiler than the kernel.
851.24Spooka#
861.29Spooka# Some toolchains generate unresolved symbols which are supposed to be
871.29Spooka# satisfied by the toolchain itself when the program is linked.
881.29Spooka# Unfortunately, we do not know which of the symbols are generated by
891.29Spooka# the toolchain.  Worse, they vary from platform to platform and
901.29Spooka# toolchain to toolchain.  The good news, however, is that this will
911.29Spooka# be detected by a compile-time failure, so we can fairly easily manage
921.29Spooka# a quirktable here.
931.46Spooka#
941.46Spooka# We also allow calling ourselves externally with e.g.:
951.46Spooka# make -f /sys/rump/Makefile.rump RUMP_SYMREN=ffs.kobj
961.46Spooka#
971.29Spooka.if ${MACHINE_CPU} == "mips"
981.29Spooka_SYMQUIRK='|_gp_disp'
991.29Spooka.elif ${MACHINE_CPU} == "hppa"
1001.29Spooka_SYMQUIRK='|\$$\$$'
1011.54Smrg.elif ${MACHINE_ARCH} == "powerpc64"
1021.55Smrg_SYMQUIRK="|PF_funcs"
1031.55Smrg.endif
1041.55Smrg
1051.55Smrg#
1061.55Smrg# Prefix quirks.  At least one toolchain generates global
1071.55Smrg# symbols with prefixes which really need to remain as prefixes
1081.55Smrg# (i.e. the '.' on the front of some ppc64 globals).  The
1091.55Smrg# way to know if you have the problem is if you get later
1101.55Smrg# complaints about symbols like 'rumpns_XrumpBLAH' or 'XrumpBLAH';
1111.55Smrg# the 'X' part was added by the toolchain and will need to
1121.55Smrg# be mentioned here.
1131.55Smrg# 
1141.55Smrg.if ${MACHINE_ARCH} == "powerpc64"
1151.55Smrg_PQ="\.?"
1161.55Smrg.else
1171.55Smrg_PQ=
1181.29Spooka.endif
1191.46Spooka
1201.46Spookarump_symren: __archivebuild
1211.46Spooka.if !defined(RUMP_SYMREN)
1221.46Spooka	@echo "Must supply RUMP_SYMREN for target rump_symren"
1231.46Spooka	@false
1241.46Spooka.endif
1251.46Spooka
1261.46Spooka# if we are called from lib build (RUMP_SYMREN is not specified),
1271.46Spooka# build the arrrrchive.  otherwise just rename symbols.
1281.24Spooka__archivebuild: .USE
1291.46Spooka.if defined(RUMP_SYMREN) && defined(RUMPTOP)
1301.46Spooka	@echo "ERROR: RUMP_SYMREN can only be used standalone"
1311.46Spooka	@false
1321.46Spooka.endif
1331.46Spooka.if defined(RUMP_SYMREN)
1341.46Spooka	${_MKMSG} " symbol rename " ${RUMP_SYMREN}
1351.46Spooka.else
1361.24Spooka	${_MKTARGET_BUILD}
1371.24Spooka	rm -f ${.TARGET}
1381.34Spooka	${AR} ${_ARFL} ${.TARGET} `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
1391.46Spooka.endif
1401.46Spooka	${NM} -go ${RUMP_SYMREN:U${.TARGET}} | ${TOOL_AWK} '	\
1411.55Smrg	    $$NF!~/^'${_PQ}'(rump|RUMP|__|_GLOBAL_OFFSET_TABLE'${_SYMQUIRK}')/ \
1421.55Smrg	      {s = $$NF; sub(/^'${_PQ}'/, "&rumpns_", s); print $$NF, s}' \
1431.24Spooka	    | sort | uniq  > renametab.${.TARGET}
1441.37Spooka	${OBJCOPY} --preserve-dates --redefine-syms \
1451.46Spooka	    renametab.${.TARGET} ${RUMP_SYMREN:U${.TARGET}}
1461.24Spooka	rm -f renametab.${.TARGET}
1471.46Spooka.if !defined(RUMP_SYMREN)
1481.36Sperry	${AR} ${_ARRANFL} ${.TARGET}
1491.46Spooka.endif
1501.47Spooka
1511.53Spooka_BSD_IOCONF_MK_USER_=1
1521.53Spooka.include <bsd.ioconf.mk>
1531.47Spooka
1541.44Spooka.-include "${NETBSDSRCDIR}/sys/arch/${MACHINE_CPU}/include/Makefile.inc"
1551.44Spooka.-include "${NETBSDSRCDIR}/sys/arch/${MACHINE}/include/Makefile.inc"
156