Add a kind element to the node tree. Improve support for XPath by
[tatoo.git] / myocamlbuild.ml
1 open Ocamlbuild_plugin
2 open Command
3
4 let includes = ref StringSet.empty
5
6 let register_include dir =
7   if not (StringSet.mem dir !includes) then begin
8     includes := StringSet.add dir !includes;
9     dep [ "extension:ml" ]
10       (List.map (fun s -> dir ^ "/" ^ s )
11          (Array.to_list (Pathname.readdir dir)))
12   end
13
14 let set_flags tag_list action_list =
15   List.iter (fun s ->
16     List.iter (fun (fl, fu) ->
17       pflag s fl fu)
18       action_list
19   ) tag_list
20
21 let macro_flags = [
22   "macro_include",
23   (fun s -> register_include s; S [A"-ppopt"; A "-I"; A"-ppopt"; A s]);
24   "macro_define", (fun s -> S [A"-ppopt"; A ("-D"^s)]);
25 ]
26
27 let () = dispatch begin
28   function
29     | Before_rules -> ()
30     | After_rules ->
31         set_flags [["ocaml";"compile"]; ["ocaml";"ocamldep"] ] macro_flags;
32         pflag [ "ocaml"; "compile" ] "warning"   (fun s -> (S[ A"-w"; A s]));
33         flag [ "ocaml"; "compile"; "debug" ] (S[ A"-g"; A"-ppopt"; A"-DDEBUG"]);
34         flag [ "ocaml"; "link"; "debug" ] (A"-g");
35         flag [ "ocaml"; "compile"; "profile"] (S[A"-ppopt"; A"-DPROFILE"]);
36         flag [ "ocaml"; "compile"; "profile"; "native"] (A"-p");
37         flag [ "ocaml"; "link"; "profile"; "native"] (A"-p");
38         pflag [ "ocaml"; "compile"; "native" ] "inline" (fun i -> (S[ A"-inline"; A i ]));
39         pflag [ "ocaml"; "compile" ] "unsafe" (fun s -> (if s = "true" then S[A"-ppopt";A "-unsafe"] else N));
40
41
42          rule "Java compilation"
43         ~prod:"%.class"
44         ~dep:"%.java"
45         begin fun env _build ->
46           let java = env "%.java" in
47           let tags = tags_of_pathname java ++ "compile" in
48           Cmd( S[ A"javac" ; P java; T tags ])
49         end
50     | _ -> ()
51 end