#	$NetBSD: Makefile.booters,v 1.25 1999/11/12 01:37:42 simonb Exp $
#
#	NOTE: $S must correspond to the top of the 'sys' tree

.BEGIN: ${.OBJDIR}/machine ${.OBJDIR}/mips
${PROG} depend all: ${.OBJDIR}/machine ${.OBJDIR}/mips
CLEANFILES+= machine mips

${.OBJDIR}/machine:
	-rm -f ${.TARGET}
	ln -s $S/arch/${MACHINE}/include ${.TARGET}

${.OBJDIR}/mips:
	-rm -f ${.TARGET}
	ln -s $S/arch/mips/include mips

# Tailor C compilation for standalone environment.
COPTS=	-Os				# -Os gives smaller code

C_MACHDEP=-mmemcpy -mno-abicalls -G 128	# even smaller code

DEFS?=	-D_STANDALONE -D_NO_PROM_DEFINES -DNO_ABICALLS \
	${BOOTDEFADD}
INCL?=	-nostdinc -I${.OBJDIR} -I$S -I${PMAX_STAND_DIR}/lib -I$S/lib/libsa

CFLAGS+=	${CWARN} ${C_MACHDEP}
AFLAGS+=	-D_LOCORE -D_KERNEL
CPPFLAGS+=	${DEFS} ${INCL}

LDBUG=	-T $S/arch/mips/conf/stand.ldscript

### find out what to use for libsa
SA_AS=		library
SAMISCMAKEFLAGS+=SA_USE_LOADFILE=yes SA_INCLUDE_NET=yes
.include "${S}/lib/libsa/Makefile.inc"
LIBSA=		${SALIB}

# We don't need libz for the first stage bootblocks
.if ${PROG} != "bootxx"

### find out what to use for libz
Z_AS=		library
.include "${S}/lib/libz/Makefile.inc"
LIBZ=		${ZLIB}
# and use compressed read in libsa
SAMISCMAKEFLAGS+=SA_USE_CREAD=yes

.else	# ${PROG} == "bootxx"
LIBZ=
.endif

PMAX_STAND_DIR?= $S/arch/pmax/stand
### find out what to use for libpmax
PMAXDIR= ${PMAX_STAND_DIR}/lib
.include "${PMAXDIR}/Makefile.inc"
LIBPMAX=		${PMAXLIB}

LIBS=	${LIBPMAX} ${LIBSA} ${LIBZ} ${LIBPMAX}
VERS_O?=vers.o

${PROG}: ${OBJS} ${LIBS}
.if ${VERS_O} != ""
	sh ${PMAX_STAND_DIR}/lib/newvers.sh ${VERSIONFILE} ${NEWVERSWHAT}
	${COMPILE.c} vers.c
.endif
	ld -Map ${PROG}.map -N -x -Ttext ${RELOC} ${LDBUG} -e start \
	    ${OBJS} ${VERS_O} ${LIBS} -o ${PROG}

CLEANFILES+=${PROG}.map
.if ${VERS_O} != ""
CLEANFILES+=vers.c vers.o
.endif

cleandir distclean: cleanlibdir

cleanlibdir:
	rm -rf lib

.include <bsd.prog.mk>

# be sure to turn off any PIC flags for standalone library code.
CPICFLAGS=
CAPICFLAGS=
CPPPICFLAGS=
APICFLAGS=
