CC = m68k-palmos-gcc
PILRC = pilrc.exe
MULTIGEN = m68k-palmos-multigen
BUILDPRC = build-prc

APP = TomCatalog
PRC = $(APP).prc
DEF = $(APP).def
SECTIONS = $(APP)-sections
RCP = resource.rcp

OBJ = dbinfo.o filter.o main.o mtable.o prefs.o proper.o sorting.o tools.o util.o $(SECTIONS).o


# Switch on some warnings by including $(WARNINGS) in CFLAGS

#WARNINGS = -Wunused -Wuninitialized -Wcomment -Wreturn-type 

# Set up the flags that will be passed to the compiler/linker
# -O2 for optimise
#
# ERROR_CHECK_FULL for lots of warnings about style, etc.
#CFLAGS = -O2 -DERROR_CHECK_LEVEL=ERROR_CHECK_NONE -palmos2.0
#
# Faster code can be created at the expense of size by uncommenting:
# CFLAGS=$(CFLAGS) -finline-functions

DEBUGCFLAGS= -g -DDEBUG_BUILD
RELEASECFLAGS= -O2
# change following from DEBUGCFLAGS to RELEASECFLAGS for a no-debug build

CFLAGS = -g -DERROR_CHECK_LEVEL=ERROR_CHECK_FULL $(RELEASECFLAGS) $(WARNINGS)


# -------------------------------------------------- 
#    Rules for compiling the program
# -------------------------------------------------- 


all: $(PRC) Makefile


$(APP).prc: $(APP) $(DEF) bin.stamp $(APP).def
	$(BUILDPRC) $(DEF) -o $(PRC) $(APP) *.bin

$(APP): $(OBJ) $(SECTIONS).ld
	$(CC) $(CFLAGS) -o $@ $(OBJ) $(SECTIONS).ld
			
bin.stamp: $(RCP) resource.h 
	$(PILRC) -q $(RCP)
	touch bin.stamp

$(SECTIONS).o: $(SECTIONS).s
	$(CC) -O2 -c $(SECTIONS).s -o $(SECTIONS).o

$(SECTIONS).s $(SECTIONS).ld: $(DEF)
	$(MULTIGEN) $(DEF)



clean:
	rm -f *.o *.s *.ld *.bin *.prc $(APP) bin.stamp
	
