1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
let mygetenv_def def x =
let x =
match Sys.os_type with
| "Win32" -> (x^"_DOS")
| _ -> x
in
try Unix.getenv x
with Not_found -> def
let (c2dro: string -> bool) =
fun cfile ->
let base = Filename.chop_extension cfile in
let dro = base ^ ".dro" in
try
let cc = try mygetenv_def "gcc" "CC" with _ -> "gcc" in
let args = [cfile; "-fPIC"; "-shared"; "-o"; dro ] in
let res = (Mypervasives.my_create_process
~std_out:Unix.stderr ~wait:true cc args)
in
if res <> Mypervasives.OK
&&
(Sys.command (String.concat " " (cc::args)) <> 0)
then (
print_string "c2dro failed to call the c compiler\n";
print_string "Try to define the CC env variable.\n";
flush stdout;
false
) else true
with e ->
print_string (Printexc.to_string e^"\nTry to define the CC env variable.\n");
flush stdout;
false