1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 2001-2006, 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
36 with Namet
; use Namet
;
38 with Output
; use Output
;
43 package body MLib
.Tgt
is
45 Flat_Namespace
: aliased String := "-Wl,-flat_namespace";
46 -- Instruct the linker to build the shared library as a flat
47 -- namespace image. The default is a two-level namespace image.
49 Shared_Libgcc
: aliased String := "-shared-libgcc";
51 No_Shared_Libgcc_Options
: aliased Argument_List
:=
52 (1 => Flat_Namespace
'Access);
53 With_Shared_Libgcc_Options
: aliased Argument_List
:=
54 (1 => Flat_Namespace
'Access,
55 2 => Shared_Libgcc
'Access);
61 function Archive_Builder
return String is
66 -----------------------------
67 -- Archive_Builder_Options --
68 -----------------------------
70 function Archive_Builder_Options
return String_List_Access
is
72 return new String_List
'(1 => new String'("cr"));
73 end Archive_Builder_Options
;
79 function Archive_Ext
return String is
88 function Archive_Indexer
return String is
93 -----------------------------
94 -- Archive_Indexer_Options --
95 -----------------------------
97 function Archive_Indexer_Options
return String_List_Access
is
99 return new String_List
'(1 => new String'("-c"));
100 end Archive_Indexer_Options
;
102 ---------------------------
103 -- Build_Dynamic_Library --
104 ---------------------------
106 procedure Build_Dynamic_Library
107 (Ofiles
: Argument_List
;
108 Foreign
: Argument_List
;
109 Afiles
: Argument_List
;
110 Options
: Argument_List
;
111 Options_2
: Argument_List
;
112 Interfaces
: Argument_List
;
113 Lib_Filename
: String;
115 Symbol_Data
: Symbol_Record
;
116 Driver_Name
: Name_Id
:= No_Name
;
117 Lib_Version
: String := "";
118 Auto_Init
: Boolean := False)
120 pragma Unreferenced
(Foreign
);
121 pragma Unreferenced
(Afiles
);
122 pragma Unreferenced
(Interfaces
);
123 pragma Unreferenced
(Symbol_Data
);
124 pragma Unreferenced
(Auto_Init
);
126 Lib_File
: constant String :=
127 Lib_Dir
& Directory_Separator
& "lib" &
128 Fil
.Append_To
(Lib_Filename
, DLL_Ext
);
130 Shared_Options
: Argument_List_Access
;
132 Symbolic_Link_Needed
: Boolean := False;
135 if Opt
.Verbose_Mode
then
136 Write_Str
("building relocatable shared library ");
137 Write_Line
(Lib_File
);
140 -- Invoke gcc with -shared-libgcc, but only for GCC 4 or higher
142 if GCC_Version
>= 4 then
143 Shared_Options
:= With_Shared_Libgcc_Options
'Access;
145 Shared_Options
:= No_Shared_Libgcc_Options
'Access;
148 -- If specified, add automatic elaboration/finalization
150 if Lib_Version
= "" then
152 (Output_File
=> Lib_File
,
154 Options
=> Options
& Shared_Options
.all,
155 Driver_Name
=> Driver_Name
,
156 Options_2
=> Options_2
);
160 if Is_Absolute_Path
(Lib_Version
) then
162 (Output_File
=> Lib_Version
,
164 Options
=> Options
& Shared_Options
.all,
165 Driver_Name
=> Driver_Name
,
166 Options_2
=> Options_2
);
167 Symbolic_Link_Needed
:= Lib_Version
/= Lib_File
;
171 (Output_File
=> Lib_Dir
& Directory_Separator
& Lib_Version
,
173 Options
=> Options
& Shared_Options
.all,
174 Driver_Name
=> Driver_Name
,
175 Options_2
=> Options_2
);
176 Symbolic_Link_Needed
:=
177 Lib_Dir
& Directory_Separator
& Lib_Version
/= Lib_File
;
180 if Symbolic_Link_Needed
then
183 Oldpath
: String (1 .. Lib_Version
'Length + 1);
184 Newpath
: String (1 .. Lib_File
'Length + 1);
187 pragma Unreferenced
(Result
);
190 (Oldpath
: System
.Address
;
191 Newpath
: System
.Address
) return Integer;
192 pragma Import
(C
, Symlink
, "__gnat_symlink");
195 Oldpath
(1 .. Lib_Version
'Length) := Lib_Version
;
196 Oldpath
(Oldpath
'Last) := ASCII
.NUL
;
197 Newpath
(1 .. Lib_File
'Length) := Lib_File
;
198 Newpath
(Newpath
'Last) := ASCII
.NUL
;
200 Delete_File
(Lib_File
, Success
);
202 Result
:= Symlink
(Oldpath
'Address, Newpath
'Address);
206 end Build_Dynamic_Library
;
212 function DLL_Ext
return String is
221 function DLL_Prefix
return String is
230 function Dynamic_Option
return String is
232 return "-dynamiclib";
239 function Is_Object_Ext
(Ext
: String) return Boolean is
248 function Is_C_Ext
(Ext
: String) return Boolean is
257 function Is_Archive_Ext
(Ext
: String) return Boolean is
259 return Ext
= ".dylib" or else Ext
= ".a";
266 function Libgnat
return String is
271 ------------------------
272 -- Library_Exists_For --
273 ------------------------
275 function Library_Exists_For
276 (Project
: Project_Id
;
277 In_Tree
: Project_Tree_Ref
) return Boolean
280 if not In_Tree
.Projects
.Table
(Project
).Library
then
281 Prj
.Com
.Fail
("INTERNAL ERROR: Library_Exists_For called " &
282 "for non library project");
287 Lib_Dir
: constant String :=
289 (In_Tree
.Projects
.Table
(Project
).Library_Dir
);
290 Lib_Name
: constant String :=
292 (In_Tree
.Projects
.Table
(Project
).Library_Name
);
295 if In_Tree
.Projects
.Table
(Project
).Library_Kind
= Static
then
296 return Is_Regular_File
297 (Lib_Dir
& Directory_Separator
& "lib" &
298 Fil
.Append_To
(Lib_Name
, Archive_Ext
));
301 return Is_Regular_File
302 (Lib_Dir
& Directory_Separator
& "lib" &
303 Fil
.Append_To
(Lib_Name
, DLL_Ext
));
307 end Library_Exists_For
;
309 ---------------------------
310 -- Library_File_Name_For --
311 ---------------------------
313 function Library_File_Name_For
314 (Project
: Project_Id
;
315 In_Tree
: Project_Tree_Ref
) return Name_Id
318 if not In_Tree
.Projects
.Table
(Project
).Library
then
319 Prj
.Com
.Fail
("INTERNAL ERROR: Library_File_Name_For called " &
320 "for non library project");
325 Lib_Name
: constant String :=
327 (In_Tree
.Projects
.Table
(Project
).Library_Name
);
331 Name_Buffer
(1 .. Name_Len
) := "lib";
333 if In_Tree
.Projects
.Table
(Project
).Library_Kind
=
335 Add_Str_To_Name_Buffer
(Fil
.Append_To
(Lib_Name
, Archive_Ext
));
337 Add_Str_To_Name_Buffer
(Fil
.Append_To
(Lib_Name
, DLL_Ext
));
343 end Library_File_Name_For
;
349 function Object_Ext
return String is
358 function PIC_Option
return String is
363 -----------------------------------------------
364 -- Standalone_Library_Auto_Init_Is_Supported --
365 -----------------------------------------------
367 function Standalone_Library_Auto_Init_Is_Supported
return Boolean is
370 end Standalone_Library_Auto_Init_Is_Supported
;
372 ---------------------------
373 -- Support_For_Libraries --
374 ---------------------------
376 function Support_For_Libraries
return Library_Support
is
379 end Support_For_Libraries
;