1 (***********************************************************************)
5 (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
7 (* Copyright 1996 Institut National de Recherche en Informatique et *)
8 (* en Automatique. All rights reserved. This file is distributed *)
9 (* under the terms of the Q Public License version 1.0. *)
11 (***********************************************************************)
13 (* $Id: ccomp.ml 9093 2008-10-16 15:57:00Z doligez $ *)
15 (* Compiling C files and building C libraries *)
18 if !Clflags.verbose then begin
25 let run_command cmdline = ignore(command cmdline)
27 (* Build @responsefile to work around Windows limitations on
28 command-line length *)
29 let build_diversion lst =
30 let (responsefile, oc) = Filename.open_temp_file "camlresp" "" in
31 List.iter (fun f -> Printf.fprintf oc "%s\n" f) lst;
33 at_exit (fun () -> Misc.remove_file responsefile);
37 let lst = List.filter (fun f -> f <> "") lst in
38 let quoted = List.map Filename.quote lst in
39 let s = String.concat " " quoted in
40 if String.length s >= 4096 && Sys.os_type = "Win32"
41 then build_diversion quoted
44 let quote_prefixed pr lst =
45 let lst = List.filter (fun f -> f <> "") lst in
46 let lst = List.map (fun f -> pr ^ f) lst in
49 let quote_optfile = function
51 | Some f -> Filename.quote f
53 let compile_file name =
57 (match !Clflags.c_compiler with
60 if !Clflags.native_code
61 then Config.native_c_compiler
62 else Config.bytecomp_c_compiler)
63 (String.concat " " (List.rev !Clflags.ccopts))
64 (quote_prefixed "-I" (List.rev !Clflags.include_dirs))
65 (Clflags.std_include_flag "-I")
66 (Filename.quote name))
68 let create_archive archive file_list =
69 Misc.remove_file archive;
70 let quoted_archive = Filename.quote archive in
71 match Config.ccomp_type with
73 command(Printf.sprintf "link /lib /nologo /out:%s %s"
74 quoted_archive (quote_files file_list))
77 command(Printf.sprintf "ar rc %s %s"
78 quoted_archive (quote_files file_list)) in
79 if r1 <> 0 || String.length Config.ranlib = 0
81 else command(Config.ranlib ^ " " ^ quoted_archive)
83 let expand_libname name =
84 if String.length name < 2 || String.sub name 0 2 <> "-l"
88 "lib" ^ String.sub name 2 (String.length name - 2) ^ Config.ext_lib in
90 Misc.find_in_path !Config.load_path libname
101 let call_linker mode output_name files extra =
102 let files = quote_files files in
104 if mode = Partial then
105 Printf.sprintf "%s%s %s %s"
106 Config.native_pack_linker
107 (Filename.quote output_name)
111 Printf.sprintf "%s -o %s %s %s %s %s %s %s"
112 (match !Clflags.c_compiler, mode with
114 | None, Exe -> Config.mkexe
115 | None, Dll -> Config.mkdll
116 | None, MainDll -> Config.mkmaindll
117 | None, Partial -> assert false
119 (Filename.quote output_name)
120 (if !Clflags.gprofile then Config.cc_profile else "")
121 "" (*(Clflags.std_include_flag "-I")*)
122 (quote_prefixed "-L" !Config.load_path)
125 (String.concat " " (List.rev !Clflags.ccopts))