#
#   Copyright (C) 1994-2001 Digitool, Inc
#   This file is part of Opensourced MCL.
#
#   Opensourced MCL is free software; you can redistribute it and/or
#   modify it under the terms of the GNU Lesser General Public
#   License as published by the Free Software Foundation; either
#   version 2.1 of the License, or (at your option) any later version.
#
#   Opensourced MCL is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#   Lesser General Public License for more details.
#
#   You should have received a copy of the GNU Lesser General Public
#   License along with this library; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

VPATH = ../
RM = /bin/rm
# Versions of GNU as >= 2.9.1 all seem to work
# AS = gas-2.9.1
AS = as
M4 = m4
ASFLAGS = -mregnames
M4FLAGS = -DLINUX
CDEFINES = -DLINUX
CDEBUG = -g
COPT =

kernel_current_version = 	"0x04008000"
kernel_implementation_version =	"0x04008000"

.s.o:
	$(M4) $(M4FLAGS) -I../ $< | $(AS) $(ASFLAGS) -o $@
.c.o:
	$(CC) -c $< $(CDEFINES) $(CDEBUG) $(COPT) -o $@

SPOBJ = pad.o spjump.o subprims.o  sp_call.o sp_lambda.o sp_bind.o \
	sp_catch.o sp_ffi.o sp_heap_cons.o  sp_stack_cons.o sp_values.o \
	sp_vref.o sp_builtin.o sp_end.o

COBJ  = pmcl-kernel.o gc.o bits.o kernel-init.o lisp-exceptions.o mathtrap.o \
	loader.o pef.o thread_manager.o lisp-debug.o 

DEBUGOBJ = lispdcmd.o plprint.o plsym.o plbt.o ppc_print.o
KERNELOBJ= $(COBJ) asmutils.o qtppc.o imports.o

SPINC =	lisp.s m4macros.m4 constants.s macros.s errors.s uuo.s

CHEADERS = area.h bits.h constants.h lisp-errors.h gc.h lisp.h \
	lisp-exceptions.h lisp_globals.h macros.h memprotect.h loader.h

# Subprims linked into the kernel ?
# Yes:

KSPOBJ = $(SPOBJ)
all:	../../ppccl


# No:

# KSPOBJ=
# all:	../../ppccl ../../subprims.so

OSLIBS = -ldl -lm 


../../ppccl:	$(KSPOBJ) $(KERNELOBJ) $(DEBUGOBJ)
	$(CC) $(CDEBUG)    -o $@ -T ./elf32ppclinux.x $(KSPOBJ) $(KERNELOBJ) $(DEBUGOBJ) $(OSLIBS)


../../subprims.so: $(SPOBJ)
	ld -shared -o $@ $(SPOBJ)

$(SPOBJ): $(SPINC)
$(COBJ): $(CHEADERS)
$(DEBUGOBJ): $(CHEADERS) lispdcmd.h

pef.o:	pef.c pef.h $(CHEADERS)
	$(CC) -c $(CDEBUG) $(COPT) $(CDEFINES) \
	-DKERNEL_CURRENT_VERSION=$(kernel_current_version) \
	-DKERNEL_IMPLEMENTATION_VERSION=$(kernel_implementation_version) \
	-DKERNEL_CFRG_NAME="\"pmcl-kernel4.1\""	\
	../pef.c -o $@

thread_manager.o: thread_manager.c qt.h


cclean:
	$(RM) -f $(KERNELOBJ) $(DEBUGOBJ) ../../ppccl

clean:	cclean
	$(RM) -f $(SPOBJ) ../../subprims.so

