sql: multi-table UPDATE
[sqlgg.git] / myocamlbuild_config.ml
blob059ca9174f6864ad1b9ff320fd44492d9edf392f
1 (**
2 This ocamlbuild plugin will try to find libraries by name using (in order)
3 - local myocamlbuild.config file
4 - ocamlfind
6 Sample myocamlbuild.config :
8 extlib=C:/my/contrib/extlib-1.5.1
9 deriving=C:/my/contrib/deriving-0.1.1/lib
10 oUnit=C:/my/contrib/ounit-1.0.3
14 (** querying ocamlfind *)
16 let chomp s =
17 let is_nl ch = match ch with | '\n' | '\r' -> true | _ -> false in
18 let rec cut n =
19 if n = 0 then 0 else if is_nl s.[n-1] then cut (n-1) else n
21 let ls = String.length s in
22 let n = cut ls in
23 if n = ls then s else String.sub s 0 n
25 let ocamlfind lib =
26 let cin = Unix.open_process_in (Printf.sprintf "ocamlfind -query %s" lib) in
27 let s = chomp (input_line cin) in
28 (* let s = Filename.quote s in*)
29 ignore (Unix.close_process_in cin);
32 (** querying config *)
34 let file_lines name =
35 let l = ref [] in
36 begin try
37 let ch = open_in name in
38 begin try while true do l := input_line ch :: !l done with End_of_file -> () end;
39 close_in_noerr ch
40 with
41 exn -> ()
42 end;
45 let read_config name =
46 let l = file_lines name in
47 let split s =
48 let index = String.index s '=' in
49 (String.sub s 0 index, String.sub s (index+1) ((String.length s) - index - 1))
51 let split s = try split s with _ -> "","" in
52 List.map split l
54 (** usage *)
56 let config = read_config "myocamlbuild.config"
57 let () =
58 match config with
59 | [] -> prerr_endline "No config, will use ocamlfind"
60 | _ -> prerr_endline "Using config : ";
61 List.iter (fun (x,y) -> Printf.eprintf "%s=%s\n%!" x y) config
63 let lib name =
64 try
65 List.assoc name config
66 with exn ->
67 try
68 ocamlfind name
69 with exn ->
70 "+" ^ name