#*********************************************************************#
#                                                                     #
#                           Objective Caml                            #
#                                                                     #
#            Pierre Weis, projet Cristal, INRIA Rocquencourt          #
#                                                                     #
#  Copyright 2000 Institut National de Recherche en Informatique et   #
#  en Automatique.  All rights reserved.  This file is distributed    #
#  under the terms of the GNU Library General Public License.         #
#                                                                     #
#*********************************************************************#

VERSION=1.2

OLDVERSION=1.1
PACKAGEVERSIONFILE=graphics.ml
DOCVERSIONFILE=doc/graphps.tex

LIB = graphics.cma
LIBOPT = graphics.cmxa

SOURCES = graphics.ml
SOURCES1 = $(SOURCES:.mly=.ml)
SOURCES2 = $(SOURCES1:.mll=.ml)
OBJS = $(SOURCES2:.ml=.cmo)
OBJSOPT = $(SOURCES2:.ml=.cmx)

CAMLC = ocamlc
CAMLOPT = ocamlopt
CAMLDEP = ocamldep
CAMLLEX = ocamllex
CAMLYACC = ocamlyacc

WITHPSGRAPHICS = graphics.cma

all: lib libopt documentation
opt: allopt
allopt: libopt

lib: depend $(LIB)

$(LIB): $(OBJS)
	$(CAMLC) -a -o $(LIB) $(OBJS)

libopt: depend $(LIBOPT)

$(LIBOPT): $(OBJSOPT)
	$(CAMLOPT) -a -o $(LIBOPT) $(OBJSOPT)

documentation:
	cd doc; $(MAKE) all

install:
	- mkdir $(LIBDIR)/graphps
	cp -p $(SOURCES:.ml=.mli) $(LIBDIR)/graphps/
	cp -p $(OBJS) $(LIB) $(LIBDIR)/graphps/

installopt:
	- mkdir $(LIBDIR)/graphps
	cp -p $(SOURCES:.ml=.mli) $(LIBDIR)/graphps/
	cp -p $(OBJSOPT) $(LIBOPT) $(LIBDIR)/graphps/

# Just for $(PACKAGE) maintainers, when changing the package version number
version:
	for i in $(PACKAGEVERSIONFILE) $(DOCVERSIONFILE); do \
	echo $$i; \
	mv $$i $$i~; \
	sed -e '/ersion/s/$(OLDVERSION)/$(VERSION)/' $$i~ > $$i; \
	done
	

# Just for $(PACKAGE) maintainers, distribution of the software.
# Need an INSTALL file in the main directory.
# Need a doc directory where the documentation has been written,
# presumably in HTML with an index.html file. This directory is copied
# onto the WEB site of the package, as mentioned in $(WEBSITEDIR)
PACKAGE=graphps
VERSION=1.1
WEBSITEDIR=/net/pauillac/infosystems/www/$(PACKAGE)
FTPDIR=/net/pauillac/infosystems/ftp/cristal/caml-light/bazar-ocaml

distribute:
	rm -rf release
	rm -rf $(WEBSITEDIR)/*
	mkdir release
	cd release; cvs co bazar-ocaml/$(PACKAGE); \
	find . -name '.cvsignore' -print | xargs rm; \
	find . -name 'CVS' -print | xargs rm -rf; \
	cp -p bazar-ocaml/$(PACKAGE)/README bazar-ocaml/$(PACKAGE)/doc/; \
	cp -p bazar-ocaml/$(PACKAGE)/INSTALL bazar-ocaml/$(PACKAGE)/doc/; \
	cp -pr bazar-ocaml/$(PACKAGE)/doc/* $(WEBSITEDIR)/; \
	ln -s $(WEBSITEDIR)/index.html $(WEBSITEDIR)/eng.htm
	- chgrp -R caml $(WEBSITEDIR)
	- chmod -R g+w $(WEBSITEDIR)
	cd release; mv bazar-ocaml/$(PACKAGE) $(PACKAGE)-$(VERSION); \
	tar zcvf $(PACKAGE)-$(VERSION).tgz $(PACKAGE)-$(VERSION); \
	mv -f $(PACKAGE)-$(VERSION).tgz $(FTPDIR)
	rm -rf release

.SUFFIXES:
.SUFFIXES: .ml .mli .cmo .cmi .cmx .mll .mly

.ml.cmo:
	$(CAMLC) -c $<

.mli.cmi:
	$(CAMLC) -c $<

.ml.cmx:
	$(CAMLOPT) -c $<

.mll.cmo:
	$(CAMLLEX) $<
	$(CAMLC) -c $*.ml

.mll.cmx:
	$(CAMLLEX) $<
	$(CAMLOPT) -c $*.ml

.mly.cmo:
	$(CAMLYACC) $<
	$(CAMLC) -c $*.mli
	$(CAMLC) -c $*.ml

.mly.cmx:
	$(CAMLYACC) $<
	$(CAMLOPT) -c $*.mli
	$(CAMLOPT) -c $*.ml

.mly.cmi:
	$(CAMLYACC) $<
	$(CAMLC) -c $*.mli

.mll.ml:
	$(CAMLLEX) $<

.mly.ml:
	$(CAMLYACC) $<

clean:
	rm -f *.cm[iox] *.o *~ .*~ #*#
	rm -f .depend; $(CAMLDEP) *.mli *.ml > .depend
	rm -f $(LIB) $(LIBOPT)
	cd doc; $(MAKE) clean
	cd test; $(MAKE) clean

depend: $(SOURCES2)
	$(CAMLDEP) *.mli *.ml > .depend

include .depend
include Makefile.config
