# Phony targets are scoped, so you probably want to declare them first.

.PHONY: all install uninstall test doc tar clean web


VERSION = $(nth 1, $(shell grep @version src/delimited_overloading.mli))

TARBALL="/tmp/pa_do-$(VERSION).tar.gz"

########################################################################
# OCaml configuration.

# This project requires ocamlfind (default - false).
#
USE_OCAMLFIND = false
#
# 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 +=

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

OCAMLFLAGS += -annot
OCAMLCFLAGS += -g
# OCAMLOPTFLAGS +=
# OCAML_LINK_FLAGS +=
# OCAML_BYTE_LINK_FLAGS +=
# OCAML_NATIVE_LINK_FLAGS +=

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

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

# OCaml native plugin

%.cmxs: %.cmx
    section rule
        if $(not $(NATIVE_ENABLED))
            err. =
                extends $(UnbuildableException)
                message = $(string $"You are trying to build OCaml native code file: "%.cmxs$"
However, the NATIVE_ENABLED flag is not set.
Include the following definition in your OMakefile
if you really want to build this file.
       NATIVE_ENABLED = true")
                target = $(file %.cmxs)
            raise $(err)
        else
            %.cmxs: %.cmx
                $(OCamlOpt) -shared -o $@ $<


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

# FILES[] =
#    file1
#    file2
#
# PROGRAM =
# OCAML_LIBS +=
# OCAML_CLIBS +=
# OCAML_OTHER_LIBS +=
# OCAML_LIB_FLAGS +=
#
# .DEFAULT: $(OCamlProgram $(PROGRAM), $(FILES))

.STATIC:
  OCAML_VERSION = $(split ".", $(shell $(OCAMLC) -version))
  # Native Dynlink is supported since OCaml 3.11.0:
  DYNLINK_SUPPORTED = $(and $(ge $(nth 0, $(OCAML_VERSION)), 3), \
			$(ge $(nth 1, $(OCAML_VERSION)), 11))
  OCAMLDOC_OPT_EXISTS = $(CheckProg ocamldoc.opt)
  OCAMLDOC = $(if $(OCAMLDOC_OPT_EXISTS), ocamldoc.opt, ocamldoc)

# "Force" a tag to be defined for each released tarball
tar:
  bzr export $(TARBALL) -r "tag:$(VERSION)"
  @echo "Created tarball '$(TARBALL)'."

# Subdirectories.

.SUBDIRS: src tests doc examples

# force the .STATIC rule to be re-evaluated (for e.g. change the OCaml version)
clean:
  rm -f $(glob *.omc *~)
