.SUFFIXES: .xbm .bmp .rcp .dir

ENG=patience.prc
IT=patience-it.prc
TARGETS=$(ENG) $(IT)
LANG=eng it
PROG = patience
ZIP = patience.zip
SRCTAR = patienceSrc.tar.gz
SRCS = aces.c calc.c cards.c golf.c klondike.c montana.c patience.c \
	pdisp.c spider.c spiderette.c tabby.c towers.c yukon.c eight.c \
	canfield.c vegas.c freecell.c wish.c song.c
OBJS = aces.o calc.o cards.o golf.o klondike.o montana.o patience.o \
	pdisp.o spider.o spiderette.o tabby.o towers.o yukon.o eight.o \
	canfield.o vegas.o freecell.o wish.o song.o
HDRS = patience.h cards.h patienceRsc.h patienceGeom.h
GHDRS = klondike.h spider.h
XBMS = 	rank2.xbm \
	rank3.xbm \
	rank4.xbm \
	rank5.xbm \
	rank6.xbm \
	rank7.xbm \
	rank8.xbm \
	rank9.xbm \
	rankA.xbm \
	rankJ.xbm \
	rankK.xbm \
	rankQ.xbm \
	rankT.xbm \
	suitClub.xbm \
	suitDiamond.xbm \
	suitHeart.xbm \
	suitSpade.xbm
BMPS =	rank2.bmp \
	rank3.bmp \
	rank4.bmp \
	rank5.bmp \
	rank6.bmp \
	rank7.bmp \
	rank8.bmp \
	rank9.bmp \
	rankA.bmp \
	rankJ.bmp \
	rankK.bmp \
	rankQ.bmp \
	rankT.bmp \
	suitClub.bmp \
	suitDiamond.bmp \
	suitHeart.bmp \
	suitSpade.bmp

RES = patienceRsc.rcp
ICON = patience.pbitm
ICONRES=tAIB03e8.bin

DOC = readme.txt

BUILD = Makefile $(SRCS) $(HDRS) $(GHDRS) $(XBMS) $(RES) $(ICON) $(DOC)

RLOC= rloc0000.$(PROG).grc
GRCS = code0000.$(PROG).grc code0001.$(PROG).grc data0000.$(PROG).grc $(RLOC)
PREF= pref0000.$(PROG).grc

PREFIX = /local/PalmOS
TOOLS= $(PREFIX)/bin
#TOOLS= /local/src/prc/prc-tools-0.4.2
CC = $(PREFIX)/bin/m68k-palmos-coff-gcc

#uncomment this if you want to build a gdb debuggable version
#DEFINES = -DDEBUG
DEFINES = -DNDEBUG

CSFLAGS = -O2 -S $(DEFINES)
CFLAGS = -O2 $(DEFINES) -Wall -Wstrict-prototypes -fno-builtin

LIBS = $(LDIR) -lgdb -lc -lmf -lgcc

PILRC = $(TOOLS)/pilrc
TXT2BITM = $(TOOLS)/txt2bitm
OBJRES = $(TOOLS)/obj-res -reloc
#OBJRES = $(TOOLS)/obj-res
#BUILDPRC = $(TOOLS)/build-prc
BUILDPRC = /local/src/prc/prc-tools-0.4.2/build-prc

ICONTEXT = "Patience"
APPID = Pati

.S.o:
	$(CC) $(TARGETFLAGS) -c $<

.c.s:
	$(CC) $(CSFLAGS) $<

.xbm.bmp:
	xbmtopbm $< | ppmtobmp -windows > $@

all: $(TARGETS)

$(ZIP): $(TARGETS) $(DOC)
	zip $@ $(TARGETS) $(DOC)

$(SRCTAR): $(BUILD)
	tar czf $(SRCTAR) $(BUILD)

$(ENG): eng
	cd eng && $(BUILDPRC) ../$@ $(ICONTEXT) $(APPID) $(GRCS) *.bin $(PREF)

eng: $(RES) $(BMPS) patienceRsc.h $(GRCS) $(ICONRES)
	rm -rf $@
	mkdir $@
	$(PILRC) -L $@ $(RES) $@
	cp $(GRCS) $(PREF) $(ICONRES) $@

$(IT): it
	cd it && $(BUILDPRC) ../$@ $(ICONTEXT) $(APPID) $(GRCS) *.bin $(PREF)

it: $(RES) $(BMPS) patienceRsc.h $(GRCS) $(ICONRES)
	rm -rf $@
	mkdir $@
	$(PILRC) -L $@ $(RES) $@
	cp $(GRCS) $(PREF) $(ICONRES) $@

$(ICONRES): $(ICON)
	$(TXT2BITM) $(ICON)
	
$(GRCS): $(PROG)
	$(OBJRES) $(PROG)

$(PROG): $(OBJS)
	$(CC) -Wl,-M -Wl,-r -Wl,-dc $(CFLAGS) $(OBJS) -o $(PROG) $(LIBS)

$(OBJS): $(HDRS)

spider.o spiderette.o: spider.h
klondike.o vegas.o: klondike.h

clean:
	rm -rf MakeOut $(OBJS) $(TARGETS) $(PROG) $(BMPS) $(LANG) $(GRCS) $(PREF) $(ZIP) $(SRCTAR)
