#######################################################################
# Makefile sample for a project built from VC++
# Commonly used  Automatic Variables:
#	  $< represents the first dependency
#	  $^ represents all dependencies
#	  $? represents all dependencies that are newer than the target
#	  $@ represents the target 
#######################################################################
all:
	make $(OUTPUTDIR)$(APP).prc

#######################################################################
# Enter information relative to your project here
#######################################################################
PROGDBNAME=Sample
PROGCREATOR=RNi0
APP=Sample
RCPFILE=Resources.rcp
RSRCINC=ResourceDefines.h

SRCDIR=../Src/
RSRCDIR=../Rsc/
OUTPUTDIR=../Obj/
BUILDDIR=../Build/

# Enter all .o files for your project
OBJS=$(OUTPUTDIR)Main.o $(OUTPUTDIR)Utils.o $(OUTPUTDIR)MainForm.o $(OUTPUTDIR)SecondForm.o

# Define CFLAGS to either DEBUGCFLAGS or RELEASECFLAGS and PRCFLAGS
#DEBUGCFLAGS = -palmos3.5 -g -DDEBUG_BUILD -Wall -DCMD_LINE_BUILD -DEMULATION_LEVEL=0 -mdebug-labels
#RELEASECFLAGS = -palmos3.5 -O3 -Wall -DCMD_LINE_BUILD -DEMULATION_LEVEL=0

# DEBUG Build
CFLAGS = -palmos3.5 -g -DDEBUG_BUILD -Wall -DCMD_LINE_BUILD -DEMULATION_LEVEL=0  -mdebug-labels
PRCFLAGS      = --backup -t appl -v 1

#######################################################################
# Define Dependencies here
#######################################################################
$(OUTPUTDIR)Main.o: $(BUILDDIR)Makefile $(RSRCDIR)$(RSRCINC) $(SRCDIR)MainForm.h $(SRCDIR)SecondForm.h $(SRCDIR)Utils.h
$(OUTPUTDIR)MainForm.o: $(BUILDDIR)Makefile $(RSRCDIR)$(RSRCINC) $(SRCDIR)MainForm.h
$(OUTPUTDIR)SecondForm.o: $(BUILDDIR)Makefile $(RSRCDIR)$(RSRCINC) $(SRCDIR)SecondForm.h
$(OUTPUTDIR)Utils.o: $(BUILDDIR)Makefile $(RSRCDIR)$(RSRCINC) $(SRCDIR)Utils.h

#######################################################################
# DO NOT CHANGE HERE
#######################################################################
CC = m68k-palmos-gcc

#$(OUTPUTDIR)$(APP).prc: $(OUTPUTDIR)$(APP) $(OUTPUTDIR)bin.stamp $(BUILDDIR)$(APP).def
#	(cd $(OUTPUTDIR); build-prc $(BUILDDIR)$(APP).def $(APP) *.bin -o $(APP).prc)
$(OUTPUTDIR)$(APP).prc: $(OUTPUTDIR)$(APP).code.1.sym $(OUTPUTDIR)bin.stamp
	(cd $(OUTPUTDIR); build-prc $(PRCFLAGS) $(APP).prc $(PROGDBNAME) $(PROGCREATOR) $(APP).code.1.sym *.bin)

$(OUTPUTDIR)$(APP).code.1.sym: $(OBJS)
	$(CC) $(CFLAGS) -o $@ $(OBJS)

$(OUTPUTDIR)%.o: $(SRCDIR)%.c 
	$(CC) $(CFLAGS) -c $< -o $@ -I $(RSRCDIR) 2>&1 | errmsgs -vs

$(OUTPUTDIR)bin.stamp: $(RSRCDIR)$(RCPFILE) $(RSRCDIR)$(RSRCINC)
	( cd $(OUTPUTDIR); rm *.bin; pilrc -V -I $(SRCDIR) -I $(RSRCDIR) $(RSRCDIR)$(RCPFILE) ; touch bin.stamp)

clean:
	rm -f $(OBJS) $(OUTPUTDIR)$(APP).* $(OUTPUTDIR)*.bin $(OUTPUTDIR)bin.stamp
