OCAMLC = ../ocamlc
RUNTEST = runtest

default: all 
all: test

test:	$(RUNTEST)
	./runtest_to_html.pl

readme:	$(RUNTEST) 
	./runtest_to_html.pl -f readme


io.cmo:
	$(OCAMLC) -c io.ml

.PHONY: clean depend all test

RUNTEST_ML_FILES = $(RUNTEST)_db.ml $(RUNTEST)_pretty.ml $(RUNTEST)_caml.ml $(RUNTEST)_shell.ml $(RUNTEST)_library.ml $(RUNTEST).ml
RUNTEST_MLI_FILES = $(RUNTEST)_db.mli $(RUNTEST)_pretty.mli $(RUNTEST)_shell.mli $(RUNTEST)_library.mli
RUNTESTOBJFILES = $(RUNTEST_ML_FILES:.ml=.cmo)


$(RUNTEST): $(RUNTESTOBJFILES) io.cmo
	$(OCAMLC) -thread -o $@ str.cma unix.cma threads.cma $+

clean:
	rm -rf $(RUNTEST) tmp out *.cmi *.cmo *.html tests_db/tests.db store

depend: .depend
DEPENDS = $(RUNTEST_ML_FILES) $(RUNTEST_MLI_FILES)
.depend: $(DEPENDS)
	$(CAMLDEP) $(DEPENDS) >$@-tmp
	mv $@-tmp $@

# rules
stem_of_mli_sources = $(RUNTEST_MLI_FILES:.mli=)
stem_of_ml_sources = $(RUNTEST_ML_FILES:.ml=)
ml_without_mli_sources = $(filter-out $(stem_of_mli_sources),$(stem_of_ml_sources))
ml_and_mli_sources = $(filter $(stem_of_mli_sources),$(stem_of_ml_sources))

cmo_of_ml_and_mli_sources = $(ml_and_mli_sources:=.cmo)
cmi_of_mli_sources = $(stem_of_mli_sources:=.cmi)
cmo_of_ml_without_mli_sources = $(ml_without_mli_sources:=.cmo)
cmi_of_ml_without_mli_sources = $(ml_without_mli_sources:=.cmi)

CAMLDEP=ocamldep

compile = $(OCAMLC) -thread -c str.cma

$(cmo_of_ml_and_mli_sources) : %.cmo : %.ml %.cmi
	$(compile) $<

$(cmi_of_mli_sources) : %.cmi : %.mli
	$(compile) $<

$(cmi_of_ml_without_mli_sources) : %.cmi : %.ml
	$(compile) $<

$(cmo_of_ml_without_mli_sources) : %.cmo : %.ml
	$(compile) $<

-include .depend
