4 This ocamlbuild plugin will try to find libraries by name using (in order)
5 - local myocamlbuild.config file
8 Sample myocamlbuild.config :
10 extlib=C:/my/contrib/extlib-1.5.1
11 deriving=C:/my/contrib/deriving-0.1.1/lib
12 oUnit=C:/my/contrib/ounit-1.0.3
16 (** querying ocamlfind *)
19 let is_nl ch
= match ch
with | '
\n'
| '
\r'
-> true | _
-> false in
21 if n
= 0 then 0 else if is_nl s
.[n
-1] then cut (n
-1) else n
23 let ls = String.length s
in
25 if n = ls then s
else String.sub s
0 n
28 let cin = Unix.open_process_in
(Printf.sprintf
"ocamlfind -query %s" lib
) in
29 let s = chomp (input_line
cin) in
30 (* let s = Filename.quote s in*)
31 ignore
(Unix.close_process_in
cin);
34 (** querying config *)
39 let ch = open_in name
in
40 begin try while true do l := input_line
ch :: !l done with End_of_file
-> () end;
47 let read_config name
=
48 let l = file_lines name
in
50 let index = String.index s '
='
in
51 (String.sub
s 0 index, String.sub
s (index+1) ((String.length
s) - index - 1))
53 let split s = try split s with _
-> "","" in
58 let config = read_config "myocamlbuild.config"
61 | [] -> prerr_endline
"No config, will use ocamlfind"
62 | _
-> prerr_endline
"Using config : ";
63 List.iter
(fun (x
,y
) -> Printf.eprintf
"%s=%s\n%!" x y
) config
67 List.assoc name
config
74 let extern ?cma pkg_name
= Ocamlbuild_plugin.ocaml_lib ~
extern:true ~dir
:(lib pkg_name
) (match cma
with Some
s -> s | None
-> pkg_name
)