#######################################################################
# Makefile for ClockEveryWhere Hack
# Please read the readme.txt file that came in the ClockEveryWhere 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

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

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
PRCFLAGS    = --backup -t HACK -v 1
HACKBIN     = $(HACKSRC:.c=.bin)

ALLFLAGS	= -palmos3.5 -Wall
#DEBUGCFLAGS     = -g  $(ALLFLAGS) \
#	-DERROR_CHECK_LEVEL=ERROR_CHECK_FULL -DDEBUG=1 -DCMD_LINE_BUILD -DEMULATION_LEVEL=0 -mdebug-labels
#RELEASECFLAGS   = -O2 $(ALLFLAGS) -DERROR_CHECK_LEVEL=ERROR_CHECK_NONE -DEMULATION_LEVEL=0

DEBUGCFLAGS     = $(ALLFLAGS) -g -DnoDISPLAY_INFO -DDEBUG_BUILD -mdebug-labels
RELEASECFLAGS   = $(ALLFLAGS) -O3 -DnoDISPLAY_INFO -DEMULATION_LEVEL=0


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

release:
	make CFLAGS="$(RELEASECFLAGS)" all
	rm -f *.o *.grc *.bin hackresbin

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

all: $(HACK).prc

$(HACKSRC): utils.o

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

# 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
	$(CC) $(CFLAGS) -nostartfiles -o $(*F) $< utils.o
	$(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 utils.c

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

