Display caching and iteration statistics at the end of evaluation.
[tatoo.git] / build
1 #!/usr/bin/env ocaml
2
3 let file_content =
4   let buffer = Buffer.create 128 in
5   begin fun f ->
6     Buffer.clear buffer;
7     try
8       let in_f = open_in f in
9       while true do
10         let line = input_line in_f in
11         Buffer.add_string buffer line;
12         Buffer.add_char buffer ' ';
13       done;
14       failwith "finished"
15     with
16       e -> let s = Buffer.contents buffer in s
17   end
18
19 let target = ref [ ]
20 let debug = ref false
21 let profile = ref false
22 let verbose = ref false
23 let trace = ref false
24
25 let dir = Sys.getcwd ()
26 let project_root = Filename.dirname Sys.argv.(0)
27
28 let () =
29   for i = 1 to Array.length Sys.argv - 1 do
30     match Sys.argv.(i) with
31     | "-d" -> debug := true
32     | "-p" -> profile := true
33     | "-v" -> verbose := true
34     | "-t" -> trace := true
35     | x -> target := x :: !target
36   done
37 let otrace = if !trace then " -tag htmltrace " else ""
38 let oprofile = if !profile then " -tag profile " else ""
39 let odebug = if !debug then " -tag debug " else ""
40 let clean_first = ref false
41 let () =
42   Sys.chdir project_root;
43   Printf.printf "Entering directory `%s'\n%!" project_root
44
45 let otarget = List.fold_left (fun acc t ->
46   if t = "clean" || t = "-clean" then (clean_first := true; acc)
47   else
48     let t =
49       if Filename.check_suffix t ".otarget" then
50         file_content ((Filename.chop_suffix t ".otarget") ^ ".itarget")
51       else t
52     in
53     t ^ " " ^ acc) "" (if (!target == []) then [ "main.otarget" ] else !target)
54 let overbose = if !verbose then " -classic-display " else ""
55 let clean_cmd = if !clean_first then "ocamlbuild -clean;" else ""
56 let build_cmd = if otarget = "" then "" else
57     Printf.sprintf "ocamlbuild -use-ocamlfind %s %s %s %s %s"
58       overbose otrace oprofile  odebug otarget
59 let i = Sys.command  (clean_cmd ^ build_cmd)
60 let () = Sys.chdir dir;
61   Printf.printf "Leaving directory `%s'\n%!" project_root
62 let _ = exit i