2 #use "myocamlbuild_config.ml"
4 let valid_targets = [ "distclean"; "clean"; "all" ]
9 let set r s () = r := s
10 let cons r s () = r := s :: !r
13 let flavor = ref "native"
17 [ "-verbose", Unit (set verbose " -classic-display"),
18 " Display compilation commands";
20 "-enable-debug", Unit (cons tags "-tag debug"),
21 " Build with debugging code";
23 "-enable-profile", Unit (cons tags "-tag profile"),
24 " Build with profiling code";
26 "-enable-log", Unit (cons tags "-tag log"),
27 " Build with tracing code enabled";
29 "-byte", Unit (set flavor "byte"),
30 " Produce bytecode instead of native code";
31 "-j", Int (fun i -> if i < 0 || i > 1024
32 then raise (Bad ("Invalid job count: " ^ string_of_int i))
34 " Spawns n parallel jobs (0 for unlimited, max = 1024, default = 0)"
37 "usage: " ^ Sys.argv.(0) ^
38 " [options] target ... target\nvalid targets are: " ^
39 ( match valid_targets with
40 [] | [ _ ] -> assert false
41 | l::ll -> (String.concat ", " ll) ^ " and " ^ l)
45 if List.mem x valid_targets
46 then targets := x :: !targets
47 else raise (Bad ("Invalid target: " ^ x))
50 targets := List.rev !targets;
51 if !targets = [] then targets := [ "all" ]
54 let tests_targets = []
56 let () = Cmdline.parse ()
59 Printf.sprintf "ocamlbuild %s %s -j %i "
60 !Cmdline.verbose (String.concat " " !Cmdline.tags) !Cmdline.jobs
62 List.map begin function
63 | "distclean" -> "rm -f myocamlbuild_config.ml; ocamlbuild -clean"
64 | "clean" -> "ocamlbuild -clean"
65 | "all" -> ocamlbuild ^ (List.assoc !Cmdline.flavor main_targets)
67 ocamlbuild ^ (List.assoc (test,!Cmdline.flavor) tests_targets)
70 let () = List.iter (fun cmd -> ignore (Sys.command cmd) ) cmd_list