.PHONY: clean doc

################################################
#
# This project requires ocamlfind
#
USE_OCAMLFIND = true

OCAMLPACKS[] =
     extlib
     str


if $(not $(OCAMLFIND_EXISTS))
   eprintln('This project requires ocamlfind, but is was not found.')
   eprintln('You need to install ocamlfind and run "omake --configure".')
   exit 1

#
# Include path
#


#
# Compile native or byte code?
#
NATIVE_ENABLED = $(OCAMLOPT_EXISTS)
BYTE_ENABLED = true

#
# Various options
#
#OCAMLFLAGS    +=
OCAMLPPFLAGS   += -pp 'camlp4o'
OCAMLDEPFLAGS  += $(OCAMLPPFLAGS)


################################################
# Build an OCaml program
#

FILES[] =
	abc
	asm
	ast
	bytes
	lisp
	node
	bindCheck
	closureTrans
	closTrans
	codegen
	cpool
	instruction
	moduleTrans
	label
	lexer
	parsec
	sexp
	pSet
	tuple
	varResolve
	interCode

OCAMLINCLUDES += ../../base/
OCAML_LIBS += ../../base/base

PROGRAM = habc-scm
# OCAML_OTHER_LIBS +=

.DEFAULT: habc-scm$(EXE)

OCamlProgram($(PROGRAM), main $(FILES))
OCamlLibrary($(PROGRAM), $(FILES))

doc :
	ocamldoc -html $(OCAMLPPFLAGS) -v -d ../html/ *.mli
################################################
#
# additonal rules
#

%.ml: %.mlp match_body.ml opcode.ml
    @rm -f $@
    @echo "(* CAUTION: this is a generated file.  If you edit it, all changes will be lost! *)" > $@
    $(CPP) $*.mlp >> $@
    @chmod 444 $@


match_body.ml: ../util/instruction$(EXE) ../util/instruction.txt
    ../util/instruction$(EXE) -m < ../util/instruction.txt > $@
    ../util/instruction$(EXE) -s < ../util/instruction.txt >> $@

opcode.ml: ../util/instruction$(EXE) ../util/instruction.txt
    ../util/instruction$(EXE) -t < ../util/instruction.txt > $@

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