# @configure_input@
include ../../include/config.Makefile
VPATH = @srcdir@
BOOKNAME = Macaulay2-@PACKAGE_VERSION@-book

DVIPSFLAGS = -z
TEX=latex

all:
check:

%.bux : %.tex
	$(TEX) $*
	makeindex $*.idx
	mv $*.dvi $*-prelim.dvi
	cp $*.aux $*.bux
.PRECIOUS: %.bux
%.bbl : %.bux
	cp $*.bux $*.aux
	bibtex $*
%.dvi : %.tex
%.dvi : %.bbl
	$(TEX) $*
	makeindex $*.idx
	if grep -s "Rerun to get cross-references right." $*.log; \
	then $(TEX) $*; \
	     makeindex $*.idx ; \
	fi
%.ps : %.dvi
	dvips $(DVIPSFLAGS) $< $(OUTPUT_OPTION)
	rm -f body.tmp head.tmp

%.pdf : %.tex
	pdf$(TEX) $*
	makeindex $*.idx
	pdf$(TEX) $*

# doesn't work currently...
# all: $(BOOKNAME).tex

$(BOOKNAME).bbl : papers.bib

# doesn't work currently...
# all: $(BOOKNAME).dvi $(BOOKNAME).ps $(BOOKNAME).pdf

## for M2book.pdf put these lines in texmf.cnf
# main_memory = 1263000
# hash_extra = 15000
# pool_size = 300000
# max_strings = 30000

$(BOOKNAME).tex : ../cache/Macaulay2-doc book.m2 booktex.m2
	@pre_exec_prefix@/bin/M2@EXE@ -q book.m2 -e 'exit 0'
	mv M2book.tmp $(BOOKNAME).tex

clean:; rm -rf Macaulay2-*-book.*

distclean: clean
	rm -f Makefile
