let rebuild_plugin_if_needed () =
let a = up_to_date_or_copy plugin_file in
let b = (not we_have_a_config_file) or up_to_date_or_copy plugin_config_file in
let c = (not we_have_a_config_file_interface) or up_to_date_or_copy plugin_config_file_interface in
if a && b && c && we_have_a_plugin then
()
else begin
if !Options.native_plugin
&& not (sys_file_exists ((!Ocamlbuild_where.libdir)/"ocamlbuildlib.cmxa")) then
begin
Options.native_plugin := false;
eprintf "Warning: Won't be able to compile a native plugin"
end;
let plugin_config =
if we_have_a_config_file then
if we_have_a_config_file_interface then
S[P plugin_config_file_interface; P plugin_config_file]
else P plugin_config_file
else N in
let cma, cmo, more_options, compiler =
if !Options.native_plugin then
"cmxa", "cmx", (if profiling then A"-p" else N), !Options.ocamlopt
else
"cma", "cmo", (if debugging then A"-g" else N), !Options.ocamlc
in
let ocamlbuildlib, ocamlbuild, libs =
if (not !Options.native_plugin) && !*My_unix.is_degraded then
"ocamlbuildlightlib", "ocamlbuildlight", N
else
"ocamlbuildlib", "ocamlbuild", A("unix"-.-cma)
in
let ocamlbuildlib = ocamlbuildlib-.-cma in
let ocamlbuild = ocamlbuild-.-cmo in
let dir = !Ocamlbuild_where.libdir in
if not (sys_file_exists (dir/ocamlbuildlib)) then
failwith (sprintf "Cannot find %S in ocamlbuild -where directory" ocamlbuildlib);
let dir = if Pathname.is_implicit dir then Pathname.pwd/dir else dir in
let cmd =
Cmd(S[compiler; A"-I"; P dir; libs; more_options;
P(dir/ocamlbuildlib); plugin_config; P plugin_file;
P(dir/ocamlbuild); A"-o"; Px (plugin^(!Options.exe))])
in
Shell.chdir !Options.build_dir;
Shell.rm_f (plugin^(!Options.exe));
Command.execute cmd
end