Clean-up the build system.
[tatoo.git] / myocamlbuild.ml
index a1fe8e9..41730a6 100644 (file)
@@ -1,15 +1,23 @@
 open Ocamlbuild_plugin
 open Command
 
-let includes = Hashtbl.create 17
+let includes = ref StringSet.empty
+
 let register_include dir =
-  if not (Hashtbl.mem includes dir) then begin
-    Hashtbl.add includes 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]);
@@ -19,12 +27,14 @@ let macro_flags = [
 let () = dispatch begin
   function
     | Before_rules ->
-        List.iter (fun s ->
-          List.iter (fun (fl, fu) ->
-            pflag s fl fu) macro_flags
-        )
-          [["ocaml";"compile"];
-           ["ocaml";"ocamldep"] ]
-;
+        set_flags [["ocaml";"compile"]; ["ocaml";"ocamldep"] ] macro_flags;
+        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));
+
     | _ -> ()
 end