-Wl,--allow-multiple-definition
.endif
+# Disable magic and ASR passes for the kernel.
+USE_MAGIC=no
+
.include <minix.service.mk>
########################
# Build Minix
########################
-export BUILDVARS=$(echo "${BUILDVARS} -V MKBITCODE=yes"| sed -e 's,-V MKMAGIC=yes,-V MKMAGIC=yes -V DBG=-g -V STRIPFLAG=-s -V CPPFLAGS=-D_MINIX_MAGIC=1,')
+export BUILDVARS
if [ "${REBUILD_MINIX}" == "yes" ]; then
# data. For VM, we need to do the exact opposite, since for VM, the malloc
# state is transferred as is. Thus, if the magic pass is enabled, tell it
# to skip the regular malloc instrumentation features.
-.if !empty(OPTFLAGS:M*-magic*)
-OPTFLAGS.vm?= ${OPTFLAGS} \
- -magic-disable-mem-functions \
- -magic-disable-malloc-skip
-.endif
+MAGICFLAGS= -magic-disable-mem-functions -magic-disable-malloc-skip
.include "arch/${MACHINE_ARCH}/Makefile.inc"
.include <minix.service.mk>
# Get (more) internal minix definitions and declarations.
CPPFLAGS += -D_MINIX_SYSTEM=1
+# For MKMAGIC builds, link services against libmagicrt and run the magic pass
+# on them, unless they have specifically requested to be built without bitcode.
+.if ${USE_BITCODE:Uno} == "yes" && ${USE_MAGIC:Uno} == "yes"
+LIBMAGICST?= ${DESTDIR}${LIBDIR}/libmagicrt.bcc
+MAGICPASS?= ${NETBSDSRCDIR}/minix/llvm/bin/magic.so
+
+DPADD+= ${LIBMAGICST} ${MAGICPASS}
+
+.for _P in ${PROGS:U${PROG}}
+BITCODE_LD_FLAGS_1ST.${_P}?= ${LIBMAGICST}
+.endfor
+
+MAGICFLAGS?=
+OPTFLAGS+= -load ${MAGICPASS} -magic ${MAGICFLAGS}
+.endif # ${USE_BITCODE:Uno} == "yes" && ${USE_MAGIC:Uno} == "yes"
+
.include <bsd.prog.mk>
DBG= -Os
.endif
+.if ${MKMAGIC:Uno} == "yes"
+CPPFLAGS+= -D_MINIX_MAGIC=1
+STRIPFLAG= -s
+DBG=-g
+.endif
+
#LSC: Be a bit smarter about the default compiler
.if exists(/usr/pkg/bin/clang) || exists(/usr/bin/clang)
CC?= clang