.PHONY: clean
FILES[] =
	module
	binding
	closureTrans
	bytes
	label
	abc
	cpool
	revList
	instruction
	iSpec
	asm
	codegen
	override
	main

CPPFLAGS+=-I../type

PROGRAM=../codegen

OCAMLOPT   = ocamlopt -for-pack $(capitalize $(basename $(PROGRAM)))
OCAMLOPTLINK= ocamlopt

OCamlProgram(gen_inst,gen_inst)
OCamlLibrary(codegen, $(FILES))
MyOCamlPackage($(PROGRAM), $(FILES))

OUNIT_LIBS+=astUtil

OUnitTest(bytes        , bytes label)
OUnitTest(abc          , abc label bytes)
OUnitTest(revList      , revList)
OUnitTest(cpool        , cpool revList)
OUnitTest(closureTrans , closureTrans module)
OUnitTest(asm          , asm cpool revList bytes)
OUnitTest(codegenExpr  , codegen label iSpec)
OUnitTest(codegenStmt  , codegen label iSpec)
OUnitTest(codegenClass , codegen label iSpec)
OUnitTest(override     , override binding module)
OUnitTest(module       , module)
OUnitTest(binding      , binding module)

.DEFAULT:

match_body.h: gen_inst$(EXE) instruction.txt
    ./gen_inst$(EXE) -m < instruction.txt > $@

opcode.h: gen_inst$(EXE) instruction.txt
    ./gen_inst$(EXE) -t < instruction.txt > $@

.SCANNER: instruction.ml : instruction.mlp
    grep "#include \"" $< | sed 's/.*"\(.*\)".*/'$@': \1/'

clean:
	ocaml-clean opcode.h match_body.h instruction.ml gen_inst$(EXE)
