# trace EC fonts into TFM and PFA

ECFONTS = ecbx10 ecbx12 ecbx5 ecbx6\
	ecbx7 ecbx8 ecbx9  ecrm10 ecrm12\
	ecrm17 ecrm5 ecrm6 ecrm7 ecrm8 ecrm9 ecsl10\
	ecsl12 ecsl8 ecsl9 ecsc9 ecsc10 ecsc12 ecsc14\
	eccc10 eccc12\
	ecbi8 ecbi9 ecbi10 ecbi12 ecbi14 ecbi17 \
	ecrb7 ecrb10 ecrb12 ecrb14 ecrb17\
	ecss10 ecss12 ecss17\
	ecb7 ecb8 ecb9 ecb10 ecb12 \
	ecss8 ecss9  ecssdc10\
	ecti10 ecti12 ecti7 ecti8 ecti9 ectt10\
	ectt12 ectt8 ectt9 

TFMS=$(addprefix $(builddir)/tfm/,$(addsuffix .tfm,$(ECFONTS)))
PFAS=$(addprefix $(builddir)/pfa/,$(addsuffix .pfa,$(ECFONTS)))

builddir=.

include VERSION

NAME=ec-fonts-mftraced
DISTDIR=$(builddir)/$(NAME)-$(VERSION)
TARBALL=$(DISTDIR).tar.gz
WWWDIR=base.lilypond.org:/var/www/lilypond/download/fonts/

prefix=$(DESTDIR)/usr
docdir=$(prefix)/share/doc
sysconfdir=$(DESTDIR)/etc

TEXMF=
export TEXMF

TEXDIR=$(prefix)/share/texmf
TEXCONFDIR=$(prefix)/share/texmf
##TEXCONFDIR=$(sysconfdir)/texmf

PATHSUF=$(NAME)
PFADIR=$(TEXDIR)/fonts/type1/public/$(PATHSUF)
TFMDIR=$(TEXDIR)/fonts/tfm/public/$(PATHSUF)

#teTeX-2.0.x
MAPDIR20=$(TEXCONFDIR)/dvips/$(PATHSUF)
#teTeX-3.0
MAPDIR=$(TEXCONFDIR)/fonts/map/dvips/$(PATHSUF)


MAPFILE=$(builddir)/ec-mftrace.map
README_FILES = ChangeLog COPYING INSTALL LICENSE README
DISTFILES=GNUmakefile configure ec-mftrace.spec.in ec-mftrace.spec ecb.mf\
 generate-map-file.py VERSION $(README_FILES)
CYGWIN_FILES = changelog ec-fonts-mftraced.hint mknetrel mknetrel.doc\
 postinstall-ec-fonts-mftraced.sh README.in
CYGWIN_DISTFILES=$(CYGWIN_FILES:%=cygwin/%)
DEBIAN_FILES = changelog control copyright dirs postinst postrm prerm \
	rules conffiles
DEBIAN_DISTFILES=$(DEBIAN_FILES:%=debian/%)

default: $(TFMS) $(PFAS) $(MAPFILE)
all: default

$(builddir)/ec-mftrace.spec: ec-mftrace.spec.in VERSION
	sed 's/@VERSION@/$(VERSION)/g' < $< > $@

$(builddir)/cygwin/README: cygwin/README.in VERSION
	mkdir -p $(builddir)/cygwin		 
	sed 's/@VERSION@/$(VERSION)/g' < $< > $@

$(builddir)/tfm/%.tfm:
	@rm -f $(builddir)/output-dir
	@-mkdir $(builddir)/tfm 2>/dev/null
	-mktextfm $(notdir $(basename $@)) > $(builddir)/output-dir
	cp `cat $(builddir)/output-dir` $(builddir)/tfm

$(builddir)/tfm.make: $(builddir)/tfm/ecbx10.tfm
	sed -e 's@^@VARTEXFONTS=@' -e 's@/[^/]*$$@@' $(builddir)/output-dir > $(builddir)/tfm.make

include $(builddir)/tfm.make

$(builddir)/tfm/%.tfm: $(VARTEXFONTS)/%.tfm
	cp $< $@

$(builddir)/pfa/%.pfa: 
	@-mkdir $(builddir)/pfa 2>/dev/null
	TEXMF= mftrace --simplify --potrace $(notdir $(basename $@))
	mv $(notdir $@) $(builddir)/pfa/

$(MAPFILE): GNUmakefile 
	python generate-map-file.py $(PFAS) > $@

install: $(TFMS) $(PFAS)
	install -d $(PFADIR)
	install -m644 $(PFAS) $(PFADIR)

	install -d $(TFMDIR)
	install -m644 $(TFMS) $(TFMDIR)

	install -d $(MAPDIR)
	install -m644 $(MAPFILE) $(MAPDIR)

	#teTeX-2.0 compatibility	
	-ln -sf $(MAPDIR) $(MAPDIR20)

	install -d $(docdir)/$(NAME)
	install -m644 $(README_FILES) $(docdir)/$(NAME)

	@echo "Run texhash before using."


dist: $(DISTFILES) $(DEBIAN_DISTFILES) $(CYGWIN_DISTFILES)
	mkdir $(DISTDIR)
	ln $(DISTFILES) $(DISTDIR)

	mkdir $(DISTDIR)/cygwin
	ln $(CYGWIN_DISTFILES) $(DISTDIR)/cygwin

	mkdir $(DISTDIR)/debian
	ln $(DEBIAN_DISTFILES) $(DISTDIR)/debian

	tar -C $(builddir) -zcf $(TARBALL) $(NAME)-$(VERSION)
	rm -rf $(DISTDIR)

www-dist: dist
	scp $(TARBALL) $(WWWDIR)

rpm: dist
	rpmbuild -tb $(TARBALL)

rpm-dist: rpm
	scp $(HOME)/usr/src/redhat/RPMS/noarch/$(NAME)-$(VERSION)*.noarch.rpm \
		$(WWWDIR)

clean:
	-rm $(TFMS) $(PFAS) 2>/dev/null

deb: $(DISTFILES)
	debuild 

# inject ready made fonts into the ^Z-ed build process.
inject:
	@mkdir -p $(HOME)/usr/src/redhat/BUILD/$(NAME)-$(VERSION)/pfa
	@mkdir -p $(HOME)/usr/src/redhat/BUILD/$(NAME)-$(VERSION)/tfm
	cp $(TFMS) $(HOME)/usr/src/redhat/BUILD/$(NAME)-$(VERSION)/tfm
	cp $(PFAS) $(HOME)/usr/src/redhat/BUILD/$(NAME)-$(VERSION)/pfa
