# milo/Makefile
#
# This file is subject to the terms and conditions of the GNU General Public
# License. See the file COPYING in the main directory of this archive for more
# details.

CC		= mips-linux-gcc -Wa,-mips3
AS		= mips-linux-as -mips3
AR		= mips-linux-ar
LD		= mips-linux-ld
STRIP		= mips-linux-strip
MAKE		= make

# Try this first. MILO will run in kseg1 (unmapped,uncached)

LOADADDR	= 0xa0600000

# Then try this one to run MILO in kseg0 (unmapped,cached).
# If it fails, use the above LOADADDR.

#LOADADDR	= 0x80600000

# Kernel start address. This is usually 0x80000000, but any
# other address up to 0x80500000 may be used for testing.

#KERNELBASE      = 0xA0000000
KERNELBASE       = 0x80000000


CFLAGS		= -I./include -I/usr/mips-linux/include -O2 -mips3 -mcpu=r4000 \
		  -D__KERNEL__ -DLOADADDR=$(LOADADDR) -DKERNELBASE=$(KERNELBASE)

LDFLAGS		= -N -oformat ecoff-littlemips -Ttext $(LOADADDR)

LIBS		= lib/libstand.a
SUBDIRS		= lib

DISTFILES	= README TODO COPYING ChangeLog Makefile milo hello vmlinux \
		  milo.c identify.c hello.c vmlinux.c crt0.S launch.S \
		  lib/Makefile lib/__main.c lib/cachectl.S lib/console.c \
		  lib/ctype.c lib/dumptlb.c lib/fflush.c lib/fprintf.c \
		  lib/get_nlist.c lib/getopt.c lib/printf.c lib/puts.c \
		  lib/stdfd.c lib/strerror.c lib/vsprintf.c \
		  include/bootstrap.h include/cachectl.h include/console.h \
		  include/malloc.h include/arc/arc.h include/arc/errno.h \
		  include/identify.h lib/libstand.a

all:		dummy subdirs

ifeq (.depend,$(wildcard .depend))
include .depend
endif

disk:		subdirs hello milo vmlinux
		mwrite -n hello a:
		mwrite -n milo a:
#		mwrite -n vmlinux a:

dist:		$(DISTFILES)
		tar cvf milo.tar $(DISTFILES)
		rm -f milo.tar.gz
		gzip milo.tar

subdirs:	$(SUBDIRS)
		set -e;for i in $(SUBDIRS); do $(MAKE) -C $$i;done

hello:		hello.o crt0.o $(LIBS)
		$(LD) $(LDFLAGS) -e __entry -o hello crt0.o hello.o $(LIBS)


milo:		milo.o crt0.o launch.o identify.o $(LIBS)
		$(LD) $(LDFLAGS) -e __entry -o milo \
		crt0.o milo.o identify.o launch.o $(LIBS)

vmlinux:	vmlinux.o $(LIBS)
		$(LD) -N -Ttext $(KERNELBASE) -o vmlinux vmlinux.o $(LIBS)

crt0.o:		crt0.S
		$(CC) $(CFLAGS) -c crt0.S

clean:
		cd lib; make clean
		-rm -f *.[os] *.bak

distclean:	clean
		cd lib; make distclean
		-rm -f .depend milo vmlinux hello milo.tar.gz

depend dep:
		cd lib; make depend
		for i in *.c; do echo -n "./";$(CPP) $(CFLAGS) -M $$i;done \
			> .tmpdepend
		mv .tmpdepend .depend

ifeq (.depend,$(wildcard .depend))
dummy:

else
.depend:
	@echo "Generating dependencies..."
	@echo
	$(MAKE) depend
	@echo
	@echo "Successful. Try re-making (ignore the error that follows)"
	@echo
	exit 1

dummy:	.depend

endif
