36d35
< let _ = Printexc.record_backtrace true
83,90d81
<   (* taking out spaces at end : problems occuring under windows build *)
<   let rec trim_right s =
<     let length = String.length s in
<     match s.[length-1] with
<     |' '|'\n'|'\r'|'\t' -> trim_right (String.sub s 0 (length-1))
<     |_ -> s in
<   let suf = trim_right suf in
<   let s = trim_right s in
130,134c121
< let path_sep =
<   match (Sys.os_type = "Win32")with
<   |false ->":"
<   |true -> ";";;
< 
---
> let path_sep = ":";;
153,156c140
< let get_path () =
<   let s = list_of_path (getenv "PATH") in
< (*   List.iter print_endline s; *)
<   s;;
---
> let get_path () = list_of_path (getenv "PATH");;
233,238d216
< (* patch single_write raising exceptions under windows *)
< let single_write =
<   match (Sys.os_type = "Win32")with
<   |true -> write
<   |false -> single_write
< 
306d283
< 
398,524d374
< 
< (* wrapping execution and fork use to be windows compliant,
<    using therefore create_process *)
< module WinExec =
<   struct
<     let read_text_file f =
<       let ic = open_in f in
<       let rec read s =
<         try
<           let line = input_line ic in
<           read (line::s)
<         with End_of_file ->
<           (List.rev s) in
<       let s = read [] in
<       close_in ic;
<       s
< 
<     let clear f =
<       try
<         Sys.remove f
<       with _ -> ()
< 
<     let default_temp_dir = "C:/temp/"
<     let execvp_to_list cmd args =
<       (* we create file based stdin and stdout, giving the temp dir *)
<       let dir =
<         try
<           Unix.getenv "TEMP"
<         with _ -> default_temp_dir in
<       let makeFile dir tag =
<         let makeAddend ()=
<           let addend = Random.int 20000 in
<           Digest.to_hex (Digest.string (Marshal.to_string addend [])) in
<         let file = ref (dir^makeAddend()^tag) in
<         while (Sys.file_exists !file) do
<           file := dir^makeAddend()^tag;
<         done;
<         !file in
<       let output = makeFile dir "output.txt" in
<       let error = makeFile dir "err.txt" in
<       let (sil,sor,ser) =
<         let sil, sir = pipe () in
<         let sor = Unix.openfile output [O_WRONLY;O_CREAT] 0o640 in
<         let ser = Unix.openfile error [O_WRONLY;O_CREAT] 0o640 in
<         (sil,sor,ser) in
<       let pid =
<         create_process_env cmd (Array.append [| cmd |] args) (Unix.environment())
<           sil sor ser in
<       let _,status = Unix.waitpid [] pid in
<       Unix.close sor;
<       Unix.close ser;
<       match status with
<       | WEXITED 0 ->
<           let res = read_text_file output in
<           clear output;
<           clear error;
<           res
<       | WEXITED i ->
<           let errorTrace =read_text_file error in
<           (* we can print the error trace if needed *)
<           clear output;
<           clear error;
<           raise Exec_failure
<       | _ ->
<           clear output;
<           clear error;
<           raise Exec_failure
< 
<     let execvp_redirect redirections cmd args  =
<       let perm = 0o640 in
<       let temp_file =
<         if List.exists (function In_from_string _ -> true | _ -> false)
<             redirections
<         then Some (create_temp_file ~ext: ".in" ())
<         else None in
<       let rec make_redirect rd =
<         match rd with
<           In_from_file file ->
<             let desc_file = openfile file [O_RDONLY] perm in
<             try_finalize (dup2 desc_file) stdin close desc_file
<         | Out_to_file file ->
<             let desc_file = openfile file [O_WRONLY;O_CREAT;O_TRUNC] perm in
<             try_finalize (dup2 desc_file) stdout close desc_file
<         | Err_to_file file  ->
<             let desc_file = openfile file [O_WRONLY;O_CREAT;O_TRUNC] perm in
<             try_finalize (dup2 desc_file) stderr close desc_file
<         | Out_append_to_file file ->
<             let desc_file = openfile file [O_WRONLY;O_APPEND;O_CREAT] perm in
<             try_finalize (dup2 desc_file) stdout close desc_file
<         | Err_to_out -> dup2 stdout stderr
<         | In_from_string s ->
<             begin match temp_file with
<               Some tmp ->
<                 file_of_string ~file: tmp ~contents: s;
<                 make_redirect (In_from_file tmp);
<             | None -> assert false
<             end
<         | Out_null ->
<             make_redirect (Out_to_file "/dev/null")
<         | Err_null ->
<             make_redirect (Err_to_file "/dev/null")
<         | Silent ->
<             make_redirect Out_null;
<             make_redirect Err_to_out;
<       in
<       (* we save stdin, stdout, stderr to restore them after fork *)
<       let stdout_back = Unix.dup Unix.stdout in
<       let stderr_back = Unix.dup Unix.stderr in
<       let stdin_back = Unix.dup Unix.stdin in
<       List.iter make_redirect redirections;
<       let pid = create_process cmd (Array.append [|cmd|] args) Unix.stdin Unix.stdout Unix.stderr in
<       let _,res = waitpid [] pid in
<       begin match temp_file with
<       |Some tmp -> unlink_f tmp
<       | _ -> ()
<       end;
<       (* restorting stdin, stdout, stderr *)
<       Unix.dup2 stdout_back Unix.stdout;
<       Unix.dup2 stderr_back Unix.stderr;
<       Unix.dup2 stdin_back Unix.stdin;
<       res;;
< end
< 
< (* under windows, replace the two functions by those provided by WinExec module *)
< open WinExec;;
< 
< 
756,761d605
< 
< let exe_extension =
<   match (Sys.os_type="Win32") with
<   |true -> ".exe"
<   |false -> "";;
< 
763c607
<   let ocamlc = ocaml_prog ("ocamlc"^exe_extension) in
---
>   let ocamlc = ocaml_prog "ocamlc" in
771,773c615,617
<     ocaml = ocaml_prog ("ocaml"^exe_extension) ;
<     ocamlopt = ocaml_prog ~err: withopt ("ocamlopt"^exe_extension) ;
<     ocamldoc = ocaml_prog ("ocamldoc"^exe_extension) ;
---
>     ocaml = ocaml_prog "ocaml" ;
>     ocamlopt = ocaml_prog ~err: withopt "ocamlopt" ;
>     ocamldoc = ocaml_prog "ocamldoc" ;
775,782c619,626
<     ocamlyacc = ocaml_prog ("ocamlyacc"^exe_extension) ;
<     ocamllex = ocaml_prog ("ocamllex"^exe_extension) ;
<     ocamldep = ocaml_prog ("ocamldep"^exe_extension) ;
<     ocamlmklib = ocaml_prog ("ocamlmklib"^exe_extension) ;
<     ocamlmktop = ocaml_prog ("ocamlmktop"^exe_extension) ;
<     ocamlprof = ocaml_prog ("ocamlprof"^exe_extension) ;
<     camlp4 = ocaml_prog ("camlp4"^exe_extension) ;
<     ocamlfind = ocaml_prog ~err: ocamlfind ("ocamlfind"^exe_extension) ;
---
>     ocamlyacc = ocaml_prog "ocamlyacc" ;
>     ocamllex = ocaml_prog "ocamllex" ;
>     ocamldep = ocaml_prog "ocamldep" ;
>     ocamlmklib = ocaml_prog "ocamlmklib" ;
>     ocamlmktop = ocaml_prog "ocamlmktop" ;
>     ocamlprof = ocaml_prog "ocamlprof" ;
>     camlp4 = ocaml_prog "camlp4" ;
>     ocamlfind = ocaml_prog ~err: ocamlfind "ocamlfind" ;
984c828
<   try ocaml_prog ~err: true ("ocamlbuild"^exe_extension)
---
>   try ocaml_prog ~err: true "ocamlbuild"
