caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Aleksey Nogin <nogin@metaprl.org>
To: Joel Reymont <joelr1@gmail.com>
Cc: Caml List <caml-list@inria.fr>, omake@metaprl.org
Subject: Re: Example OMakefile to package OCaml code as a C library
Date: Fri, 30 Mar 2007 09:27:23 -0700	[thread overview]
Message-ID: <460D3A6B.8040006@metaprl.org> (raw)
In-Reply-To: <E31EC467-CDA0-42F5-9D18-AB4C1A5AEB0A@gmail.com>

On 28.03.2007 01:40, Joel Reymont wrote:

> Does anyone have an example OMakefile that can be used to package OCaml 
> code as a C library?
> 
> This is along the lines of what I'm trying to accomplish:
> 
> ocamlopt -output-obj -o fibcaml.o fib.ml
> ocamlopt -c fibwrap.c
> cp /usr/local/lib/ocaml/libasmrun.a libfib.a
> ar r libfib.a fibcaml.o fibwrap.o
> 
Joel,

The above seems relatively straightforward. I would imagine that you can 
give ocamlopt a list of .cmx files instead of the .ml files (this should 
make things more modular and incremental). So you just do something like:

-----------

LIB = fib
CFILES = fibwrap
MLFILES = fib

OCAMLLIB = $(dir $"$(shell $(OCAMLC) -where)")

$(LIB)caml$(EXT_OBJ): $(addsuffix .cmx, $(MLFILES))
    $(OCAMLOPT) $(OCAMLFLAGS) $(OCAMLOPTFLAGS) -output-obj -o $@ 
$(OCamlLinkSort $+)

OBJS = $(addsuffix $(EXT_OBJ), $(LIB)caml $(CFILES))

lib$(LIB)$(EXT_LIB): $(OCAMLLIB)/libasmrun$(EXT_LIB) $(OBJS)
    cp -f $< $@
    ar q $@ $(OBJS)

----------

The above can also be easily made into a function that can be reused:

----------

OCAMLLIB = $(dir $"$(shell $(OCAMLC) -where)")

MakeWrapLib(LIB, MLFILES, CFILES) =
    $(LIB)caml$(EXT_OBJ): $(addsuffix .cmx, $(MLFILES))
       $(OCAMLOPT) $(OCAMLFLAGS) $(OCAMLOPTFLAGS) -output-obj -o $@ 
$(OCamlLinkSort $+)

    OBJS = $(addsuffix $(EXT_OBJ), $(LIB)caml $(CFILES))

    lib$(LIB)$(EXT_LIB): $(OCAMLLIB)/libasmrun$(EXT_LIB) $(OBJS)
       cp -f $< $@
       ar q $@ $(OBJS)

    return lib$(LIB)$(EXT_LIB)

MakeWrapLib(fib, fib, fibwrap)

----------

Aleksey


      reply	other threads:[~2007-03-30 16:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-28  8:40 Joel Reymont
2007-03-30 16:27 ` Aleksey Nogin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=460D3A6B.8040006@metaprl.org \
    --to=nogin@metaprl.org \
    --cc=caml-list@inria.fr \
    --cc=joelr1@gmail.com \
    --cc=omake@metaprl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).