#
# Makefile for octave's doc directory
#
# John W. Eaton
# jwe@che.utexas.edu
# Department of Chemical Engineering
# The University of Texas at Austin

TOPDIR = ..

srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@

include $(TOPDIR)/Makeconf

INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@

SOURCES =

TEXINFO = amuse.texi arith.texi bugs.texi bugs1.texi control.texi \
	cp-idx.texi diffeq.texi expr.texi extend.texi fn-idx.texi \
	func.texi gnuinfo.texi gpl.texi help.texi history.texi \
	hsuser.texi image.texi in-idx.texi install.texi install1.texi \
	intro.texi invoke.texi io.texi linalg.texi matrix.texi \
	nonlin.texi octave.texi op-idx.texi optim.texi plot.texi \
	poly.texi preface.texi program.texi quad.texi rd-idx.texi \
	rluser.texi set.texi signal.texi special.texi stats.texi \
	stmt.texi strings.texi system.texi var.texi vr-idx.texi

LIB_TEXINFO = liboctave.texi

FAQ_TEXINFO = FAQ.texi

ALL_TEXINFO = $(TEXINFO) $(LIB_TEXINFO) $(FAQ_TEXINFO)

REFCARD = refcard.tex refcard-a4.tex refcard-legal.tex refcard-letter.tex 

FORMATTED =  octave.dvi octave.ps octave.info octave.info-[0-9]* \
	FAQ.info FAQ.dvi FAQ.ps refcard-a4.dvi refcard-a4.ps \
	refcard-legal.dvi refcard-legal.ps \
	refcard-letter.dvi refcard-letter.ps
#	liboctave.dvi liboctave.ps liboctave.info liboctave.info-[0-9]*

DISTFILES = Makefile.in conf.texi.in conf.texi texinfo.tex dir \
	octave.1 $(REFCARD) $(ALL_TEXINFO) $(FORMATTED)

SPELL = $(patsubst %.texi, %.spell, $(ALL_TEXINFO))

%.spell : %.texi
	rm -f $@
	sed -e 's/@@/ at /g' -e 's/@[a-zA-Z]*//g' $< | spell > $@.tmp
	mv $@.tmp $@

all: octave.info octave.dvi octave.ps FAQ.info FAQ.dvi FAQ.ps \
	refcard-a4.dvi refcard-a4.ps refcard-legal.dvi refcard-legal.ps \
	refcard-letter.dvi refcard-letter.ps
#	liboctave.info liboctave.dvi liboctave.ps
.PHONY: all

octave.info: $(TEXINFO) conf.texi
	-makeinfo -I$(srcdir) octave.texi

octave.dvi: $(TEXINFO) conf.texi
	texi2dvi $(srcdir)/octave.texi

octave.ps: octave.dvi
	dvips -o octave.ps octave.dvi

FAQ.info: FAQ.texi
	-makeinfo -I$(srcdir) FAQ.texi

FAQ.dvi: FAQ.texi
	texi2dvi $(srcdir)/FAQ.texi

FAQ.ps: FAQ.dvi
	dvips -o FAQ.ps FAQ.dvi

liboctave.info: $(LIB_TEXINFO) conf.texi
	-makeinfo -I$(srcdir) liboctave.texi

liboctave.dvi: $(LIB_TEXINFO) conf.texi
	texi2dvi $(srcdir)/liboctave.texi

liboctave.ps: liboctave.dvi
	dvips -o liboctave.ps liboctave.dvi

refcard-a4.dvi: refcard-a4.tex refcard.tex
	TEXINPUTS="$(TEXINPUTS):$(srcdir)" ; export TEXINPUTS ; \
	  tex $(srcdir)/refcard-a4.tex

refcard-a4.ps: refcard-a4.dvi
	dvips -T 297mm,210mm -o refcard-a4.ps refcard-a4.dvi

refcard-legal.dvi: refcard-legal.tex refcard.tex
	TEXINPUTS="$(TEXINPUTS):$(srcdir)" ; export TEXINPUTS ; \
	  tex $(srcdir)/refcard-legal.tex

refcard-legal.ps: refcard-legal.dvi
	dvips -T 14in,8.5in -o refcard-legal.ps refcard-legal.dvi

refcard-letter.dvi: refcard-letter.tex refcard.tex
	TEXINPUTS="$(TEXINPUTS):$(srcdir)" ; export TEXINPUTS ; \
	  tex $(srcdir)/refcard-letter.tex

refcard-letter.ps: refcard-letter.dvi
	dvips -T 11in,8.5in -o refcard-letter.ps refcard-letter.dvi

../INSTALL.OCTAVE: install1.texi install.texi
	-makeinfo --no-header -I$(srcdir)/doc install1.texi
	-mv INSTALL ../INSTALL.OCTAVE

../BUGS: bugs1.texi bugs.texi
	-makeinfo --no-header -I$(srcdir)/doc bugs1.texi
	-mv BUGS ../BUGS

# This mess is supposed to prevent us from making info files
# unnecessarily when building Octave in a subdirectory.

conf.texi: $(srcdir)/../src/version.h ../Makeconf Makefile conf.texi.in
	@echo "Making conf.texi from conf.texi.in..."
	@(version_val=${version}; \
	sed < $(srcdir)/conf.texi.in > conf.texi.tmp \
	-e "s;%OCTAVE_VERSION%;$$version_val;" \
	-e "s;%OCTAVE_HOME%;${prefix};")
	@if test "$(srcdir)" = "." ; then \
	  $(top_srcdir)/move-if-change conf.texi.tmp conf.texi; \
	else \
	  if cmp conf.texi.tmp $(srcdir)/conf.texi > /dev/null; then \
	    echo conf.texi is unchanged; \
	    rm -f conf.texi.tmp; \
	  else \
	    mv -f conf.texi.tmp conf.texi; \
	  fi; \
	fi

check: all
.PHONY: check

install: all
	$(top_srcdir)/mkinstalldirs $(mandir) $(infodir)
	@if test -d $(mandir) ; then \
	  rm -f $(mandir)/octave.$(manext) ; \
	  echo "installing $(srcdir)/octave.1 in $(mandir)" ; \
	  $(INSTALL_DATA) $(srcdir)/octave.1 $(mandir)/octave.$(manext) ; \
	fi
	@if test -d $(infodir) ; then \
	  rm -f $(infodir)/octave.info* ; \
	  echo "installing info files in $(infodir)" ; \
	  if test -f octave.info ; then \
	    for f in octave.info* ; do \
	      $(INSTALL_DATA) $$f $(infodir)/$$f ; \
	    done ; \
	  else \
	    for f in $(srcdir)/octave.info* ; do \
	      $(INSTALL_DATA) $$f $(infodir)/`basename $$f` ; \
	    done ; \
	  fi ; \
	  if test -f $(infodir)/dir ; then \
	    if grep "^\* Octave: (octave)." $(infodir)/dir > /dev/null ; then \
	      true ; \
	    else \
	      echo "" ; \
	      echo "You should add the following entry" ; \
	      echo "" ; \
	      echo "* Octave: (octave)." ; \
	      echo "	Interactive language for numerical computations." ; \
	      echo "" ; \
	      echo "to $(infodir)/dir." ; \
	      echo "" ; \
	    fi ; \
	  else \
	    echo "installing $(srcdir)/dir in $(infodir)" ; \
	    $(INSTALL_DATA) $(srcdir)/dir $(infodir)/dir ; \
	  fi ; \
	fi
.PHONY: install

uninstall:
	rm -f $(infodir)/octave.info* $(infodir)/liboctave.info*
	rm -f $(mandir)/octave.$(manext)
.PHONY: uninstall

tags: $(SOURCES)
	ctags $(SOURCES)

TAGS: $(SOURCES)
	etags $(SOURCES)

spell: $(SPELL)
.PHONY: spell

clean:
	rm -f *.info *.info-* octave.cp octave.fn octave.in \
	octave.ky octave.op octave.pg octave.rd octave.tp octave.vr \
	octave.cps octave.fns octave.ins octave.kys octave.ops \
	octave.pgs octave.rds octave.tps octave.vrs octave.aux \
	octave.log octave.toc octave.dvi octave.ps liboctave.cp \
	liboctave.fn liboctave.pg liboctave.tp liboctave.cps \
	liboctave.fns liboctave.pgs liboctave.tps liboctave.aux \
	liboctave.log liboctave.toc liboctave.dvi liboctave.ps \
	refcard-*.dvi refcard-*.ps
.PHONY: clean

mostlyclean:
	rm -f *.info *.info-*
.PHONY: mostlyclean

distclean: clean
	rm -f Makefile
.PHONY: distclean

realclean: distclean
	rm -f tags TAGS
.PHONY: realclean

local-dist: all
	ln $(DISTFILES) ../`cat ../.fname`/doc
.PHONY: local-dist

dist: all
	ln $(DISTFILES) ../`cat ../.fname`/doc
.PHONY: dist

doc-dist: all
	ln $(FORMATTED) ../`cat ../.fname`/doc
.PHONY: doc-dist
