#
#   This file is part of SKS.  SKS 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 (at your option) 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 
#
# $Id: Makefile,v 1.7 2003/10/10 18:09:01 yminsky Exp $

CINCLUDES=-I`ocamlc -where` $(BDBINCLUDE)
CC=gcc
CXX=g++
CFLAGS=-O3 -Werror-implicit-function-declaration $(CINCLUDES) $(BDBLIB) -I .
CXXFLAGS=-O3 $(CINCLUDES) $(BDBLIB) -I .

MKLIB=ocamlmklib
RANLIB=ranlib
OCAMLDEP=ocamldep $(PP)
CAMLINCLUDE=
COMMONCAMLFLAGS= $(CAMLINCLUDE) $(PP) #-thread 
CAMLLIBS=unix.cma str.cma mylibs.cma 
OCAMLFLAGS=$(COMMONCAMLFLAGS) -g 
OCAMLOPTFLAGS=$(COMMONCAMLFLAGS) -inline 40 

ifndef LIBDB
LIBDB=-ldb-4.1
endif

COBJS = bdb_stubs.o

ocextr: ocextr.ml
	$(OCAMLOPT) -o ocextr ocextr.ml

libbdb.a: $(COBJS)
	$(MKLIB) -custom -o bdb $(COBJS)

bdb_stubs.o: bdb_stubs.h bdb_stubs.c

bdb.ml: ocextr bdb_stubs.c
	./ocextr bdb_stubs.c > bdb.ml

bdb.cma: bdb.cmo libbdb.a
	$(MKLIB) -custom -o bdb bdb.cmo -lbdb $(LIBDB)

bdb.cmxa: bdb.cmx libbdb.a
	$(MKLIB) -custom -o bdb bdb.cmx -lbdb $(LIBDB)

bdbcaml: bdb.cma
	ocamlmktop -o bdbcaml -custom unix.cma bdb.cma $^

partialclean:
	rm -f *.cm*

clean: partialclean
	rm -f *.a *.o

install:
	cp libmldb.a $(LIBDIR)/libmldb.a
	cd $(LIBDIR); $(RANLIB) libmldb.a
	cp db.cma db.cmi db.mli $(LIBDIR)

installopt:
	cp db.cmx db.cmxa db.a $(LIBDIR)
	cd $(LIBDIR); $(RANLIB) db.a



# Common rules
.SUFFIXES: .ml .mli .cmo .cmi .cmx

.ml.o:
	$(OCAMLOPT) -output-obj $(OCAMLOPTFLAGS) $< 

.cpp.o:
	$(CXX) $(CXXFLAGS) -c $<

.c.o:
	$(CC) $(CFLAGS) -c $< 

.c.obj:
	$(CC) $(CFLAGS) /c $< 

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

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

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

# Dependencies
#dep:
#	$(OCAMLDEP) $(INCLUDES) *.ml *.mli > .depend

#include .depend


# DO NOT DELETE
