Add configure and remake generated files to .gitignore
[tatoo.git] / build
diff --git a/build b/build
index 4dba756..75781b0 100755 (executable)
--- a/build
+++ b/build
@@ -1,9 +1,23 @@
 #!/usr/bin/env ocaml
 
-let target = ref "main.otarget"
+let read_lines f =
+  let lines = ref [] in
+  let in_f = open_in f in
+  try
+    while true do
+      let line = input_line in_f in
+      if String.length line != 0 then lines := line :: !lines
+    done;
+    []
+  with
+    End_of_file -> close_in in_f; List.rev !lines
+;;
+
+let target = ref [ ]
 let debug = ref false
 let profile = ref false
 let verbose = ref false
+let trace = ref false
 
 let dir = Sys.getcwd ()
 let project_root = Filename.dirname Sys.argv.(0)
@@ -14,21 +28,32 @@ let () =
     | "-d" -> debug := true
     | "-p" -> profile := true
     | "-v" -> verbose := true
-    | x -> target := x
+    | "-t" -> trace := true
+    | x -> target := x :: !target
   done
-
+let otrace = if !trace then " -tag htmltrace " else ""
 let oprofile = if !profile then " -tag profile " else ""
-let odebug = if !profile then " -tag debug " else ""
-let otarget = if !target = "clean" then " -clean " else !target
-let overbose = if !verbose then " -classic-display " else ""
+let odebug = if !debug then " -tag debug " else ""
+let clean_first = ref false
 let () =
   Sys.chdir project_root;
   Printf.printf "Entering directory `%s'\n%!" project_root
 
-let cmd = Printf.sprintf "ocamlbuild -use-ocamlfind %s %s %s %s"
-  overbose  oprofile  odebug otarget
-let i = Sys.command cmd
+let otarget = List.fold_left (fun acc t ->
+  if t = "clean" || t = "-clean" then (clean_first := true; acc)
+  else
+    let t =
+      if Filename.check_suffix t ".otarget" then
+        String.concat " " (read_lines ((Filename.chop_suffix t ".otarget") ^ ".itarget"))
+      else t
+    in
+    t ^ " " ^ acc) "" (if (!target == []) then [ "main.otarget" ] else !target)
+let overbose = if !verbose then " -classic-display " else ""
+let clean_cmd = if !clean_first then "ocamlbuild -clean;" else ""
+let build_cmd = if otarget = "" then "" else
+    Printf.sprintf "ocamlbuild -use-ocamlfind %s %s %s %s %s"
+      overbose otrace oprofile  odebug otarget
+let i = Sys.command  (clean_cmd ^ build_cmd)
 let () = Sys.chdir dir;
   Printf.printf "Leaving directory `%s'\n%!" project_root
 let _ = exit i
-