From: "Nicolas Pouillard" <nicolas.pouillard@gmail.com>
To: "Joel Reymont" <joelr1@gmail.com>
Cc: "Caml List" <caml-list@inria.fr>
Subject: Re: [Caml-list] Producing a C wrapper with ocamlbuild or OMake
Date: Wed, 28 Mar 2007 10:53:50 +0200 [thread overview]
Message-ID: <cd67f63a0703280153g16bebd08v176c74f26b4824ab@mail.gmail.com> (raw)
In-Reply-To: <026CA3D4-5A8B-4083-B429-DE5AEC418C0A@gmail.com>
On 3/28/07, Joel Reymont <joelr1@gmail.com> wrote:
> Folks,
>
> I'm trying to produce a C library from my OCaml code. I found these
> instructions on the net:
>
> 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
>
> How would I accomplish the same with ocamlbuild, which I'm using now,
> or with OMake?
>
Just add some rules...
Here is a plugin example that I will add to the example directory.
open Ocamlbuild_plugin;;
open Command;;
let cc = A"cc";;
let ar = A"ar";;
let libasmrun = !*Ocamlbuild_pack.Ocaml_utils.stdlib_dir/"libasmrun.a";;
dispatch begin function
| After_rules ->
rule "output C obj"
~dep:"%.ml"
~prod:"%caml.o"
begin fun env _ ->
let caml_o = env "%caml.o" and ml = env "%.ml" in
Cmd(S[!Options.ocamlopt; A"-output-obj"; P ml; A"-o"; Px caml_o])
end;
rule "build C lib"
~deps:["%wrap.o"; "%caml.o"]
~prod:"lib%.a"
begin fun env _ ->
let wrap_o = env "%wrap.o" and caml_o = env "%caml.o"
and lib_a = env "lib%.a" in
Seq[cp libasmrun lib_a;
Cmd(S[ar; A"r"; Px lib_a; P caml_o; P wrap_o])]
end;
rule "build main"
~deps:["libfib.a"; "main.o"]
~prod:"main"
begin fun _ _ ->
Cmd(S[cc; P"main.o"; P"libfib.a"; A"-o"; Px"main"])
end;
| _ -> ()
end
--
Nicolas Pouillard
next prev parent reply other threads:[~2007-03-28 8:53 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-27 23:10 Joel Reymont
2007-03-28 8:53 ` Nicolas Pouillard [this message]
[not found] ` <cd67f63a0703280158g559eff38pb6cca758682cad4a@mail.gmail.com>
2007-03-28 9:04 ` [Caml-list] " Joel Reymont
2007-03-28 12:38 ` Nicolas Pouillard
2007-03-28 13:25 ` Joel Reymont
2007-03-28 13:57 ` Nicolas Pouillard
2007-03-28 14:10 ` Joel Reymont
2007-03-28 15:46 ` Nicolas Pouillard
2007-03-28 18:58 ` Joel Reymont
2007-03-28 21:13 ` Nicolas Pouillard
2007-03-28 14:44 ` Joel Reymont
2007-03-28 15:49 ` Nicolas Pouillard
2007-03-28 22:46 ` Joel Reymont
2007-03-29 11:20 ` Nicolas Pouillard
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=cd67f63a0703280153g16bebd08v176c74f26b4824ab@mail.gmail.com \
--to=nicolas.pouillard@gmail.com \
--cc=caml-list@inria.fr \
--cc=joelr1@gmail.com \
/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