#
# Set the variables on the next few lines of this makefile according
# to the directions in the file "INSTALL".  Then `make' to build the
# scripts, `make install' to copy scripts to IDVIBIN and libraries
# to IDVILIB, `make installwww' to copy class files to IDVIWWWDIR/classes,
# and `make installwwwfonts' to copy all of your pk font files to 
# IDVIWWWDIR/pk.  Read the section "DECIDE WHAT TO DO ABOUT FONTS"
# in the file "INSTALL" if you do not want to copy all of your pk
# font files onto your web server.
#

FONTSOURCE=/usr/local/lib/tex/pk
DPI=300
IDVILIB=/usr/local/lib/idvi
IDVIBIN=/usr/local/bin
IDVIWWW=http://my.server/lib/idvi
IDVIWWWDIR=/usr/www/idvi
NETSCAPE=netscape
JAVA=${NETSCAPE} -java
DEFAULTS=

############################################################################
#                                                                          #
# You should not need to change anything below this line.                  #
#                                                                          #
############################################################################

FONTLINKS=${IDVILIB}/pk

CODEBASE=${IDVIWWW}/classes/
ARCHIVE=viewerclasses.zip
CODEBASEDIR=${IDVIWWWDIR}/classes
FONTBASE=${IDVIWWW}/pk/
FONTBASEDIR=${IDVIWWWDIR}/pk

TESTWWW=${IDVIWWW}/test/
TESTWWWDIR=${IDVIWWWDIR}/test

LIBFILES=images.prefix fonts.prefix psheader.ps idviclasses.zip jdkclasses.zip copyfont template.html

all : idvi copyfont

install : installbin installlib installfonts
uninstall : uninstallbin uninstalllib
#uninstallfonts is defined below

installwww : installwwwclasses installwwwfontdir
uninstallwww : uninstallwwwclasses
#uninstallwwwfonts is defined below

clean :
	rm -f idvi copyfont
	rm -rf testdir testepsfdir ${TESTWWWDIR}

idvi : idvi.dist Makefile
	@ \
	echo 'Creating script "idvi" from "idvi.dist"'; \
	{ \
		echo '#!/bin/sh'; \
		echo; \
		echo 'FONTSOURCE="${FONTLINKS}"'; \
		echo 'DPI="${DPI}"'; \
		echo 'FONTBASE="${FONTBASE}"'; \
		echo 'CODEBASE="${CODEBASE}"'; \
		echo 'ARCHIVE="${ARCHIVE}"'; \
		echo 'IDVILIB="${IDVILIB}"'; \
		echo 'DEFAULTS="${DEFAULTS}"'; \
		echo 'JAVA="${JAVA}"'; \
		echo; \
		cat idvi.dist; \
	} > idvi

copyfont : copyfont.dist Makefile
	@ \
	echo 'Creating script "copyfont" from "copyfont.dist"'; \
	{ \
		echo '#!/bin/sh'; \
		echo; \
		echo 'FONTSOURCE="${FONTLINKS}"'; \
		echo 'FONTBASE="${FONTBASE}"'; \
		echo; \
		cat copyfont.dist; \
	} > copyfont

installbin : idvi
	@if [ ! -d ${IDVIBIN} ]; then \
		echo 'Creating directory "'${IDVIBIN}'"'; \
		mkdir ${IDVIBIN}; \
		chmod 755 ${IDVIBIN}; \
	fi
	@echo 'Copying scripts "idvi" and "idvi.local" to directory "${IDVIBIN}"'
	@cp idvi ${IDVIBIN}
	@rm -f ${IDVIBIN}/idvi.local
	@ln ${IDVIBIN}/idvi ${IDVIBIN}/idvi.local
	@chmod 755 ${IDVIBIN}/idvi ${IDVIBIN}/idvi.local;

uninstallbin :
	@echo 'Deleting scripts "idvi" and "idvi.local" from directory "${IDVIBIN}"'
	@rm -f ${IDVIBIN}/idvi ${IDVIBIN}/idvi.local

installlib : copyfont
	@if [ ! -d ${IDVILIB} ]; then \
		echo 'Creating directory "'${IDVILIB}'"'; \
		mkdir ${IDVILIB}; \
		chmod 755 ${IDVILIB}; \
	fi
	@echo 'Copying script "copyfont" and other files to directory "${IDVILIB}"'
	@cp images.prefix fonts.prefix psheader.ps idviclasses.zip jdkclasses.zip copyfont template.html ${IDVILIB}
	@chmod 744 ${IDVILIB}/images.prefix ${IDVILIB}/fonts.prefix ${IDVILIB}/psheader.ps ${IDVILIB}/idviclasses.zip ${IDVILIB}/jdkclasses.zip ${IDVILIB}/template.html
	@chmod 755 ${IDVILIB}/copyfont

uninstalllib :
	@echo 'Deleting script "copyfont" and other IDVI files from directory "${IDVILIB}"'
	@rm -f ${IDVILIB}/images.prefix ${IDVILIB}/fonts.prefix ${IDVILIB}/psheader.ps ${IDVILIB}/idviclasses.zip ${IDVILIB}/jdkclasses.zip ${IDVILIB}/copyfont ${IDVILIB}/template.html

installfonts:
	@if [ ! -d ${IDVILIB} ]; then \
		echo 'Creating directory "'${IDVILIB}'"'; \
		mkdir ${IDVILIB}; \
		chmod 755 ${IDVILIB}; \
	fi
	@linkfonts( ) { \
		echo 'Creating links to pk font files in directory "'$$1'"'; \
		if [ "`echo *`" != "*" ]; then \
			for name in *; do \
				if [ -d $$name ]; then \
					( cd $$name; linkfonts $$1/$$name ); \
				else \
					ln -s $$1/$$name ${FONTLINKS}/$$name; \
				fi; \
			done; \
		fi; \
	}; \
	if [ ! \( -h ${FONTLINKS} -o -d ${FONTLINKS} \) ]; then \
		cd ${FONTSOURCE}; \
		if [ "`echo */.`" = "*/." ]; then \
			echo 'Creating link to pk font directory "'${FONTSOURCE}'"'; \
			ln -s ${FONTSOURCE} ${FONTLINKS}; \
		else \
			mkdir ${FONTLINKS}; \
			chmod 755 ${FONTLINKS}; \
			linkfonts ${FONTSOURCE}; \
		fi; \
	fi

uninstallfonts:
	@echo 'Deleting directory "'${IDVILIB}'/pk"'
	@rm -rf ${IDVILIB}/pk

installwwwclasses:
	@if [ ! -d ${IDVIWWWDIR} ]; then \
		echo 'Creating directory "'${IDVIWWWDIR}'"'; \
		mkdir ${IDVIWWWDIR}; \
		chmod 755 ${IDVIWWWDIR}; \
	fi
	@if [ ! -d ${CODEBASEDIR} ]; then \
		echo 'Creating directory "'${CODEBASEDIR}'"'; \
		mkdir ${CODEBASEDIR}; \
		chmod 755 ${CODEBASEDIR}; \
	fi
	@echo 'Extracting class files into directory "'${CODEBASEDIR}'"'
	@cp viewerclasses.zip ${CODEBASEDIR}
	@cd ${CODEBASEDIR}; umask 022; unzip viewerclasses.zip

uninstallwwwclasses:
	@echo 'Deleting directory "${CODEBASEDIR}"'
	@rm -rf ${CODEBASEDIR}

installwwwfontdir:
	@if [ ! -d ${IDVIWWWDIR} ]; then \
		echo 'Creating directory "'${IDVIWWWDIR}'"'; \
		mkdir ${IDVIWWWDIR}; \
		chmod 755 ${IDVIWWWDIR}; \
	fi
	@if [ ! -d ${FONTBASEDIR} ]; then \
		echo 'Creating directory "'${FONTBASEDIR}'"'; \
		mkdir ${FONTBASEDIR}; \
		chmod 755 ${FONTBASEDIR}; \
	fi

installwwwfonts:
	@if [ ! -d ${IDVIWWWDIR} ]; then \
		echo 'Creating directory "'${IDVIWWWDIR}'"'; \
		mkdir ${IDVIWWWDIR}; \
		chmod 755 ${IDVIWWWDIR}; \
	fi
	@if [ ! -d ${FONTBASEDIR} ]; then \
		echo 'Creating directory "'${FONTBASEDIR}'"'; \
		mkdir ${FONTBASEDIR}; \
		chmod 755 ${FONTBASEDIR}; \
	fi
	@echo 'Copying pk font files to directory "'${FONTBASEDIR}'"'
	@cd ${FONTLINKS}; \
	umask 022; \
	cp * ${FONTBASEDIR}

uninstallwwwfonts:
	@echo 'Deleting directory "${FONTBASEDIR}";
	@rm -rf ${FONTBASEDIR}

test :
	@if [ ! -d testdir ]; then \
		echo 'Creating directory "testdir"'; \
		mkdir testdir; \
	fi
	cp test.dvi testsource.html testdir;
	cd testdir; \
	${IDVIBIN}/idvi.local -title "IDVI Local Test" -index index.html test.dvi
	@echo 'Starting Netscape to view test output.  Quit Netscape after verifying output.'
	CLASSPATH=${IDVILIB}/idviclasses.zip ${NETSCAPE} file:`pwd`/testdir/index.html

testwww :
	@if [ ! -d ${TESTWWWDIR} ]; then \
		echo 'Creating directory "'${TESTWWWDIR}'"'; \
		mkdir ${TESTWWWDIR}; \
		chmod 755 ${TESTWWWDIR}; \
	fi
	@SOURCE=`pwd`; \
	echo cd ${TESTWWWDIR}; \
	cd ${TESTWWWDIR}; \
	umask 022; \
	cp $$SOURCE/test.dvi .; \
	cp $$SOURCE/testsource.html .; \
	${IDVIBIN}/idvi -title "IDVI Test" -index index.html test.dvi
	@echo 'Starting Netscape to view testwww output.'
	${NETSCAPE} ${TESTWWW}index.html

testepsf :
	@if [ ! -d testepsfdir ]; then \
		echo 'Creating directory "'${TESTWWWDIR}'"'; \
		mkdir testepsfdir; \
	fi
	cp testepsf.dvi testepsfsource.html octahedron.eps testepsfdir
	cd testepsfdir; \
	${IDVIBIN}/idvi.local -title "IDVI Local Test With Postscript" -index index.html testepsf.dvi
	@echo 'Starting Netscape to view testepsf output.  Quit Netscape after verifying output.'
	CLASSPATH=${IDVILIB}/idviclasses.zip ${NETSCAPE} file:`pwd`/testepsfdir/index.html
