caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Pietro Abate <Pietro.Abate@pps.jussieu.fr>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Ocamlbuild with findlib + camlp4
Date: Thu, 6 Mar 2008 23:14:07 +0100	[thread overview]
Message-ID: <20080306221407.GA31976@uranium.pps.jussieu.fr> (raw)
In-Reply-To: <182204.66150.qm@web54607.mail.re2.yahoo.com>

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


  reply	other threads:[~2008-03-06 22:14 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-05 13:41 Dario Teixeira
2008-03-05 15:08 ` [Caml-list] " Romain Bardou
2008-03-06 15:31   ` Dario Teixeira
2008-03-06 15:46     ` Pietro Abate
2008-03-06 19:45       ` Dario Teixeira
2008-03-06 22:14         ` Pietro Abate [this message]
2008-03-07  9:26     ` Romain Bardou
2008-03-07 14:46       ` Dario Teixeira
2008-03-07 15:01         ` Nicolas Pouillard
2008-03-07 16:12           ` Dario Teixeira
2008-03-08 11:36             ` Nicolas Pouillard
2008-03-10 15:33               ` Dario Teixeira
2008-03-10 16:15                 ` Romain Bardou
2008-03-10 21:13                   ` Dario Teixeira
2008-03-10 19:56                 ` Arnaud Spiwack
2008-03-10 21:15                   ` Dario Teixeira
2008-03-11 10:37                 ` Nicolas Pouillard
2008-03-11 13:49                   ` Romain Bardou
2008-03-11 15:03                     ` Romain Bardou
2008-03-11 17:32                   ` Dario Teixeira
2008-03-11 20:17                     ` Richard Jones
2008-03-11 10:41       ` Nicolas Pouillard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080306221407.GA31976@uranium.pps.jussieu.fr \
    --to=pietro.abate@pps.jussieu.fr \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).