#
#  Copyright (c) 2000, 2001, 2002 by Gustavo Broos.
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2.0
#  of the License, or (at your option) any later version.
#
#  Makefile to build any of the two versions of the program.
#  The HackMaster version is built by default.  Use 'make stand-alone'
#  to build the stand-alone version.  This is a very ugly and time
#  consuming makefile (but safe for hackmaster/stand-alone build
#  requirements).
#

cflags= -c -O2 -palmos4 -DVKBFrm=10300 -DVKBMenu=10100
lflags= -O2
rflags= -E -P -DVKBFrm=10300 -DVKBMenu=10100

chflags= -c -O2 -palmos4 -DHACK -DVKBFrm=5000 -DVKBMenu=5000
lhflags= -O2
rhflags= -E -P -DHACK -DVKBFrm=5000 -DVKBMenu=5000

hackmaster:topalmresh buildh clean

stand-alone:topalmres build clean

build:
	build-prc -o vkbse.prc alone.def *.bin SetupHandler.coff code03e8.Trap.coff.grc

buildh:
	build-prc -o vkbhack.prc hack.def *.bin Trap.coff code07d0.SetupHandler.coff.grc

topalmres:resources link
	m68k-palmos-obj-res -l Trap.coff
	mv GLib0000.Trap.coff.grc code03e8.Trap.coff.grc

topalmresh:resourcesh linkh
	m68k-palmos-obj-res -l SetupHandler.coff
	mv GLib0000.SetupHandler.coff.grc code07d0.SetupHandler.coff.grc

link:compile
	m68k-palmos-gcc $(lflags) -nostartfiles VKBInputSeg.o  VKBShared.o -o Trap.coff
	m68k-palmos-gcc $(lflags) VKBSetupHandler.o VKBStandAlone.o VKBShared.o -o SetupHandler.coff

linkh:compileh
	m68k-palmos-gcc $(lflags) -nostartfiles VKBInputSeg.o VKBShared.o -o Trap.coff
	m68k-palmos-gcc $(lflags) -nostartfiles VKBSetupHandler.o VKBShared.o -o SetupHandler.coff

compile:VKBStandAlone.c VKBInput.c VKBShared.c VKBSetupHandler.c VKBInput.h VKBIncludeAll.h
	m68k-palmos-gcc $(cflags) VKBStandAlone.c -o VKBStandAlone.o
	m68k-palmos-gcc $(cflags) VKBInput.c -o VKBInputSeg.o
	m68k-palmos-gcc $(cflags) VKBSetupHandler.c -o VKBSetupHandler.o
	m68k-palmos-gcc $(cflags) VKBShared.c -o VKBShared.o

compileh:VKBInput.c VKBShared.c VKBSetupHandler.c VKBInput.h VKBIncludeAll.h
	m68k-palmos-gcc $(chflags) VKBInput.c -o VKBInputSeg.o
	m68k-palmos-gcc $(chflags) VKBSetupHandler.c -o VKBSetupHandler.o
	m68k-palmos-gcc $(chflags) VKBShared.c -o VKBShared.o

resources:VKBInput.rcp VKBRcp.h ../data/icons/*.bmp
	gcc $(rflags) VKBInputToProcess.h -o VKBInputTail.rcp
	make echotext
	cat VKBInputTail.rcp >> VKBInput.rcp
	rm VKBInputTail.rcp
	pilrc -H VKBAuto.h VKBInput.rcp

resourcesh:VKBInput.rcp VKBRcp.h ../data/icons/*.bmp
	gcc $(rhflags) VKBInputToProcess.h -o VKBInputTail.rcp
	make echotext
	cat VKBInputTail.rcp >> VKBInput.rcp
	rm VKBInputTail.rcp
	pilrc -H VKBAuto.h VKBInput.rcp

clean:
	rm -f *.o
	rm -f *.grc
	rm -f *.bin
	rm -f *.coff
	mv -f *.prc ../binaries
	ls -l ../binaries/*.prc

echotext:
	echo "//" > VKBInput.rcp
	echo "// Copyright (c) 2000, 2001, 2002 by Gustavo Broos." >> VKBInput.rcp
	echo "//" >> VKBInput.rcp
	echo "// This program is free software; you can redistribute it and/or" >> VKBInput.rcp
	echo "// modify it under the terms of the GNU General Public License" >> VKBInput.rcp
	echo "// as published by the Free Software Foundation; either version 2.0" >> VKBInput.rcp
	echo "// of the License, or (at your option) any later version." >> VKBInput.rcp
	echo "//" >> VKBInput.rcp
	echo "// This file is a resources definition file for the program." >> VKBInput.rcp
	echo "//" >> VKBInput.rcp
	echo "//" >> VKBInput.rcp
	echo "" >> VKBInput.rcp
	echo "//Generated by the makefile, do not modify." >> VKBInput.rcp
	echo "" >> VKBInput.rcp
	echo "#include \"VKBRcp.h\"" >> VKBInput.rcp



