# Makefile for the MetaOCaml tutorial

OCAMLC=metaocamlc
OCAMLOPT=ocamlopt
MOCAMLOPT=metaocamlopt
MOCAML=metaocaml

.SUFFIXES: .ml .mli .cmo .cmi .cmx .tex .pdf

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

clean::
	rm -f *.cm[ixo] *.[oa] *~ a.out

# All tests
tests: power_rts powerf_rts filter complex mvmult_full run_image

# Power example
power_rts: power_rts.ml square.cmx
	$(MOCAMLOPT) -o $@ square.cmx power_rts.ml
	./$@
	rm -f power_rts

clean:: 
	rm -f power_rts

powerf_rts: powerf_rts.cmo
	$(OCAMLC) -o $@ $@.cmo
	./powerf_rts

clean:: 
	rm -f powerf_rts

square.cmo: square.ml
square.cmx: square.ml

pw7.cmo: pw7.ml

clean:: 
	rm -f pw7.ml

filter:	filter.cmo
	$(OCAMLC) -o $@ filter.cmo 
	./$@
	rm -f $@

# Complex vectors
cmplx.cmi: cmplx.mli

# Shonan challenges
complex.cmo: complex.ml ring.cmo vector.cmo cmplx.cmi

complex: complex.cmo ring.cmo vector.cmo
	$(OCAMLC) -o $@ ring.cmo vector.cmo complex.cmo 
	./$@
	rm -f $@

clean:: 
	rm -f complex

mvmult_full.cmo: mvmult_full.ml ring.cmo vector.cmo

mvmult_full: mvmult_full.cmo
	$(OCAMLC) -o $@ ring.cmo vector.cmo mvmult_full.cmo 
	./$@
	rm -f $@

# DSL for image processing
.PHONY: image

image: grayimg.cmi grayimg.cmo \
	imgdsl.cmi img_ex.cmo \
	img_interp.cmo img_comp.cmo \
	grayimg.cmx

run_image: image
	echo -n '#use "img_trans.ml";;' | $(MOCAML) 

clean:: 
	rm -f run_image

grayimg.cmo: grayimg.cmi

# Offshoring
.PHONY: offshoring run_offshoring run_offshoring_ext run_addv_ml

offshoring: c_ast.cmi c_pp.cmo file_stub.cmo offshore_pp.cmo

run_offshoring:
	metaocaml c_pp.cmo offshore_pp.cmo offshore_simple.ml

run_offshoring_ext:
	metaocaml c_pp.cmo offshore_pp.cmo file_stub.cmo offshore_ext.ml

run_offshoring_ext_c:
	gcc -Wall -W -o $@ offshore_ext_gen.c
	./$@
	rm -f $@

run_addv_ml:
	metaocaml c_pp.cmo offshore_pp.cmo addv.ml

run_addv:
	gcc -Wall -W -o $@ addv_gen.c
	./$@
	rm -f $@

# Tagless-final embedding
.PHONY: tf

tf: c_ast.cmi c_pp.cmo cde.cmi cde_ex.cmi c_cde.cmo

