[
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: | 2008-03-07 (09:24) |
From: | Romain Bardou <Romain.Bardou@l...> |
Subject: | Re: [Caml-list] Ocamlbuild with findlib + camlp4 |
> Anyway, ideally one should be able to specify in the _tags file the findlib > packages that each ml file depends upon. Well, doesn't the following plugin do what you want? ########################### open Ocamlbuild_plugin open Command (* list of packages *) let packages = ["nums"; "str"; "unix"] (* ocamlfind command *) let ocamlfind x = S[A"ocamlfind"; x] let _ = dispatch begin function | Before_options -> Options.ocamlc := ocamlfind & A"ocamlc"; Options.ocamlopt := ocamlfind & A"ocamlopt"; Options.ocamldep := ocamlfind & A"ocamldep"; Options.ocamldoc := ocamlfind & A"ocamldoc" | After_rules -> flag ["ocaml"; "link"; "linkpkg"] & A"-linkpkg"; List.iter (fun pkg -> flag ["ocaml"; "pkg_"^pkg] & S[A"-package"; A pkg]) packages | _ -> () end ########################### This tells Ocamlbuild to use ocamlfind, and also defines some tags: * The "linkpkg" tag, which adds the "-linkpkg" flag when linking. Tag your output files with it (your .byte or .native files), not the source files. * The "pkg_nums", "pkg_str", and "pkg_unix" tags (simply add packages to the "packages" list if you need other packages) which add the "-package nums", "-package str" and "-package unix" options respectively. Tag your source files with the -package options they should use when compiling, and your output files with the -package options they should use when linking. As an exercise you could even add a tag "ocamlfind" which would allow you to use ocamlfind only when you want to. Now you should be able to use ocamlfind with different options depending on tags. Disclaimer: * I know it compiles but I didn't have time to construct a dummy project which would allow me to test this extension. * It does nothing to handle camlp4, but you should be able to add the correct options yourself. Please tell me if it is what you needed or not :) -- Romain Bardou