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