#	$NetBSD: Makefile.libkern,v 1.4 2009/08/12 21:18:42 dsl Exp $

# 
# Variable definitions for libkern.  
#
# Before including this, you _must_ set
#   KERNDIR: location of sys/lib/libkern
#
# You *may* set:
#   LIBKERN_ARCH: architecture subdir to be used
#   KERNCPPFLAGS: see Makefile.inc
#   KERNMICPPFLAGS: see Makefile.inc
#

.include <bsd.own.mk>

.if defined(LIBKERN_ARCH) && !empty(LIBKERN_ARCH) && \
    exists(${KERNDIR}/arch/${LIBKERN_ARCH})
ARCHSUBDIR=     ${LIBKERN_ARCH}
.elif defined(MACHINE_ARCH) && !empty(MACHINE_ARCH) && \
    exists(${KERNDIR}/arch/${MACHINE_ARCH})
ARCHSUBDIR=     ${MACHINE_ARCH}
.elif defined(MACHINE_CPU) && !empty(MACHINE_CPU) && \
    exists(${KERNDIR}/arch/${MACHINE_CPU})
ARCHSUBDIR=     ${MACHINE_CPU}
.endif

M= ${KERNDIR}/arch/${ARCHSUBDIR}

CPPFLAGS+=	-I$M ${KERNCPPFLAGS} ${KERNMISCCPPFLAGS}

.include "${.PARSEDIR}/../../../common/lib/libc/Makefile.inc"
.include "${.PARSEDIR}/../../../common/lib/libutil/Makefile.inc"
.include "${.PARSEDIR}/../../../common/lib/libprop/Makefile.inc"

CPPFLAGS+=	-I${KERNDIR}/../../../common/include

.PATH.c: ${KERNDIR}
.if exists ($M/Makefile.inc)
.PATH.c: $M
.PATH.S: $M
.include "$M/Makefile.inc"
.endif

.if (${MACHINE_ARCH} != "alpha")
# Quad support
SRCS+=	adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c iordi3.c \
	lshldi3.c lshrdi3.c moddi3.c muldi3.c negdi2.c notdi2.c qdivrem.c \
	subdi3.c  ucmpdi2.c udivdi3.c umoddi3.c xordi3.c
.endif

# Other stuff
SRCS+=	__cmsg_alignbytes.c cpuset.c inet_addr.c intoa.c
SRCS+=	md4c.c md5c.c rmd160.c sha1.c sha2.c
SRCS+=	pmatch.c arc4random.c bcd.c mcount.c mertwist.c crc32.c

SRCS+=	strsep.c strstr.c
SRCS+=	strlcpy.c strlcat.c
SRCS+=	memcpy.c memmove.c
SRCS+=	strchr.c strrchr.c
SRCS+=	popcount32.c popcount64.c

SRCS+=	strtoll.c strtoull.c strtoumax.c

SRCS+=	xlat_mbr_fstype.c

SRCS+=	heapsort.c ptree.c rb.c

# Files to clean up
CLEANFILES+= lib${LIB}.o lib${LIB}.po

# Remove from SRCS the .c files for any .S files added by the MD makefiles,
# also remove from SRCS the .c files for the .S and .c files in NO_SRCS.
#
# Usage: 
# Add .S files to NO_SRSC when another .S file provides the entry points.
# Add .c files to NO_SRSC when another .c file provides the entry points.

.for check_file in ${SRCS:M*.S} ${NO_SRCS}
unwanted_file := ${SRCS:M${check_file:.S=.c}}
.if "${unwanted_file}" != ""
SRCS := ${SRCS:N${unwanted_file}}
.endif
.endfor

