#    Copyright (C) 2001,2002 Anton Kirilov Zinoviev

#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.

#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.

#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#    My e-mail is zinoviev@debian.org

# We need to overwrite the standard texmf.cnf in order to generate
#    hugelatex.fmt
TEXMFCNF=.:/etc/texmf
export TEXMFCNF

SHELL = /bin/sh

GSFONTS = /usr/share/fonts/type1/gsfonts

CYRFINST = /usr/share/texmf/source/latex/t2/cyrfinst

TEXFACES = ftm fhv fcr fag fbk fnc fpl fta fsj fzc
TEXENCS = OT1 T1 TS1 T2A T2B T2C

#################################################################

all:	plvplfd tfmvf cyrfonts.map

cyrfonts.map:	cyrfonts-map.m4
	m4 cyrfonts-map.m4 >cyrfonts.map

.PHONY: clean
clean:
	-rm -f latex_mtx latex_fonts copyafms tfmvf
	-rm -f $(finst_myfiles)
	-rm -f makefonts.tex cyrfonts.map
	-rm -f $(face_enc_tex) $(face_mtx_tex)
	-rm -f *.etx *.mtx fnstcorr.tex cyralias.tex
	-rm -f *.afm *.pl *.tfm *.mtx *.fd *.vpl *.vf *.log
	-rm -f *~
	-rm -f hugelatex.fmt hugelatex.log hugelatex.aux texsys.aux

hugelatex.fmt:
	initex '\input hugelatex.ini \dump'

face_mtx_tex = $(TEXFACES:%=%-mtx.tex)

$(face_mtx_tex) : face = $(@:%-mtx.tex=%)
$(face_mtx_tex) : makemtx.perl
	perl makemtx.perl $(face) 6w >$@

face_enc_tex = $(foreach enc, $(TEXENCS), $(addsuffix -$(enc).tex, $(TEXFACES)))

$(face_enc_tex) : face_enc = $(subst -,/,$(@:%.tex=%))
$(face_enc_tex) : face = $(subst /,,$(dir $(face_enc)))
$(face_enc_tex) : enc = $(notdir $(face_enc))
$(face_enc_tex): makefonts.perl latex_mtx
	perl makefonts.perl $(face) $(enc) >$@

latex_mtx: copyall $(face_mtx_tex)
	set -e && for i in $(face_mtx_tex); do\
		latex $$i; \
	done
	touch latex_mtx

latex_fonts: copyall latex_mtx hugelatex.fmt $(face_enc_tex)
	set -e && for i in $(face_enc_tex); do\
		virtex \&hugelatex $$i; \
	done
	touch latex_fonts

cyrfinstfiles = $(wildcard \
		$(CYRFINST)/*.etx \
		$(CYRFINST)/derivatives/*.etx \
		$(CYRFINST)/cyrillic.mtx \
		$(CYRFINST)/etc/fnstcorr.tex \
		$(CYRFINST)/etc/cyralias.tex \
		../6r.etx \
		)

finst_myfiles = $(notdir $(cyrfinstfiles))

$(finst_myfiles): $(cyrfinstfiles)
	cp $(cyrfinstfiles) .

copyafms:
	cp $(GSFONTS)/s050000l.afm psyr.afm
	../shortenafm ../afm/teams.afm >ftar6w.afm
	../shortenafm ../afm/teamsb.afm >ftab6w.afm
	../shortenafm ../afm/teamsi.afm >ftaro6w.afm
	../shortenafm ../afm/teamsbi.afm >ftabo6w.afm
	../shortenafm ../afm/n019003d.afm >fhvr6w.afm
	../shortenafm ../afm/n019004d.afm >fhvb6w.afm
	../shortenafm ../afm/n019023d.afm >fhvro6w.afm
	../shortenafm ../afm/n019024d.afm >fhvbo6w.afm
	../shortenafm ../afm/n021003d.afm >ftmr6w.afm
	../shortenafm ../afm/n021004d.afm >ftmb6w.afm
	../shortenafm ../afm/n021023d.afm >ftmri6w.afm
	../shortenafm ../afm/n021024d.afm >ftmbi6w.afm
	../shortenafm ../afm/n022003d.afm >fcrr6w.afm
	../shortenafm ../afm/n022004d.afm >fcrb6w.afm
	../shortenafm ../afm/n022023d.afm >fcrro6w.afm
	../shortenafm ../afm/n022024d.afm >fcrbo6w.afm
	../shortenafm ../afm/a010013d.afm >fagr6w.afm
	../shortenafm ../afm/a010015d.afm >fagb6w.afm
	../shortenafm ../afm/a010033d.afm >fagro6w.afm
	../shortenafm ../afm/a010035d.afm >fagbo6w.afm
	../shortenafm ../afm/b018012d.afm >fbkr6w.afm
	../shortenafm ../afm/b018015d.afm >fbkb6w.afm
	../shortenafm ../afm/b018032d.afm >fbkri6w.afm
	../shortenafm ../afm/b018035d.afm >fbkbi6w.afm
	../shortenafm ../afm/c059013d.afm >fncr6w.afm
	../shortenafm ../afm/c059016d.afm >fncb6w.afm
	../shortenafm ../afm/c059033d.afm >fncri6w.afm
	../shortenafm ../afm/c059036d.afm >fncbi6w.afm
	../shortenafm ../afm/p052003d.afm >fplr6w.afm
	../shortenafm ../afm/p052004d.afm >fplb6w.afm
	../shortenafm ../afm/p052023d.afm >fplri6w.afm
	../shortenafm ../afm/p052024d.afm >fplbi6w.afm
	../shortenafm ../afm/OldSlavicRegu.afm >fsjr6w.afm
	../shortenafm ../afm/z003034d.afm >fzcri6w.afm
	touch copyafms

copyall: $(finst_myfiles) copyafms

plvplfd: latex_fonts

tfmvf:	plvplfd
	rm p*.pl p*.vpl p*.tfm p*.vf
	for f in *.vpl; do vptovf $$f; done
	for f in *.pl; do pltotf $$f; done
	touch tfmvf

.PHONY: checkroot
checkroot:
	test root = "`whoami`"
