summaryrefslogtreecommitdiff
path: root/ocaml-binary-annot/utils/ccomp.ml
diff options
context:
space:
mode:
authorFabrice Le Fessant <Fabrice.Le_fessant@inria.fr>2010-11-11 06:38:31 +0000
committerFabrice Le Fessant <Fabrice.Le_fessant@inria.fr>2010-11-11 06:38:31 +0000
commit174df0ab26c2fb06a075df6fe8d598fd89234cd9 (patch)
tree3ddbb0018e6476873891710a95f04190bddff923 /ocaml-binary-annot/utils/ccomp.ml
downloadocaml-174df0ab26c2fb06a075df6fe8d598fd89234cd9.tar.gz
New branch binary-annot by Fabrice Le Fessant from r10789
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/binary-annot@10790 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'ocaml-binary-annot/utils/ccomp.ml')
-rw-r--r--ocaml-binary-annot/utils/ccomp.ml127
1 files changed, 127 insertions, 0 deletions
diff --git a/ocaml-binary-annot/utils/ccomp.ml b/ocaml-binary-annot/utils/ccomp.ml
new file mode 100644
index 0000000000..94a29217dc
--- /dev/null
+++ b/ocaml-binary-annot/utils/ccomp.ml
@@ -0,0 +1,127 @@
+(***********************************************************************)
+(* *)
+(* Objective Caml *)
+(* *)
+(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
+(* *)
+(* Copyright 1996 Institut National de Recherche en Informatique et *)
+(* en Automatique. All rights reserved. This file is distributed *)
+(* under the terms of the Q Public License version 1.0. *)
+(* *)
+(***********************************************************************)
+
+(* $Id$ *)
+
+(* Compiling C files and building C libraries *)
+
+let command cmdline =
+ if !Clflags.verbose then begin
+ prerr_string "+ ";
+ prerr_string cmdline;
+ prerr_newline()
+ end;
+ Sys.command cmdline
+
+let run_command cmdline = ignore(command cmdline)
+
+(* Build @responsefile to work around Windows limitations on
+ command-line length *)
+let build_diversion lst =
+ let (responsefile, oc) = Filename.open_temp_file "camlresp" "" in
+ List.iter (fun f -> Printf.fprintf oc "%s\n" f) lst;
+ close_out oc;
+ at_exit (fun () -> Misc.remove_file responsefile);
+ "@" ^ responsefile
+
+let quote_files lst =
+ let lst = List.filter (fun f -> f <> "") lst in
+ let quoted = List.map Filename.quote lst in
+ let s = String.concat " " quoted in
+ if String.length s >= 4096 && Sys.os_type = "Win32"
+ then build_diversion quoted
+ else s
+
+let quote_prefixed pr lst =
+ let lst = List.filter (fun f -> f <> "") lst in
+ let lst = List.map (fun f -> pr ^ f) lst in
+ quote_files lst
+
+let quote_optfile = function
+ | None -> ""
+ | Some f -> Filename.quote f
+
+let compile_file name =
+ command
+ (Printf.sprintf
+ "%s -c %s %s %s %s"
+ (match !Clflags.c_compiler with
+ | Some cc -> cc
+ | None ->
+ if !Clflags.native_code
+ then Config.native_c_compiler
+ else Config.bytecomp_c_compiler)
+ (String.concat " " (List.rev !Clflags.ccopts))
+ (quote_prefixed "-I" (List.rev !Clflags.include_dirs))
+ (Clflags.std_include_flag "-I")
+ (Filename.quote name))
+
+let create_archive archive file_list =
+ Misc.remove_file archive;
+ let quoted_archive = Filename.quote archive in
+ match Config.ccomp_type with
+ "msvc" ->
+ command(Printf.sprintf "link /lib /nologo /out:%s %s"
+ quoted_archive (quote_files file_list))
+ | _ ->
+ let r1 =
+ command(Printf.sprintf "ar rc %s %s"
+ quoted_archive (quote_files file_list)) in
+ if r1 <> 0 || String.length Config.ranlib = 0
+ then r1
+ else command(Config.ranlib ^ " " ^ quoted_archive)
+
+let expand_libname name =
+ if String.length name < 2 || String.sub name 0 2 <> "-l"
+ then name
+ else begin
+ let libname =
+ "lib" ^ String.sub name 2 (String.length name - 2) ^ Config.ext_lib in
+ try
+ Misc.find_in_path !Config.load_path libname
+ with Not_found ->
+ libname
+ end
+
+type link_mode =
+ | Exe
+ | Dll
+ | MainDll
+ | Partial
+
+let call_linker mode output_name files extra =
+ let files = quote_files files in
+ let cmd =
+ if mode = Partial then
+ Printf.sprintf "%s%s %s %s"
+ Config.native_pack_linker
+ (Filename.quote output_name)
+ files
+ extra
+ else
+ Printf.sprintf "%s -o %s %s %s %s %s %s %s"
+ (match !Clflags.c_compiler, mode with
+ | Some cc, _ -> cc
+ | None, Exe -> Config.mkexe
+ | None, Dll -> Config.mkdll
+ | None, MainDll -> Config.mkmaindll
+ | None, Partial -> assert false
+ )
+ (Filename.quote output_name)
+ (if !Clflags.gprofile then Config.cc_profile else "")
+ "" (*(Clflags.std_include_flag "-I")*)
+ (quote_prefixed "-L" !Config.load_path)
+ (String.concat " " (List.rev !Clflags.ccopts))
+ files
+ extra
+ in
+ command cmd = 0