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: asmlibrarian.ml 7079 2005-09-24 16:45:56Z xleroy $ *)
15 (* Build libraries of .cmx files *)
22 File_not_found of string
23 | Archiver_error of string
25 exception Error of error
30 find_in_path !load_path name
32 raise(Error(File_not_found name)) in
33 let (info, crc) = Compilenv.read_unit_info filename in
34 info.ui_force_link <- !Clflags.link_everything;
35 (* There is no need to keep the approximation in the .cmxa file,
36 since the compiler will go looking directly for .cmx files.
37 The linker, which is the only one that reads .cmxa files, does not
38 need the approximation. *)
39 info.ui_approx <- Clambda.Value_unknown;
40 (Filename.chop_suffix filename ".cmx" ^ ext_obj, (info, crc))
42 let create_archive file_list lib_name =
43 let archive_name = chop_extension_if_any lib_name ^ ext_lib in
44 let outchan = open_out_bin lib_name in
46 output_string outchan cmxa_magic_number;
47 let (objfile_list, descr_list) =
48 List.split (List.map read_info file_list) in
50 (fun file_name (unit, crc) ->
51 Asmlink.check_consistency file_name unit crc)
54 { lib_units = descr_list;
55 lib_ccobjs = !Clflags.ccobjs;
56 lib_ccopts = !Clflags.ccopts } in
57 output_value outchan infos;
58 if Ccomp.create_archive archive_name objfile_list <> 0
59 then raise(Error(Archiver_error archive_name));
64 remove_file archive_name;
69 let report_error ppf = function
70 | File_not_found name ->
71 fprintf ppf "Cannot find file %s" name
72 | Archiver_error name ->
73 fprintf ppf "Error while creating the library %s" name