BIN_DIR = /usr/local/bin
REQUIRES = gdome2
PREDICATES =
OCAMLOPTIONS = -package "$(REQUIRES)" -predicates "$(PREDICATES)"
OCAMLC = ocamlfind ocamlc $(OCAMLOPTIONS) -g
OCAMLOPT = ocamlfind ocamlopt $(OCAMLOPTIONS)
OCAMLDEP = ocamldep

LIBRARIES = $(shell ocamlfind query -recursive -predicates "byte $(PREDICATES)" -format "%d/%a" $(REQUIRES))
LIBRARIES_OPT = $(shell ocamlfind query -recursive -predicates "native $(PREDICATES)" -format "%d/%a" $(REQUIRES))

all: $(TESTOBJS) test
opt: $(TESTOBJS:.cmo=.cmx) test.opt

DEPOBJS = test.ml

TESTOBJS = test.cmo

depend:
	$(OCAMLDEP) $(DEPOBJS) > .depend

test: $(TESTOBJS) $(LIBRARIES)
	$(OCAMLC) -linkpkg -o test $(TESTOBJS)

test.opt: $(TESTOBJS:.cmo=.cmx) $(LIBRARIES_OPT)
	$(OCAMLOPT) -linkpkg -o test.opt $(TESTOBJS:.cmo=.cmx)

.SUFFIXES: .ml .mli .cmo .cmi .cmx
.ml.cmo: $(LIBRARIES)
	$(OCAMLC) -c $<
.mli.cmi: $(LIBRARIES)
	$(OCAMLC) -c $<
.ml.cmx: $(LIBRARIES_OPT)
	$(OCAMLOPT) -c $<

clean:
	rm -f *.cm[iox] *.o test test.opt

install:
	cp test test.opt $(BIN_DIR)

uninstall:
	rm -f $(BIN_DIR)/test $(BIN_DIR)/test.opt

.PHONY: install uninstall clean

include .depend
