########################################################################
# 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 OMakeroot file.
# You will not normally need to modify this file.
# By default, your changes should be placed in the
# OMakefile in this directory.
#
# If you decide to modify this file, note that it uses exactly
# the same syntax as the OMakefile.
#

#
# Include the standard installed configuration files.
# Any of these can be deleted if you are not using them,
# but you probably want to keep the Common file.
#
open build/C
open build/OCaml
open build/LaTeX

# Other C libraries - used when making .cma or .cmxa libraries.
# Should be of the form '-cclib -lpam' or such like
OTHER_CLIBS=

#
# The command-line variables are defined *after* the
# standard configuration has been loaded.
#
DefineCommandVars()

OCamlLibraryClib(name, files, clibs) =
   name = $(file $(name))

   OFILES   = $(addsuffix $(EXT_OBJ), $(files))
   CMOFILES = $(addsuffix .cmo, $(files))
   CMXFILES = $(addsuffix .cmx, $(files))

   CLIB      = $(file $(name)$(EXT_LIB))
   BYTELIB   = $(file $(name).cma)
   NATIVELIB = $(file $(name).cmxa)

   __BYTE_CLIBS = $(addsuffix $(EXT_LIB), $(clibs))
   __NATIVE_CLIBS = $(addsuffix $(EXT_LIB), $(clibs))
   _BYTE_CLIBS = $(addprefix $(absname $(CWD))/, $(__BYTE_CLIBS))
   _NATIVE_CLIBS = $(addprefix $(absname $(CWD))/, $(__NATIVE_CLIBS))
   BYTE_CLIBS = $(mapprefix -cclib, $(_BYTE_CLIBS))
   NATIVE_CLIBS = $(mapprefix -cclib, $(_NATIVE_CLIBS))

   #
   # Link commands
   #
   $(BYTELIB): $(CMOFILES) $(_BYTE_CLIBS)
        $(OCAMLFIND) $(OCAMLLINK) $(LAZY_OCAMLFINDFLAGS) $(OCAMLFLAGS) $(OCAMLCFLAGS) \
                $(OCAML_LIB_FLAGS) -a -o $@ $(OCamlLinkSort $(CMOFILES)) -custom $(BYTE_CLIBS) $(OCAML_LINK_FLAGS) $(OTHER_CLIBS)

   $(NATIVELIB) $(CLIB): $(CMXFILES) $(OFILES) $(_NATIVE_CLIBS)
        $(OCAMLFIND) $(OCAMLOPTLINK) $(LAZY_OCAMLFINDFLAGS) $(OCAMLFLAGS) $(OCAMLOPTFLAGS) \
                $(OCAML_LIB_FLAGS) -a -o $(NATIVELIB) $(OCamlLinkSort $(CMXFILES)) $(NATIVE_CLIBS) $(OTHER_CLIBS) 

   return $(array $(if $(NATIVE_ENABLED), $(NATIVELIB)), $(if $(NATIVE_ENABLED), $(CLIB)), $(if $(BYTE_ENABLED), $(BYTELIB)))

#
# The documentation generator
#
OCAMLDOC = ocamldoc

#
# Generation of documentation from .ml or .mli files
#
OCamlDoc(name, modules, type) =
    private.CMIFILES = $(addsuffix .cmi, $(modules))
    .PHONY: doc
    dir = $(ROOT)/doc
    doc: $(CMIFILES)
        python $(ROOT)/doc/doc.py $(dir) $(name) $(type) "$(modules)" "$(OCAMLINCLUDES)" "$(OCAMLPACKS)" "$(OCAML_LIBS)"

OCamlDocProgram(name, modules) =
	OCamlDoc($(name), $(modules), "program")
	
OCamlDocLibrary(name, modules) =
	OCamlDoc($(name), $(modules), "library")

#
# Use Camlp4
#
UseCamlp4(packs, files) =
       OCAMLPACKS     += $(packs)
       OCAMLFINDFLAGS += -syntax camlp4o
       $(addsuffix .cmx, $(files)):
       $(addsuffix .o, $(files)):
       $(addsuffix .cmi, $(files)):
       $(addsuffix .cmo, $(files)):
       
#
# Include the OMakefile in this directory.
#
.SUBDIRS: .

