#
# Makefile
#
# makefile LED (SrcEdit).
#
# Copyright 2002, Mark Garlanger
#

# compiler commands

CC       = m68k-palmos-gcc
C++      = m68k-palmos-g++
MULTIGEN = m68k-palmos-multigen
PILRC    = pilrc
OBJRES   = m68k-palmos-obj-res
BUILDPRC = build-prc

# flags
PILRCDIR   = Pilrc/
#CCFLAGS   = -palmos4 -O2 -Wall
CCFLAGS    = -palmos5 -O2 -DHIRES_SUPPORT -Wall
#CCFLAGS   = -palmos4 -O2 -DSONY_SUPPORT -Wall
DEBUGFLAGS = -g -mdebug-labels
BMPDIR     = Pilrc/
PILRCFLAGS = -I $(BMPDIR) -q
BINDIR     = Pilrc/

# source / outputs
OBJS     = Led.o Led3.o Led4.o LedGlobals.o TextContents.o
EXEC     = SrcEdit.prc
BMPS     = $(BMPDIR)*.bmp
TXTS     = $(BMPDIR)*.txt
BINS     = $(BINDIR)*.bin
RCPNAME  = $(PILRCDIR)SrcEdit.rcp
DEFNAME  = $(PILRCDIR)SrcEdit.def


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

debug: CCFLAGS += $(DEBUGFLAGS)
debug: $(EXEC)

release: $(EXEC)

# compile requirements
$(EXEC): SrcEdit led.rcp_bin
	$(BUILDPRC) -o $(EXEC) $(DEFNAME) SrcEdit $(BINS)

# dummy target to generate all the .bin files.
led.rcp_bin: $(RCPNAME) Led_res.h $(BMPS) $(TXTS)
	$(PILRC) $(PILRCFLAGS) $(RCPNAME) $(BMPDIR)
	touch led.rcp_bin

SrcEdit: $(OBJS)  SrcEdit-sections.o
	$(CC) $(CCFLAGS) $(OBJS) SrcEdit-sections.o SrcEdit-sections.ld -o SrcEdit
#	$(OBJRES) SrcEdit

SrcEdit-sections.s SrcEdit-sections.ld: $(DEFNAME)
	$(MULTIGEN) $(DEFNAME)


# compile rules
.SUFFIXES: .c .o .s .cpp

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

.s.o:
	$(CC) -c $(CCFLAGS) $<

.cpp.o:
	$(C++) -c $(CCFLAGS) $<

Led.o: Led.cpp
Led3.o: Led3.cpp
Led4.o: Led4.cpp
LedGlobals.o: LedGlobals.c
TextContents.o: TextContents.cpp

# clean-up funtions
clean:
	rm -f *.[oas] *.bin bin.res *.grc *~ *.prc *.rcp_bin\
	 $(BINDIR)*.bin *.ld SrcEdit Pilrc/*~

distclean: 
	rm -f *.[oa] *.bin bin.res *.[pg]rc *~ Pilrc/*~

dist-clean: clean

