# Set the version here and it will propogate to the rest of the program.

VERSION=0.3.0

# No user-servicable parts beyond this point.

BUILD_DATE=`date '+%d %b %Y'`

AS=m68k-palmos-gcc
ASFLAGS=-c

CC=m68k-palmos-gcc
CFLAGS=-Wstrict-prototypes -O2 -g

LD=m68k-palmos-gcc
LDFLAGS=-g

BUILDPRC=build-prc
MULTIGEN=multigen
M4=m4
PILRC=pilrc

OBJS=main.o list.o chooser.o design.o io.o util.o \
	listprop.o prefs.o find.o linkaware.o grid.o edit.o

.c.o:
	$(CC) $(CFLAGS) -c $<

db.prc: db ts-bin
	$(BUILDPRC) db.def db *.bin

db-sample.prc: db ts-bin-sample
	$(BUILDPRC) --output=db-sample.prc db.def db *.bin

db-de.prc: db ts-bin-de
	$(BUILDPRC) --output=db-de.prc db.def db *.bin

db-nl.prc: db ts-bin-nl
	$(BUILDPRC) --output=db-nl.prc db.def db *.bin

db-ja.prc: db ts-bin-ja
	$(BUILDPRC) --output=db-ja.prc db.def db *.bin

ts-res: db.rcp
	rm -rf ts-res res
	mkdir res
	$(M4) -Ilangs -D__BUILD_DATE__="$(BUILD_DATE)" -D__VERSION__="$(VERSION)" db.rcp > res/res.tmp
	touch ts-res

ts-bin: ts-res
	rm -f *.bin ts-bin*
	$(PILRC) -q res/res.tmp
	echo a > Link0001.bin
	touch ts-bin

ts-bin-sample: ts-res
	rm -f *.bin ts-bin*
	$(PILRC) -q -L SAMPLE res/res.tmp
	echo a > Link0001.bin
	touch ts-bin-sample

ts-bin-de: ts-res
	rm -f *.bin ts-bin*
	$(PILRC) -q -L DE res/res.tmp
	echo a > Link0001.bin
	touch ts-bin-de

ts-bin-nl: ts-res
	rm -f *.bin ts-bin*
	$(PILRC) -q -L NL res/res.tmp
	echo a > Link0001.bin
	touch ts-bin-nl

ts-bin-ja: ts-res
	rm -f *.bin ts-bin*
	$(PILRC) -q -Fj -L JA res/res.tmp
	echo a > Link0001.bin
	touch ts-bin-ja

db-sections.o: db-sections.s
db-sections.s db-sections.ld: db.def
	$(MULTIGEN) db.def

db: $(OBJS) db-sections.o db-sections.ld
	$(LD) $(LDFLAGS) -o db db-sections.ld db-sections.o $(OBJS) -lPalmOSGlue

chooser.c: enum.h db.h
design.c: enum.h db.h
edit.c: enum.h db.h linkaware.h
find.c: enum.h db.h
io.c: db.h
linkaware.c: linkaware.h
list.c: enum.h db.h
listprop.c: enum.h db.h
main.c: enum.h db.h linkaware.h
prefs.c: enum.h db.h
util.c: enum.h db.h

db.rcp: enum.h

clean:
	rm -f *~
	rm -f db *.o db-sections.s db-sections.ld
	rm -f *.bin ts-*
	rm -rf res

distclean: clean
	rm -f db*.prc
