From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p529dQG6005050 for ; Thu, 2 Jun 2011 11:39:26 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvcDABla502GnQCBkWdsb2JhbABTmBiOGRQBAQEBCQsLBxQDIqlPnw2GIQSgGQ X-IronPort-AV: E=Sophos;i="4.65,308,1304287200"; d="scan'208";a="110090577" Received: from shiva.jussieu.fr ([134.157.0.129]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 02 Jun 2011 11:39:21 +0200 Received: from hydrogene.pps.jussieu.fr (hydrogene.pps.jussieu.fr [134.157.168.1]) by shiva.jussieu.fr (8.14.4/jtpda-5.4) with ESMTP id p529ctUo084037 for ; Thu, 2 Jun 2011 11:39:08 +0200 (CEST) X-Ids: 165 Received: by hydrogene.pps.jussieu.fr (Postfix, from userid 2065) id 10D77C0017; Thu, 2 Jun 2011 11:38:54 +0200 (CEST) Date: Thu, 2 Jun 2011 11:38:54 +0200 From: Pietro Abate To: caml-list@inria.fr Message-ID: <20110602093853.GA27434@pps.jussieu.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Operating-System: GNU/Linux User-Agent: Mutt/1.5.20 (2009-06-14) X-Miltered: at jchkmail.jussieu.fr with ID 4DE75A2F.000 by Joe's j-chkmail (http : // j-chkmail dot ensmp dot fr)! X-j-chkmail-Enveloppe: 4DE75A2F.000/134.157.168.1/hydrogene.pps.jussieu.fr/hydrogene.pps.jussieu.fr/ Subject: [Caml-list] conditional compilation and ocamlbuild 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