#
#  RLdev documentation
#  Copyright (C) 2006 Haeleth
#  Revised 2009-2011 by Richard 23
#
#  This program is free software; you can redistribute it and/or modify it under
#  the terms of the GNU General Public License as published by the Free Software
#  Foundation; either version 2 of the License, or (at your option) any later
#  version.
#
#  This program is distributed in the hope that it will be useful, but WITHOUT
#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
#  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
#  details.
#
#  You should have received a copy of the GNU General Public License along with
#  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
#  Place - Suite 330, Boston, MA  02111-1307, USA.
#

PROGRAM = mkfundoc
FILES = mkfundoc
GENERATED = mkfundoc.ml
OCamlGeneratedFiles($(GENERATED))
OCamlProgram($(PROGRAM), $(FILES))

TEXFILES = manual usage kepago reallive functions gameexe vasnames gpl licenses
GENERATED += functions.tex gameexe.tex manual.tex

%.tex: %.fundoc $(PROGRAM)$(EXE)
  ./$(PROGRAM)$(EXE) < $< > $@

manual.tex: manual.tex.in $(version_file)
  rm -f $@
  section
    verfile = $(fopen $(version_file),r)
    verstr = $(nth 3,$(split $(gets $(verfile))))
    close($(verfile))
    stdout = $(fopen $@,w)
    println(%)
    println(% THIS IS A GENERATED FILE: edit $@.in instead!)
    println(%)
    fsubst (manual.tex.in)
    case $"!!DATE!!"
      value $(shell date -I)
    case $"!!VERSION!!"
      value $(verstr)
    close($(stdout))

.PHONY: alldoc clean dochtml docpdf

if $(ENABLE_HEVEA)
  dochtml: $(addsuffix .tex,$(TEXFILES))
    hevea -fix -moreentities -O -noiso manual
else
  dochtml:
    @echo HTML documentation disabled by configure

if $(ENABLE_PDFLATEX)
  docpdf: $(addsuffix .tex,$(TEXFILES))
    pdflatex manual
    makeindex manual
    makeindex manual.cdx -o manual.cnd
    makeindex manual.fdx -o manual.fnd
    makeindex manual.gdx -o manual.gnd
    pdflatex manual
    pdflatex manual
else
  docpdf:
    @echo PDF documentation disabled by configure

alldoc: dochtml docpdf

clean:
  $(RM) *.omc $(GENERATED) $(addsuffixes .cmi .cmo .cmx $(EXT_OBJ),$(FILES)) $(PROGRAM)$(EXE)
  $(RM) *.aux manual.{html,pdf,cdx,cnd,fdx,fnd,gdx,gnd,haux,hcnd,hind,hfdx,hfnd,hgdx,hgnd,htoc,idx,ilg,ind,log,out,toc}
