# Uses GNU make extensions

modules=tok deftab parse opt val io intp val2 io2 intp2 batch repl

target=conser

libs=str

tar=$(modules:%=%.ml) $(modules:%=%.mli) $(target:%=%.ml) \
	conser.html mail2.txt Makefile README COPYING \
	conser.java conser.hs \
	cat.cons hello.cons rot13.cons quine.cons \
	hq9+.cons brainfuck.cons unlambda.cons

$(target): $(modules:%=%.cmo) $(target).cmo
	ocamlc -o $@ $(libs:%=%.cma) $+

x$(target) : $(modules:%=%.cmx) $(target).cmx
	ocamlopt -o $@ $(libs:%=%.cmxa) $+

$(target).cmo: $(target).ml $(modules:%=%.cmi)
	ocamlc -c $<

$(target).o $(target).cmx: $(target).ml $(modules:%=%.cmi)
	ocamlopt -c $<

$(modules:%=%.cmi): $(modules:%=%.mli)

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

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

%.o %.cmx: %.ml %.cmi
	ocamlopt -c $<

clean:
	$(RM) core a.out *.cmi *.cmo *.cmx *.o *~ $(target) x$(target) *.tar.gz

snapshot:
	DIR=$(target)-`date +%Y%m%d`; \
	mkdir $$DIR; \
	ln $(tar) $$DIR; \
	tar cfz $$DIR.tar.gz $$DIR; \
	$(RM) -r $$DIR
