# milo/lib/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
AS		= mips-linux-as -mips3
AR		= mips-linux-ar
LD		= mips-linux-ld
STRIP		= mips-linux-strip
MAKE		= make

#
# Set this to 1 to compile Milo with extra debugging code
#
DEBUG		= -DDEBUG=0

CFLAGS		= -I../include -I/usr/mips-linux/include -O2 -mips2 \
		  -Wa,-mips3 -mcpu=r4400 -D__KERNEL__ $(DEBUG)

LDFLAGS		= -N -oformat ecoff-littlemips

LIBOBJS		= console.o vsprintf.o ctype.o fprintf.o printf.o stdfd.o \
		  __main.o strerror.o getopt.o getopt1.o puts.o string.o \
		  strcasecmp.o strncscmp.o mkargs.o C-ctype_ct.o ctype-info.o \
		  ISO88591-ctype.o ISO88591_ct.o strtol.o atob.o \
		  ISO88591_mb.o fopen.o fclose.o __sflags.o __sfp.o fflush.o \
		  errno.o errlist.o perror.o creat.o dumpcp0r.o debuglevel.o

ifeq (../.full,$(wildcard ../.full))
#
# These files are either copyrighted itself or can't be rebuild
# without some other copyrighted files.
#
LIBOBJS		+= glue.o sleep.o seek.o exit.o open.o close.o read.o write.o \
		   setenv.o unsetenv.o putenv.o malloc.o mallocinit.o \
		   mallocdebug.o getchar.o gets.o cachectl.o arc.o string.o \
		   getenv.o
endif

all:		dummy libstand.a

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

#
# Used by the main Makefile to strip of all object files that
# may be rebuilt with the "lawyerware" distribution.
#
lite:
		$(AR) ds libstand.a $(LIBOBJS)

libstand.a:	$(LIBOBJS)
		$(AR) rcs libstand.a $(LIBOBJS)

cachectl.o:	cachectl.S
		$(CC) $(CFLAGS) -c cachectl.S
clean:
		-rm -f *.[o]

distclean:	clean
		if [ -f ../.full ]; then rm -f libstand.a; fi
		-rm -f .depend *.bak *~ *.orig *.rej \#*\# a.out

depend:
		set -e;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
