1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Objective Caml *)
|
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 *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* Automatique. Distributed only by permission. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1995-07-11 11:03:29 -07:00
|
|
|
(* Build libraries of .cmx files *)
|
|
|
|
|
|
|
|
open Misc
|
|
|
|
open Config
|
|
|
|
open Compilenv
|
|
|
|
|
|
|
|
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 =
|
1996-02-15 08:19:09 -08:00
|
|
|
let archive_name = Filename.chop_suffix lib_name ".cmxa" ^ 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
|
|
|
|
output_value outchan descr_list;
|
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
|
|
|
|
|
|
|
|
open Format
|
|
|
|
|
|
|
|
let report_error = function
|
|
|
|
File_not_found name ->
|
|
|
|
print_string "Cannot find file "; print_string name
|
1996-02-15 08:19:09 -08:00
|
|
|
| Archiver_error name ->
|
|
|
|
print_string "Error while creating the library ";
|
|
|
|
print_string name
|
1995-07-11 11:03:29 -07:00
|
|
|
|