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 (***********************************************************************)
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
34 output_string oc
(Filename.quote f
); output_char oc '
\n'
38 at_exit
(fun () -> Misc.remove_file responsefile
);
44 (List.map
(fun f
-> if f
= "" then f
else Filename.quote f
) lst
) in
45 if Sys.os_type
= "Win32" && String.length
s >= 256
46 then build_diversion lst
49 let quote_optfile = function
51 | Some f
-> Filename.quote f
53 let compile_file name
=
58 (String.concat
" " (List.rev
!Clflags.ccopts
))
60 (List.rev_map
(fun dir
-> "-I" ^ dir
) !Clflags.include_dirs
))
61 (Clflags.std_include_flag
"-I")
62 (Filename.quote name
))
64 let create_archive archive file_list
=
65 Misc.remove_file archive
;
66 let quoted_archive = Filename.quote archive
in
67 match Config.ccomp_type
with
69 command(Printf.sprintf
"link /lib /nologo /out:%s %s"
70 quoted_archive (quote_files file_list
))
73 command(Printf.sprintf
"ar rc %s %s"
74 quoted_archive (quote_files file_list
)) in
75 if r1 <> 0 || String.length
Config.ranlib
= 0
77 else command(Config.ranlib ^
" " ^
quoted_archive)
79 let expand_libname name
=
80 if String.length name
< 2 || String.sub name
0 2 <> "-l"
84 "lib" ^
String.sub name
2 (String.length name
- 2) ^
Config.ext_lib
in
86 Misc.find_in_path
!Config.load_path
libname
91 (* Handling of msvc's /link options *)
93 let make_link_options optlist
=
94 let rec split linkopts otheropts
= function
95 | [] -> String.concat
" " otheropts
96 ^
" /link /subsystem:console "
97 ^
String.concat
" " linkopts
99 if String.length opt
>= 5 && String.sub opt
0 5 = "/link"
100 then split (String.sub opt
5 (String.length opt
- 5) :: linkopts
)
102 else split linkopts
(opt
:: otheropts
) rem
103 in split [] [] optlist
105 (* Handling of Visual C++ 2005 manifest files *)
107 let merge_manifest exefile
=
108 let manfile = exefile ^
".manifest" in
109 if not
(Sys.file_exists
manfile) then 0 else begin
111 command (Printf.sprintf
"mt -nologo -outputresource:%s -manifest %s"
112 (Filename.quote exefile
)
113 (Filename.quote
manfile)) in
114 Misc.remove_file
manfile;