* [Caml-list] conditional compilation and ocamlbuild
@ 2011-06-02 9:38 Pietro Abate
2011-06-02 9:49 ` Gabriel Scherer
0 siblings, 1 reply; 3+ messages in thread
From: Pietro Abate @ 2011-06-02 9:38 UTC (permalink / raw)
To: caml-list
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] conditional compilation and ocamlbuild
2011-06-02 9:38 [Caml-list] conditional compilation and ocamlbuild Pietro Abate
@ 2011-06-02 9:49 ` Gabriel Scherer
2011-06-03 9:51 ` Pietro Abate
0 siblings, 1 reply; 3+ messages in thread
From: Gabriel Scherer @ 2011-06-02 9:49 UTC (permalink / raw)
To: Pietro Abate; +Cc: caml-list
[-- Attachment #1: Type: text/plain, Size: 3016 bytes --]
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
<Pietro.Abate@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(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
>
>
[-- Attachment #2: Type: text/html, Size: 4793 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] conditional compilation and ocamlbuild
2011-06-02 9:49 ` Gabriel Scherer
@ 2011-06-03 9:51 ` Pietro Abate
0 siblings, 0 replies; 3+ messages in thread
From: Pietro Abate @ 2011-06-03 9:51 UTC (permalink / raw)
To: caml-list
On Thu, Jun 02, 2011 at 11:49:35AM +0200, Gabriel Scherer wrote:
> 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.
even if this is a hack, I guess this is exactly what I'm going to do. I
could add a more complicated ocamlbuild rule to mangle the source, but I
think it's not worth it...
thanks for the feedback.
>
> On Thu, Jun 2, 2011 at 11:38 AM, Pietro Abate <Pietro.Abate@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(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
>
>
>
--
----
http://en.wikipedia.org/wiki/Posting_style
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-06-03 9:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-02 9:38 [Caml-list] conditional compilation and ocamlbuild Pietro Abate
2011-06-02 9:49 ` Gabriel Scherer
2011-06-03 9:51 ` Pietro Abate
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox