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