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 DLL_Prefix return String is
215 function Dynamic_Option return String is
217 return "-dynamiclib";
224 function Is_Object_Ext (Ext : String) return Boolean is
233 function Is_C_Ext (Ext : String) return Boolean is
242 function Is_Archive_Ext (Ext : String) return Boolean is
244 return Ext = ".dylib" or else Ext = ".a";
251 function Libgnat return String is
256 ------------------------
257 -- Library_Exists_For --
258 ------------------------
260 function Library_Exists_For
261 (Project : Project_Id; In_Tree : Project_Tree_Ref) return Boolean
264 if not In_Tree.Projects.Table (Project).Library then
265 Prj.Com.Fail ("INTERNAL ERROR: Library_Exists_For called " &
266 "for non library project");
271 Lib_Dir : constant String :=
273 (In_Tree.Projects.Table (Project).Library_Dir);
274 Lib_Name : constant String :=
276 (In_Tree.Projects.Table (Project).Library_Name);
279 if In_Tree.Projects.Table (Project).Library_Kind =
282 return Is_Regular_File
283 (Lib_Dir & Directory_Separator & "lib" &
284 Fil.Ext_To (Lib_Name, Archive_Ext));
287 return Is_Regular_File
288 (Lib_Dir & Directory_Separator & "lib" &
289 Fil.Ext_To (Lib_Name, DLL_Ext));
293 end Library_Exists_For;
295 ---------------------------
296 -- Library_File_Name_For --
297 ---------------------------
299 function Library_File_Name_For
300 (Project : Project_Id;
301 In_Tree : Project_Tree_Ref) return Name_Id
304 if not In_Tree.Projects.Table (Project).Library then
305 Prj.Com.Fail ("INTERNAL ERROR: Library_File_Name_For called " &
306 "for non library project");
311 Lib_Name : constant String :=
313 (In_Tree.Projects.Table (Project).Library_Name);
317 Name_Buffer (1 .. Name_Len) := "lib";
319 if In_Tree.Projects.Table (Project).Library_Kind =
321 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, Archive_Ext));
324 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, DLL_Ext));
330 end Library_File_Name_For;
336 function Object_Ext return String is
345 function PIC_Option return String is
350 -----------------------------------------------
351 -- Standalone_Library_Auto_Init_Is_Supported --
352 -----------------------------------------------
354 function Standalone_Library_Auto_Init_Is_Supported return Boolean is
357 end Standalone_Library_Auto_Init_Is_Supported;
359 ---------------------------
360 -- Support_For_Libraries --
361 ---------------------------
363 function Support_For_Libraries return Library_Support is
366 end Support_For_Libraries;