#line 383 "/home/travis/build/felix-lang/felix/src/packages/toolchain.fdoc"
  include "std/felix/toolchain_interface";
  
    gen cxx_depcheck (tc: toolchain_t, src:string, dst:string) : bool =
    {
      fun == (a:list[string], b:list[string]) =
      {
        match a,b with
        | #Empty,Empty => return true;
        | Cons (h1,t1), Cons (h2,t2) =>
           if h1 != h2 do
             return false;
           done
           return t1 == t2; // tail call
        | _ =>return false;
        endmatch;
      }
  
      fun maxf (t:double) (f:string) => max (t, FileStat::dfiletime (f, #FileStat::future_time));
  
      var new_switches = cat ' ' #(tc.get_base_cxx_compile_flags);
  
      var result, deps = tc.cxx_dependency_generator (src=src);
      if result != 0 do
        println$ "[flx_depchk] C++ Dependency generator FAILED on " + src;
        return false;
      done
      var newdeps = tc.dependency_parser deps;
      var depfile = dst + ".d";
      var olddeptxt = load depfile;
      var old_switches, olddeps =
        match filter (fun (s:string)=> s != "") (split (olddeptxt,"\n")) with
        | h ! t => h,t
        | _ => "",Empty[string]
      ;
  
      var samedeps = new_switches == old_switches and newdeps == olddeps;
      //if not samedeps do
      //  println$ "DEPS CHANGED";
      //  println$ "Old deps = " + olddeps.str;
      //  println$ "New deps = " + newdeps.str;
      //done
      save$ depfile, new_switches ! newdeps;
      var fresh = samedeps and #{
        var t = fold_left maxf #FileStat::past_time newdeps;
        return t < FileStat::dfiletime (dst, #FileStat::past_time);
      };
      //println$ "[flx] Output " + dst + " is " + if fresh then "FRESH" else "STALE" endif;
      return fresh;
    }
  
    gen c_depcheck (tc: toolchain_t, src:string, dst:string) : bool =
    {
      fun == (a:list[string], b:list[string]) =
      {
        match a,b with
        | #Empty,Empty =>  return true;
        | Cons (h1,t1), Cons (h2,t2) =>
           if h1 != h2 do
             return false;
           done
           return t1 == t2; // tail call
        | _ => return false;
        endmatch;
      }
  
      fun maxf (t:double) (f:string) =>
        max(t, FileStat::dfiletime (f, #FileStat::future_time))
      ;
  
      var new_switches = cat ' ' #(tc.get_base_c_compile_flags);
      var result, deps = tc.c_dependency_generator (src=src);
      if result != 0 do
        println$ "[flx_depchk] C Dependency generator FAILED on " + src;
        return false;
      done
      var newdeps = tc.dependency_parser deps;
      var depfile = dst + ".d";
      var olddeptxt = load depfile;
      var old_switches, olddeps =
        match filter (fun (s:string)=> s != "") (split (olddeptxt,"\n")) with
        | h ! t => h,t
        | _ => "",Empty[string]
      ;
  
      var samedeps = new_switches == old_switches and newdeps == olddeps;
      save$ depfile, new_switches ! newdeps;
      var fresh = samedeps and #{
        var t = fold_left maxf #FileStat::past_time newdeps;
        return t < FileStat::dfiletime (dst, #FileStat::past_time);
      };
      //println$ "[flx] Output " + dst + " is " + if fresh then "FRESH" else "STALE" endif;
      return fresh;
    }