open Ocamlbuild_plugin
-open Command
+let includes =
+ let open Pathname in
+ let d = Array.to_list (readdir "include") in
+ List.map (concat "include") d
-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 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 ->
- List.iter (fun s ->
- List.iter (fun (fl, fu) ->
- pflag s fl fu) macro_flags
- )
- [["ocaml";"compile"];
- ["ocaml";"ocamldep"] ]
-;
- | _ -> ()
-end
+let () =
+ dispatch (function
+ | After_rules ->
+ dep ["ocaml";"compile";] includes;
+ dep ["ocaml";"ocamldep"; ] includes;
+ pflag ["ocaml";"compile";] "ppopt" (fun s -> S [A"-ppopt"; A (s)]);
+ pflag ["ocaml";"ocamldep";] "ppopt" (fun s -> S [A"-ppopt"; A (s)]);
+ | _ -> ()
+ )