123456789101112131415161718192021222324252627282930313233343536373839(* Time-stamp: <modified the 10/02/2016 (at 14:14) by Erwan Jahier> *)(****************************************************************************)letmygetenv_defdefx=letx=matchSys.os_typewith|"Win32"->(x^"_DOS")|_->xintryUnix.getenvxwithNot_found->def(* try to compile a C file into a dro file *)let(c2dro:string->bool)=funcfile->letbase=Filename.chop_extensioncfileinletdro=base^".dro"intryletcc=trymygetenv_def"gcc""CC"with_->"gcc"inletargs=[cfile;"-fPIC";"-shared";"-o";dro]inletres=(Mypervasives.my_create_process~std_out:Unix.stderr~wait:trueccargs)inifres<>Mypervasives.OK&&(* well, try with Sys.command that sometimes works
better wrt path issues *)(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";flushstdout;false)elsetruewithe->print_string(Printexc.to_stringe^"\nTry to define the CC env variable.\n");flushstdout;false