Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Pietro Abate <Pietro.Abate@pps.jussieu.fr>
To: caml-list@inria.fr
Subject: [Caml-list] conditional compilation and ocamlbuild
Date: Thu, 2 Jun 2011 11:38:54 +0200	[thread overview]
Message-ID: <20110602093853.GA27434@pps.jussieu.fr> (raw)

Hello list,

I've three modules a.ml, b.ml and common.ml. A and B both
use Common, but Common is compiled with Camlp4MacroParser
to exclude/include part of the code.

The problem I want to include some part of the code when 
I compile A and exclude it when I compile B.

so the canonical way to use Camlp4MacroParser is to add a rule like

<common.ml>: pp(camlp4o Camlp4MacroParser.cmo -DISTRUE)

and when I compile everything I get something like :

$ocamlbuild -classic-display b.byte a.byte
/usr/bin/ocamldep -modules b.ml > b.ml.depends
/usr/bin/ocamldep -pp 'camlp4o Camlp4MacroParser.cmo -DISTRUE' -modules common.ml > common.ml.depends
/usr/bin/ocamlc -c -pp 'camlp4o Camlp4MacroParser.cmo -DISTRUE' -o common.cmo common.ml
/usr/bin/ocamlc -c -o b.cmo b.ml
/usr/bin/ocamlc common.cmo b.cmo -o b.byte
/usr/bin/ocamldep -modules a.ml > a.ml.depends
/usr/bin/ocamlc -c -o a.cmo a.ml
/usr/bin/ocamlc common.cmo a.cmo -o a.byte

now, both A and B use common.ml compiled with -DISTRUE .
But this is not what I want.

I'm pretty sure I can't use _tags in this situation. But I'm
not sure how to write a simple myocamlbuild rule to basically
creating two common.cmo. 

One for A as
/usr/bin/ocamlc -c -pp 'camlp4o Camlp4MacroParser.cmo -DISTRUE' -o common.cmo common.ml

and one for B as
/usr/bin/ocamlc -c -pp 'camlp4o Camlp4MacroParser.cmo' -o common.cmo common.ml

-----------a.ml -------
let a = print_endline (Common.func ())

-----------b.ml -------
let a = print_endline (Common.func ())

----------common.ml -------
let func () =
IFDEF ISTRUE THEN
"is true"
ELSE
"is not true"
END

I guess the idea is to add a rule that says :
if you are compiling A then run the preprocessor with -DISTRUE otherwise
without it. But doing this I want also to force ocamlbuild not to reuse an
existing common.cmo that maybe was compiled from a "different" source...

Of course my real problem is a bit more complicated as in the conditional
compilation process I exclude/include calls an external C library and
I want to avoid linking this external C library to binaries that do not use
it at all ...

pietro
-- 
----
http://en.wikipedia.org/wiki/Posting_style

             reply	other threads:[~2011-06-02  9:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-02  9:38 Pietro Abate [this message]
2011-06-02  9:49 ` Gabriel Scherer
2011-06-03  9:51   ` Pietro Abate

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=20110602093853.GA27434@pps.jussieu.fr \
    --to=pietro.abate@pps.jussieu.fr \
    --cc=caml-list@inria.fr \
    /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