#
#	Simple makefile for the webc project
#
#	The home system for this is at:
#		http://mordred.armoredpenguin.com/~regan/Webc/
#

.SUFFIXES: .wc .html

.wc.html:
	./webc $*.wc
	chmod a+r $*.html

OBJ	= api.html directives.html examples.html funcs.html invoke.html \
	  macros.html overview.html sug.html watchit.html webc.html

VERSION   := $(shell fgrep "Version = " webc | sed "s/.*v\([0-9.]*\).*/\1/")
BINDIR	  = /usr/local/bin
LCDIR	  = /usr/local/lib/webc/lc

all:	version.wh $(OBJ)
	chmod a+x webc
	#ln -fs webc.html index.html
	cp webc.html index.html

version.wh:
	echo "#define _WEBC-VERSION_ $(VERSION)" >version.wh

install: all
	install -p -m a=rx webc $(BINDIR)
	-install -d $(LCDIR)
	install -p -m a=r  *.lc lc/*.lc $(LCDIR)

clean:
	rm -f $(OBJ) SupportBin/webc version.wh index.html

#	Create the distribution tar file once we have removed any
#	extraneous files.
dist:	tar
tar:	clean dotar all

#	Create the tar file.
dotar:
	rm -f webc.tar.gz Webc
	ln -sf Webc ../webc-$(VERSION)
	cd ..; tar --exclude RCS --exclude "*tar.gz" --exclude "*.swp" \
		-cz -h -f webc.tar.gz webc-$(VERSION)
	rm -f ../webc-$(VERSION)
	mv -f ../webc.tar.gz webc-$(VERSION).tar.gz
	chmod a+r,a-w webc-*tar.gz
	ln -sf webc-$(VERSION).tar.gz webc.tar.gz


###
###	Special utility rules
###

perms:
	rm -f index.html
	ln -s webc.html index.html
	chmod a-w,a+r *.lc *.wc *.wh *.wh2 *.h announce.0.19 [A-Z]*
	chmod 755 RCS

# Ensure that all of the generated HTML files are in the pagefile.
# If there are any HTML files not in the pagefile, it should show up here.
checkpage:	all
	find . -type f -name "*.html" | sort -u | sed "s/\.\///" >/tmp/$$.1
	sort -u pagelist.h >/tmp/$$.2
	diff /tmp/$$.1 /tmp/$$.2
	rm -f /tmp/$$.1 /tmp/$$.2


###
###	The following rules build special distributions, and are not
###	needed for normal use.
###

# Build a distribution.
distribution:	clean
	cd ..; tar --exclude RCS -czf Webc.tar.gz Webc
	cp -f webc SupportBin/webc
	chmod 555 SupportBin/webc
	SupportBin/checksum --update --exclude RCS
	rm -f webcpkg.tar.gz
	tar -cf webcpkg.tar SupportBin/webc Config/checksums
	gzip -9 webcpkg.tar
	rm -f SupportBin/webc
	mv -f ../Webc.tar.gz .
	chmod 644 *.tar.gz
	make

# Unpack the current package
unpack:
	cd ..; tar xvfz `ls -1d Webc/webc-* | tail -1`
	cd ..; mv -f Webc Webc.old; mv -f webc-* Webc; cd Webc; make dist
	@cd /; echo "You are probably in the wrong directory."
	@cd /; echo "Type:"
	@cd /; echo "    cd ../Webc"

# This is used in *lots* of places
# Now most places get updates from ao.com
update:	all distribution tar
	# Distribute on deanna.peak.org
	@echo "cd /info/vh/cornvalley/Webc"	> /tmp/publish
	@echo "del webc.tar.gz"			>>/tmp/publish
	@echo "put webc.tar.gz"			>>/tmp/publish
	@echo "del webcpkg.tar.gz"		>>/tmp/publish
	@echo "put webcpkg.tar.gz"		>>/tmp/publish
	@ncftp kira.peak.org			< /tmp/publish
	@rm -f /tmp/publish
	@echo "Now log onto deanna.peak.org and type:"
	@echo "    cd /info/vh/cornvalley"
	@echo "    find Webc -type f -exec chmod +w {} \;"
	@echo "    find Webc -type l -exec rm {} \;"
	@echo "    tar xpfz Webc/webc.tar.gz"
	@echo "    cd Webc"
	@echo "    make clean all tar"

	# This should probably get put into /usr/local/bin on kira and troi,
	# and possibly on some of the IQ machines.
