X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=blobdiff_plain;f=myocamlbuild.ml;h=0ea5ff0097df2a0e8d24edecff73593f1e46cd77;hp=2d9913ed76fd456be656e45551f5cbb4da6c495b;hb=9b3611f8b650edf4183169a9c2c4317e13be536d;hpb=30bc0bb1291426e5e26eb2dee1ffc41e4c246349 diff --git a/myocamlbuild.ml b/myocamlbuild.ml index 2d9913e..0ea5ff0 100644 --- a/myocamlbuild.ml +++ b/myocamlbuild.ml @@ -1,28 +1,51 @@ open Ocamlbuild_plugin open Command -let ocamlfind_packages = "unix,ulex,expat,camlp4,camlp4.lib,camlp4.macro" +let includes = ref StringSet.empty -let ocamlfind x = S[ T (Tags.singleton "ocamlfind"); - A "ocamlfind"; x ; - A "-package"; - A ocamlfind_packages; - A "-syntax"; - A "camlp4o"; - A "-ppopt"; A "-I"; A"-ppopt"; A"include" - ] +let register_include dir = + if not (StringSet.mem dir !includes) then begin + includes := StringSet.add dir !includes; + dep [ "extension:ml" ] + (List.map (fun s -> dir ^ "/" ^ s ) + (Array.to_list (Pathname.readdir dir))) + end + +let set_flags tag_list action_list = + List.iter (fun s -> + List.iter (fun (fl, fu) -> + pflag s fl fu) + action_list + ) tag_list + +let macro_flags = [ + "macro_include", + (fun s -> register_include s; S [A"-ppopt"; A "-I"; A"-ppopt"; A s]); + "macro_define", (fun s -> S [A"-ppopt"; A ("-D"^s)]); +] let () = dispatch begin function - | Before_rules -> - Options.ocamlc := ocamlfind (A"ocamlc"); - Options.ocamlopt := ocamlfind (A"ocamlopt"); - Options.ocamldep := ocamlfind (A"ocamldep"); - Options.ocamldoc := ocamlfind (A"ocamldoc"); - Options.ocamlmktop := ocamlfind (A"ocamlmktop"); - dep [ "extension:ml" ] - (List.map (fun s -> "include/" ^ s ) - (Array.to_list (Pathname.readdir "include"))); - flag [ "ocaml"; "link" ] (A"-linkpkg") + | Before_rules -> () + | After_rules -> + set_flags [["ocaml";"compile"]; ["ocaml";"ocamldep"] ] macro_flags; + pflag [ "ocaml"; "compile" ] "warning" (fun s -> (S[ A"-w"; A s])); + flag [ "ocaml"; "compile"; "debug" ] (S[ A"-g"; A"-ppopt"; A"-DDEBUG"]); + flag [ "ocaml"; "link"; "debug" ] (A"-g"); + flag [ "ocaml"; "compile"; "profile"] (S[A"-ppopt"; A"-DPROFILE"]); + flag [ "ocaml"; "compile"; "profile"; "native"] (A"-p"); + flag [ "ocaml"; "link"; "profile"; "native"] (A"-p"); + pflag [ "ocaml"; "compile"; "native" ] "inline" (fun i -> (S[ A"-inline"; A i ])); + pflag [ "ocaml"; "compile" ] "unsafe" (fun s -> (if s = "true" then S[A"-ppopt";A "-unsafe"] else N)); + + + rule "Java compilation" + ~prod:"%.class" + ~dep:"%.java" + begin fun env _build -> + let java = env "%.java" in + let tags = tags_of_pathname java ++ "compile" in + Cmd( S[ A"javac" ; P java; T tags ]) + end | _ -> () end