# Copyright (c) 1999-2003 by Wayne C. Gramlich.
# All rights reserved.

# Permission to use, copy, modify, distribute, and sell this software
# for any purpose is hereby granted without fee provided that the above
# copyright notice and this permission are retained.  The author makes
# no representations about the suitability of this software for any purpose.
# It is provided "as is" without express or implied warranty.

ROOT := ..

include $(ROOT)/Makefile_common.mk
include $(ROOT)/Makefile_private.mk

VERSION := 0.52

UCL_SOURCES :=			\
	example1
UCL_ASMS := ${UCL_SOURCES:%=%.asm}
UCL_HEXES := ${UCL_SOURCES:%=%.hex}
UCL_LSTS := ${UCL_SOURCES:%=%.lst}
UCL_GENERATED :=		\
	${UCL_ASMS}		\
	${UCL_HEXES}		\
	${UCL_LSTS}

DOWNLOAD_HTML := download.html

TARBALL := ucl-$(VERSION).tar.gz
ZIPBALL := ucl-$(VERSION).zip

IMAGE_BASES :=		\
	buttons		\
	compile_mode	\
	debug_mode	\
	editor
GIFS := ${IMAGE_BASES:%=%.gif}
PNGS := ${IMAGE_BASES:%=%.png}
SOURCES :=		\
	Makefile	\
	index.html	\
	ucl.tcl		\
	compiler.tcl	\
	edit.tcl	\
	example1.ucl	\
	${PNGS}

VERSION_DIRECTORY := ucl-$(VERSION)

# Some pattern targets:

%.png: %.gif
	giftopnm $< | pnmtopng > $@

# Some targets:

.PHONY: all

all: $(DOWNLOAD_HTML)

$(DOWNLOAD_HTML): $(TARBALL) $(ZIPBALL)
	rm -f $@
	echo "<HTML>" > $@
	echo "<Head>" >> $@
	echo "<Title>&micro;CL Download Page</Title>" >> $@
	echo "</Head>" >> $@
	echo "<Body>" >> $@
	echo "</Body>" >> $@
	echo "<H1>&micro;CL Download Page</H1>" >> $@
	echo "<P>The latest version of &micro;CL is $(VERSION)." >> $@
	echo "It can be obtained from either:" >> $@
	echo "<DL>" >> $@
	echo " <DT><A HRef=\"ucl-$(VERSION).tar.gz\">ucl-$(VERSION).tar.gz</A></DT>" >> $@
	echo "  <DD>Tar Gzip File</DD>" >> $@
	echo " <DT><A HRef=\"ucl-$(VERSION).zip\">ucl-$(VERSION).zip</A></DT>" >> $@
	echo "  <DD>Zip File</DD>" >> $@
	echo " <DT><A HRef=\"ucl.tcl\">ucl.tcl</A> (Version $(VERSION))</DT>" >> $@
	echo "  <DD>Just the compiler start-up script</DD>" >> $@
	echo " <DT><A HRef=\"compiler.tcl\">compiler.tcl</A> (Version $(VERSION))</DT>" >> $@
	echo "  <DD>Just some random numbers</DD>" >> $@
	echo " <DT><A HRef=\"ucl_random_numbers\">ucl_random_numbers</A></DT>" >> $@
	echo "  <DD>Just the shared compiler and programming env.</DD>" >> $@
	echo " <DT><A HRef=\"edit.tcl\">edit.tcl</A> (Version $(VERSION))</DT>" >> $@
	echo "  <DD>Just the editor start-up script</DD>" >> $@
	echo "</DL>" >> $@
	echo "From NetScape Navigator, it is as simple as holding down" >> $@
	echo "the shift key and clicking on one of the two links above." >> $@
	echo "</P>" >> $@
	echo "<HR>" >> $@
	echo "<Address>" >> $@
	echo "<A HRef=\"../../copyright.html\">Copyright</A>" >> $@
	echo "(c) 2000 by" >> $@
	echo "<A HRef=\"../../gramlich.html\">Wayne C. Gramlich</A>" >> $@
	echo "All rights reserved." >> $@
	echo "</Address>" >> $@
	echo "</HTML>" >> $@

$(TARBALL): $(VERSION_DIRECTORY)
	rm -f ucl-$(VERSION).tar $@
	tar cf ucl-$(VERSION).tar $(VERSION_DIRECTORY)
	gzip ucl-$(VERSION).tar

$(ZIPBALL): $(VERSION_DIRECTORY)
	rm -f $@
	zip -rq $@ $(VERSION_DIRECTORY)

$(VERSION_DIRECTORY): ${SOURCES}
	ucl random
	rm -rf $@
	mkdir $@
	cp ${SOURCES} ucl_random_numbers $@
	mkdir $@/tests
	cp tests/Makefile tests/*ucl tests/*.golden $@/tests
	(cd $@ ; ln -s ucl.tcl ucl )

clean:
	rm -rf $(VERSION_DIRECTORY) $(TARBALL) $(ZIPBALL) $(DOWNLOAD_HTML)
	$(CLEAN)

copy: source.html
	rm -rf $(COPY_DIRECTORY)
	mkdir -p $(COPY_DIRECTORY)
	cp ${ALL_SOURCES} $(COPY_DIRECTORY)

