#################################################################################
#                Odot                                                           #
#                                                                               #
#    Copyright (C) 2005 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.1 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 Lesser 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                                          #
#################################################################################

MASTER=master.Makefile

include $(MASTER)

INCLUDES=-I +lablgtk2
COMPFLAGS=$(INCLUDES)
LINKFLAGS=$(INCLUDES)

LIB=odot.cmxa
LIB_A=$(LIB:.cmxa=.a)
LIB_CMI=$(LIB:.cmxa=.cmi)
LIB_BYTE=$(LIB:.cmxa=.cma)

# Compilation
#############

CMOFILES=\
	odot_version.cmo \
	odot_misc.cmo \
	odot_parser.cmo \
	odot_lexer.cmo \
	odot.cmo

CMXFILES= $(CMOFILES:.cmo=.cmx)
CMIFILES= $(CMOFILES:.cmo=.cmi)

VIEW_CMOFILES=odot_view.cmo
VIEW_CMXFILES= $(VIEW_CMOFILES:.cmo=.cmx)
VIEW_CMIFILES= $(VIEW_CMOFILES:.cmo=.cmi)


LIB_VIEW=odot_view.cmx
LIB_VIEW_O=$(LIB_VIEW:.cmx=.o)
LIB_VIEW_CMI=$(LIB_VIEW:.cmx=.cmi)
LIB_VIEW_BYTE=$(LIB_VIEW:.cmx=.cmo)

all: byte opt
byte: $(LIB_BYTE)
opt: $(LIB)
test: $(LIB_BYTE) test.ml
	$(OCAMLC) $(INCLUDES) -o test.x unix.cma $(LIB_BYTE) test.ml

gui: gui_opt gui_byte
gui_opt: $(VIEW_CMIFILES) $(VIEW_CMXFILES)
gui_byte: $(VIEW_CMIFILES) $(VIEW_CMOFILES)

test_gui: $(LIB_BYTE) gui_byte test_gui.ml
	$(OCAMLC) $(INCLUDES) -o test_gui.x unix.cma \
	lablgtk.cma lablgnomecanvas.cma $(LIB_BYTE) $(VIEW_CMOFILES) test_gui.ml

$(LIB): $(CMIFILES) $(CMXFILES)
	$(OCAMLOPT) -a -o $@ $(CMXFILES)

$(LIB_BYTE): $(CMIFILES) $(CMOFILES)
	$(OCAMLC) -a -o $@ $(CMOFILES)

TESTFILES=test.dot test2.dot test3.dot test4.dot test5.dot test6.dot
check: test $(TESTFILES)
	for i in $(TESTFILES) ; do \
	echo testing with file $$i ; \
	./test.x $$i > $$i.test ; \
	dot -Tps -o test.ps $$i ; \
	dot -Tps -o test2.ps $$i.test ; \
	(diff test.ps test2.ps > /dev/null && echo ok) || echo test failed on file $$i ; \
	rm -f test.ps test2.ps $$i.test ; done

# Documentation :
#################
dump.odoc: *.ml *.mli
	$(OCAMLDOC) $(OCAMLPP) $(COMPFLAGS) -keep-code -dump dump.odoc `ls $^ | grep -v test`

doc:
	$(MKDIR) ocamldoc
	$(OCAMLDOC) $(OCAMLPP) $(COMPFLAGS) \
	-t "The Odot library" \
	-html \
	-d ocamldoc \
	odot.mli odot_view.mli

# myself

master.Makefile: master.Makefile.in \
	odot_version.ml.in config.status
	./config.status

config.status: configure
	./config.status --recheck

configure: configure.in
	autoconf

# backup, clean and depend :
############################

distclean: clean
	$(RM) config.cache config.log config.status master.Makefile
	$(RM) autom4te.cache
	$(RM) odot_version.ml odot_gui_installation.ml

clean::
	$(RM) *~ \#*\#
	$(RM) *.cmo *.cmi *.cmx *.a *.o *.cma *.cmxa *.odoc *.annot
	$(RM) odot_parser.ml{i,} odot_lexer.ml odot_parser.output odot_gui_base.ml
	$(RM) $(EXE) $(EXE_BYTE) test.x test_gui.x

.depend depend: odot_parser.ml odot_lexer.ml
	$(RM) .depend
	$(OCAMLDEP) *.ml *.mli > .depend

dummy:

include .depend

#################
# Installation
#################
install: dummy
	$(CP) $(LIB_BYTE) $(LIB_CMI) $(OCAMLLIB)
	if test -f $(LIB); then \
	$(CP) $(LIB) $(LIB_A) $(OCAMLLIB); fi
	if test -f $(LIB_VIEW); then \
	$(CP) $(LIB_VIEW) $(LIB_VIEW_CMI) $(LIB_VIEW_O) $(OCAMLLIB); fi
	if test -f $(LIB_VIEW_BYTE); then \
	$(CP) $(LIB_VIEW_BYTE) $(LIB_VIEW_CMI) $(OCAMLLIB); fi


###########################
# additional dependencies
###########################
