title: Ocamlbuild plugin: build dynamic dependencies only if the target has changed
body: <p>I'm trying to write an ocamlbuild plugin. The goal is to build Qt apps (<em>without</em> OCaml code for the time being). To handle the final linking phase, I have written the list of objs, mocs, uis and rcs in a .qtobjs file (like a .itarget), and the list of Qt libs in a .qtpackages file. The rule that applies to these files parses these lists and dynamically builds the objects, mocs and so on before linking everything.</p>
  
  <p>The problem is that I would like not to dynamically build the targets that have not changed. See the rule below:</p>
  
  <pre><code>rule "Link a c++ executable that uses Qt."
    ~deps:["%.qtobjs"; "%.qtpackages"]
    ~prod:"%.cxxnative"
    (fun env build -&gt;
       let dir = Pathname.dirname (env "%.qtobjs") in
       let output = env "%.cxxnative" in
       let objlist = pwd / (env "%.qtobjs") in
       let liblist = pwd / (env "%.qtpackages") in
       let packages = read_lines liblist in
       let lflags = List.map (fun p -&gt; "-l"^p) packages
                    @ find_all "lflags" in
       let objs = List.map (fun o -&gt; dir / o) (read_lines objlist) in
  
  
  
       (* Here, I would like to forget the targets that have not changed *)
       let objs_to_build = List.filter 
           (fun target -&gt; 
              (* something to tell if "target" has to be rebuilt *))
           objs in
  
  
  
       (* This is where I build the dependencies : *)
       let success_builds = build 
           (List.map (fun o -&gt; [o]) 
           objs_to_build) in
  
  
       let objects = filter_map
           (function
             | Outcome.Good x when get_extension x = "opp" -&gt;
               Some (pwd / "_build" / (update_extension "o" x))
             | Outcome.Good _ -&gt; None 
               (* Because I don't want to link the ui.h file generated by uic *)
             | Outcome.Bad exn -&gt; raise exn)
           success_builds in
       let tags_objs = tags_of_pathname (env "%.qtobjs") ++ "link" in
       let tags_packs = tags_of_pathname (env "%.qtpackages") in
       Cmd (S [A (find_one "cxx"); T tags_objs; T tags_packs; Command.atomize lflags;
               A "-o"; P output; Command.atomize objects]));
  </code></pre>
  
  <p>I would like not to call "build" when it's not necessary.</p>
  
  <p>NB: a function</p>
  
  <pre><code>newer_than: Pathname.t -&gt; Pathname.t -&gt; bool
  </code></pre>
  
  <p>could solve my problem.</p>