#
# $Id: Makefile,v 1.5 1999/12/05 13:47:44 lindig Exp $
# 
# Targets
#
# all		bytecode binaries (default)
# clean		removes intermediate files
# realclean	removes additionally binaries and libraries
# dist		creates source file tar 
# depend	updates dependencies
# install	Install stuff
# uninstall     Remove installed files
#

# basic variables and rules for compiling Objective Caml projects
# are imported from the top level to ensure consistency.

SHELL =		/bin/sh

# -----------------------------------------------------------------------------
# default target
# -----------------------------------------------------------------------------

all::		ALWAYS

# -----------------------------------------------------------------------------
# Name for binaries and tar files
# -----------------------------------------------------------------------------

NAME =		ocaml-mysql

# -----------------------------------------------------------------------------
# Include all system dependent settings which are determined by
# autoconf.  The main part of the Makefile is thus not autoconf
# generated which makes software development easier:  otherwise every
# change to the Makefile must go into Makefile.in and then a new
# Makefile must be generated.
# -----------------------------------------------------------------------------

# -----------------------------------------------------------------------------
# All paths like $(prefix) are defined in configure
# -----------------------------------------------------------------------------

include config

# -----------------------------------------------------------------------------
# OCaml compiler flags
# -----------------------------------------------------------------------------

INCLUDE =	
CFLAGS = 	$(INCLUDE) -labels -g -pp camlp4o
# OFLAGS = 	$(INCLUDE) -labels -unsafe -noassert -labels
# OFLAGS = 	$(INCLUDE) -labels -verbose
OFLAGS = 	$(INCLUDE) -labels -pp camlp4o
DFLAGS =        $(INCLUDE) -pp camlp4o
#
# compilation rules
#

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

.mli.cmi:
		$(CAMLC) $(CFLAGS) -c $<
.ml.cmo:
		$(CAMLC) $(CFLAGS) -c $<
.ml.cmx:	
		$(CAMLOPT) $(OFLAGS) -c $<

# -----------------------------------------------------------------------------
# C compiler flags (autoconf detected settings are in config)
# -----------------------------------------------------------------------------

.SUFFIXES:	.c .o .lo

CCINC =      	$(CAMLINC) $(MYSQLINC)
LDLIB =       	$(MYSQLLIB)


LD	=	$(CC) $(CCFLAGS) $(LDLIB)

.c.o:
		$(CC) $(CCFLAGS) $(CCINC) -c $<

.c.lo:
		$(CC) $(CCFLAGS) $(CCINC) -fPIC -o $@ -c $<


# -----------------------------------------------------------------------------
# enter modules (.ml), interfaces (.mli) and generated modules below 
# -----------------------------------------------------------------------------

# .ml file generated by some tool like lex and yacc.

GENERATED = 	

clean::;	rm -f $(GENERATED)

# interfaces and modules. Modules from GENERATED must be repeared because 
# the ML variable defines also the link order.

MLI =		mysql.mli

ML = 	  	mysql.ml	\
		demo.ml		\


CMO =           $(ML:.ml=.cmo)
CMX =		$(CMO:.cmo=.cmx)
OBJ =		$(CMO:.cmo=.o)
CMI =		$(CMO:.cmo=.cmi) $(MLI:.mli=.cmi)

clean::; 	rm -f $(CMO) $(CMX) $(OBJ) $(CMI)


# -----------------------------------------------------------------------------
# Targets
# -----------------------------------------------------------------------------

all:: mysqlstatic.cma mysqltop demo.cmo

opt: mysql.cmxa

ocmysql.o: config.h

mysqlstatic.cma: mysql.cmo libocmysql.a
	$(CAMLLINK) -a -custom -o mysqlstatic.cma mysql.cmo -cclib -locmysql \
	-cclib $(MYSQLLIB) -cclib -lmysqlclient 

mysqldyn.cma: mysql.cmo dllocmysql.so
	$(CAMLLINK) -a -o mysqldyn.cma mysql.cmo -dllib -locmysql \
	-cclib $(MYSQLLIB) -cclib -lmysqlclient 

mysql.cmxa: mysql.cmx libocmysql.a
	$(CAMLOLINK) -a -o mysql.cmxa mysql.cmx -cclib -locmysql \
	-cclib $(MYSQLLIB) -cclib -lmysqlclient

dllocmysql.so: ocmysql.lo
	$(CC) -shared -o dllocmysql.so ocmysql.lo

libocmysql.a: ocmysql.o
	ar rc libocmysql.a ocmysql.o
	ranlib libocmysql.a

mysqltop: mysqlstatic.cma
	$(CAMLTOP) -custom -o mysqltop mysqlstatic.cma -cclib -L.

install: mysqlstatic.cma mysql.cmxa libocmysql.a mysql.a mysql.cmi mysql.mli META
	$(CAMLFIND) install mysql $^
	$(INSTALL) mysqltop $(bindir)

uninstall:
	$(CAMLFIND) remove mysql
	rm -f $(bindir)/mysqltop

clean::;
	rm -f ocmysql.o dllocmysql.so libocmysql.a mysql.cmo mysqltop mysql.cmx mysql.o mysql.cmi \
	 mysql.cma mysql.cmxa mysql.a

# realclean includes clean'ing
realclean::	clean


# -----------------------------------------------------------------------------
# cmo: just make all .cmo files (for interactive use in the toplevel)
# -----------------------------------------------------------------------------

cmo:		$(CMO)

# -----------------------------------------------------------------------------
# autoconf 
# -----------------------------------------------------------------------------

clean::;	rm -f config.log config.status
		rm -f config.cache

configure:	configure.in
		autoconf

# -----------------------------------------------------------------------------
# update version
# -----------------------------------------------------------------------------

version:
		etc/shtool version -n $(NAME) VERSION


# -----------------------------------------------------------------------------
# documentation
# -----------------------------------------------------------------------------

interface.tex: mysql.mli
	ocamlweb --noweb --no-preamble --no-index $< > $@

mysql.html: mysql.tex interface.tex
	hevea -o mysql.html ocamlweb.sty mysql.tex

README: mysql.tex interface.tex
	hevea -o README ocamlweb.sty -text mysql.tex

mysql.dvi: mysql.tex interface.tex
	latex mysql.tex

doc man:	mysql.dvi mysql.html README

realclean::;	rm -f $(NAME).dvi $(NAME).pdf $(NAME).txt README $(NAME).html


# -----------------------------------------------------------------------------
# build a source/binary distribution
# -----------------------------------------------------------------------------


FILES.SRC:	ALWAYS
		find .  -follow						\
			   -name '*.in'				-print	\
			-o -name "META"				-prune  \
			-o -name "config.h"			-print  \
			-o -name 'config.*'			-prune	\
			-o -name "config"			-prune  \
			-o -name '*.a' 				-prune	\
			-o -name "*.so"				-prune  \
			-o -name '*.log'			-prune	\
			-o -name '*.aux'			-prune	\
			-o -name '*.haux'			-prune  \
			-o -name '*.o' 				-prune	\
			-o -name "*.lo"				-prune  \
			-o -name '*.cmi' 			-prune	\
			-o -name '*.cmo'			-prune 	\
			-o -name '*.cma'			-prune 	\
			-o -name '*.cmxa'			-prune 	\
			-o -name '*.cmx'			-prune  \
			-o -name '*.tar*'			-prune  \
			-o -name '*.tmp*'			-prune  \
			-o -name 'mysqltop'			-prune  \
                        -o -name 'FILES.*'                      -prune  \
			-o -name '$(NAME)'                      -prune  \
                        -o -name '$(NAME).opt'                  -prune  \
			-o -name '*~'				-prune  \
		     	-o -type f -print				\
			| sort | 			\
		sed 	-e 's|^\./|$(NAME)-$(VERSION)/|'  > $@


DIST =          $(NAME)-$(VERSION).tar.gz

dist:            configure $(DIST)

$(DIST):	FILES.SRC
		ln -s . $(NAME)-$(VERSION) 
		tar cvhf - `cat FILES.SRC` | gzip > $@
		rm -f $(NAME)-$(VERSION)
		rm -f FILES.SRC 

WWW =		$(HOME)/www/lindig/software

www:		dist
		cp $(DIST) 	$(WWW)/download
		cp readme.html	$(WWW)/mysql-readme.html
		cp mysql.html	$(WWW)
		cp ocaml.css	$(WWW)

# -----------------------------------------------------------------------------
# update dependencies 
# -----------------------------------------------------------------------------

# all code created by generators must be there before dependencies
# are calculated!


depend DEPEND:	$(GENERATED)
		$(CAMLDEP) $(DFLAGS) *.mli *.ml > DEPEND

#
# dummy target
#

ALWAYS:;

# -----------------------------------------------------------------------------
# dependencies - include manually if your make does not support include
# -----------------------------------------------------------------------------

-include DEPEND

