A simple OCaml packager

This file describes this very simple OCaml packager.

Motivation and overview

Suppose you have a list of modules: A, B, C, and you which to package them in a module X. What one would like, regardless of how A, B, and C were compiled and whether they are inside deep directories or not, is to package them in a module X. This would allow an application, linked with the X library containing A B and C to write:
    open X
    A.f  1 2;
    B.g "adsf" "xxx";
This simple tool achieves this goal, at the loss of separate compilation of the X internals. The ideal solution is also supported, but it is slightly problematic with the current version of OCaml. First, I'll describe the ideal solution, then, the problem, and finally, the current workaround. The ideal solution works as follows. take modules A, B, and C, and create a file named X.ml that looks like this:
    module A = A    
    module B = B
    module C = C
Then, a library (X.cma, or X.cmxa) containing A,B,C is created. The interface files a.mli, b.mli, and c.mli are agglomerated into x.mli. Files x.ml and x.mli are compiled and checked against each other. Applications can then compile against x.cmi, and link with x.{cma,cmxa}. There is a caveat: an application using x.cma may also link with its very own A,B, and C modules. This can cause havoc, because symbol names will overlap. The current version of OCaml does not resolve this. The work-around we currently have in place is to simply copy module bodies into x.ml. For example, we'll have:
    module A = struct
      let f = ..
      let g = ..

    module B = struct
      let a = ..
      let b = ..

    module C = struct
      let x = ..
This has the drawback that separate compilation for X is lost. However, it works!


The tool is named emrg. usage is as follows:

-o direct the output to a file name 
-ml merge ML files
-mli merge MLI files
-copy copy ML module bodies

emrg can handle long path names, such as /A/B/zoo.ml. Note that when compiling the resultant library file (x.ml), provide ocamlc with the proper include paths. An example makefile is provided.

Links and download

The complete package package (~3K).

Browse:    Makefile   Makefile.nt   a.ml   a.mli   b.ml   b.mli   emrg.ml

Send support questions to Ohad Rodeh
Last modified: Thu Jan 10 06:30:38 EST 2002