##########################################################################
#                   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

# 


TARGET=

TEMPLATES= templates/template_*
PIXMAPS= pixmaps/*.xpm

start:all

options: dummy
	cd $@ && $(MAKE) $(TARGET)
okey: dummy
	cd $@ && $(MAKE) $(TARGET)
configwin: dummy
	cd $@ && $(MAKE) $(TARGET)
gpattern: dummy
	cd $@ && $(MAKE) $(TARGET)
ocamlcvs: dummy
	cd $@ && $(MAKE) $(TARGET)
zoggy: dummy
	cd $@ && $(MAKE) $(TARGET)
mlchat: dummy
	cd $@ && $(MAKE) $(TARGET)
ioxml: dummy
	cd $@ && $(MAKE) $(TARGET) DESTDIR=$(DESTDIR)
report: dummy
	cd $@ && $(MAKE) $(TARGET)
toolhtml: dummy
	cd $@ && $(MAKE) $(TARGET)
dbforge: dummy
	cd $@ && $(MAKE) $(TARGET)

cameleon:dummy
	cd $@ && $(MAKE) $(TARGET)

omom: dummy
	cd $@ && $(MAKE) $(TARGET)

plugins:dummy
	cd $@ && $(MAKE) $(TARGET)

all:
	$(MAKE) byte
	if test "$(OCAMLOPT)" != no ; then $(MAKE) opt; fi

byte: dummy
	$(MAKE) TARGET=$@ iter
	@if test "$(OCAMLDIR)" != ""; then $(MAKE) bonus; fi

opt: dummy
	$(MAKE) TARGET=$@ iter

depend:dummy
	$(MAKE) TARGET=$@ iter

upto_toolhtml:options okey configwin zoggy ioxml report toolhtml
	@if test "$(OCAMLOPT)" != no; then $(MAKE) upto_toolhtml.opt; fi

upto_toolhtml.opt: dummy
	for i in options okey configwin zoggy ioxml report toolhtml ;\
	do (cd $$i && $(MAKE) opt); done

# Documentation :
#################
CAMELEON_ODOC=doc/cameleon.odoc
STDLIB_ODOC=doc/stdlib.odoc
doc: doc_cameleon doc_stdlib

doc_dbf_types.odoc:dummy
	$(OCAMLDOC) -pp "camlp4o $(ROOT)/ioxml/pa_ioXML.cmo" -I ioxml $(COMPFLAGS) \
	dbforge/dbf_types.ml -dump $@

doc_cameleon: doc_dbf_types.odoc dummy
	$(OCAMLDOC) $(OCAMLPP) $(INCLUDES) -d doc -html \
	-dump $(CAMELEON_ODOC) \
	-load doc_dbf_types.odoc \
	-colorize-code -t "Cameleon" \
	options/options.mli \
	okey/okey.mli \
	configwin/configwin.mli \
	gpattern/gpattern.mli \
	ocamlcvs/ocamlcvs.mli \
	report/report.mli \
	toolhtml/toolhtml.mli \
	mlchat/mlchat.mli \
	cameleon/cam_plug.mli

doc_toolhtml: dummy
	$(OCAMLDOC) $(OCAMLPP) $(INCLUDES) \
	-html -d $(HOME)/public_html/Tools/cameleon/toolhtml  \
	-colorize-code -t Toolhtml toolhtml/toolhtml.mli

doc_stdlib:dummy
	$(OCAMLDOC) -I +threads \
	-dump $(STDLIB_ODOC) \
	-colorize-code -t "OCaml standard library" \
	`ls $(OCAMLLIB)/*.mli | grep -v outcometree`

clean_doc: dummy
	cd doc && $(MAKE) clean
	$(RM) $(CAMELEON_ODOC) $(STDLIB_ODOC)

manual: dummy
	cd doc && $(MAKE)



# Version number :
##################
version:
	rpl $(OLDVERSION) $(NEWVERSION) cameleon/cam_installation.ml.in \
	configwin/configwin_messages.ml \
	dbforge/dbf_messages.ml \
	mlchat/chat_messages.ml \
	ocamlcvs/ocvs_messages.ml \
	omom/omom_messages.ml \
	report/rep_messages.ml \
	zoggy/zog_messages.ml 

# installation :
################
install:dummy
	$(MAKE) TARGET=$@ iter
	$(MKDIR) $(TEMPLATESDIR)
	$(MKDIR) $(PIXMAPSDIR)
	$(CP) $(TEMPLATES) $(TEMPLATESDIR)
	$(CP) $(PIXMAPS) $(PIXMAPSDIR)
	if test -d $(LIBDIR) ; then : ; else $(MKDIR) $(LIBDIR) ; fi
	if test -f $(CAMELEON_ODOC) ; then $(CP) $(CAMELEON_ODOC) $(LIBDIR); fi
	if test -f $(STDLIB_ODOC) ; then $(CP) $(STDLIB_ODOC) $(LIBDIR); fi
	@if test "$(OCAMLDIR)" != ""; then $(MAKE) install_bonus; fi
	$(MAKE) install_plugins

install_bonus:dummy
	cd epeire && $(MAKE) install
	cd camtop && $(MAKE) install

install_plugins:dummy
	cd omom && $(MAKE) install_plugins
	cd plugins && $(MAKE) install_plugins


install_upto_toolhtml:
	cd options && $(MAKE) install
	cd okey && $(MAKE) install
	cd configwin && $(MAKE) install
	cd zoggy && $(MAKE) install
	cd ioxml && $(MAKE) install
	cd report && $(MAKE) install
	cd toolhtml && $(MAKE) install

# cleaning :
############
clean:dummy
	$(MAKE) TARGET=$@ iter
	$(RM) camtop/ocaml
	@if test "$(OCAMLDIR)" != ""; then $(MAKE) clean_bonus; fi
	$(MAKE) clean_doc


clean_bonus:dummy
	cd camtop && $(MAKE) clean
	cd epeire && $(MAKE) clean

distclean_bonus:dummy
	rm -fr epeire camtop

distclean: 
	$(MAKE) clean_doc
	$(MAKE) TARGET=$@ iter
	@if test "$(OCAMLDIR)" != ""; then $(MAKE) distclean_bonus; fi
	$(RM) config.* master.Makefile

iter:dummy
	cd options && $(MAKE) $(TARGET)
	cd okey && $(MAKE) $(TARGET)
	cd configwin && $(MAKE) $(TARGET)
	cd gpattern && $(MAKE) $(TARGET)
	cd ioxml && $(MAKE) $(TARGET)
	cd ocamlcvs && $(MAKE) $(TARGET)
	cd zoggy && $(MAKE) $(TARGET)
	cd mlchat && $(MAKE) $(TARGET)
	cd report && $(MAKE) $(TARGET)
	cd toolhtml && $(MAKE) $(TARGET)
	cd dbforge && $(MAKE) $(TARGET)
	cd cameleon && $(MAKE) $(TARGET)
	cd omom && $(MAKE) $(TARGET)
	cd plugins && $(MAKE) $(TARGET)

# Bonus, needs the OCaml sources compiled somewhere :
#####################################################
bonus: gtktop epeire

gtktop:dummy
	(cd camtop && $(MAKE))

epeire: dummy
	(cd epeire && $(MAKE) all)



# myself :
##########
master.Makefile: master.Makefile.in config.status
	./config.status

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

configure: configure.in
	autoconf 


dummy:
