MANFILES = asy.1 xasy.1x
ASYFILES = $(wildcard *.asy) latexusage.asy
SOURCE = asymptote.texi version.texi options
ASY = ../asy -dir ../base -config ""
DOCFILES = asymptote.pdf CAD.pdf

docdir = $(DESTDIR)/usr/local/share/doc/asymptote
infodir = $(DESTDIR)${datarootdir}/info
datarootdir = ${prefix}/share
INSTALL = /usr/bin/ginstall -c
TEXI2DVI = texi2dvi

export docdir infodir INSTALL

all:    doc

html:	asymptote/index.html

man:	$(DOCFILES) asy.1

faq:	
	cd FAQ; $(MAKE) faq

doc:	asymptote.dvi asymptote.info html man faq

%.png:	%.asy
	$(ASY) -f png $<

%.eps:	%.asy
	$(ASY) -f eps $<

%.pdf:	%.asy
	$(ASY) -f pdf $<

latexusage.asy: latexusage.tex
	latex latexusage

latexusage.dvi: latexusage.asy
	$(ASY) latexusage
	latex latexusage

latexusage.eps: latexusage.dvi
	dvips -o latexusage.eps latexusage

latexusage.png: latexusage.eps
	convert -density 144x144 +antialias -geometry 50%x \
		latexusage.eps latexusage.png
latexusage.pdf: latexusage.dvi
	dvipdf latexusage

options: ../settings.cc
	$(ASY) -h 2>&1 | grep -iv Asymptote > options

asy.1: options asy.1.begin asy.1.end
	cat options | grep \^- | sed -e "s/-\(.*\)  \([A-Z].*\)/.TP\n.B -\1\n\2\./" | sed -e "/^.B/ s/-/\\\\-/g" | cat asy.1.begin - asy.1.end > asy.1

asymptote.dvi: $(SOURCE) $(ASYFILES:.asy=.eps)
	ln -sf asymptote.texi asymptote_.texi
	$(TEXI2DVI) asymptote_.texi
	mv asymptote_.dvi asymptote.dvi

asymptote.info: $(SOURCE) $(ASYFILES:.asy=.png)
	makeinfo asymptote

asymptote.pdf: $(SOURCE) $(ASYFILES:.asy=.pdf)
	$(TEXI2DVI) --pdf asymptote.texi

CAD.pdf: CAD.tex CAD1.eps 
	latex CAD
	latex CAD
	latex CAD
	dvipdf CAD

asymptote/index.html: $(SOURCE) $(ASYFILES:.asy=.eps) $(ASYFILES:.asy=.png)
	mkdir -p asymptote
	cp *.png asymptote
	makeinfo --html asymptote

clean: FORCE
	rm -f $(ASYFILES:.asy=.pdf) $(DOCFILES)
	rm -f *.eps *.png latexusage.{asy,dvi,eps,png,log,aux,*.eps}
	rm -f {asymptote,asymptote_}.{aux,cp,cps,dvi,fn,info,ky,log,pg,pdf,toc,tp,vr} 
	rm -f asymptote_.texi asymptote.info-*
	rm -f CAD.{aux,dvi,log,pdf,toc}
	rm -rf asymptote

install: man faq
	cd FAQ; $(MAKE) install
	${INSTALL} -d -m 755 $(docdir) $(mandir)/man1
	${INSTALL} -p -m 644 $(DOCFILES) $(docdir)
	${INSTALL} -p -m 644 $(MANFILES) $(mandir)/man1

install-all: doc install
	cd FAQ; $(MAKE) install-info
	${INSTALL} -d -m 755 $(infodir)
	${INSTALL} -p -m 644 asymptote.info $(infodir)
	-${INSTALL} -p -m 644 asymptote.info-* $(infodir)
	-if test -z "$(DESTDIR)"; then \
		install-info --infodir=$(infodir) asymptote.info; \
	fi

uninstall: uninstall-all

uninstall-all:
	cd FAQ; $(MAKE) uninstall
	-cd $(mandir)/man1; rm $(MANFILES)
	-rm -f $(addprefix $(docdir)/,$(DOCFILES))
	-install-info --remove --infodir=$(infodir) asymptote.info
	-rm -f $(infodir)/asymptote.info $(infodir)/asymptote.info-*

distclean: FORCE clean
	rm -f version.texi
	cd FAQ; make distclean
FORCE:
