1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
2011-07-27 07:17:02 -07:00
|
|
|
(* OCaml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
1995-07-11 11:03:29 -07:00
|
|
|
(* Build libraries of .cmx files *)
|
|
|
|
|
|
|
|
open Misc
|
|
|
|
open Config
|
2010-05-19 04:29:38 -07:00
|
|
|
open Cmx_format
|
1995-07-11 11:03:29 -07:00
|
|
|
|
|
|
|
type error =
|
|
|
|
File_not_found of string
|
1996-02-15 08:19:09 -08:00
|
|
|
| Archiver_error of string
|
1995-07-11 11:03:29 -07:00
|
|
|
|
|
|
|
exception Error of error
|
|
|
|
|
|
|
|
let read_info name =
|
|
|
|
let filename =
|
|
|
|
try
|
|
|
|
find_in_path !load_path name
|
|
|
|
with Not_found ->
|
|
|
|
raise(Error(File_not_found name)) in
|
1995-11-09 05:21:49 -08:00
|
|
|
let (info, crc) = Compilenv.read_unit_info filename in
|
1996-04-18 09:26:54 -07:00
|
|
|
info.ui_force_link <- !Clflags.link_everything;
|
1995-11-09 05:21:49 -08:00
|
|
|
(* There is no need to keep the approximation in the .cmxa file,
|
|
|
|
since the compiler will go looking directly for .cmx files.
|
|
|
|
The linker, which is the only one that reads .cmxa files, does not
|
|
|
|
need the approximation. *)
|
|
|
|
info.ui_approx <- Clambda.Value_unknown;
|
1996-02-15 08:19:09 -08:00
|
|
|
(Filename.chop_suffix filename ".cmx" ^ ext_obj, (info, crc))
|
1995-07-11 11:03:29 -07:00
|
|
|
|
|
|
|
let create_archive file_list lib_name =
|
2005-09-24 09:45:56 -07:00
|
|
|
let archive_name = chop_extension_if_any lib_name ^ ext_lib in
|
1995-07-11 11:03:29 -07:00
|
|
|
let outchan = open_out_bin lib_name in
|
|
|
|
try
|
|
|
|
output_string outchan cmxa_magic_number;
|
|
|
|
let (objfile_list, descr_list) =
|
|
|
|
List.split (List.map read_info file_list) in
|
2002-04-04 01:00:16 -08:00
|
|
|
List.iter2
|
|
|
|
(fun file_name (unit, crc) ->
|
|
|
|
Asmlink.check_consistency file_name unit crc)
|
|
|
|
file_list descr_list;
|
2000-03-09 01:12:28 -08:00
|
|
|
let infos =
|
|
|
|
{ lib_units = descr_list;
|
|
|
|
lib_ccobjs = !Clflags.ccobjs;
|
2013-06-05 09:34:40 -07:00
|
|
|
lib_ccopts = !Clflags.all_ccopts } in
|
2000-03-09 01:12:28 -08:00
|
|
|
output_value outchan infos;
|
1996-11-07 02:55:02 -08:00
|
|
|
if Ccomp.create_archive archive_name objfile_list <> 0
|
1996-02-15 08:19:09 -08:00
|
|
|
then raise(Error(Archiver_error archive_name));
|
1995-07-11 11:03:29 -07:00
|
|
|
close_out outchan
|
|
|
|
with x ->
|
|
|
|
close_out outchan;
|
|
|
|
remove_file lib_name;
|
|
|
|
remove_file archive_name;
|
|
|
|
raise x
|
|
|
|
|
2000-04-21 01:13:22 -07:00
|
|
|
open Format
|
1995-07-11 11:03:29 -07:00
|
|
|
|
2000-04-21 01:13:22 -07:00
|
|
|
let report_error ppf = function
|
|
|
|
| File_not_found name ->
|
|
|
|
fprintf ppf "Cannot find file %s" name
|
1996-02-15 08:19:09 -08:00
|
|
|
| Archiver_error name ->
|
2000-04-21 01:13:22 -07:00
|
|
|
fprintf ppf "Error while creating the library %s" name
|