
@SET_MAKE@
LATEX=@LATEX@
PDFLATEX=@PDFLATEX@
TEX=@TEX@
TEXHASH=@TEXHASH@

prefix=@prefix@$(null)
datarootdir=@datarootdir@$(null)
datadir=@datadir@$(null)
exec_prefix=@exec_prefix@$(null)
libdir=@libdir@$(null)
previewtexmfdir = @previewtexmfdir@$(null)
previewdocdir = @previewdocdir@$(null)
TEXMFGEN = @TEXMFGEN@

DESTDIR=
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
MKINSTALLDIRS = ../../mkinstalldirs

all: $(TEXMFGEN) preview.drv preview-mk.ins preview.dvi preview.pdf

install: install-texmf install-texmf-doc

install-texmf: $(TEXMFGEN)
	-$(MKINSTALLDIRS) $(DESTDIR)$(previewtexmfdir)
	for x in $(TEXMFGEN) ; do \
	  echo $(INSTALL_DATA) $$x $(DESTDIR)$(previewtexmfdir) ; \
	  $(INSTALL_DATA) $$x $(DESTDIR)$(previewtexmfdir) ; \
	done
# Isn't the texmfdir directory without "tex/latex/preview" available?
	@ texmfdir="$(DESTDIR)$(previewtexmfdir)/../../.."; \
	if [ -r "$$texmfdir"/ls-R ]; then \
	  $(TEXHASH) "$$texmfdir";  \
	else \
	  echo "Warning: Cannot update ls-R database in $$texmfdir"; \
	  sleep 2; \
	fi

install-texmf-doc: preview.dvi
	-$(MKINSTALLDIRS) $(DESTDIR)$(previewdocdir)
	$(INSTALL_DATA) preview.dvi $(DESTDIR)$(previewdocdir)

preview-mk.ins: preview.dtx bootstrap.ins
	$(TEX) '\nonstopmode \input bootstrap.ins'

#only for standalone preview.sty package:
preview.ins: preview.dtx
	$(TEX) '\nonstopmode\def\jobname{.ins}\input docstrip ' \
	'\generate{\file{preview.ins}{\from{preview.dtx}{installer}}}' \
	'\endbatchfile'

$(TEXMFGEN) preview.drv: preview.dtx preview-mk.ins
	$(TEX) '\nonstopmode \input preview-mk.ins'

preview.dvi: preview.drv preview.dtx preview.sty
	$(LATEX) '\nonstopmode \input preview.drv'
	$(LATEX) '\nonstopmode \input preview.drv'
	$(LATEX) '\nonstopmode \input preview.drv'

preview.pdf: preview.drv preview.dtx preview.sty
	$(PDFLATEX) '\nonstopmode \AtBeginDocument{\OnlyDescription}\input{preview.drv}'
	$(PDFLATEX) '\nonstopmode \AtBeginDocument{\OnlyDescription}\input{preview.drv}'
	$(PDFLATEX) '\nonstopmode \AtBeginDocument{\OnlyDescription}\input{preview.drv}'

clean:
	rm -f *~ *.aux *.dvi *.drv *.log 
	rm -f $(TEXMFGEN) preview.ins preview-mk.ins 
