Permalink
Fetching contributors…
Cannot retrieve contributors at this time
86 lines (70 sloc) 2.32 KB
let cxx_rule () =
let deps = ["%.hpp"; "%.cpp"; "%.h"] and prod = "%.o" in
let action env _ =
let src = env "%.cpp" and obj = env "%.o" in
let cxx = expand "${cxx} ${cc_optimization} ${cxxflags}" in
let tags = tags_of_pathname src ++ "c++" ++ "compile" in
Cmd (S [Sh cxx; T tags; A "-c"; P src; A "-o"; Px obj]) in
rule "cxx: hpp & cpp & h -> o" ~deps ~prod action
let () = Rules.add cxx_rule
let mark_tags () =
let module Ocamlbuild_compat = struct
let mark_tag_used = ignore
include Ocamlbuild_plugin
end in
let open Ocamlbuild_compat in
List.iter mark_tag_used [
"pkg_core_bench";
"tests";
"pkg_piqirun";
"pkg_core";
]
(* we will pass this manually, util it is fixed *)
let pr_6184_hack = function
| After_rules ->
(* Pass -predicates to ocamldep *)
pflag ["ocaml"; "ocamldep"] "predicate" (fun s -> S [A "-predicates"; A s]);
| _ -> ()
let pass_pp_to_link = function
| After_rules ->
let set acts = pflag acts "pp" (fun s -> S [A "-pp"; A s]) in
set ["link"];
set ["c"; "compile"];
| _ -> ()
let chop_extension file =
try Filename.chop_extension file
with exn -> invalid_arg ("Failed to chop extension from '" ^ file ^ "'")
let unit_of_package pkg =
let open MyOCamlbuildFindlib in
let ocamlfind s =
run_and_read (exec_from_conf "ocamlfind" ^ " " ^ s) in
let archive = ocamlfind ("query -format %a -predicates byte " ^ pkg) in
if String.length archive > 3
then Some (chop_extension archive)
else None
let predicate_used_packages = function
| After_rules ->
MyOCamlbuildFindlib.find_packages () |>
List.iter (fun pkg -> match unit_of_package pkg with
| None -> ()
| Some lib ->
flag ["ocaml"; "link"; "pkg_"^pkg]
(S [A "-predicates"; A ("used_"^lib)]))
| _ -> ()
let predicate_used_libs = function
| After_rules ->
package_default.MyOCamlbuildBase.lib_ocaml |>
List.iter (fun (lib,_,_) ->
flag ["ocaml"; "link"; "use_"^lib]
(S [A "-predicates"; A ("used_"^lib)]))
| _ -> ()
let () =
mark_tags ();
Ocamlbuild_plugin.dispatch (fun stage ->
Rules.dispatch stage;
dispatch_default stage;
pr_6184_hack stage;
pass_pp_to_link stage;
predicate_used_libs stage;
predicate_used_packages stage;
Ppx_driver_ocamlbuild.dispatch stage)