--- /dev/null
+#!/usr/bin/env ocaml
+#use "myocamlbuild_config.ml"
+
+let valid_targets = [ "distclean"; "clean"; "all" ]
+
+module Cmdline =
+ struct
+ open Arg
+ let set r s () = r := s
+ let targets = ref []
+ let flavor = ref "native"
+ let debug = ref ""
+ let profile = ref ""
+ let verbose = ref ""
+ let jobs = ref 0
+ let specs = align
+ [ "-verbose", Unit (set verbose "-classic-display"),
+ " Display compilation commands";
+
+ "-debug", Unit (set debug "-tag debug"),
+ " Build with debugging code";
+
+ "-profile", Unit (set profile "-tag profile"),
+ " Build with profiling code";
+
+ "-byte", Unit (set flavor "byte"),
+ " Produce bytecode instead of native code";
+ "-j", Int (fun i -> if i < 0 || i > 1024
+ then raise (Bad ("Invalid job count: " ^ string_of_int i))
+ else jobs:= i),
+ " Spawns n parallel jobs (0 for unlimited, max = 1024, default = 0)"
+ ]
+ let usage_msg =
+ "usage: " ^ Sys.argv.(0) ^
+ " [options] target ... target\nvalid targets are: " ^
+ ( match valid_targets with
+ [] | [ _ ] -> assert false
+ | l::ll -> (String.concat ", " ll) ^ " and " ^ l)
+ let parse () =
+ parse specs
+ (fun x ->
+ if List.mem x valid_targets
+ then targets := x :: !targets
+ else raise (Bad ("Invalid target: " ^ x))
+ )
+ usage_msg;
+ targets := List.rev !targets;
+ if !targets = [] then targets := [ "all" ]
+ end
+
+let tests_targets = []
+;;
+let () = Cmdline.parse ()
+let cmd_list =
+ let ocamlbuild =
+ Printf.sprintf "ocamlbuild %s %s %s -j %i "
+ !Cmdline.verbose !Cmdline.profile !Cmdline.debug !Cmdline.jobs
+ in
+ List.map begin function
+ | "distclean" -> "rm myocamlbuild_config.ml; ocamlbuild -clean"
+ | "clean" -> "ocamlbuild -clean"
+ | "all" -> ocamlbuild ^ (List.assoc !Cmdline.flavor main_targets)
+ | test ->
+ ocamlbuild ^ (List.assoc (test,!Cmdline.flavor) tests_targets)
+ end !Cmdline.targets
+
+let () = List.iter (fun cmd -> ignore (Sys.command cmd) ) cmd_list