########################################################################
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this file, to deal in the File without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the File, and to permit persons to whom the
# File is furnished to do so, subject to the following condition:
#
# THE FILE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE FILE OR
# THE USE OR OTHER DEALINGS IN THE FILE.

########################################################################
# The standard OMakefile.
# You will usually need to modify this file for your project.

# Delete this line once you have configured this file

########################################################################
# Subdirectories.
# You may want to include some subdirectories in this project.
# If so, define the subdirectory targets and uncomment this section.
#

# .SUBDIRS: src

########################################################################
# OCaml configuration.
# Delete this section if you are not building OCaml files.
#

################################################
# Configuration.  You may want to modify any of these configuration
# variables.
#

#
# This project requires ocamlfind (default - false).
#
# USE_OCAMLFIND = true
#
# OCAMLPACKS[] =
#    pack1
#    pack2
#
# 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
#
OCAMLINCLUDES += +labltk +camlp4

#
# Compile native or byte code? 
#
# The default values are defined as follows:
#
# NATIVE_ENABLED = $(OCAMLOPT_EXISTS)
# BYTE_ENABLED = $(not $(OCAMLOPT_EXISTS))
NATIVE_ENABLED = 1
BYTE_ENABLED = 1

#
# Various options
#
OCAMLFLAGS = -g -warn-error a -rectypes
#OCAMLCFLAGS   +=
#OCAMLOPTFLAGS +=
# OCAML_LINK_FLAGS +=
OCAML_BYTE_LINK_FLAGS += labltk.cma
OCAML_NATIVE_LINK_FLAGS += labltk.cmxa

OCAMLPPFLAGS += -pp "camlp4o pa_pl.cmo"
OCAMLDEPFLAGS += $(OCAMLPPFLAGS)

# we assume that all pa_pl dependencies have been met (compiled)
# otherwise we get deadlock (some_file -> pa_pl -> GrbProcs -> pa_pl)
.SCANNER: pa_%.cmo: pa_%.ml
    section
        println($"$@: ") # no dependencies

# pa_pl.ml opens GrbProcs.ml and therefore depends on it,
# so we have to bootstrap GrbProcs.ml beforehand
pa_%.cmo: pa_%.ml
    $(OCAMLC) $(OCAMLFLAGS) $(OCAMLCFLAGS) $(PREFIXED_OCAMLINCLUDES) -c GrbCommons.ml
    $(OCAMLC) $(OCAMLFLAGS) $(OCAMLCFLAGS) $(PREFIXED_OCAMLINCLUDES) -c GrbProcs.ml
    $(OCAMLC) $(OCAMLFLAGS) $(OCAMLCFLAGS) $(PREFIXED_OCAMLINCLUDES) -pp camlp4of.opt -c $<

# every file is preprocessed with pa_pl.cmo and
# therefore depends on it to be compiled
.SCANNER: scan-ocaml-%.ml: %.ml pa_pl.cmo

# OCAML_LIBS = src/libgrb

################################################
# Generated files
#
# Workaround for the fact that ocamldep does not pay attention to .mll
# and .mly files.
#
# OCamlGeneratedFiles(parser.ml lexer.ml)

################################################
# Build an OCaml library
#

# FILES[] =
#    file1
#    file2
#
# LIB = main
#
# .DEFAULT: $(OCamlLibrary $(LIB), $(FILES))

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

GRBFILES[] = 
    GrbCommons
    GrbGraphs
    GrbInput
    GrbProcs
    GrbTrPubencReplace
    GrbTrSimplifyIsOK
    GrbTrSimplifyIsEq1
    GrbTrSimplifyIsEq2
    GrbTrIsOKtoFalse
    GrbTrMistypedEdge
    GrbTrFuseTwoAndOr
    GrbTrFuseTwoLongOr
    GrbTrCombineNodesWithSameInputs
    GrbTrReduceNodeDims
    GrbTrCutSingleAndOr
    GrbTrPassOverId
    GrbTrDtoCOverId
    GrbTrMoveOverMux
    GrbTrMoveOverLMux
    GrbTrMoveDtoCMux
    GrbTrMoveDtoCLMux
    GrbTrApplyZero
    GrbTrDropUnit
    GrbTrProjTuple
    GrbTrRemoveDead
    GrbTrSymmEncReplace
    GrbTrDecombineNode
    GrbTrIsEqtoFalse
    GrbTranslate
    GrbGraphType
    GrbInteract
    GrbUDraw

GRBRUNFILES[] =
    $(GRBFILES)
    GrbDriver

OCamlLibrary(libgrb, $(GRBFILES))
OCamlProgram(grb, $(GRBRUNFILES))
.DEFAULT: grb.opt grb.run
