#	$Id: Makefile,v 1.2 2004/04/29 17:38:50 pefo Exp $ */
#
#
# Copyright (c) 2003 Opsycon AB  (www.opsycon.se)
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
#	This product includes software developed by Opsycon AB, Sweden.
#	This product includes software developed by Patrik Lindergren.
# 4. The name of the author may not be used to endorse or promote products
#    derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#

# source tree is located via $S relative to the compilation directory
ifndef S
S:=$(shell cd ../..; pwd)
endif

include ${S}/tools/scripts/pmon.conf.gmk


CLIBDIR=	${SDK}/libc/arch/${MACHINE_ARCH}
CLIBDST=	${CLIBDIR}/obj
OBJDIR=		${CLIBDST}
INC+=		-I${CLIBDIR} -I${CLIBDST}

CLEANFILES=	${OBJDIR}/libc.a \
		${OBJDIR}/crt0.o ${OBJDIR}/crtbegin.o ${OBJDIR}/crtend.o

VPATH=		${CLIBDIR} ${CLIBDIR}/sys ${CLIBDIR}/gen \
		${SDK}/libc/gen ${SDK}/libc/net ${SDK}/libc/locale \
		${SDK}/libc/stdio  ${SDK}/libc/stdlib ${SDK}/libc/string \
		${SDK}/libc/sys \
		${S}/lib/libc ${S}/lib/libc/arch/${MACHINE_ARCH}

all::	__always_make_cliblib ${CLIB} ${LIBCRT0} ${CRTBEGIN} ${CRTEND}


include ${SDK}/libc/gen/Makefile.inc
include ${SDK}/libc/locale/Makefile.inc
include ${SDK}/libc/net/Makefile.inc
include ${SDK}/libc/stdio/Makefile.inc
include ${SDK}/libc/stdlib/Makefile.inc
include ${SDK}/libc/string/Makefile.inc
include ${SDK}/libc/sys/Makefile.inc
include ${SDK}/libc/arch/${MACHINE_ARCH}/Makefile.inc
include ${S}/tools/scripts/pmon.lib.gmk

OBJS+=	${SYSOBJS}

all depend clean::
ifndef MACHINE_ARCH
	@echo "MACHINE_ARCH must be defined!"
	@false
endif

${CLIB}: ${OBJS}
	@echo building standard ${LIB} library for SDK
	@rm -f $@
	@${AR} cq $@ ${OBJS}
	${RANLIB} $@

${LIBCRT0}: ${OBJDIR}/crt0.o
	@echo building crt0.o for SDK
	@cp ${OBJDIR}/crt0.o ${LIBCRT0}

${CRTBEGIN}: ${OBJDIR}/crtbegin.o
	@echo building crtbegin.o for SDK
	@cp ${OBJDIR}/crtbegin.o ${CRTBEGIN}

${CRTEND}: ${OBJDIR}/crtend.o
	@echo building crtend.o for SDK
	@cp ${OBJDIR}/crtend.o ${CRTEND}

depend::__always_make_cliblib
	@${CLIBMAKE} depend

__always_make_cliblib:	
	@mkdir -p ${CLIBDST} 
	@mkdir -p `dirname ${CLIB}` 
	@rm -f ${CLIBDST}/machine
	@ln -s ${S}/sys/arch/${MACHINE_ARCH}/include ${CLIBDST}/machine

#
#
