##############################################################################
#
#  Makefile: Build the entire LispMe system                          
#                                                                    
#  LispMe System (c) FBI Fred Bayer Informatics                      
#                                                                    
#  Distributed under the GNU General Public License;                 
#  see the README file. This code comes with NO WARRANTY.            
#                                                                    
#  Modification history                                              
#                                                                    
#  When?      What?                                              Who?
#  -------------------------------------------------------------------
#  27.07.1997 New                                                FBI
#  25.10.1999 Prepared for GPL release                           FBI
#  30.03.2000 Adapted for PRC-tools 2.0 and SDK 3.5              FBI
#
##############################################################################

##############################################################################
#                                  
# This makefile is for Windows NT 4.0 using the GNU C compiler and PRC tools 
# for Pilot, version 2.0           
#
##############################################################################

##############################################################################
#
# change these for your environmant
#
##############################################################################
MATHLIB  = E:/pilot/sdk/mathlib
HAPI     = E:/pilot/handbase21/hapi

##############################################################################
# Application ID
##############################################################################
APPID    = fbLM
ADDEF    = -Wall

##############################################################################
# shell, compiler, tools
##############################################################################
SHELL    = sh
CC       = m68k-palmos-gcc
AS       = m68k-palmos-gcc
BUILDPRC = build-prc
OBJRES   = obj-res

##############################################################################
# compiler and linker flags
##############################################################################
CFLAGS   = -Wall -O2 -DAPPID=\'$(APPID)\' -I$(MATHLIB) -I$(HAPI) \
           -Wimplicit -Wmissing-declarations
ASFLAGS  = -c

#-----------------------------------------------------------------------------
# Dependencies
#-----------------------------------------------------------------------------
arith.o:   arith.c arith.h vm.h LispMe.h fpstuff.h util.h cplx.h 
arith.h:   builtin.h
builtin.o: builtin.c builtin.h util.h vm.h comp.h io.h arith.h
builtin.h: store.h
comp.o:    comp.c builtin.h comp.h vm.h util.h LispMe.h
comp.h:    store.h
comp.s:    comp.c builtin.h comp.h vm.h util.h LispMe.h
cplx.o:    cplx.c cplx.h fpstuff.h store.h store.h util.h arith.h
cplx.h:    store.h
date.o:    date.c date.h vm.h io.h util.h fpstuff.h
date.h:    builtin.h
dm.o:      dm.c dm.h io.h LispMe.h vm.h util.h arith.h
dm.h:      builtin.h
extend.h:  lists.h graphic.h gui.h hbase.h misc.h port.h file.h date.h dm.h socket.h strport.h #sample.h
file.o:    file.c file.h io.h LispMe.h vm.h util.h
file.h:    builtin.h port.h
fpstuff.o: fpstuff.c fpstuff.h store.h
graphic.o: graphic.c graphic.h util.h io.h comp.h vm.h LispMe.h
graphic.h: builtin.h
gui.o:     gui.c gui.h io.h util.h LispMe.h vm.h graphic.h date.h
gui.h:     builtin.h
hbase.o:   hbase.c hbase.h vm.h util.h io.h LispMe.h
hbase.h:   builtin.h
io.o:      io.c io.h LispMe.h fpstuff.h arith.h vm.h util.h builtin.h
io.h:      store.h port.h
Launch.o:  Launch.c
LispMe.o:  LispMe.c LispMe.h io.h vm.h comp.h util.h sess.h setup.h builtin.h lists.h
lists.o:   lists.c lists.h vm.h util.h LispMe.h
lists.h:   builtin.h
misc.o:    misc.c misc.h vm.h io.h util.h LispMe.h comp.h fpstuff.h
mish.h:    builtin.h
ParHack.o: ParHack.c ParHack.h
port.o:    port.c port.h file.h io.h comp.h
port.h:    builtin.h
#sample.o:  sample.c sample.h comp.h vm.h io.h
#sample.h:  builtin.h
sess.o:    sess.c sess.h store.h LispMe.h util.h io.h file.h
sess.h:    store.h
setup.o:   setup.c setup.h store.h sess.h util.h LispMe.h io.h
setup.h:   store.h
socket.o:  socket.c socket.h
socket.h:  builtin.h port.h
store.o:   store.c LispMe.h vm.h util.h builtin.h
strport.o: strport.c strport.h util.h
strport.h: builtin.h
util.o:    util.c util.h LispMe.h gui.h io.h
util.h:    store.h
vm.o:      vm.c vm.h comp.h LispMe.h fpstuff.h cplx.h util.h builtin.h arith.h
vm.h:      store.h

#-----------------------------------------------------------------------------
# build final prc from code, data, reloc and gui resources
# Extract only relevant code resource from Launch and put it into LispMe.prc
# under a different resource id
#-----------------------------------------------------------------------------
../LispMe.prc: LispMe Launch LispMe.stamp
	$(OBJRES) Launch 
	mv code0001.Launch.grc code2329.Launch.grc
	$(BUILDPRC) -o../LispMe.prc LispMe.def LispMe *.bin code2329.Launch.grc
	rm -f *.bin
	rm -f *.grc

../ParHack.prc: ParHack ParHack.stamp
	$(BUILDPRC) -o../ParHack.prc ParHack.def ParHack *.bin
	rm -f *.bin 

#-----------------------------------------------------------------------------
# gui resources
#-----------------------------------------------------------------------------
LispMe.stamp: LispMe.rcp Launch.rcp ../bitmaps/*.bmp
	pilrc -q Launch.rcp >rc.log 2>&1
	mv tAIB03e9.bin tAIB2329.bin
	mv tAIB03e8.bin tAIB2328.bin
	pilrc -q LispMe.rcp >>rc.log 2>&1

ParHack.stamp: ParHack.rcp
	pilrc -q ParHack.rcp 

#-----------------------------------------------------------------------------
# linking coff-executable
#-----------------------------------------------------------------------------
LispMe:  LispMe.o util.o store.o fpstuff.o io.o hbase.o graphic.o misc.o \
         cplx.o gui.o comp.o vm.o file.o sess.o setup.o builtin.o arith.o \
	 date.o dm.o lists.o socket.o strport.o port.o \
         LispMe-sections.o LispMe-sections.ld 

LispMe-sections.o: LispMe-sections.s

LispMe-sections.s LispMe-sections.ld: LispMe.def
	multigen LispMe.def 

ParHack: ParHack.o
	$(CC) -nostartfiles ParHack.o -o ParHack

Launch: Launch.o
	$(CC) -nostartfiles Launch.o -o Launch

##############################################################################
# directory cleanup
##############################################################################
clean: tidy
	rm -f *.prc  

tidy:
	rm -f *.o *.a *.log hst LispMe ParHack Launch 
	rm -f LispMe-sections*

##############################################################################
# Build the entire LispMe system
##############################################################################
all:    ../LispMe.prc ../ParHack.prc

vm.s: vm.c
	$(CC) $(CFLAGS) --verbose-asm -S -ovm.s vm.c