#	$Id: Makefile,v 1.8 2007-11-27 23:07:22 chris_77 Exp $	
# ocaml-gnuplot/demos
# Copyright (C) Christophe TROESTLER

include ../Makefile.conf

OCAMLFLAGS 	= -I ../
OCAMLOPTFLAGS	= -I ../
WEBDIR		= ../../webpublishing
WEBDIRDOC	= $(WEBDIR)/Gnuplot

DEMOS_LIBS 	= parse_args.ml
DEMOS 		= $(wildcard ex*.ml)

PKGS 	= $(shell grep "requires" ../META.in | \
		sed -e "s/.*\"\([^\"]*\)\".*/\1/")
PKGS 	+= gnuplot
PKGS_CMA = $(addsuffix .cma, $(PKGS))

.PHONY: demos byte opt

demos: byte
byte: $(DEMOS:.ml=.exe)
opt: $(DEMOS:.ml=.com)

ex%.exe: ex%.ml ../gnuplot.cma $(DEMOS_LIBS:.ml=.cmo)
	$(OCAMLC) -o $@ $(OCAMLFLAGS) $(PKGS_CMA) $(DEMOS_LIBS:.ml=.cmo) $<
ex%.com: ex%.ml ../gnuplot.cmxa $(DEMOS_LIBS:.ml=.cmx)
	$(OCAMLOPT) -o $@ $(OCAMLOPTFLAGS) $(PKGS_CMA:.cma=.cmxa) \
	  $(DEMOS_LIBS:.ml=.cmx) $<

parse_args.cmi: parse_args.mli ../gnuplot.cmi
parse_args.cmo: parse_args.ml parse_args.cmi ../gnuplot.cma
parse_args.cmx: parse_args.ml parse_args.cmi ../gnuplot.cmxa

# Caml general dependencies
.SUFFIXES: .ml .mli .cmo .cmi .cmx
%.cmi: %.mli
	$(OCAMLC) $(OCAMLFLAGS) -c $<
%.cmo: %.ml
	$(OCAMLC) $(OCAMLFLAGS) -c $<
%.cma: %.cmo
	$(OCAMLC) $(OCAMLFLAGS) -a -o $@  $^
%.cmx: %.ml
	$(OCAMLOPT) $(OCAMLOPTFLAGS) -c $<
%.cmxa: %.cmx
	$(OCAMLOPT) $(OCAMLOPTFLAGS) -a -o $@  $^

.PHONY: depend
depend: .depend
.depend: $(SOURCES) $(wildcard *.mli)
	$(OCAMLDEP) $^ > .depend

include .depend

########################################################################

.PHONY: clean dist-clean
clean:
	@ rm -f *~ .*~ *.{o,a} *.cm[aiox] *.cmxa *.annot *.exe *.com
	@ rm -f ex*-*.{png,plt,eps,ps,dat}

dist-clean: clean
	rm .depend
