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

VERSION=0.3.1

# No user-servicable parts beyond this point.

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

AS=m68k-palmos-gcc
ASFLAGS=-c

CC=m68k-palmos-gcc
CFLAGS=-Wall -Werror -O2 -g

LD=m68k-palmos-gcc
LDFLAGS=-g

BUILDPRC=build-prc
MULTIGEN=multigen
M4=m4
PILRC=pilrc
TOUCH=touch
RM_RF=rm -rf
RM_F=rm -f
MKDIR_P=mkdir -p

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 sort.o names.o \
	MobileDB.o JFile3.o

all: db-en.prc

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

db-en.prc: db ts-bin-en
	$(BUILDPRC) --output=db-en.prc db.def db .res/*.bin

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

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

db-it.prc: db ts-bin-it
	$(BUILDPRC) --output=db-it.prc db.def db .res/*.bin

db-fr.prc: db ts-bin-fr
	$(BUILDPRC) --output=db-fr.prc db.def db .res/*.bin

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

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

db-pt.prc: db ts-bin-pt
	$(BUILDPRC) --output=db-pt.prc db.def db .res/*.bin

ts-res: db.rcp langs/en.rcp langs/de.rcp langs/pt.rcp langs/nl.rcp \
	langs/fr.rcp langs/ja.rcp langs/sample.rcp
	$(RM_RF) ts-res .res/
	$(MKDIR_P) .res
	$(M4) -Ilangs -D__BUILD_DATE__="$(BUILD_DATE)" -D__VERSION__="$(VERSION)" db.rcp > .res/res.tmp
	$(TOUCH) ts-res

ts-bin-en: ts-res
	$(RM_F) ts-bin*
	$(PILRC) -q -L EN -allowEditID .res/res.tmp .res
	$(TOUCH) ts-bin

ts-bin-sample: ts-res
	$(RM_F) ts-bin*
	$(PILRC) -q -L SAMPLE -allowEditID .res/res.tmp .res
	$(TOUCH) ts-bin-sample

ts-bin-de: ts-res
	$(RM_F) ts-bin*
	$(PILRC) -q -L DE -allowEditID .res/res.tmp .res
	$(TOUCH) ts-bin-de

ts-bin-it: ts-res
	$(RM_F) ts-bin*
	$(PILRC) -q -L IT -allowEditID .res/res.tmp .res
	$(TOUCH) ts-bin-it

ts-bin-fr: ts-res
	$(RM_F) ts-bin*
	$(PILRC) -q -L FR -allowEditID .res/res.tmp .res
	$(TOUCH) ts-bin-fr

ts-bin-nl: ts-res
	$(RM_F) ts-bin*
	$(PILRC) -q -L NL -allowEditID .res/res.tmp .res
	$(TOUCH) ts-bin-nl

ts-bin-ja: ts-res
	$(RM_F) ts-bin*
	$(PILRC) -q -Fj -L JA -allowEditID .res/res.tmp .res
	$(TOUCH) ts-bin-ja

ts-bin-pt: ts-res
	$(RM_F) ts-bin*
	$(PILRC) -q -L PT -allowEditID .res/res.tmp .res
	$(TOUCH) ts-bin-pt

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_RF) .res/ ts-*

distclean: clean
	$(RM_F) db*.prc
