##########################################################################
#                   Cameleon                                             #
#                                                                        #
#      Copyright (C) 2002 Institut National de Recherche en Informatique et   #
#      en Automatique. All rights reserved.                              #
#                                                                        #
#      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  #
#      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                                                   #
#                                                                        #
#      Contact: Maxence.Guesdon@inria.fr                                #
##########################################################################


include ../master.Makefile

LATEX=latex
BIBTEX=bibtex
DVIPS=dvips
ODOCTOOL=ocamldoc
HEVEA=hevea
HEVEA_FLAGS=-exec xxdate.exe
HACHA=hacha
RM = rm -f 

all: manual.ps 

JPGFILES=main_window.jpg file_types.jpg menus.jpg \
	zoggy/mainwindow.jpg zoggy/hello.jpg \
	libs/configwin.jpg topcameleon/camtop.jpg \
	omom/omom-edit-1.jpg omom/omom-edit-2.jpg \

EPSFILES=$(JPGFILES:.jpg=.eps)

GEN_LATEX=odoc_command_latex.cmo
GEN_HTML=odoc_command.cmo
PRINT_HTML=odoc_print_html.cmo

GEN_LATEX_PLUGIN=$(OCAMLDOC) -g odoc_command_latex.cmo -tables-only $(COMPFLAGS) \
		-latextitle 2,subsubsection -notrailer -noheader \
		-o $@ $<

GEN_HTML_PLUGIN=$(OCAMLDOC) -g odoc_command.cmo -tables-only $(COMPFLAGS) $<

odoc_generators:$(GEN_HTML) $(GEN_LATEX)

PLUGINS_SRC=../plugins/utils.ml ../plugins/editors.ml ../plugins/make.ml \
	../plugins/chat.ml ../omom/omom_plugin.ml

DOC_PLUGINS_TEX= pluginutils.tex plugineditors.tex pluginmake.tex \
	pluginchat.tex pluginomom.tex plugins.tex
DOC_PLUGINS_HTML=$(DOC_PLUGINS_TEX:.tex=.html)

LIBS_TEX=cam_plug.tex mlchat.tex \
	ocamlcvs.tex options.tex okey.tex configwin.tex gpattern.tex \
	commands.tex 

manual.ps: manual $(EPSFILES) $(LIBS_TEX) $(DOC_PLUGINS_TEX) 
	$(LATEX) $<
	$(BIBTEX) $<
	$(LATEX) $<
	$(LATEX) $<
	$(DVIPS) -o $@ $<.dvi

cam_plug.tex: ../cameleon/cam_plug.mli
	$(OCAMLDOC) $(OCAMLPP) $(INCLUDES) \
	-latextitle 1,subsection \
	-latextitle 2,subsubsection \
	-latextitle 3,paragraph \
	-noheader -notrailer -latex $< \
	-o $@

Cam_plug.html: ../cameleon/cam_plug.mli
	$(OCAMLDOC) $(OCAMLPP) $(INCLUDES) \
	-colorize-code -html $<

mlchat.tex: ../mlchat/mlchat.mli ../mlchat/mlchat.ml
	$(OCAMLDOC) $(OCAMLPP) $(INCLUDES) \
	-noheader -notrailer -latex $^ \
	-latex-type-prefix "TYP" \
	-o $@

Mlchat.html: ../mlchat/mlchat.mli ../mlchat/mlchat.ml
	$(OCAMLDOC) $(OCAMLPP) $(INCLUDES) \
	-colorize-code -html $^

ocamlcvs.tex: ../ocamlcvs/ocamlcvs.mli ../ocamlcvs/ocamlcvs.ml
	$(OCAMLDOC) $(OCAMLPP) $(INCLUDES) \
	-noheader -notrailer -latex $^ \
	-latex-type-prefix "TYP" \
	-o $@

Ocamlcvs.html: ../ocamlcvs/ocamlcvs.mli ../ocamlcvs/ocamlcvs.ml
	$(OCAMLDOC) $(OCAMLPP) $(INCLUDES) \
	-colorize-code -html $^

options.tex: ../options/options.mli
	$(OCAMLDOC) $(OCAMLPP) $(INCLUDES) \
	-noheader -notrailer -latex $< \
	-latex-type-prefix "TYP" \
	-latextitle 1,subsection\
	-latextitle 2,subsubsection\
	-o $@

Options.html: ../options/options.mli
	$(OCAMLDOC) $(OCAMLPP) $(INCLUDES) \
	-colorize-code -html $<

okey.tex: ../okey/okey.mli
	$(OCAMLDOC) $(OCAMLPP) $(INCLUDES) \
	-noheader -notrailer -latex $< \
	-latex-type-prefix "TYP" \
	-latextitle 1,subsection\
	-latextitle 2,subsubsection\
	-o $@

Okey.html: ../okey/okey.mli
	$(OCAMLDOC) $(OCAMLPP) $(INCLUDES) \
	-colorize-code -html $<

configwin.tex: ../configwin/configwin.mli
	$(OCAMLDOC) $(OCAMLPP) $(INCLUDES) \
	-noheader -notrailer -latex $< \
	-latex-type-prefix "TYP" \
	-latextitle 1,subsection\
	-latextitle 2,subsubsection\
	-o $@

Configwin.html: ../configwin/configwin.mli
	$(OCAMLDOC) $(OCAMLPP) $(INCLUDES) \
	-colorize-code -html $<

gpattern.tex: ../gpattern/gpattern.mli ../gpattern/gpattern.ml
	$(OCAMLDOC) $(OCAMLPP) $(INCLUDES) \
	-noheader -notrailer -latex $^ \
	-latex-type-prefix "TYP" \
	-latextitle 1,subsection\
	-latextitle 2,subsubsection\
	-o $@

Gpattern.html: ../gpattern/gpattern.mli
	$(OCAMLDOC) $(OCAMLPP) $(INCLUDES) \
	-colorize-code -html $<

pluginutils.tex:  ../plugins/utils.ml $(GEN_LATEX)
	$(GEN_LATEX_PLUGIN)

plugineditors.tex:../plugins/editors.ml $(GEN_LATEX)
	$(GEN_LATEX_PLUGIN) 

pluginchat.tex: ../plugins/chat.ml $(GEN_LATEX)
	$(GEN_LATEX_PLUGIN)

pluginomom.tex:../omom/omom_plugin.ml $(GEN_LATEX)
	$(GEN_LATEX_PLUGIN) 

pluginmake.tex:../plugins/make.ml $(GEN_LATEX)
	$(GEN_LATEX_PLUGIN) 

commands.tex:../cameleon/cam_messages.ml $(GEN_LATEX)
	$(GEN_LATEX_PLUGIN) 

plugins.tex:$(GEN_LATEX) $(PLUGINS_SRC)
	$(OCAMLDOC) -g odoc_command_latex.cmo $(COMPFLAGS) \
	-latextitle 2,subsection -notrailer -noheader \
	-o $@ $(PLUGINS_SRC)


pluginutils.html:../plugins/utils.ml $(GEN_HTML)
	$(GEN_HTML_PLUGIN) 
	mv Utils.html $@

plugineditors.html: ../plugins/editors.ml $(GEN_HTML)
	$(GEN_HTML_PLUGIN)
	mv Editors.html $@

pluginchat.html: ../plugins/chat.ml $(GEN_HTML)
	$(GEN_HTML_PLUGIN)
	mv Chat.html $@

pluginomom.html: ../omom/omom_plugin.ml $(GEN_HTML)
	$(GEN_HTML_PLUGIN)
	mv Omom_plugin.html $@

pluginmake.html:../plugins/make.ml $(GEN_HTML)
	$(GEN_HTML_PLUGIN)
	mv Make.html $@

commands.html:../cameleon/cam_messages.ml $(GEN_HTML)
	$(GEN_HTML_PLUGIN) 
	mv Cam_messages.html $@

plugins.html:$(GEN_HTML) 
	$(OCAMLDOC) -g odoc_command.cmo $(COMPFLAGS) \
	-t "Plug-ins" \
	$(PLUGINS_SRC)
	mv index.html $@

plugin_example.html: ../plugins/utils.ml $(PRINT_HTML)
	tail +11 $< > foo.ml
	$(OCAMLDOC) -g $(PRINT_HTML) $(COMPFLAGS) \
	-colorize-code -nopage \
	-o $@ foo.ml
	$(RM) foo.ml

manual:

html: manual.tex Cam_plug.html Mlchat.html Ocamlcvs.html \
	Options.html Okey.html Configwin.html Gpattern.html \
	$(DOC_PLUGINS_HTML) commands.html plugin_example.html 
	$(HEVEA) $(HEVEA_FLAGS) $<
	$(HACHA) `basename $< tex`html
	$(MKDIR) $@
	$(CP)  *.html $(JPGFILES) $@
	$(CP) doc_style.css $@/style.css

%.eps: %.jpg
	convert $< $@

clean:
	$(RM) *.bbl *.blg *.dvi *.aux *.log *.html *~ *.toc
	$(RM) *.ps $(EPSFILES)
	$(RM) $(DOC_PLUGINS_TEX) $(LIBS_TEX)
	$(RM) *.cm*
	$(RM) -r html
	$(RM) next_motif.gif previous_motif.gif contents_motif.gif
