Version française
Home     About     Download     Resources     Contact us    
Browse thread
Checking for caml version from C
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Kaustuv Chaudhuri <kaustuv.chaudhuri@i...>
Subject: Re: [Caml-list] Checking for caml version from C
On Wed, Sep 15, 2010 at 9:29 PM,  <rixed@happyleptic.org> wrote:
> I'd like to know if there is a standard way to check for
> Ocaml version with the C preprocessor

Not sure about standard ways, but here's one ugly way:

   % cat ugly.c
   #if OCAML_MAJOR == 3 && OCAML_MINOR == 12
     Hello 3.12 world
   #else
     Hello non-3.12 world
   #endif

   % ocamlc -version
   3.12.1+dev4 (2010-09-03)

   % ocamlc \
       -ccopt -DOCAML_MAJOR=`ocamlc -version | cut -d'.' -f1` \
       -ccopt -DOCAML_MINOR=`ocamlc -version | cut -d'.' -f2` \
       -ccopt -E \
       ugly.c
   # 1 "ugly.c"
   # 1 "<built-in>"
   # 1 "<command-line>"
   # 1 "ugly.c"

     Hello 3.12 world


(Drop the -ccopt -E option when you use it, obviously.)

-- Kaustuv