« Return to Thread: "ocaml_beginners"::[] Conditional compilation

Re: "ocaml_beginners"::[] Conditional compilation

by clconway :: Rate this Message:

Reply to Author | View in Thread

On 10/28/07, Matthieu Dubuget <matthieu.dubuget@...> wrote:

> cultural_sublimation a écrit :
> >
> >
> > Fellow Camels,
> >
> > How does one handle conditional compilation in OCaml? I want certain
> > pieces of debugging code to be included only if a certain environment
> > variable is set. This sort of thing is really easy to do in the C
> > preprocessor with #ifdefs.
> >
> > And yes, I know I can use cpp also with OCaml, but I was wondering
> > if there was a more "bactrian" way of doing this.
> >
> > Thanks,
> > C.S.
> >
>
> You can use camlp4 with pa_macro.
> You have then #define, #if construction,
> and can use -D ident and -U ident to add or
> remove macro definition.
>
> I do not have the magic invocation at hand,
> but you'll find.

In OCaml version <= 3.09:
ocamlc -pp "camlp4o pa_macro.cmo"

To define/undefine symbols on the command line:
ocamlc -pp "camlp4o pa_macro.cmo -DFOO -UBAR"

See also here for camlp4 extensions for debugging and command-line
macros with values:
http://www.cs.nyu.edu/~cconway/tools/index.html

Regards,
Chris

 « Return to Thread: "ocaml_beginners"::[] Conditional compilation