#
#   Copyright (C) 1994-2001 Digitool, Inc
#   This file is part of OpenMCL.  
#
#   OpenMCL is licensed under the terms of the Lisp Lesser GNU Public
#   License , known as the LLGPL and distributed with OpenMCL as the
#   file "LICENSE".  The LLGPL consists of a preamble and the LGPL,
#   which is distributed with OpenMCL as the file "LGPL".  Where these
#   conflict, the preamble takes precedence.  
#
#   OpenMCL is referenced in the preamble as the "LIBRARY."
#
#   The LLGPL is also available online at
#   http://opensource.franz.com/preamble.html

VPATH = ..
RM = /bin/rm
LD = ld
LDFLAGS = -arch ppc -dynamic  -o $@ -e start -seg1addr 0x00101000 
# -stack_addr 0xC0000000 -stack_size 0x00100000
AS = as
M4 = gm4
M4FLAGS = -DDARWIN
ASFLAGS =
CDEFINES = -DDARWIN -traditional-cpp
CDEBUG = -g
COPT = -O2


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

SPOBJ = 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 \
	thread_manager.o lisp-debug.o image.o

DEBUGOBJ = lispdcmd.o plprint.o plsym.o plbt.o ppc_print.o
KERNELOBJ= imports.o $(COBJ) asmutils.o qtppc.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 lisptypes.h \
	lisp-exceptions.h lisp_globals.h macros.h memprotect.h image.h

# Subprims linked into the kernel ?
# Yes:

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


# No:

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

OSLIBS = -lcrt1.o -lcc_dynamic -lSystem


../../dppccl:	 $(KSPOBJ) $(KERNELOBJ) $(DEBUGOBJ)
	$(LD)  $(LDFLAGS) $(KSPOBJ) $(KERNELOBJ) $(DEBUGOBJ)   $(OSLIBS)


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

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

MAGIC_PADDING_VALUE=4544
pad.o:	../pad.s
	$(M4) -DMAGIC_PADDING_VALUE=$(MAGIC_PADDING_VALUE) $< | as -o $@

thread_manager.o: thread_manager.c qt.h

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

# Some earlier versions of this Makefile built "subprims_r.o".  
# (That file is now defunct.)
clean:	cclean
	$(RM) -f $(SPOBJ) $(KSPOBJ) subprims_r.o

strip:	../../dppccl
	strip -s retain ../../dppccl
