WARNS?=		1
MKMAN=		no
CPPFLAGS+=	-I${.CURDIR}/../../..
LDSTATIC?=	-static
OBJCOPY?=	objcopy
ELF2ECOFF=	${OBJCOPY} -O ecoff-bigmips

S=	${.CURDIR}/../../../..

.BEGIN: machine mips
${PROG} realdepend realall: machine mips
CLEANFILES+= machine mips

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

COPTS=		-g
AFLAGS+=	-x assembler-with-cpp -traditional-cpp -D_LOCORE
CPPFLAGS+=	-D_STANDALONE -DNO_ABICALLS
CPPFLAGS+=	-nostdinc -I${.OBJDIR} -I${S} -I${.CURDIR}
# compiler flags for smallest code size
GP?=		-G 0
CFLAGS=		${DEBUG} ${COPTS} ${CWARNFLAGS} ${GP} -mmemcpy -mno-abicalls \
		-mno-half-pic
LDBUG=		-T$S/arch/mips/conf/kern.ldscript

TEXTADDR?=	88002000

LINKFLAGS=	-Map ${PROG}.map -N -x ${LDBUG} -Ttext ${TEXTADDR} -e start ${GP} -g --oformat elf32-bigmips

SRCS=	start.S
SRCS+=	arcdiag.c dumpconf.c stdio.c tlb.S
SRCS+=	arcbios.c

### find out what to use for libkern
KERN_AS=	library
KERNMISCCPPFLAGS+=-Wno-pointer-arith
.include "${S}/lib/libkern/Makefile.inc"
LIBKERN=	${KERNLIB}

### find out what to use for libsa
SA_AS=		library
SAMISCCPPFLAGS+=-Wno-pointer-arith
SAMISCMAKEFLAGS+="SA_USE_LOADFILE=no"
.include "${S}/lib/libsa/Makefile.inc"
LIBSA=		${SALIB}

LIBS=		${LIBSA} ${LIBKERN}
PROG=		arcdiag

${PROG}: ${OBJS} ${LIBS}
	${LD} ${LINKFLAGS} -o ${PROG} ${OBJS} ${VERS_O} ${LIBS}
	@${SIZE} ${PROG}
	@${OBJDUMP} --disassemble-all ${PROG} > ${PROG}.dis
	@${ELF2ECOFF} ${PROG} ${PROG}.ecoff
	@${SIZE} ${PROG}.ecoff

cleandir distclean: cleanlibdir

cleanlibdir:
	rm -rf lib

.include <bsd.prog.mk>

