1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 2001-2005, Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc. --
26 ------------------------------------------------------------------------------
28 -- This package provides a set of target dependent routines to build
29 -- static, dynamic and shared libraries.
31 -- This is the Darwin version of the body.
35 with Namet
; use Namet
;
37 with Output
; use Output
;
41 package body MLib
.Tgt
is
46 No_Arguments
: aliased Argument_List
:= (1 .. 0 => null);
47 Empty_Argument_List
: constant Argument_List_Access
:= No_Arguments
'Access;
49 Wl_Init_String
: aliased String := "-Wl,-init";
50 Wl_Init
: constant String_Access
:= Wl_Init_String
'Access;
52 Init_Fini_List
: constant Argument_List_Access
:=
53 new Argument_List
'(1 => Wl_Init,
55 -- Used to put switches for automatic elaboration. Note that there is no
56 -- linking option on Darwin for automatic finalization of a shared
63 function Archive_Builder return String is
68 -----------------------------
69 -- Archive_Builder_Options --
70 -----------------------------
72 function Archive_Builder_Options return String_List_Access is
74 return new String_List'(1 => new String'("cr"));
75 end Archive_Builder_Options;
81 function Archive_Ext return String is
90 function Archive_Indexer return String is
95 -----------------------------
96 -- Archive_Indexer_Options --
97 -----------------------------
99 function Archive_Indexer_Options return String_List_Access is
101 return new String_List'(1 => new String'("-c"));
102 end Archive_Indexer_Options;
104 ---------------------------
105 -- Build_Dynamic_Library --
106 ---------------------------
108 procedure Build_Dynamic_Library
109 (Ofiles : Argument_List;
110 Foreign : Argument_List;
111 Afiles : Argument_List;
112 Options : Argument_List;
113 Options_2 : Argument_List;
114 Interfaces : Argument_List;
115 Lib_Filename : String;
117 Symbol_Data : Symbol_Record;
118 Driver_Name : Name_Id := No_Name;
119 Lib_Version : String := "";
120 Auto_Init : Boolean := False)
122 pragma Unreferenced (Foreign);
123 pragma Unreferenced (Afiles);
124 pragma Unreferenced (Interfaces);
125 pragma Unreferenced (Symbol_Data);
127 Lib_File : constant String :=
128 Lib_Dir & Directory_Separator & "lib" &
129 Fil.Ext_To (Lib_Filename, DLL_Ext);
131 Version_Arg : String_Access;
132 Symbolic_Link_Needed : Boolean := False;
134 Init_Fini : Argument_List_Access := Empty_Argument_List;
137 if Opt.Verbose_Mode then
138 Write_Str ("building relocatable shared library ");
139 Write_Line (Lib_File);
142 -- If specified, add automatic elaboration/finalization
145 Init_Fini := Init_Fini_List;
146 Init_Fini (2) := new String'("-Wl,_" & Lib_Filename
& "init");
149 if Lib_Version
= "" then
151 (Output_File
=> Lib_File
,
153 Options
=> Options
& Init_Fini
.all,
154 Driver_Name
=> Driver_Name
,
155 Options_2
=> Options_2
);
158 -- Instruct the linker to build the shared library as a flat
159 -- namespace image, which is not the default. The default is a two
160 -- level namespace image.
162 Version_Arg
:= new String'("-Wl,-flat_namespace");
164 if Is_Absolute_Path (Lib_Version) then
166 (Output_File => Lib_Version,
168 Options => Options & Version_Arg & Init_Fini.all,
169 Driver_Name => Driver_Name,
170 Options_2 => Options_2);
171 Symbolic_Link_Needed := Lib_Version /= Lib_File;
175 (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
177 Options => Options & Version_Arg & Init_Fini.all,
178 Driver_Name => Driver_Name,
179 Options_2 => Options_2);
180 Symbolic_Link_Needed :=
181 Lib_Dir & Directory_Separator & Lib_Version /= Lib_File;
184 if Symbolic_Link_Needed then
187 Oldpath : String (1 .. Lib_Version'Length + 1);
188 Newpath : String (1 .. Lib_File'Length + 1);
191 pragma Unreferenced (Result);
194 (Oldpath : System.Address;
195 Newpath : System.Address) return Integer;
196 pragma Import (C, Symlink, "__gnat_symlink");
199 Oldpath (1 .. Lib_Version'Length) := Lib_Version;
200 Oldpath (Oldpath'Last) := ASCII.NUL;
201 Newpath (1 .. Lib_File'Length) := Lib_File;
202 Newpath (Newpath'Last) := ASCII.NUL;
204 Delete_File (Lib_File, Success);
206 Result := Symlink (Oldpath'Address, Newpath'Address);
210 end Build_Dynamic_Library;
216 function DLL_Ext return String is
225 function Dynamic_Option return String is
227 return "-dynamiclib";
234 function Is_Object_Ext (Ext : String) return Boolean is
243 function Is_C_Ext (Ext : String) return Boolean is
252 function Is_Archive_Ext (Ext : String) return Boolean is
254 return Ext = ".dylib" or else Ext = ".a";
261 function Libgnat return String is
266 ------------------------
267 -- Library_Exists_For --
268 ------------------------
270 function Library_Exists_For
271 (Project : Project_Id; In_Tree : Project_Tree_Ref) return Boolean
274 if not In_Tree.Projects.Table (Project).Library then
275 Prj.Com.Fail ("INTERNAL ERROR: Library_Exists_For called " &
276 "for non library project");
281 Lib_Dir : constant String :=
283 (In_Tree.Projects.Table (Project).Library_Dir);
284 Lib_Name : constant String :=
286 (In_Tree.Projects.Table (Project).Library_Name);
289 if In_Tree.Projects.Table (Project).Library_Kind =
292 return Is_Regular_File
293 (Lib_Dir & Directory_Separator & "lib" &
294 Fil.Ext_To (Lib_Name, Archive_Ext));
297 return Is_Regular_File
298 (Lib_Dir & Directory_Separator & "lib" &
299 Fil.Ext_To (Lib_Name, DLL_Ext));
303 end Library_Exists_For;
305 ---------------------------
306 -- Library_File_Name_For --
307 ---------------------------
309 function Library_File_Name_For
310 (Project : Project_Id;
311 In_Tree : Project_Tree_Ref) return Name_Id
314 if not In_Tree.Projects.Table (Project).Library then
315 Prj.Com.Fail ("INTERNAL ERROR: Library_File_Name_For called " &
316 "for non library project");
321 Lib_Name : constant String :=
323 (In_Tree.Projects.Table (Project).Library_Name);
327 Name_Buffer (1 .. Name_Len) := "lib";
329 if In_Tree.Projects.Table (Project).Library_Kind =
331 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, Archive_Ext));
334 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, DLL_Ext));
340 end Library_File_Name_For;
346 function Object_Ext return String is
355 function PIC_Option return String is
360 -----------------------------------------------
361 -- Standalone_Library_Auto_Init_Is_Supported --
362 -----------------------------------------------
364 function Standalone_Library_Auto_Init_Is_Supported return Boolean is
367 end Standalone_Library_Auto_Init_Is_Supported;
369 ---------------------------
370 -- Support_For_Libraries --
371 ---------------------------
373 function Support_For_Libraries return Library_Support is
376 end Support_For_Libraries;