From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p529o3Nb005384 for ; Thu, 2 Jun 2011 11:50:03 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlICAMJb503RVdy2mGdsb2JhbAA9AQMSl2aGZwGHWwgUAQEBAQEICQ0HFCWIcaNDjB6CPIRUOYhiAQEDBoYbBII4ji+LNjuDQQ X-IronPort-AV: E=Sophos;i="4.65,308,1304287200"; d="scan'208";a="84501965" Received: from mail-vx0-f182.google.com ([209.85.220.182]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 02 Jun 2011 11:49:57 +0200 Received: by vxc34 with SMTP id 34so936993vxc.27 for ; Thu, 02 Jun 2011 02:49:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=+YQ1nO4zNM5kr0qx1Jg6Qa/L/sWPPdpAbLw4KUb2bwc=; b=xU1ItIZLyvJvVzmS+x0CLKLNxEZePBZNdYwtIwYf+Ka7YDDuwRBwCIquUeuCwu1QqH ZoJm6Vr/BbC+VXSfTLB+ywR4vvEMxCEQ6ayUeCgvL5r8wxr4rkQ3f4cPIEH54PGbMYBu Jj9JQVvYCpz8ml1Kv+jwkfXbKs0dOWLQc96fw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=ajC+YNA4Pos2h8b1bLD0ZaCu7/QPEAQmCUAZHX3PaIxzdyelQTCa+ZbES9hWGZjdxs ddTAHD8T7Z+zE8Fin2EXQMnET8j/ojSvWtEofDC4WELMtZpvaW2vnuVIu1DIT3iHahlC s8dvmEw9DVmMqLvPrlXWp6T2FWVYki1b8IKvs= Received: by 10.52.162.72 with SMTP id xy8mr696897vdb.87.1307008195147; Thu, 02 Jun 2011 02:49:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.158.225 with HTTP; Thu, 2 Jun 2011 02:49:35 -0700 (PDT) In-Reply-To: <20110602093853.GA27434@pps.jussieu.fr> References: <20110602093853.GA27434@pps.jussieu.fr> From: Gabriel Scherer Date: Thu, 2 Jun 2011 11:49:35 +0200 Message-ID: To: Pietro Abate Cc: caml-list@inria.fr Content-Type: multipart/alternative; boundary=bcaec53f95dd30b7ad04a4b78f09 Subject: Re: [Caml-list] conditional compilation and ocamlbuild --bcaec53f95dd30b7ad04a4b78f09 Content-Type: text/plain; charset=ISO-8859-1 It's a hack, but have you considered symlinking common.ml to a different name (common_without_distrue, no idea) to bypass the per-name tag attribution and caching logic of Ocamlbuild? You could also generate files on the fly (add ocamlbuild rules to generate common_for_a.ml and common_for_b.ml, then have a and b depend on those modules). The problem is that it changes the name of the Common module for a.ml and b.ml. On Thu, Jun 2, 2011 at 11:38 AM, Pietro Abate wrote: > 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 > > : 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 > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > --bcaec53f95dd30b7ad04a4b78f09 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable It's a hack, but have you considered symlinking common.ml to a different name (common_without_distrue, no idea) t= o bypass the per-name tag attribution and caching logic of Ocamlbuild?
You could also generate files on the fly (add ocamlbuild rules to generate = common_for_a.ml and common_for_b.ml, then have a and b depend on those m= odules).

The problem is that it changes the name of the Common module for a.ml and b.ml.

On Thu, Jun 2, 2011 at 11:38 AM, Pietro Abate <Pietro.Abat= e@pps.jussieu.fr> wrote:
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(ca= mlp4o 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' -mod= ules
common.ml > comm= on.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<= /a>
/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<= /a>
/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.cm= o common.ml

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

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

----------common.ml ----= ---
let func () =3D
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<= br> existing common.cmo that maybe was compiled from a "different" so= urce...

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
--
----
ht= tp://en.wikipedia.org/wiki/Posting_style

--
Caml-list mailing list. =A0Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


--bcaec53f95dd30b7ad04a4b78f09--