2 module type Format = sig
7 val target_of : source_object -> target_object
8 val string_of_source_object : source_object -> string
9 val string_of_target_object : target_object -> string
11 val build : source_object -> unit
13 val mtime_of_source_object : source_object -> float option
14 val mtime_of_target_object : target_object -> float option
17 module Make = functor (F:Format) -> struct
19 let prerr_endline _ = ();;
22 match F.mtime_of_source_object a, F.mtime_of_target_object b with
23 | Some a, Some b -> a < b
24 | _ -> false (* XXX check if correct *)
27 match F.mtime_of_target_object a, F.mtime_of_target_object b with
28 | Some a, Some b -> a < b
29 | _ -> false (* XXX check if correct *)
32 let is_built t = younger_s_t t (F.target_of t);;
34 let rec needs_build deps compiled (t,dependencies) =
35 prerr_endline ("Checking if "^F.string_of_source_object t^" needs to be built");
36 if List.mem t compiled then
37 (prerr_endline "already compiled";
40 if not (is_built t) then
41 (prerr_endline (F.string_of_source_object t^
42 " is not built, thus needs to be built");
48 (needs_build deps compiled)
49 (List.map (fun x -> x, List.assoc x deps) dependencies)
52 (F.string_of_source_object t^" depends on "^F.string_of_source_object (fst unsat)^
53 " that needs to be built, thus needs to be built");
58 List.find (younger_t_t (F.target_of t)) (List.map F.target_of dependencies)
61 (F.string_of_source_object t^" depends on "^F.string_of_target_object
62 unsat^" and "^F.string_of_source_object t^".o is younger than "^
63 F.string_of_target_object unsat^", thus needs to be built");
65 with Not_found -> false
68 let is_buildable compiled deps (t,dependencies) =
69 prerr_endline ("Checking if "^F.string_of_source_object t^" is buildable");
70 let b = needs_build deps compiled (t,dependencies) in
72 (prerr_endline (F.string_of_source_object t^
73 " does not need to be built, thus it not buildable");
78 List.find (needs_build deps compiled)
79 (List.map (fun x -> x, List.assoc x deps) dependencies)
82 (F.string_of_source_object t^" depends on "^
83 F.string_of_source_object (fst unsat)^
84 " that needs build, thus is not buildable");
88 ("None of "^F.string_of_source_object t^
89 " dependencies needs to be built, thus it is buildable");
93 let rec make compiled deps =
94 let todo = List.filter (is_buildable compiled deps) deps in
96 (List.iter F.build (List.map fst todo);
97 make (compiled@List.map fst todo) deps)
100 let make deps = make [] deps