.PHONY: all clean
.PRECIOUS: %.ml %.mli %.cmi %.cmo

vpath %.mll ../../msort
vpath %.mly ../../msort
vpath %.ml ../../msort
vpath %.mli ../../msort

M := U DepParser DepLexer Dep Dat Main
CMI := $(addsuffix .cmi, $(M))
CMO := $(addsuffix .cmo, $(M))
D := $(addsuffix .d, $(M))
DI := $(addsuffix .di, $(M))

all: msort

clean:
	rm -f msort $(CMI) $(CMO) $(D) $(DI)
	rm -f DepParser.ml DepParser.mli DepLexer.ml

msort: $(CMO)
	ocamlc -o msort $(CMO)

%.cmi: %.mli
	ocamlc -c -o $@ $<

%.cmo: %.ml %.cmi
	ocamlc -c -o $@ $<

%.mli %.ml: %.mly
	ocamlyacc -b$* $<

%.ml: %.mll
	ocamllex -o $@ $<

%.d: %.ml
	../../ocamldep -I ../../msort $< > $@

%.di: %.mli
	../../ocamldep -I ../../msort $< > $@

# ocamldep only knows about Ocaml files,
# make sure to generate all the needed ones before
# computing the dependencies between them.
$(DI): DepParser.mli

DepLexer.cmo: DepLexer.cmi
Dep.cmo: DepLexer.cmo

include $(D) $(DI)
