Version française
Home     About     Download     Resources     Contact us    
Browse thread
Ocamlbuild with findlib + camlp4
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Dario Teixeira <darioteixeira@y...>
Subject: Ocamlbuild with findlib + camlp4
Hi,

I'm trying to create an Ocamlbuild plugin for an application that uses
PG'OCaml.  This library relies on a Camlp4 syntax extension, and comes by
default with a META file for findlib that enables one to simply type on the
command line:

ocamlfind ocamlc -package pgocaml.statements -syntax camlp4o -c test.ml

I still don't grok Ocamlbuild quite enough to automate this behaviour.
The best I have so far is the plugin below; it adds support for findlib, and
creates a "use_pgocaml" tag that explicitly loads all the modules required by
the syntax extension.  Note that "use_pgocaml" makes no use of the findlib
support; while it works, this is of course hackish and ugly.  Ideally,
"use_pgocaml" should simply tell ocamlbuild to use findlib to automatically
load all the modules.

Any ideas on how this could be achieved?  (And incidentally, I vote for
"built-in findlib support" as my #1 wish for Ocamlbuild).

Thanks in advance!
Dario Teixeira


##############################################################################

open Ocamlbuild_plugin
open Command

let ocamlfind x =
        let packages = "pcre,extlib,lwt,ocsigen,pgocaml,json-wheel" in
        S[A"ocamlfind"; x; A"-package"; A packages];;

dispatch begin function

        | Before_options ->
                Options.ocamlc := ocamlfind & A"ocamlc";
                Options.ocamlopt := ocamlfind & A"ocamlopt";
                Options.ocamldep := ocamlfind & A"ocamldep"

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

		let root = "/home/dario/.godi/lib/ocaml/" in
                let str = root ^ "std-lib/str.cma"
                and pcre = root ^ "pkg-lib/pcre/pcre.cma"
                and extlib = root ^ "pkg-lib/extlib/extLib.cma"
                and calendar = root ^ "pkg-lib/calendar/calendar.cma"
                and csv = root ^ "pkg-lib/csv/csv.cma"
                and pgocaml = root ^ "site-lib/pgocaml/pgocaml.cma"
                and pa_pgsql = root ^ "site-lib/pgocaml/pa_pgsql.cmo" in
                flag ["ocaml"; "pp"; "use_pgsql"] (S[A str; A pcre; A extlib; A
calendar; A csv; A pgocaml; A pa_pgsql])

        | _ -> ()
end;;

##############################################################################





      ___________________________________________________________ 
Rise to the challenge for Sport Relief with Yahoo! For Good  

http://uk.promotions.yahoo.com/forgood/