# 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.

VERSION		= 0.17

CC		= mips-linux-gcc
AS		= mips-linux-as -mcpu=r4400 -mips3
AR		= mips-linux-ar
LD		= mips-linux-ld
MAKE		= make

#
# Use the following options for Acer PICA 1 machines.
#
LOADADDR	= 0xa0600000
STRIP		= mips-linux-strip

#
# Use the following options for Deskstation Tynes.
# Don't strip executables - there is a bug in mips-linux-strip that changes
# the type of executable from impure to paged. Unfortunately the Deskstation
# doesn't accept paged executables.
#
#LOADADDR	= 0x80600000
#STRIP		= echo

#
# 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) \
		  -DVERSION=$(VERSION)

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

SUBDIRS		= lib

DISTFILES	= README TODO COPYING ChangeLog Makefile milo hello vmlinux \
		  milo.c identify.c acer_pica_61.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/getopt1.c lib/printf.c \
		  lib/puts.c lib/mkargs.c lib/stdfd.c lib/strerror.c \
		  lib/vsprintf.c lib/string.c lib/strcasecmp.c lib/strncscmp.c \
		  lib/C-ctype_ct.c lib/ctype-info.c lib/ISO88591-ctype.c \
		  lib/ISO88591_ct.c lib/ISO88591_mb.c \
		  include/stand/bootstrap.h include/stand/console.h \
		  include/stand/malloc.h include/arc/arc.h include/arc/errno.h \
		  include/arc/stdlib.h include/stand/identify.h \
		  include/stand/mkargs.h include/stand/ctype.h lib/libstand.a

PROGS		= milo vmlinux hello

all:		dummy subdirs $(PROGS)

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

disk:		$(PROGS)
		mwrite -n $(PROGS) a:

dist:		$(DISTFILES)
		-rm -rf milo-$(VERSION)
		mkdir milo-$(VERSION)
		tar cf - $(DISTFILES) | (cd milo-$(VERSION) && tar xf -)
		tar cvvf milo-$(VERSION).tar milo-$(VERSION)
		gzip -f9 milo-$(VERSION).tar
		rm -rf milo-$(VERSION)

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

milo:		milo.o crt0.o launch.o identify.o acer_pica_61.o subdirs
		$(LD) $(LDFLAGS) -e __entry -o milo \
		crt0.o milo.o identify.o acer_pica_61.o launch.o -Llib -lstand
		$(STRIP) milo

vmlinux:	vmlinux.o subdirs
		$(LD) -N -Ttext $(KERNELBASE) -o vmlinux vmlinux.o -Llib -lstand

hello:		hello.o crt0.o subdirs
		$(LD) $(LDFLAGS) -e __entry -o hello crt0.o hello.o -Llib -lstand
		$(STRIP) hello

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

clean:		clean-local clean-recursive

clean-local:
		-rm -f *.[os] a.out

clean-recursive:
		@set -e;for i in $(SUBDIRS); do (cd $$i && $(MAKE) clean);done

distclean:	distclean-local distclean-recursive

distclean-local:	clean-local
		-rm -f .depend .tmpdepend *.bak *~ milo vmlinux hello
		-rm -f milo-$(VERSION).tar.gz

distclean-recursive:
		@set -e;for i in $(SUBDIRS); do (cd $$i && $(MAKE) distclean);done

depend:		depend-local depend-recursive

depend-local:
		set -e;for i in *.c; do echo -n "./";$(CPP) $(CFLAGS) -M $$i; \
			done > .tmpdepend
		mv .tmpdepend .depend

depend-recursive:
		@set -e;for i in $(SUBDIRS); do (cd $$i && $(MAKE) depend);done

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
