

# Author:
# Juhapekka Tolvanen
# http://iki.fi/juhtolv
# juhtolv (at) iki (dot) fi

#  This Makefile is public domain. There is no warranty.

BASENAME = sosl70c
DOCSBASENAME = 000LUEMUT
CM-SUPER-DIR = /usr/share/texmf/fonts/type1/public/cm-super 

help :
	@echo 'usage: make <targer>'
	@echo 'Available targets:'
	@echo ''
	@echo 'all                     : All. (Not cleaning. Purging only when necessary.)'
	@echo ''
	@echo 'html                    : Compile all html-files.'
	@echo 'tex4ht-onepage          : Compile HTML in one page.'
	@echo 'tex4ht-splitpageone     : Compile split HTML (level 1).'
	@echo 'tex4ht-splitpagetwo     : Compile split HTML (level 2).'
	@echo ''
	@echo 'dvi                     : Compile all DVI-files.'
	@echo ''
	@echo 'postscript              : Compile all PostScript-files (Makes DVI-file, too.).'
	@echo ''
	@echo "pdf                     : Compile all PDF-files (except $(DOCSBASENAME).pdf)."
	@echo 'pdf-print               : Compile all PDF-files for print. (Makes DVI- and PostScript-files, too).'
	@echo 'pdf-screen              : Compile all PDF-files for screen.'
	@echo ''
	@echo 'swf                     : Compile Macromedia... Umm... Err... Adobe Flash -file.'
	@echo ''
	@echo 'hnb                     : Convert outline of hnb (http://hnb.sf.net/) to other formats.'
	@echo "docs                    : Convert documentationfile $(DOCSBASENAME).txt to other formats."
	@echo ''
	@echo 'purge-dvi               : Remove auxiliary-files of DVIs.'
	@echo 'clean-dvi               : Remove all DVIs and their auxiliary files.'
	@echo 'clean-ps                : Remove all PostScript-files. (Do not remove DVI-files or their auxiliary files).'
	@echo 'purge-screen-pdf        : Remove auxiliary files made during screen-pdf.'
	@echo 'clean-screen-pdf        : Remove PDF-file for screen and all its auxiliary files.'
	@echo 'purge-print-pdf         : Remove auxiliary files made during print-pdf.'
	@echo 'clean-print-pdf         : Remove PDF-file for screen and all its auxiliary files. (Do not remove PostScript- or DVI-files).'
	@echo 'clean-all-pdf           : Remove all pdf-files and their auxiliary files (Do not remove PostScript- or DVI-files).'
	@echo 'clean-swf               : Remove Macromedia Flash -files.'
	@echo 'purge-html              : Remove all auxiliary files of HTML'
	@echo 'clean-html-onepage      : Remove one-page-HTML and all auxiliary files.'
	@echo 'clean-html-splitpageone : Remove split-page-HTML (Level 1) and their auxiliary files.'
	@echo 'clean-html-splitpagetwo : Remove split-page-HTML (Level 2) and their auxiliary files.' 
	@echo 'clean-html              : Remove HTML-files and all their auxiliary files.'
	@echo 'purge hnb               : Remove all converted files of hnb.'
	@echo "purge-docs              : Remove auxiliary-files of documentationfile $(DOCSBASENAME).txt ."
	@echo "clean-docs              : Remove all PDF and HTML-files converted from documentationfile $(DOCSBASENAME).txt ."
	@echo ''
	@echo 'purge-emacs             : Remove backups of emacsen'
	@echo 'purge                   : Remove all auxiliary files and other such crap and backups of emacsen.'
	@echo 'clean                   : Remove both auxiliary files and final viewable and printable files.'

#all : clean pdf postscript html swf hnb docs
#all : clean postscript pdf html hnb docs
all : clean postscript pdf hnb docs


# For multibib:

.SUFFIXES: .aux .bbl
AUX=$(wildcard *.aux)
BBL=$(AUX:.aux=.bbl)


multibib: $(BBL)

.aux.bbl:
	- bibtex $*


# HTML

tex4ht-onepage :
	make purge-html
	htlatex $(BASENAME).tex "xhtml,uni-html" " -cunihtf -cmozhtf"
	make purge-bibtex
	- bibtex $(BASENAME)
	make multibib
	htlatex $(BASENAME).tex "xhtml,uni-html" " -cunihtf -cmozhtf"
	mv -f $(BASENAME)*.html *.css $(BASENAME)*.png html.tex4ht.dir/

tex4ht-onepage-alt :
	make purge-html
	latex -src-special -file-line-error-style $(BASENAME).tex
	make purge-bibtex
	- bibtex $(BASENAME)
	make multibib
	htlatex $(BASENAME).tex "xhtml,uni-html" " -cunihtf -cmozhtf"
	mv -f $(BASENAME)*.html *.css $(BASENAME)*.png html.tex4ht.dir/

# This does not work for me:
tex4ht-splitpageone :
	make purge-html
	htlatex $(BASENAME).tex "xhtml,uni-html,1" " -cunihtf -cmozhtf"
	make purge-bibtex
	- bibtex $(BASENAME)
	make multibib
	htlatex $(BASENAME).tex "xhtml,uni-html,1" " -cunihtf -cmozhtf"
	mv -f $(BASENAME)*.html *.css $(BASENAME)*.png html.tex4ht.split1.dir/

# This does not work for me:
tex4ht-splitpageone-alt :
	make purge-html
	latex -src-special -file-line-error-style $(BASENAME).tex
	make purge-bibtex
	- bibtex $(BASENAME)
	make multibib
	mk4ht xhlatex $(BASENAME).tex "xhtml,uni-html4,1" " -cunihtf -cmozhtf"
	mv -f $(BASENAME)*.html *.css $(BASENAME)*.png html.tex4ht.split1.dir/


# This does not work for me:
tex4ht-splitpagetwo :
	make purge-html
	mk4ht xhlatex $(BASENAME).tex "xhtml,uni-html4,2" " -cunihtf -cmozhtf"
	make purge-bibtex
	- bibtex $(BASENAME)
	make multibib
	mk4ht xhlatex $(BASENAME).tex "xhtml,uni-html4,2" " -cunihtf -cmozhtf"
	mv -f $(BASENAME)*.html *.css $(BASENAME)*.png html.tex4ht.split2.dir/

# This does not work for me:
tex4ht-splitpagetwo-alt :
	make purge-html
	latex -src-special -file-line-error-style $(BASENAME).tex
	make purge-bibtex
	- bibtex $(BASENAME)
	make multibib
	mk4ht xhlatex $(BASENAME).tex "xhtml,uni-html4,2" " -cunihtf -cmozhtf"
	mv -f $(BASENAME)*.html *.css $(BASENAME)*.png html.tex4ht.split2.dir/


# This does not work for me:
tex4ht-splitpagethree :
	make purge-html
	mk4ht xhlatex $(BASENAME).tex "xhtml,uni-html4,3" " -cunihtf -cmozhtf"
	make purge-bibtex
	- bibtex $(BASENAME)
	make multibib
	mk4ht xhlatex $(BASENAME).tex "xhtml,uni-html4,3" " -cunihtf -cmozhtf"
	mv -f $(BASENAME)*.html *.css $(BASENAME)*.png html.tex4ht.split3.dir/

#html : tex4ht-onepage tex4ht-splitpageone tex4ht-splitpagetwo tex4ht-splitpagethree
#html : tex4ht-onepage tex4ht-splitpageone tex4ht-splitpagetwo
html : tex4ht-onepage


# Docbook: 
tex4ht-docbook :
	make purge-html
	mk4ht dblatex $(BASENAME).tex
	make purge-bibtex
	- bibtex $(BASENAME)
	make multibib
	mk4ht dblatex $(BASENAME).tex
	mv -f $(BASENAME)*.xml html.tex4ht.docbook.dir/


# OpenOffice.org (Buggy!):
tex4ht-ooo :
	make purge-html
	mk4ht oolatex $(BASENAME).tex "xhtml,ooffice" " -cmozhtf" "-coo"
	make purge-bibtex
	- bibtex $(BASENAME)
	make multibib
	mk4ht oolatex $(BASENAME).tex "xhtml,ooffice" " -cmozhtf" "-coo"
	mv -f $(BASENAME)*.odt html.tex4ht.ooo.dir/

# MS Word -compatible HTML
tex4ht-msword :
	make purge-html
	mk4ht htlatex $(BASENAME).tex "html,word" "symbol/!" "-cvalidate"
	make purge-bibtex
	- bibtex $(BASENAME)
	make multibib
	mk4ht htlatex $(BASENAME).tex "html,word" "symbol/!" "-cvalidate"
	mv -f $(BASENAME)*.html  $(BASENAME).html *.css $(BASENAME)*.png html.tex4ht.msword.dir/

# DVI, PS and PDF

dvi : purge-dvi
	latex -src-special -file-line-error-style $(BASENAME).tex
	make purge-bibtex
	- bibtex $(BASENAME)
	make multibib
	latex -src-specials -file-line-error-style $(BASENAME).tex
	while grep 'Rerun to get' $(BASENAME).log > /dev/null; do latex -src-specials -file-line-error-style $(BASENAME).tex ; done
	latex -src-specials -file-line-error-style $(BASENAME).tex
	cp -f mv12ptlapinakyva.eps dvi/mv12ptlapinakyva.eps
	mv -f $(BASENAME).dvi dvi/$(BASENAME).dvi

# Uses recorder-option of tex. Files read by LaTeX-sourcefile have extension ".fls" by default.
dvi-recorder : purge-dvi
	latex -src-special -file-line-error-style -recorder $(BASENAME).tex
	make purge-bibtex
	- bibtex $(BASENAME)
	make multibib
	latex -src-specials -file-line-error-style -recorder $(BASENAME).tex
	while grep 'Rerun to get' $(BASENAME).log > /dev/null; do latex -src-specials -file-line-error-style -recorder $(BASENAME).tex ; done
	latex -src-specials -file-line-error-style -recorder $(BASENAME).tex
	cp -f mv12ptlapinakyva.eps dvi/mv12ptlapinakyva.eps
	mv -f $(BASENAME).dvi dvi/$(BASENAME).dvi

postscript : dvi
	cp -f dvi/$(BASENAME).dvi ./$(BASENAME).dvi
	dvips -z -Ppdf -Pwww -Pcmz -Pamz -Poutline -Pcm-super -Phfbright -G0 -j0 -f -t a4 -Z -o $(BASENAME).ps $(BASENAME).dvi
	mv -f $(BASENAME).ps ps/
	rm -f $(BASENAME).dvi

pdf-screen :
	make purge-dvi
	pdflatex -src-specials -file-line-error-style $(BASENAME).tex
	make purge-bibtex
	- bibtex $(BASENAME)
	make multibib
	pdflatex -src-specials -file-line-error-style  $(BASENAME).tex
	while grep 'Rerun to get' $(BASENAME).log > /dev/null; do pdflatex -src-specials -file-line-error-style $(BASENAME).tex ; done
	pdflatex -src-specials -file-line-error-style $(BASENAME).tex
	mv -f $(BASENAME).pdf pdf/$(BASENAME).screen.pdf

pdf-print : postscript
	cp -f ps/$(BASENAME).ps ./
	ps2pdf14 -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true $(BASENAME).ps
	mv -f $(BASENAME).pdf pdf/$(BASENAME).print.pdf
	rm -f $(BASENAME).ps

pdf : pdf-print pdf-screen

# pdf2swf is right now missing
swf : pdf-screen
	cp -f pdf/$(BASENAME).screen.pdf ./
	pdf2swf -f -F $(CM-SUPER-DIR) -t $(BASENAME).screen.pdf
	mv -f ./$(BASENAME).screen.swf ./swf/
	rm -f $(BASENAME).screen.pdf

hnb : purge-hnb
	cd hnb ; hnb gradu.hnb -e 'go root' 'export_opml gradu.opml' 'export_html gradu.html' 'export_ascii gradu.txt' 'export_htmlcss gradu.css.html' ; cd ..


docs : purge-docs
	rst2latex --language=fi --report=5 --toc-entry-backlinks --section-numbering --strip-comments --stylesheet=RST --graphicx-option=pdftex --font-encoding=T1 --use-verbatim-when-possible $(DOCSBASENAME).txt $(DOCSBASENAME).tex
	pdflatex -src-specials -file-line-error-style $(DOCSBASENAME).tex
	while grep 'Rerun to get' $(DOCSBASENAME).log > /dev/null ; do pdflatex -src-specials -file-line-error-style $(DOCSBASENAME).tex ; done
	pdflatex -src-specials -file-line-error-style $(DOCSBASENAME).tex
	rst2html --language=fi --report=5 --toc-entry-backlinks --footnote-backlinks --section-numbering --strip-comments  $(DOCSBASENAME).txt $(DOCSBASENAME).html


# purge and clean

purge-dvi :
	rm -vf $(BASENAME).dvi $(BASENAME).aux $(BASENAME).bbl $(BASENAME).blg $(BASENAME).log $(BASENAME).toc $(BASENAME).lot
	rm -vf *.aux *.bbl *.blg *.brf *.tmp *.log *.toc *.lot *.out

clean-dvi : purge-dvi
	rm -vf dvi/$(BASENAME).dvi
	rm -vf dvi/mv12ptlapinakyva.eps

clean-ps :
	rm -vf ps/$(BASENAME).ps

purge-screen-pdf :
	rm -vf *.aux *.bbl *.blg *.brf *.tmp *.log *.toc *.lot *.out

clean-screen-pdf : purge-screen-pdf
	rm -vf pdf/$(BASENAME).screen.pdf $(BASENAME).screen.pdf

purge-print-pdf :
	rm -vf *.aux *.bbl *.blg *.brf *.tmp *.log *.toc *.lot *.out

clean-print-pdf : purge-print-pdf
	rm -vf pdf/$(BASENAME).print.pdf $(BASENAME).print.pdf

clean-all-pdf : clean-screen-pdf clean-print-pdf

clean-swf :
	rm -vf ./swf/$(BASENAME).screen.swf

purge-html : purge-dvi
	rm -vf $(BASENAME).idv $(BASENAME).lg $(BASENAME).tmp $(BASENAME).xref $(BASENAME).4ct $(BASENAME).4tc $(BASENAME).html $(BASENAME)*.html $(BASENAME)*.css *.4og $(BASENAME).tmp

clean-html-onepage : purge-html
	rm -vf html.tex4ht.dir/*

clean-html-splitpageone : purge-html
	rm -vf html.tex4ht.split1.dir/*

clean-html-splitpagetwo : purge-html
	rm -vf html.tex4ht.split2.dir/*

clean-html-splitpagethree : purge-html
	rm -vf html.tex4ht.split3.dir/*

clean-html : clean-html-onepage clean-html-splitpageone clean-html-splitpagetwo clean-html-splitpagethree

purge-docs :
	rm -vf $(DOCSBASENAME).aux $(DOCSBASENAME).bbl $(DOCSBASENAME).blg $(DOCSBASENAME).brf $(DOCSBASENAME).tmp $(DOCSBASENAME).log $(DOCSBASENAME).toc $(DOCSBASENAME).lot $(DOCSBASENAME).out

clean-docs : purge-docs
	rm -vf $(DOCSBASENAME).tex $(DOCSBASENAME).html $(DOCSBASENAME).pdf

purge-hnb :
	cd hnb ; rm -vf gradu.opml gradu.html gradu.css.html gradu.txt ; cd ..

purge-emacs :
	rm -vf *~

purge-bibtex :
	rm -vf *.bbl *.blg

purge : purge-dvi purge-screen-pdf purge-print-pdf purge-html purge-emacs purge-docs purge-bibtex

clean : clean-dvi clean-ps clean-all-pdf clean-swf clean-html purge-hnb purge-emacs purge-bibtex clean-docs
