## -*- coding: utf-8 -*-
USER=	beyert
HOST=	shell.berlios.de
REMOTE_PATH=	/home/groups/joytran/htdocs/documentation
STYLESHEETS=	tex2page
FONTS=
LATEX_FILE=	manual
PDF_FILE=	manual
PDF_PATH=	pdf
HTML_PATH=	html
HTML_FILES=	manual.html manual-Z-H-1.html manual-Z-H-2.html \
	manual-Z-H-3.html manual-Z-H-4.html manual-Z-S.css
IMAGE_FORMAT=	jpg
IMAGE_FILES=	0203121918-diagram

## Needed to ensure that there are no additional lossy artifacts in the dvipdf
## backend.. (relative to pdflatex)
DVIPDF_OPTIONS=	-sPAPERSIZE=letter \
	-dMaxSubsetPct=100 -dCompatibilityLevel=1.3 \
	-dSubsetFonts=true -dEmbedAllFonts=true \
	-dAutoFilterColorImages=false \
	-dAutoFilterGrayImages=false \
	-dColorImageFilter=/FlateEncode \
	-dGrayImageFilter=/FlateEncode \
	-dMonoImageFilter=/FlateEncode \
	-dUseFlateCompression=true

all:	html pdf

html:	tex2page

pdf:	xelatex

convert-images:
.for image in ${IMAGE_FILES}
.if !exists(${image}.eps)
	@echo "converting file ${image}.${IMAGE_FORMAT} to ${image}.eps"
	convert -compress zip ${image}.${IMAGE_FORMAT} eps2:${image}.eps
.else
	@echo "file ${image}.eps already exists"
.endif
.endfor

clean-local-html:
	rm -f ${HTML_FILES} manual-Z-G-1.gif rm manual-Z-G-1.ps manual-Z-G-1.tex \
	manual-Z-G-2.tex *.hlog manual-Z-A.scm

clean-local-pdf:
	rm -f *.log *.dvi *.aux *.tmp *.out *.toc

clean-local:	clean-local-html clean-local-pdf

clean-html:	clean-local-html
	rm -rf ${HTML_PATH}

clean-pdf:	clean-local-pdf
	rm -rf ${PDF_PATH}
	rm -f *.log *.dvi *.aux *.tmp ${LATEX_FILE}.pdf

clean:	clean-html clean-pdf

latex:	convert-images
	mkdir -p ${PDF_PATH}
	cp -p ${IMAGE_FILES:=.eps} ${PDF_PATH}
	cp -p ${LATEX_FILE}.tex pdf/${LATEX_FILE}.tex
	cd ${PDF_PATH} && latex ${LATEX_FILE}.tex

dvipdf:	latex
	cd ${PDF_PATH} && dvipdf ${DVIPDF_OPTIONS} ${LATEX_FILE}.dvi

pdflatex:
	mkdir -p ${PDF_PATH}
	cp -p ${IMAGE_FILES:=.jpg} ${PDF_PATH}
	cp -p ${LATEX_FILE}.tex ${PDF_PATH}/${LATEX_FILE}.tex
	cd pdf && pdflatex ${LATEX_FILE}.tex

xelatex:
	mkdir -p ${PDF_PATH}
	cp -p ${IMAGE_FILES:=.jpg} ${PDF_PATH}
	cp -p ${LATEX_FILE}.tex ${PDF_PATH}/${LATEX_FILE}.tex
	cd pdf && xelatex ${LATEX_FILE}.tex

tex2page:
	mkdir -p ${HTML_PATH}
.if !empty(STYLESHEETS)
	cp -p ${STYLESHEETS:=.css} ${HTML_PATH}
.endif
.if !empty(FONTS)
	cp -pR ${FONTS} ${HTML_PATH}
.endif
	cp -p ${LATEX_FILE}.tex ${HTML_PATH}/${LATEX_FILE}.tex
	cd ${HTML_PATH} && tex2page ${LATEX_FILE}

upload-html:
	scp -p ${HTML_FILES:C/manual/${HTML_PATH}\/manual/g} \
	${STYLESHEETS:=.css} \
	${USER}@${HOST}:${REMOTE_PATH}/

upload-pdf:
	scp -p ${PDF_PATH}/${PDF_FILE}.pdf \
	${USER}@${HOST}:${REMOTE_PATH}/${PDF_FILE}.pdf

upload-images:
	scp -p ${IMAGE_FILES:=.jpg} ${USER}@${HOST}:${REMOTE_PATH}/

upload-documentation:	upload-html upload-pdf

upload-all:	upload-documentation upload-images
