Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
ocamlbuild: ml -> cmx & cmi & o ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-10-16 (08:30)
From: Romain Bardou <Romain.Bardou@l...>
Subject: Re: [Caml-list] ocamlbuild: ml -> cmx & cmi & o ?
> I observe that ocamlbuild does not build cmx cmi and o files from a ml 
> file (which has no associated mli) directly.  Do others see different 
> behavior?  Instead it builds cmo and cmi from the ml using ocamlc, and 
> then builds the cmx and o files from there using ocamlopt.  Is there a 
> reason I’m missing that ocamlbuild does not have a default rule for this 
> case, using only one call to ocamlopt?  If so, is there an easy way to 
> do this with a plugin?

I observe the same behavior. I think it's just a matter of reordering 
the rules in, as the following plug-in solves the 
problem thanks to "~insert: `top":

open Ocamlbuild_plugin

let () = dispatch begin function
   | After_rules ->
       rule "ml -> cmx"
         ~dep: ""
         ~prods: ["%.cmx"; "%.o"; "%.cmi"]
         ~insert: `top
         begin fun env _ ->
           let ml = env "" in
           Cmd(S[!Options.ocamlopt; A "-c"; P ml])
   | _ -> ()

Romain Bardou