#	$NetBSD: Makefile.rumpkern,v 1.104 2010/12/17 00:53:16 joerg Exp $
#

.include "${RUMPTOP}/Makefile.rump"

LIB=		rump

.PATH:	${RUMPTOP}/librump/rumpkern				\
	${RUMPTOP}/../kern					\
	${RUMPTOP}/../uvm					\
	${RUMPTOP}/../conf					\
	${RUMPTOP}/../dev					\
	${RUMPTOP}/../secmodel/suser

#
# Source modules, first the ones specifically implemented for librump.
# 
SRCS=	rump.c rumpcopy.c emul.c intr.c lwproc.c klock.c	\
	kobj_rename.c ltsleep.c memalloc.c scheduler.c		\
	signals.c sleepq.c threads.c vm.c
SRCS+=	compat.c

# Multiprocessor or uniprocessor locking.  TODO: select right
# locking at runtime.
SRCS+=	locks.c
#SRCS+=	locks_up.c

# Does the arch support multiple processors?
.if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64"
RUMP_SMP=		# defined
CPPFLAGS.rump.c+=	-DRUMP_SMP
.endif

MKREPRO?=no

.if ${MKREPRO} == "yes"
_NVFLAGS=-r
.else
_NVFLAGS=
.endif

vers.c: ${RUMPTOP}/../conf/newvers.sh ${RUMPTOP}/../conf/osrelease.sh ${RUMPTOP}/../sys/param.h
	${_MKMSG_CREATE} vers.c
	${HOST_SH} ${RUMPTOP}/../conf/newvers.sh -i RUMP-ROAST -n ${_NVFLAGS}
SRCS+=		vers.c
CLEANFILES+=	vers.c version

# use MI pmap for archs not conforming to kernel ABI
.ifndef RUMPKMOD
SRCS+=	pmap_stub.c
.endif

# autogenerated
#
SRCS+=	rump_syscalls.c rumpkern_if_wrappers.c

# "auto"generated
SRCS+=	devsw.c

#
# std kernel sources
#
# sys/kern
SRCS+=	init_sysctl_base.c	\
	kern_auth.c		\
	kern_cfglock.c		\
	kern_descrip.c		\
	kern_event.c		\
	kern_hook.c		\
	kern_ksyms.c		\
	kern_malloc_stdtype.c	\
	kern_module.c		\
	kern_mutex_obj.c	\
	kern_ntptime.c		\
	kern_proc.c		\
	kern_prot.c		\
	kern_rate.c		\
	kern_resource.c		\
	kern_stub.c		\
	kern_syscall.c		\
	kern_sysctl.c		\
	kern_tc.c		\
	kern_timeout.c		\
	kern_uidinfo.c		\
	kern_xxx.c		\
	param.c			\
	subr_devsw.c		\
	subr_callback.c		\
	subr_copy.c		\
	subr_device.c		\
	subr_evcnt.c		\
	subr_extent.c		\
	subr_hash.c		\
	subr_humanize.c		\
	subr_iostat.c		\
	subr_kobj.c		\
	subr_log.c		\
	subr_lwp_specificdata.c	\
	subr_once.c		\
	subr_prf.c		\
	subr_specificdata.c	\
	subr_time.c		\
	subr_workqueue.c	\
	subr_xcall.c		\
	sys_descrip.c		\
	sys_generic.c		\
	sys_module.c		\
	sys_pipe.c		\
	sys_select.c		\
	syscalls.c

# sys/uvm
SRCS+=	uvm_aobj.c uvm_readahead.c

# 4.4BSD secmodel.  selection is hardcoded for now
SRCS+=	secmodel_suser.c

# the funny bit.  this doesn't really belong here, but helps with the
# needs of kern_descrip.c.  And since it's a fully dynamic interface,
# it doesn't pull in other gunk.
SRCS+=	vnode_if.c

# sys/dev
SRCS+=	clock_subr.c

# Flip the comment to the other line if you want to use malloc(3)
# directly instead of the kernel allocators backed by malloc(3)/mmap(2).
# Libc malloc is a few percent faster, but doesn't emulate all kernel
# corner cases as well (not to mention if you want to debug the
# allocators themselves).
#CPPFLAGS+=	-DRUMP_USE_UNREAL_ALLOCATORS
SRCS+=		subr_kmem.c subr_percpu.c subr_pool.c subr_vmem.c

# no shlib_version because this is automatically in sync with lib/librump
SHLIB_MAJOR=    0
SHLIB_MINOR=    0

CPPFLAGS+=	-I${RUMPTOP}/librump/rumpkern -I${RUMPTOP}/librump/rumpvfs
CPPFLAGS+=	-I${RUMPTOP}/librump/rumpnet -I${RUMPTOP}/librump/rumpdev
AFLAGS+=	-D_LOCORE -Wa,-fatal-warnings

#
# If archdir exists, it is required to provide:
# 1) kobj_reloc() and kobj_machdep()
# 2) rump_cpu_bootstrap()
# 3) ...?
# 4) PROFIT!
#

#
# Check if we are building compat.  In compat mode we need to provide
# the kernel of our compat target (amd64->i386 & sparc64->sparc), so
# take MD stuff from the right arch.
#
.ifdef MLIBDIR
ARCHDIR=	${RUMPTOP}/librump/rumpkern/arch/${MLIBDIR}
LIBKERN_ARCH=	${MLIBDIR}
.elif exists(${RUMPTOP}/librump/rumpkern/arch/${MACHINE_CPU})
ARCHDIR=	${RUMPTOP}/librump/rumpkern/arch/${MACHINE_CPU}
.else
ARCHDIR=	${RUMPTOP}/librump/rumpkern/arch/${MACHINE_ARCH}
.endif
.if exists(${ARCHDIR})
.include "${ARCHDIR}/Makefile.inc"
.PATH:	${ARCHDIR}
.else
SRCS+=	kobj_stubs.c rumpcpu_generic.c
.endif

.if ${MACHINE} == "sun3"
CPPFLAGS+=	-Dsun3
.endif

# include libkern source files
KERNDIR=${RUMPTOP}/../lib/libkern
.ifdef RUMPKMOD
KERNMISCCPPFLAGS+=	-D_RUMPKERNEL
.endif
.include "${RUMPTOP}/../lib/libkern/Makefile.libkern"

# Some architectures require a little special massage with atomic
# compare-and-swap.  This is because the kernel version is using
# instructions or routines unavailable to us in userspace.  We
# use a very simple CAS routine which (correctly) assumes non-SMP
# and no preemption.  If some of these archs later develop MP
# support, switch them to use atomic_cas_generic.c
#
.if ${MACHINE_CPU} == "arm" || ${MACHINE_CPU} == "hppa" \
    || ${MACHINE_CPU} == "mips" || ${MACHINE_CPU} == "sh3" \
    || ${MACHINE_CPU} == "vax" || ${MACHINE_ARCH} == "m68000"
CPPFLAGS+=	-I${RUMPTOP}/../../common/lib/libc/atomic
.ifdef RUMP_SMP
SRCS+=		atomic_cas_generic.c
.else
SRCS+=		rump_atomic_cas_up.c
.endif
.endif

.include <bsd.lib.mk>
.include <bsd.klinks.mk>
