[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Pietro Abate <Pietro.Abate@p...> |
| Subject: | Re: [Caml-list] Ocamlbuild with findlib + camlp4 |
On Thu, Mar 06, 2008 at 07:45:05PM +0000, Dario Teixeira wrote:
> Thanks for the help. I see -- essentially you're just telling Ocamlbuild
> to ignore findlib when dealing with syntax extensions. Unfortunately
> it's not working: the database.ml file never seems to be compiled. Moreover,
> the core of the problem remains: if we're ever going to simplify the use of
> syntax extensions, we must somehow tell Ocamlbuild to use findlib. Any
> other thoughts?
bar.ml is your database module that uses a syntax extension and str
is loaded via ocamlfind in foo.ml. I guess there is a better way to
use ocamlfind more selectively. For example I don't need to use ocamlfind
to compile the syntax extension.
hope this helps.
pietro
#####$cat _tags
"pa_float.ml": use_camlp4, pp(camlp4of)
"bar.ml": camlp4o, use_float
#####$cat bar.ml
let x = Float.( 3/2 - sqrt (1/3) )
let f x =
Float.(
let pi = acos(-1) in
x/(2*pi) - x**(2/3)
)
#####$cat foo.ml
open Str
let x = Bar.x
#####$cat myocamlbuild.ml
open Ocamlbuild_plugin;;
open Command;;
let packages = "str";;
let ocamlfind x = S[A"ocamlfind"; x; A"-package"; A packages];;
dispatch begin function
| Before_options ->
Options.ocamlc := ocamlfind& A"ocamlc";
Options.ocamlopt := ocamlfind& A"ocamlopt";
| After_rules ->
flag ["ocaml"; "pp"; "use_float"] (A"pa_float.cmo");
flag ["ocaml"; "link"] (A"-linkpkg");
dep ["ocaml"; "ocamldep"; "use_float"] ["pa_float.cmo"];
| _ -> ()
end;;
#####$cat pa_float.ml
module Id = struct
let name = "pa_float"
let version = "1.0"
end
open Camlp4
module Make (Syntax : Sig.Camlp4Syntax) = struct
open Sig
include Syntax
class float_subst _loc = object
inherit Ast.map as super
method _Loc_t _ = _loc
method expr =
function
| <:expr< ( + ) >> -> <:expr< ( +. ) >>
| <:expr< ( - ) >> -> <:expr< ( -. ) >>
| <:expr< ( * ) >> -> <:expr< ( *. ) >>
| <:expr< ( / ) >> -> <:expr< ( /. ) >>
| <:expr< $int:i$ >> ->
let f = float(int_of_string i) in <:expr< $`flo:f$ >>
| e -> super#expr e
end;;
EXTEND Gram
GLOBAL: expr;
expr: LEVEL "simple"
[ [ "Float"; "."; "("; e = SELF; ")" -> (new float_subst _loc)#expr e ]
]
;
END
end
let module M = Register.OCamlSyntaxExtension Id Make in ()
#####$ocamlbuild foo.byte -classic-display
/usr/bin/ocamlopt -I /usr/lib/ocaml/3.10.0/ocamlbuild unix.cmxa /usr/lib/ocaml/3.10.0/ocamlbuild/ocamlbuildlib.cmxa myocamlbuild.ml /usr/lib/ocaml/3.10.0/ocamlbuild/ocamlbuild.cmx -o myocamlbuild
/usr/bin/ocamldep -modules foo.ml > foo.ml.depends
/usr/bin/ocamldep -pp camlp4of -modules pa_float.ml > pa_float.ml.depends
ocamlfind ocamlc -package str -c -I +camlp4 -pp camlp4of -o pa_float.cmo pa_float.ml
/usr/bin/ocamldep -pp 'camlp4o pa_float.cmo' -modules bar.ml > bar.ml.depends
ocamlfind ocamlc -package str -c -pp 'camlp4o pa_float.cmo' -o bar.cmo bar.ml
ocamlfind ocamlc -package str -c -o foo.cmo foo.ml
ocamlfind ocamlc -package str -linkpkg bar.cmo foo.cmo -o foo.byte