# Generate pdf from circuit macros using mfpic and metafont
# Requires m4, dpic, mfpic, metafont, dvipdfm
# Type "make"

#                        Required libraries
LIBDIR = $$HOME/lib
M4MACROS = mfpic.m4

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

#                        Tex source document name
DOC = example
#                        List of graphic files input into the tex document.
FIGS = pwrsupply.tex

#                        The dpic command
DPIC = dpic
#                        Use ljfive (which is 600dpi) because 1200dpi
#                        produces metafont errors on some figs
MODE = ljfive
DPI = 600
#                        The name of the metafont graphsfile
MFSOURCE = $(DOC)-mfpic

#                        Make sure latex searches the current directory
LATEX = TEXFORMATS=.: TEXFONTS=.: latex
#                        Metafont preamble to produce the diagram font
MF = MFINPUTS=.: mf "\mode:=$(MODE); scrollmode;"

.SUFFIXES: .m4 .tex
.m4.tex:
	m4 -I $(LIBDIR) $(M4MACROS) $*.m4 | $(DPIC) -m > $*.tex

$(DOC).pdf: $(DOC).dvi
	dvipdfm $(DOC)

$(DOC).dvi: $(DOC).tex $(MFSOURCE).$(DPI)gf
	$(LATEX) $(DOC)
	touch $(MFSOURCE).mf $(MFSOURCE).$(DPI)gf $(DOC).dvi

$(MFSOURCE).$(DPI)gf: $(MFSOURCE).mf
	-$(MF) "input $(MFSOURCE)" < /dev/null
	touch $(MFSOURCE).$(DPI)gf

$(MFSOURCE).mf: $(DOC).tex $(FIGS)
	touch $(DOC).aux
	-$(LATEX) $(DOC)

clobber: clean

clean:
	rm -f $(FIGS) *.aux *.mf *.dvi *.ps *.toc *.pdf *gf *pk *.log *.pdf *.tfm
