CC = m68k-palmos-gcc
CXX = m68k-palmos-g++
AS = m68k-palmos-as
CFLAGS = -palmos4 -O2 -Wall -I$(GCCDIR)
DEBUGFLAGS = -g -mdebug-labels

LIBS =
PILRC = pilrc
PILRCFLAGS = -I $(BMPDIR) -q

OBJS = 	OnBoardC.o \
	OnBoardC_Main.o \
	types.o \
	Initialization.o \
	codegen.o \
	compile.o \
	sourceFiles.o 

BINDIR = Pilrc/
BMPDIR = Pilrc/
GCCDIR = Pilrc/

RCP = $(BINDIR)OnBoardC.rcp

#set 'all' to point to target 'debug' or 'release' to set default build
all: debug

debug: CFLAGS += $(DEBUGFLAGS)
debug: OnBoardC.prc

release: OnBoardC.prc

# build the prc file from the finished binary and all associated files
OnBoardC.prc: OnBoardC $(GCCDIR)OnBoardC.def OnBoardC.rcp_bin
	build-prc -o OnBoardC.prc -t appl -n "OnBoardC" -c OnBC $(GCCDIR)OnBoardC.def OnBoardC $(BINDIR)*.bin 

# dummy target to ensure dependencies work ok
OnBoardC.rcp_bin: $(RCP) OnBoardC_res.h $(BMPDIR)*.bmp
	$(PILRC) $(PILRCFLAGS) $(RCP) $(BINDIR) && touch OnBoardC.rcp_bin

# main compile and link stage
OnBoardC: $(OBJS) OnBoardC-sections.o OnBoardC-sections.ld
	$(CC) $(LIBS) $(CFLAGS) -o OnBoardC $(OBJS) OnBoardC-sections.o OnBoardC-sections.ld

# rule to assemble the sections file
OnBoardC-sections.o: OnBoardC-sections.s

# create a sections file from 
OnBoardC-sections.s OnBoardC-sections.ld: $(GCCDIR)OnBoardC.def
	m68k-palmos-multigen $(GCCDIR)OnBoardC.def

# clear out all the temporary files and objects that build generates
clean:
	-rm -f *.o *.[pg]rc $(BINDIR)*.bin *-sections.* OnBoardC\
	*~ OnBoardC.rcp_bin Pilrc/*~

dist-clean: clean
