# Makefile for Sample Hack
# Please read the readme.txt file that came in the Sample Hack package
# Commonly used  Automatic Variables:
#	  $< represents the first dependency
#	  $^ represents all dependencies
#	  $? represents all dependencies that are newer than the target
#	  $@ represents the target 
#	  $* represents the target without the extention
#######################################################################

# Add .bin to the list of suffixes that make recognizes
.SUFFIXES:  .bin

HACK        = ClockEveryWhere
HACKNAME    = "ClockEveryWhere"
HACKID      = RMal  # make sure this matches what's in the source files
HACKSRC     = code03e8.c code03e9.c code07d0.c
HACKRES     = $(HACK).rcp ResourceDefines.h

HACKBIN     = $(HACKSRC:.c=.bin)

DEBUGCFLAGS     = -g -palmos3.5
RELEASECFLAGS   = -palmos3.5 -g -DDEBUG_BUILD -Wall -DCMD_LINE_BUILD -DEMULATION_LEVEL=0 -mdebug-labels -O3

PRCFLAGS      = --backup -t HACK -v 1


# You shouldn't have to change anything below this line

CC      = m68k-palmos-gcc
OBJRES  = m68k-palmos-obj-res

release:
	make CFLAGS="$(RELEASECFLAGS)" all

debug:
	make CFLAGS="$(DEBUGCFLAGS)" all

all: $(HACK).prc

$(HACKSRC): utils.o

utils.o:
	@echo "   build" utils.c
	$(CC) $(CFLAGS) -nostartfiles -o utils.o utils.c 2>&1 | errmsgs -vs

# This rule builds a standalone code resource (.bin) from a C source file
.c.bin:
	@echo "   build" $(*F)".c"
	$(CC) $(CFLAGS) -nostartfiles -o $(*F) $< utils.o 2>&1 | errmsgs -vs
	$(OBJRES) $(*F)
	cp code0001.$(*F).grc $@
	@echo "rm this files" $(*F)
	rm $(*F)

$(HACK).prc: hackresbin $(HACKBIN)
	build-prc $(PRCFLAGS) $@ $(HACKNAME) $(HACKID) *.bin
	@ls -l $@
	@par h $(HACK).prc

hackresbin: $(HACKRES)
	pilrc -V $(HACK).rcp
	touch $@

$(HACKBIN): $(HACK).h ResourceDefines.h

clean:
	@pwd
	rm -f *.o *.grc *.bin $(HACK).prc hackresbin
	@rmdir debug