# The installed library directory
HOMELIB = /u2/aplevich/lib

DOC = man
VERBATIM = BigResistor+1.verb BigResistor+2.verb Loop+.verb \
  Oblique+.verb FF+.verb
DOCSRC = man.tex body.tex defines.tex
PICTEX = Flowdiag+.tex BigResistor+.tex CctTable+.tex Loop+.tex Misc+.tex \
  Bip+.tex fet+.tex Oblique+.tex Liblog+.tex NOR+.tex ex8.tex FF+.tex \
  currents+.tex

# For gpic
MODE = gpic
PIC = gpic -t
POST = ;echo '\\centerline{\\box\\graph}'

# For dpic
# MODE = pstricks
# PIC = dpic -p
# PRE = echo '\\vspace{-1.25em}\\begin{center}';
# POST = ;echo '\\end{center}\\vspace{-1.25em}'
# PST = ;echo -n '[pstricks]'

M4LIBS = $(HOMELIB)/$(MODE).m4 $(HOMELIB)/libcct.m4 $(HOMELIB)/liblog.m4
.SUFFIXES: .tex .m4 .verb
.m4.tex:
	m4 $(M4LIBS) $*.m4 > $*.pic
	($(PRE) $(PIC) $*.pic $(POST)) > $*.tex
.m4.verb: $*.m4
	( echo '\\begin{verbatim}' ; cat $*.m4 ; echo '\\end{verbatim}' ) > $*.verb

$(DOC).ps: $(DOC).dvi
	dvips $(DOC) -o

$(DOC).dvi: citations $(PICTEX)
	latex $(DOC)

citations: $(DOC).bbl $(PICTEX)
	latex $(DOC)
	touch citations

$(DOC).bbl: $(DOC).aux $(DOC).bib
	bibtex $(DOC)

$(DOC).aux: $(DOCSRC) heading.tex $(VERBATIM) $(PICTEX)
	latex $(DOC)

heading.tex:
	( echo -n '\\documentstyle' $(PST) ; echo '{article}') > heading.tex

BigResistor+1.verb: BigResistor+.m4
	( echo '\\begin{verbatim}' ; sed -n -e '/PS/,/R1/p' BigResistor+.m4 ; \
    echo '\\end{verbatim}' ) > BigResistor+1.verb

BigResistor+2.verb: BigResistor+.m4
	( echo '\\begin{verbatim}' ; sed -n '/thinlines/,/PE/p' BigResistor+.m4 ; \
    echo '\\end{verbatim}' ) > BigResistor+2.verb

Oblique+.m4: ../examples/ex2.m4
	cp ../examples/ex2.m4 Oblique+.m4

ex8.m4: ../examples/ex8.m4
	cp ../examples/ex8.m4 ex8.m4

clobber: clean
	rm -f *.ps *.dvi

clean:
	rm -f *.bbl *.log *.aux *.blg citations *.verb Oblique+.m4 ex8.m4 *.uu
	rm -f *.pic $(PICTEX) heading.tex
