# Makefile for B.G.Kolker's Lernolibro XSL transformations
# Mati Pentus, 2000 June 10, 2003 October 24
# Use under 32-bit MS-Windows with make (from UnxUtils.zip).

# Requires: make, xt, perl, emtex, XML::Parser::Expat, oconv
# Some tasks require: zip, Mati::ForFiles
# Viewer tasks require: HTML browser
# The file cp866.enc must be in ...perl/site/lib/XML/Parser/Encodings/.

# Usage
#       make all

# Names of temporary files are prefixed by '0'.
# Transliteration HTML generation requires further conversions
# (not defined here).

default: index.html

version=342

# generate all (except .doc)

all: ll$(version)source.zip \
	ll$(version)txt.zip ll$(version)htm.zip ll$(version)tex.zip \
	ll$(version)ps.zip ll$(version)wx.zip ll$(version)wh.zip \
	0simple.htm


# backup source

SOURCE=ll$(version).xml ll2htm.xsl ll2htmx.xsl llhtmhf.xsl ll2ind.xsl \
	ll2doc.xsl \
	ll2tex.dos ll.sty myeo.sty \
	ll2txt.xsl ll2mtxt.xsl \
	komphtm.xsl \
	Makefile x2utf.pl x2tex.pl doc/Makefile \
	cp866.enc rm.bat
ll$(version)source.zip: $(SOURCE)
	zip -9 ll$(version)source.zip $(SOURCE)


# Unicode HTML

0utf.xml: x2utf.pl ll$(version).xml
	perl x2utf.pl ll$(version).xml 0utf.xml

0llind.xml: 0utf.xml ll2ind.xsl
	rm $@
	xt 0utf.xml ll2ind.xsl $@

index.html: 0utf.xml ll2htm.xsl llhtmhf.xsl 0llind.xml
	rm index.html
	xt 0utf.xml ll2htm.xsl

ll$(version)htm.zip: index.html
	rm ll$(version)htm.zip
	zip -9 ll$(version)htm.zip *.html


# Word doc

0simple.htm: 0utf.xml ll2doc.xsl
	rm 0simple.htm
	xt 0utf.xml ll2doc.xsl 0simple.htm
# Another Makefile in a subdirectory creates ll$(version)doc.zip
# from 0simple.htm.


# tex, dvi, PostScript

0utfx.xml: ll$(version).xml
	oconv xmldos2utf ll$(version).xml 0utfx.xml

ll2tex.xsl: ll2tex.dos
	oconv dos2utf ll2tex.dos ll2tex.xsl

0utf.tex: 0utfx.xml ll2tex.xsl
	rm 0utf.tex
	xt 0utfx.xml ll2tex.xsl 0utf.tex

0x.tex: 0utf.tex
	oconv utf2dos 0utf.tex 0x.tex

ll$(version).tex: 0x.tex x2tex.pl
	perl -p x2tex.pl 0x.tex >ll$(version).tex

ll$(version)tex.zip: ll$(version).tex ll.sty myeo.sty
	rm ll$(version)tex.zip
	zip -9 ll$(version)tex.zip ll$(version).tex ll.sty myeo.sty

ll$(version).dvi: ll$(version).tex ll.sty myeo.sty
	rlatex ll$(version).tex
	rm ll.idx
	perl -pe"s/\|/{}/g;s/!f/!e{}/g;" ll$(version).idx >ll.idx
	rind ll
	rlatex ll$(version).tex
	ren LL$(version).DVI ll$(version).dvi

viewdvi: ll$(version).dvi
	vv ll$(version).dvi

ll$(version).ps: ll$(version).dvi
	dvips32 ll$(version).dvi
	ren LL$(version).PS ll$(version).ps

viewps: ll$(version).ps
	start ll$(version).ps

ll$(version)ps.zip: ll$(version).ps
	rm ll$(version)ps.zip
	zip -9 ll$(version)ps.zip ll$(version).ps


# plain text (single file)

0utf.txt: 0utfx.xml ll2txt.xsl
	rm 0utf.txt
	xt 0utfx.xml ll2txt.xsl 0utf.txt

ll$(version).txt: 0utf.txt
	oconv utf2dos 0utf.txt ll$(version).txt
	perl -pibak -e1 ll$(version).txt
	rm ll$(version).txtbak

ll$(version)win.txt: ll$(version).txt
	oconv dos2win ll$(version).txt ll$(version)win.txt

ll$(version)txt.zip: ll$(version)win.txt
	rm ll$(version)txt.zip
	zip -9 ll$(version)txt.zip ll$(version)win.txt


# plain text (multiple files) x

slovar.txt: 0utfx.xml ll2mtxt.xsl
	rm slovar.txt
	xt 0utfx.xml ll2mtxt.xsl

winx/slovar.txt: slovar.txt
	rm winx\*.txt
	mkdir winx
	xcopy /y predisl.txt winx
	xcopy /y urok*.txt winx
	xcopy /y otvety.txt winx
	xcopy /y slovar.txt winx
	perl -mMati::ForFiles -e"package Mati;forFiles(\&utf2win,1)" -- -d winx

ll$(version)wx.zip: winx/slovar.txt
	rm ll$(version)wx.zip
	zip -9 ll$(version)wx.zip winx/*.txt
#       cd winx
#       zip -9 ../ll$(version)wx.zip *.txt
#       cd ..


# plain text (multiple files) h

winh/slovar.txt: slovar.txt
	rm winh\\*.txt
	mkdir winh
	xcopy /y winx\\*.txt winh
	perl -mMati::ForFiles -e"package Mati;forFiles(\&ikso2ho,1)" -- -d winh

ll$(version)wh.zip: winh/slovar.txt
	rm ll$(version)wh.zip
	zip -9 ll$(version)wh.zip winh/*.txt
#       cd winh
#       zip -9 ../ll$(version)wh.zip *.txt
#       cd ..


# cp1251 HTML

winhtml/index.html: index.html
	rm winhtml\index.html
	mkdir winhtml
	xcopy /y *.html winhtml
	perl -mMati::ForFiles -e"package Mati;forFiles(\&htmlunicode2winx,1)" -- -d winhtml

viewwinhtml: winhtml/index.html
	start winhtml/index.html


# Esperanto-transliteration HTML

translit/index.html: 0utf.xml ll2htmx.xsl ll2htm.xsl llhtmhf.xsl
	rm translit\index.html
	mkdir translit
	xt 0utf.xml ll2htmx.xsl
# Here by hand: convert contents of translit/ from unicode to x-format


# for debugging (cyrillic letters replaced by question marks)

0fast.xml: ll$(version).xml
	perl -pe"s/[\x80-\xff]/?/g;s/encoding=.*\?/?/;" ll$(version).xml >0fast.xml

0fast.txt: 0fast.xml ll2txt.xsl
	rm 0fast.txt
	xt 0fast.xml ll2txt.xsl 0fast.txt


# Compendium

#komp.htm: 0utf.xml komphtm0.xsl
#  del $@
#  xt 0utf.xml komphtm0.xsl $@

0komp.xml: x2utf.pl komp/komp.xml
	perl x2utf.pl komp/komp.xml $@

komp.htm: 0komp.xml komphtm.xsl
	rm $@
	xt 0komp.xml komphtm.xsl $@


# small HTML zip files

llhtm: llhtm0.zip llhtm1.zip llhtm2.zip

llhtm0.zip: index.html
	rm $@
	zip -9 $@ ch0*.html

llhtm1.zip: index.html
	rm $@
	zip -9 $@ ch1*.html

llhtm2.zip: index.html
	rm $@
	zip -9 $@ ch2*.html index.html
