From: Kim Nguyễn Date: Sun, 10 Mar 2013 10:55:12 +0000 (+0100) Subject: Workaround lame ocamlbuild issues (symlinks are not created for X-Git-Tag: v0.1~146 X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=commitdiff_plain;h=20538a1c949f89745b73f89f9d0c146dc42454a2 Workaround lame ocamlbuild issues (symlinks are not created for some reason) --- diff --git a/build b/build index d5eb3a5..1be54af 100755 --- a/build +++ b/build @@ -1,6 +1,22 @@ #!/usr/bin/env ocaml -let target = ref [ "main.otarget" ] +let file_content = + let buffer = Buffer.create 128 in + begin fun f -> + Buffer.clear buffer; + try + let in_f = open_in f in + while true do + let line = input_line in_f in + Buffer.add_string buffer line; + Buffer.add_char buffer ' '; + done; + failwith "finished" + with + e -> let s = Buffer.contents buffer in s + end + +let target = ref [ ] let debug = ref false let profile = ref false let verbose = ref false @@ -19,18 +35,25 @@ let () = let oprofile = if !profile then " -tag profile " else "" let odebug = if !profile then " -tag debug " else "" +let clean_first = ref false let otarget = List.fold_left (fun acc t -> - let t = if t = "clean" then "-clean" else t in - t ^ " " ^ acc) "" !target + if t = "clean" || t = "-clean" then (clean_first := true; acc) + else + let t = + if Filename.check_suffix t ".otarget" then + file_content ((Filename.chop_suffix t ".otarget") ^ ".itarget") + else t + in + t ^ " " ^ acc) "" (if (!target == []) then [ "main.otarget" ] else !target) let overbose = if !verbose then " -classic-display " else "" let () = Sys.chdir project_root; Printf.printf "Entering directory `%s'\n%!" project_root - -let cmd = Printf.sprintf "ocamlbuild -use-ocamlfind %s %s %s %s" - overbose oprofile odebug otarget -let i = Sys.command cmd +let clean_cmd = if !clean_first then "ocamlbuild -clean;" else "" +let build_cmd = if otarget = "" then "" else + Printf.sprintf "ocamlbuild -use-ocamlfind %s %s %s %s" + overbose oprofile odebug otarget +let i = Sys.command (clean_cmd ^ build_cmd) let () = Sys.chdir dir; Printf.printf "Leaving directory `%s'\n%!" project_root let _ = exit i - diff --git a/main.itarget b/main.itarget index 45edc29..d11e542 100644 --- a/main.itarget +++ b/main.itarget @@ -1,3 +1,4 @@ src/main.native tools/xml_diff.native tools/XPathEval.class + diff --git a/myocamlbuild.ml b/myocamlbuild.ml index 4dbf6f6..0ea5ff0 100644 --- a/myocamlbuild.ml +++ b/myocamlbuild.ml @@ -26,7 +26,8 @@ let macro_flags = [ let () = dispatch begin function - | Before_rules -> + | Before_rules -> () + | After_rules -> set_flags [["ocaml";"compile"]; ["ocaml";"ocamldep"] ] macro_flags; pflag [ "ocaml"; "compile" ] "warning" (fun s -> (S[ A"-w"; A s])); flag [ "ocaml"; "compile"; "debug" ] (S[ A"-g"; A"-ppopt"; A"-DDEBUG"]); @@ -38,7 +39,6 @@ let () = dispatch begin pflag [ "ocaml"; "compile" ] "unsafe" (fun s -> (if s = "true" then S[A"-ppopt";A "-unsafe"] else N)); - | After_rules -> rule "Java compilation" ~prod:"%.class" ~dep:"%.java"