# Makefile for Link History Hack
# Please read the readme.txt file that came in the Sample Hack package

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

HACK        = phlegm
HACKNAME    = "Phlegm Hack"
HACKID      = Phgm  # make sure this matches what's in the source files
HACKSRC     = code03e8.c code03e9.c code07d0.c
HACKRES     = $(HACK).rcp $(HACK)Rsc.h
VERSION     = 1.3

CFLAGS   = -O2 -Wall

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

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

all:    $(HACK).prc

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

# This rule builds a standalone code resource (.bin) from a C source file
.c.bin:
	$(CC) $(CFLAGS) -nostartfiles -o $(*F) $<
	$(OBJRES) $(*F)
	cp code0001.$(*F).grc $@
	rm $(*F)

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

hackresbin: $(HACKRES)
	sed -e 's/VERSION_STAMP/$(VERSION)/' $(HACK).rcp.in > $(HACK).rcp
	pilrc $(HACK).rcp
	touch $@

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

clean:
	rm -f *.grc *.bin hackresbin

veryclean: clean
	-rm -f $(HACK).prc

send:
	pilot-xfer -i $(HACK).prc

dist: all
	./html_stamp.pl $(VERSION)
	zip $(HACK)-$(VERSION).zip $(HACK).prc *.htm *.gif COPYING ChangeLog
	tar cvf $(HACK)-src-$(VERSION).tar $(HACK).prc *.htm *.gif COPYING ChangeLog Makefile *.rcp *.bmp *.c *.h *.pl *.in
	gzip -9 $(HACK)-src-$(VERSION).tar


