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, 51 Franklin Street, Fifth Floor, --
21 -- Boston, MA 02110-1301, 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
50 function Archive_Builder return String is
55 -----------------------------
56 -- Archive_Builder_Options --
57 -----------------------------
59 function Archive_Builder_Options return String_List_Access is
61 return new String_List'(1 => new String'("cr"));
62 end Archive_Builder_Options;
68 function Archive_Ext return String is
77 function Archive_Indexer return String is
82 -----------------------------
83 -- Archive_Indexer_Options --
84 -----------------------------
86 function Archive_Indexer_Options return String_List_Access is
88 return new String_List'(1 => new String'("-c"));
89 end Archive_Indexer_Options;
91 ---------------------------
92 -- Build_Dynamic_Library --
93 ---------------------------
95 procedure Build_Dynamic_Library
96 (Ofiles : Argument_List;
97 Foreign : Argument_List;
98 Afiles : Argument_List;
99 Options : Argument_List;
100 Options_2 : Argument_List;
101 Interfaces : Argument_List;
102 Lib_Filename : String;
104 Symbol_Data : Symbol_Record;
105 Driver_Name : Name_Id := No_Name;
106 Lib_Version : String := "";
107 Auto_Init : Boolean := False)
109 pragma Unreferenced (Foreign);
110 pragma Unreferenced (Afiles);
111 pragma Unreferenced (Interfaces);
112 pragma Unreferenced (Symbol_Data);
113 pragma Unreferenced (Auto_Init);
115 Lib_File : constant String :=
116 Lib_Dir & Directory_Separator & "lib" &
117 Fil.Ext_To (Lib_Filename, DLL_Ext);
119 Version_Arg : String_Access;
120 Symbolic_Link_Needed : Boolean := False;
123 if Opt.Verbose_Mode then
124 Write_Str ("building relocatable shared library ");
125 Write_Line (Lib_File);
128 -- If specified, add automatic elaboration/finalization
130 if Lib_Version = "" then
132 (Output_File => Lib_File,
135 Driver_Name => Driver_Name,
136 Options_2 => Options_2);
139 -- Instruct the linker to build the shared library as a flat
140 -- namespace image, which is not the default. The default is a two
141 -- level namespace image.
143 Version_Arg := new String'("-Wl,-flat_namespace");
145 if Is_Absolute_Path (Lib_Version) then
147 (Output_File => Lib_Version,
149 Options => Options & Version_Arg,
150 Driver_Name => Driver_Name,
151 Options_2 => Options_2);
152 Symbolic_Link_Needed := Lib_Version /= Lib_File;
156 (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
158 Options => Options & Version_Arg,
159 Driver_Name => Driver_Name,
160 Options_2 => Options_2);
161 Symbolic_Link_Needed :=
162 Lib_Dir & Directory_Separator & Lib_Version /= Lib_File;
165 if Symbolic_Link_Needed then
168 Oldpath : String (1 .. Lib_Version'Length + 1);
169 Newpath : String (1 .. Lib_File'Length + 1);
172 pragma Unreferenced (Result);
175 (Oldpath : System.Address;
176 Newpath : System.Address) return Integer;
177 pragma Import (C, Symlink, "__gnat_symlink");
180 Oldpath (1 .. Lib_Version'Length) := Lib_Version;
181 Oldpath (Oldpath'Last) := ASCII.NUL;
182 Newpath (1 .. Lib_File'Length) := Lib_File;
183 Newpath (Newpath'Last) := ASCII.NUL;
185 Delete_File (Lib_File, Success);
187 Result := Symlink (Oldpath'Address, Newpath'Address);
191 end Build_Dynamic_Library;
197 function DLL_Ext return String is
206 function Dynamic_Option return String is
208 return "-dynamiclib";
215 function Is_Object_Ext (Ext : String) return Boolean is
224 function Is_C_Ext (Ext : String) return Boolean is
233 function Is_Archive_Ext (Ext : String) return Boolean is
235 return Ext = ".dylib" or else Ext = ".a";
242 function Libgnat return String is
247 ------------------------
248 -- Library_Exists_For --
249 ------------------------
251 function Library_Exists_For
252 (Project : Project_Id; In_Tree : Project_Tree_Ref) return Boolean
255 if not In_Tree.Projects.Table (Project).Library then
256 Prj.Com.Fail ("INTERNAL ERROR: Library_Exists_For called " &
257 "for non library project");
262 Lib_Dir : constant String :=
264 (In_Tree.Projects.Table (Project).Library_Dir);
265 Lib_Name : constant String :=
267 (In_Tree.Projects.Table (Project).Library_Name);
270 if In_Tree.Projects.Table (Project).Library_Kind =
273 return Is_Regular_File
274 (Lib_Dir & Directory_Separator & "lib" &
275 Fil.Ext_To (Lib_Name, Archive_Ext));
278 return Is_Regular_File
279 (Lib_Dir & Directory_Separator & "lib" &
280 Fil.Ext_To (Lib_Name, DLL_Ext));
284 end Library_Exists_For;
286 ---------------------------
287 -- Library_File_Name_For --
288 ---------------------------
290 function Library_File_Name_For
291 (Project : Project_Id;
292 In_Tree : Project_Tree_Ref) return Name_Id
295 if not In_Tree.Projects.Table (Project).Library then
296 Prj.Com.Fail ("INTERNAL ERROR: Library_File_Name_For called " &
297 "for non library project");
302 Lib_Name : constant String :=
304 (In_Tree.Projects.Table (Project).Library_Name);
308 Name_Buffer (1 .. Name_Len) := "lib";
310 if In_Tree.Projects.Table (Project).Library_Kind =
312 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, Archive_Ext));
315 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, DLL_Ext));
321 end Library_File_Name_For;
327 function Object_Ext return String is
336 function PIC_Option return String is
341 -----------------------------------------------
342 -- Standalone_Library_Auto_Init_Is_Supported --
343 -----------------------------------------------
345 function Standalone_Library_Auto_Init_Is_Supported return Boolean is
348 end Standalone_Library_Auto_Init_Is_Supported;
350 ---------------------------
351 -- Support_For_Libraries --
352 ---------------------------
354 function Support_For_Libraries return Library_Support is
357 end Support_For_Libraries;