#  makefile -- OpenChess makefile to build OpenChess.prc
#
#  OpenChess version 2.0, is a CHESS game for Palm Pilot, adapted
#  from GNU Chess 2, for Unix/DOS environments
#  Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
#  Copyright (C) 2002, Son Altesse.
#  Copyright (C) 2005, Olaf Richter.
#
#  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 of the License, or
#  (at your option) any later version.
#
#  This program 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 General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

#
#  Target ALL
#

CFLAGS=-DSDK50
CC=m68k-palmos-gcc 

all : ./Release/OpenChess.prc

#
#  Target Remove temporary files
#
temp : 
	cd ./Release/ && \
	rm -f *.bin bin.res *~ *.grc *.o *.ld *.s

#
#  Target Clean
#
clean : 
	cd ./Release/ && \
	rm -f *.bin bin.res *~ *.grc *.prc *.o *.ld *.s OpenChess.prc OpenChess

#
#  Rule for building sourcefile gnuchess2.c
#
./Release/gnuchess2.o : gnuchess2.c OpenChess.h OpenChess_res.h
	@echo "Compiling gnuchess2.c..." && \
	$(CC) $(CFLAGS) -O3 -o ./Release/gnuchess2.o -c gnuchess2.c

#
#  Rule for building sourcefile OpenChess.c
#
./Release/OpenChess.o : OpenChess.c OpenChess.c gnuchess2.h OpenChess_res.h
	@echo "Compiling OpenChess.c..." && \
	$(CC) $(CFLAGS) -Wall -Os -o ./Release/OpenChess.o -c OpenChess.c -I"./SonySDK"

#
#  Rule for building resources
#
./Release/bin.res : OpenChess.rcp BitmapsStd.rcp OpenChess_res.h
	@echo "Compiling resource OpenChess.rcp..." && \
	pilrc -q OpenChess.rcp Release/
	@echo "Compiling resource BitmapsStd.rcp..." && \
	pilrc -q BitmapsStd.rcp Release/

#
#  Rule for building assembler stub
#
./Release/OpenChess-sections.o : ./Release/OpenChess-sections.s
	@echo "Building Assembler Stub..." && \
	$(CC) -o ./Release/OpenChess-sections.o -c ./Release/OpenChess-sections.s

#
#  Rule for building linker script
#
./Release/OpenChess-sections.s : OpenChess.def
	@echo "Building Linker Script..." && \
	cd ./Release/ && \
	m68k-palmos-multigen ../OpenChess.def

#
#  Rule for linking
#
./Release/OpenChess : ./Release/gnuchess2.o ./Release/OpenChess.o ./Release/OpenChess-sections.o
	@echo "Linking..." && \
	$(CC) -o ./Release/OpenChess ./Release/gnuchess2.o \
		./Release/OpenChess.o \
		./Release/OpenChess-sections.o \
		./Release/OpenChess-sections.ld -lPalmOSGlue -g  && \
	m68k-palmos-objdump --section-headers ./Release/OpenChess

#
#  Rule for building PRCFile
#
./Release/OpenChess.prc : ./Release/gnuchess2.o ./Release/OpenChess.o ./Release/bin.res ./Release/OpenChess-sections.o ./Release/OpenChess
	@echo "Building program file ./Release/OpenChess.prc..." && \
	cd ./Release/ && \
	build-prc -o OpenChess.prc ../OpenChess.def *.bin OpenChess
