caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Using findlib and a syntax extension with ocamlbuild
@ 2007-11-21 23:21 Paolo Donadeo
  2007-11-23 12:04 ` [Caml-list] " Nicolas Pouillard
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Donadeo @ 2007-11-21 23:21 UTC (permalink / raw)
  To: caml-list

I'm fighting again with ocamlbuild. In the (excellent!) wiki I found
two useful recipes: how to use findlib with ocamlbuild and how to
compile source code using a syntax extension. Now it happens that I
have both these needs, and I'm not so sure how to mix the ingredients
and obtain a good dish.

At the moment the solution I have discovered (by trial and error)
works well, but it doesn't seem very clean.

The involved files in my source directory are these:

./xnuncc.ml
./myocamlbuild.ml
./ext_libs/openin-20070524/pa_openin.ml
./_tags

In xnuncc.ml I use the openin extension, and xnuncc.ml is the main
compilation unit.

Here is the contents of _tags and the plugin for ocamlbuild:

======= 8< CUT HERE: _tags >8 =======
<dom> or <files> or <fragment_composer> or <test> or <doc> : include
<ext_libs/openin-20070524> : include
true : dtypes
<**/pa_openin.ml> : camlp4of, use_camlp4of
"xnuncc.ml" : camlp4o, use_openin
======= 8< END HERE: _tags >8 =======

======= 8< CUT HERE: myocamlbuild.ml >8 =======
open Ocamlbuild_plugin;;
open Command;;

let packages = "str,netstring,oUnit,extlib";;

let ocamlfind cmd = S[A"ocamlfind"; A cmd; A"-package"; A packages];;

flag ["ocaml"; "link"] (A"-linkpkg");;

dispatch begin function
  | After_options ->
      Options.ocamlc := ocamlfind "ocamlc";
      Options.ocamlopt := ocamlfind "ocamlopt";
  | After_rules ->
      ocaml_lib ~extern:true ~dir:"+camlp4" "camlp4of";
      flag ["ocaml"; "pp"; "use_openin"]
(A"ext_libs/openin-20070524/pa_openin.cmo");
      dep ["ocaml"; "ocamldep"; "use_openin"]
["ext_libs/openin-20070524/pa_openin.cmo"];
  | _ -> ()
end
======= 8< END HERE: myocamlbuild.ml >8 =======

As I wrote this works, but the aspect I don't like is why I have to
specify the full path of "ext_libs/openin-20070524/pa_openin.cmo"
instead of a simple "pa_openin.cmo", inside myocamlbuild.ml. Including
the directory "ext_libs/openin-20070524" in the _tags file does't seem
to be enough.

If I use "pa_openin.cmo", indeed, the result is an absurd (for me)
error message starting with:

======= 8< CUT HERE: error message >8 =======
Ocamlbuild knows of no rules that apply to a target named
ext_libs/openin-20070524/xnuncc.d.ml. This can happen if you ask
Ocamlbuild to build a target with the wrong extension (e.g. .opt
instead of .native) or if the source files live in directories that
have not been specified as include directories.
Backtrace:
  - Failed to build the target xnuncc.d.byte
      - Failed to build all of these:
          - Building ext_libs/openin-20070524/xnuncc.d.byte:
              - Failed to build all of these:
                  - Building ext_libs/openin-20070524/xnuncc.d.cmo:
                      - Failed to build all of these:
                          - Building ext_libs/openin-20070524/xnuncc.d.ml
                          - Building ext_libs/openin-20070524/xnuncc.ml:
                              - Failed to build all of these:
                                  - Building ext_libs/openin-20070524/xnuncc.mly
... ... ...
======= 8< END HERE: error message >8 =======

At the end of the story the question is: is this solution the best
possible for compiling a project with findlib and a syntax extension
present in a subdir of the project?

TIA,

-- 
                                            Paolo


Paolo Donadeo, Senior Software Engineer
Studio Associato 4Sigma
Email: p.donadeo@4sigma.it
~
~
:wq


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Using findlib and a syntax extension with ocamlbuild
  2007-11-21 23:21 Using findlib and a syntax extension with ocamlbuild Paolo Donadeo
@ 2007-11-23 12:04 ` Nicolas Pouillard
  2007-11-23 14:27   ` Paolo Donadeo
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Pouillard @ 2007-11-23 12:04 UTC (permalink / raw)
  To: Paolo Donadeo; +Cc: caml-list

Excerpts from Paolo Donadeo's message of Thu Nov 22 00:21:43 +0100 2007:
> I'm fighting again with ocamlbuild. In the (excellent!) wiki I found
> two useful recipes: how to use findlib with ocamlbuild and how to
> compile source code using a syntax extension. Now it happens that I
> have both these needs, and I'm not so sure how to mix the ingredients
> and obtain a good dish.
> 
> At the moment the solution I have discovered (by trial and error)
> works well, but it doesn't seem very clean.
> 
> The involved files in my source directory are these:
> 
> ./xnuncc.ml
> ./myocamlbuild.ml
> ./ext_libs/openin-20070524/pa_openin.ml
> ./_tags
> 
> In xnuncc.ml I use the openin extension, and xnuncc.ml is the main
> compilation unit.
> 
> Here is the contents of _tags and the plugin for ocamlbuild:
> 
> ======= 8< CUT HERE: _tags >8 =======
> <dom> or <files> or <fragment_composer> or <test> or <doc> : include
> <ext_libs/openin-20070524> : include
> true : dtypes
> <**/pa_openin.ml> : camlp4of, use_camlp4of
> "xnuncc.ml" : camlp4o, use_openin
> ======= 8< END HERE: _tags >8 =======

<dom> (and many others) can be rewritten "dom" since it's constant.

[...]

> If I use "pa_openin.cmo", indeed, the result is an absurd (for me)
> error message starting with:
> 

[...]

In  a  "dep"  declaration  include  directories  are  not taken in account for
building pathnames.

> At the end of the story the question is: is this solution the best
> possible for compiling a project with findlib and a syntax extension
> present in a subdir of the project?

Not  yet  (you  can  still  factorise  the "ext_libs/openin-20070524" and even
compute it, since the plugin language is OCaml).

-- 
Nicolas Pouillard aka Ertai


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Using findlib and a syntax extension with ocamlbuild
  2007-11-23 12:04 ` [Caml-list] " Nicolas Pouillard
@ 2007-11-23 14:27   ` Paolo Donadeo
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Donadeo @ 2007-11-23 14:27 UTC (permalink / raw)
  To: caml-list

> <dom> (and many others) can be rewritten "dom" since it's constant.

Ok.


> Not  yet  (you  can  still  factorise  the "ext_libs/openin-20070524" and even
> compute it, since the plugin language is OCaml).

Ok, thanks again, Nicolas.


-- 
                                            Paolo
~
~
:wq


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-11-23 14:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-21 23:21 Using findlib and a syntax extension with ocamlbuild Paolo Donadeo
2007-11-23 12:04 ` [Caml-list] " Nicolas Pouillard
2007-11-23 14:27   ` Paolo Donadeo

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).