- (* Recompile the jobs file. *)
- let file = get_jobs_filename () in
- let cmo_file = sprintf "%s/jobs.cmo" jobsdir in
- let cmd = sprintf "ocamlfind ocamlc -I +camlp4 -I %s -package unix,camlp4.lib -pp 'camlp4o %s/pa_when.cmo' -c %s -o %s"
- !libdir !libdir file cmo_file in
+ let suffix = if not Config.have_ocamlopt then "cmo" else "cmx" in
+
+ (* Recompile the jobs file(s). *)
+ let files = get_multijobs_filenames () in
+
+ (* Choose a random name for the output file. time_t is convenient.
+ * See: https://sympa-roc.inria.fr/wws/arc/caml-list/2012-03/msg00276.html?checked_cas=2
+ *)
+ let t = Int64.of_float (time ()) in
+
+ (* Compilation step. *)
+ List.iter (
+ fun file ->
+ let cmd =
+ if not Config.have_ocamlopt then
+ (* bytecode *)
+ sprintf "%s c -for-pack Jobs__%Ld -I +camlp4 -I %s -package unix,camlp4.lib -pp 'camlp4o %s/pa_when.cmo' -c %s"
+ Config.ocamlfind t !libdir !libdir file
+ else
+ (* native code *)
+ sprintf "%s opt -for-pack Jobs__%Ld -I +camlp4 -I %s -package unix,camlp4.lib -pp 'camlp4o %s/pa_when.cmo' -c %s"
+ Config.ocamlfind t !libdir !libdir file in
+ if Sys.command cmd <> 0 then (
+ eprintf "whenjobs: %s: could not compile jobs script, see earlier errors\n"
+ file;
+ eprintf "compile command was:\n%s\n" cmd;
+ exit 1
+ )
+ ) files;
+
+ (* Pack into a single file. *)
+ let filename = sprintf "%s/jobs__%Ld.%s" jobsdir t suffix in
+ let cmd =
+ let objects = List.map (
+ fun file ->
+ let base = Filename.chop_extension file in
+ base ^ if not Config.have_ocamlopt then ".cmo" else ".cmx"
+ ) files in
+ sprintf "%s %s -pack -o %s %s"
+ Config.ocamlfind
+ (if not Config.have_ocamlopt then "c" else "opt")
+ filename (String.concat " " objects) in