open Ocamlbuild_plugin
open Command
-let ocamlfind_packages = "unix,ulex,expat,camlp4,camlp4.lib,camlp4.macro"
+let includes = Hashtbl.create 17
+let register_include dir =
+ if not (Hashtbl.mem includes dir) then begin
+ Hashtbl.add includes dir ();
+ dep [ "extension:ml" ]
+ (List.map (fun s -> dir ^ "/" ^ s )
+ (Array.to_list (Pathname.readdir dir)))
+ end
-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 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")
+ List.iter (fun s ->
+ List.iter (fun (fl, fu) ->
+ pflag s fl fu) macro_flags
+ )
+ [["ocaml";"compile"];
+ ["ocaml";"ocamldep"] ]
+;
| _ -> ()
end