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 = 	debug.o \
	OnBoard.o \
	sourceFiles.o
#	Math.c
#at some point we should get Math.c to build properly in case it ever changes

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

RCP = $(BINDIR)OnBoard.rcp

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

.PHONY: debug
debug: CFLAGS += $(DEBUGFLAGS)
debug: OnBoard.prc

.PHONY: release
release: OnBoard.prc

OnBoard.prc: OnBoard $(GCCDIR)OnBoard.def OnBoard.rcp_bin
	build-prc -o OnBoard.prc -t appl -n "OnBoard" -c "OnBA" $(GCCDIR)OnBoard.def OnBoard $(BINDIR)*.bin

OnBoard.rcp_bin: $(RCP) OnBoard_res.h $(BMPDIR)*.bmp 
	$(PILRC) $(PILRCFLAGS) $(RCP) $(BINDIR) && touch OnBoard.rcp_bin

OnBoard: $(OBJS) OnBoard-sections.o OnBoard-sections.ld
	$(CC) $(CFLAGS) $(LIBS) -o OnBoard OnBoard-sections.o OnBoard-sections.ld $(OBJS)

OnBoard-sections.o: OnBoard-sections.s

OnBoard-sections.s OnBoard-sections.ld: $(GCCDIR)OnBoard.def
	m68k-palmos-multigen $(GCCDIR)OnBoard.def

seg-test: $(OBJS)
	$(CC) $(CFLAGS) $(LIBS) -o OnBoard $(OBJS)

.PHONY: clean
clean:
	-rm -f *.o *.[pg]rc $(BINDIR)*.bin *-sections.* OnBoard\
	*~ OnBoard.rcp_bin Pilrc/*~

.PHONY: dist-clean
dist-clean: clean


debug.o:  debug.h

OnBoard.o: OnBoard_res.h OnBoard.h debug.h

sourceFiles.o: OnBoard.h OnBoard_res.h

