VERSION = current
CVSTAG = -D now
# WINKIT = /local/pkg/tclkit/8.4.9/lib/tclkit-8.4.9/tclkit-win32.upx.exe
WINKIT = c:/Software/tclkit/tclkit-with-encodings.exe
SDX = c:/Software/tclkit/tclkitsh c:/Software/tclkit/sdx.kit

TGZDIST = gorilla-$(VERSION).tar.gz
ZIPDIST = gorilla-$(VERSION).zip
KITDIST = gorilla-$(VERSION).kit
WINDIST = gorilla-$(VERSION).exe

all:
	@echo "usage: make <dist> VERSION=\"<version>\" CVSTAG=\"<tag>\""
	@echo "where:"
	@echo "   <dist>    is tgz, zip, kit, exe or dist"
	@echo "   <version> is the file's version suffix"
	@echo "   <tag>     is the CVS tag or date, e.g., \"-D now\""

dist: tgz zip kit exe
tgz: $(TGZDIST)
zip: $(ZIPDIST)
kit: $(KITDIST)
exe: $(WINDIST)

.SUFFIXES:
.PHONY: phony

gorilla-$(VERSION).exe: gorilla-$(VERSION).kit
	rm -rf temp
	mkdir temp
	cp $^ temp/gorilla.kit
	(cd temp; $(SDX) unwrap gorilla.kit)
	cp pics/gorilla.ico temp/gorilla.vfs/tclkit.ico
	(cd temp; $(SDX) wrap gorilla.kit -runtime $(WINKIT))
	mv temp/gorilla.kit $@
	rm -rf temp

gorilla-$(VERSION).kit:
	rm -rf temp
	mkdir temp
	(cd temp; cvs export $(CVSTAG) gorilla)
	(cd temp/gorilla; $(SDX) qwrap gorilla.tcl)
	(cd temp/gorilla; $(SDX) unwrap gorilla.kit)
	(cp temp/gorilla/LICENSE.txt temp/gorilla/help.txt \
		temp/gorilla/isaac.tcl \
		temp/gorilla/gorilla.vfs/lib/app-gorilla/)
	(cp -R temp/gorilla/blowfish \
		temp/gorilla/twofish \
		temp/gorilla/pwsafe \
		temp/gorilla/sha1 \
		temp/gorilla/gorilla.vfs/lib)
	cp -R BWidget-1.7.0 temp/gorilla/gorilla.vfs/lib
	(cd temp/gorilla; $(SDX) wrap gorilla.kit)
	mv temp/gorilla/gorilla.kit $@
	rm -rf temp

gorilla-$(VERSION).tar.gz:
	rm -rf temp
	mkdir temp
	(cd temp ; cvs export $(CVSTAG) -d gorilla-$(VERSION) gorilla)
	(cd temp ; tar cf ../gorilla-$(VERSION).tar gorilla-$(VERSION))
	gzip -9 gorilla-$(VERSION).tar
	rm -rf temp

gorilla-$(VERSION).zip:
	rm -rf temp
	rm -f $@
	mkdir temp
	(cd temp ; cvs export $(CVSTAG) gorilla)
	(cd temp/gorilla; zip -r ../../gorilla-$(VERSION).zip *)
	rm -rf temp

distclean: clean
	rm -rf *.exe *.kit *.zip *.tar.gz

clean:
	find . -name '*~' -exec rm -f {} \;
	rm -rf config.* gorilla
	rm -rf core a.out *~ *.o *.I
	rm -rf temp
