[Omake] Local OCaml libraries with C code

Alain Frisch alain.frisch at lexifi.com
Mon Oct 1 07:34:58 PDT 2007


Hello,

How do people deal with local OCaml libraries that contain C code in
OMake?  By local, I mean local to the current project, without findlib
support.

To build such a library, one can do something like:

OCAMLFLAGS = -cclib -lmylib
OCAMLCFLAGS = -custom
OCAMLLIBS = $(OCamlLibrary ocaml_lib, ...)
$(OCAMLLIBS): libmylib$(EXT_LIB)

But then, every time one links a program against this library, one must
add an explicit dependency to libmylib$(EXT_LIB) (and extend
OCAMLINCLUDES with the directory of this file). The reason is that even
if we tell OMake that ocaml_lib.cma depends on libmylib$(EXT_LIB), this
is not really the case: if libmylib$(EXT_LIB) changes, ocaml_lib.cma
will not, but the program must be re-linked.

Currently what I do is to use a global map to store those implicit
dependencies:

IMPLICIT_OCAML_CLIBS = $(Map)

AddImplicitCLib(dir, cma, libs) =
   libs = $(file $(add-wrapper $(dir)/, $(EXT_LIB), $(libs)))
   IMPLICIT_OCAML_CLIBS = $(IMPLICIT_OCAML_CLIBS.add $(file
$(dir)/$(cma)), $(libs))
   export

GetAllImplicitCLibs(cmas) =
   ILIBS=
   foreach(l, $(cmas))
     try
       ILIBS += $(IMPLICIT_OCAML_CLIBS.find $(file $(l)))
       export
     catch Exception(v)
     export
   return $(ILIBS)


The function OCamlProgram is extended with:

    protected.ICLIBS = $(GetAllImplicitCLibs $(MLFI_LIBS))
    MLFIINCLUDES += $(dir $(set $(dirof $(ICLIBS))))

and ICLIBS is added to the dependencies $(BYTEPROG) and $(OPTPROG).

Now, in the root OMakefile, I have a sequence of calls to
AddImplicitCLib, like:

AddImplicitCLib($(ROOT)/mylibdir, ocaml_lib, libmylib)


This seems to work, though I'd prefer to put this call to
AddImplicitCLib in the directory where the library is, not in the root
of the project. (This does not work because of scoping.)

Anyway, I'd like to hear how other people would deal with the case of
Caml libraries that depend on C libraries.


   Alain




More information about the Omake mailing list