#  Makefile
#
#  (c) Copyright 2005, INRIA [Francesco Zappa Nardelli]
#
#  Redistribution and use in source and binary forms, with or without
#  modification, are permitted provided that the following conditions are met:
#
#  1. Redistributions of source code must retain the above copyright notice,
#  this list of conditions and the following disclaimer.
#  2. Redistributions in binary form must reproduce the above copyright
#  notice, this list of conditions and the following disclaimer in the
#  documentation and/or other materials provided with the distribution.
#  3. The names of the authors may not be used to endorse or promote products
#  derived from this software without specific prior written permission.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
#  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
#  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
#  NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
#  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
#  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
#  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
#  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 

# Where to install the library.
INSTALLDIR=`$(OCAMLC) -where`

# Flags for the C compiler.
CFLAGS=-O 

### End of configuration section

OCAMLRUN=ocamlrun
OCAMLC=ocamlc -g
OCAMLOPT=ocamlopt
OCAMLDEP=ocamldep
MKLIB=ocamlmklib 
OCAMLDOC=ocamldoc

C_OBJS= fresh.o\
        hashtable_cwc22.o\
        hashtable_itr_cwc22.o

CAML_OBJS=freshness.cmo

all: libfreshness.a freshness.cmi freshness.cma 

allopt: libfreshness.a freshness.cmi freshness.cmxa 

libfreshness.a: $(C_OBJS)
	$(MKLIB) -o freshness $(C_OBJS) 

freshness.cma: $(CAML_OBJS)
	$(MKLIB) -o freshness $(CAML_OBJS) 

freshness.cmxa: $(CAML_OBJS:.cmo=.cmx)
	$(MKLIB) -o freshness $(CAML_OBJS:.cmo=.cmx) 

install:
	cp freshness.cmi freshness.cma freshness.mli $(INSTALLDIR)
	cp libfreshness.a $(INSTALLDIR)
	if test -f dllfreshness.so; then cp dllfreshness.so $(INSTALLDIR); fi
	if test -f freshness.cmxa; then cp freshness.cmxa freshness.cmx freshness.a $(INSTALLDIR); fi

test: test.byt
	CAML_LD_LIBRARY_PATH="." $(OCAMLRUN) ./test.byt

test.byt: libfresh.a freshness.cma test.ml
	$(OCAMLC) -o test.byt freshness.cma test.ml

# doc: FORCE
#        cd doc; $(OCAMLDOC) -html -I .. ../cryptokit.mli

FORCE:

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

.mli.cmi:
	$(OCAMLC) -c $(COMPFLAGS) $<

.ml.cmo:
	$(OCAMLC) -c $(COMPFLAGS) $<

.ml.cmx:
	$(OCAMLOPT) -c $(COMPFLAGS) $<

.c.o:
	$(OCAMLC) -c -ccopt "$(CFLAGS)" $<

clean::
	rm -f *.cm* *.o *.a *.so *~ *.byt

.depend:
	gcc -MM *.c > .depend
	$(OCAMLDEP) *.mli *.ml >> .depend

include .depend
