1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
6 -- (GNU/Linux Version) --
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 GNU/Linux 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 .. 0);
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
);
114 -- Initialization is done through the contructor mechanism
116 Lib_File
: constant String :=
117 Lib_Dir
& Directory_Separator
& "lib" &
118 Fil
.Append_To
(Lib_Filename
, DLL_Ext
);
120 Version_Arg
: String_Access
;
121 Symbolic_Link_Needed
: Boolean := False;
124 if Opt
.Verbose_Mode
then
125 Write_Str
("building relocatable shared library ");
126 Write_Line
(Lib_File
);
129 if Lib_Version
= "" then
131 (Output_File
=> Lib_File
,
134 Driver_Name
=> Driver_Name
,
135 Options_2
=> Options_2
);
139 Maj_Version
: constant String := Lib_Version
;
140 Last_Maj
: Positive := Maj_Version
'Last;
142 Ok_Maj
: Boolean := False;
144 while Last_Maj
> Maj_Version
'First loop
145 if Maj_Version
(Last_Maj
) in '0' .. '9' then
146 Last_Maj
:= Last_Maj
- 1;
149 Ok_Maj
:= Last_Maj
/= Maj_Version
'Last and then
150 Maj_Version
(Last_Maj
) = '.';
153 Last_Maj
:= Last_Maj
- 1;
163 while Last
> Maj_Version
'First loop
164 if Maj_Version
(Last
) in '0' .. '9' then
168 Ok_Maj
:= Last
/= Last_Maj
and then
169 Maj_Version
(Last
) = '.';
174 Ok_Maj
:= Maj_Version
(1 .. Last
) = Lib_File
;
183 Version_Arg
:= new String'("-Wl,-soname," &
184 Maj_Version (1 .. Last_Maj));
187 Version_Arg := new String'("-Wl,-soname," & Lib_Version
);
190 if Is_Absolute_Path
(Lib_Version
) then
192 (Output_File
=> Lib_Version
,
194 Options
=> Options
& Version_Arg
,
195 Driver_Name
=> Driver_Name
,
196 Options_2
=> Options_2
);
197 Symbolic_Link_Needed
:= Lib_Version
/= Lib_File
;
201 (Output_File
=> Lib_Dir
& Directory_Separator
& Lib_Version
,
203 Options
=> Options
& Version_Arg
,
204 Driver_Name
=> Driver_Name
,
205 Options_2
=> Options_2
);
206 Symbolic_Link_Needed
:=
207 Lib_Dir
& Directory_Separator
& Lib_Version
/= Lib_File
;
210 if Symbolic_Link_Needed
then
213 Oldpath
: String (1 .. Lib_Version
'Length + 1);
214 Newpath
: String (1 .. Lib_File
'Length + 1);
217 pragma Unreferenced
(Result
);
220 (Oldpath
: System
.Address
;
221 Newpath
: System
.Address
) return Integer;
222 pragma Import
(C
, Symlink
, "__gnat_symlink");
225 Oldpath
(1 .. Lib_Version
'Length) := Lib_Version
;
226 Oldpath
(Oldpath
'Last) := ASCII
.NUL
;
227 Newpath
(1 .. Lib_File
'Length) := Lib_File
;
228 Newpath
(Newpath
'Last) := ASCII
.NUL
;
230 Delete_File
(Lib_File
, Success
);
232 Result
:= Symlink
(Oldpath
'Address, Newpath
'Address);
237 end Build_Dynamic_Library
;
243 function DLL_Ext
return String is
252 function DLL_Prefix
return String is
261 function Dynamic_Option
return String is
270 function Is_Object_Ext
(Ext
: String) return Boolean is
279 function Is_C_Ext
(Ext
: String) return Boolean is
288 function Is_Archive_Ext
(Ext
: String) return Boolean is
290 return Ext
= ".a" or else Ext
= ".so";
297 function Libgnat
return String is
302 ------------------------
303 -- Library_Exists_For --
304 ------------------------
306 function Library_Exists_For
307 (Project
: Project_Id
;
308 In_Tree
: Project_Tree_Ref
) return Boolean
311 if not In_Tree
.Projects
.Table
(Project
).Library
then
312 Prj
.Com
.Fail
("INTERNAL ERROR: Library_Exists_For called " &
313 "for non library project");
318 Lib_Dir
: constant String :=
320 (In_Tree
.Projects
.Table
(Project
).Library_Dir
);
321 Lib_Name
: constant String :=
323 (In_Tree
.Projects
.Table
(Project
).Library_Name
);
326 if In_Tree
.Projects
.Table
(Project
).Library_Kind
= Static
then
327 return Is_Regular_File
328 (Lib_Dir
& Directory_Separator
& "lib" &
329 Fil
.Append_To
(Lib_Name
, Archive_Ext
));
332 return Is_Regular_File
333 (Lib_Dir
& Directory_Separator
& "lib" &
334 Fil
.Append_To
(Lib_Name
, DLL_Ext
));
338 end Library_Exists_For
;
340 ---------------------------
341 -- Library_File_Name_For --
342 ---------------------------
344 function Library_File_Name_For
345 (Project
: Project_Id
;
346 In_Tree
: Project_Tree_Ref
) return Name_Id
349 if not In_Tree
.Projects
.Table
(Project
).Library
then
350 Prj
.Com
.Fail
("INTERNAL ERROR: Library_File_Name_For called " &
351 "for non library project");
356 Lib_Name
: constant String :=
358 (In_Tree
.Projects
.Table
(Project
).Library_Name
);
362 Name_Buffer
(1 .. Name_Len
) := "lib";
364 if In_Tree
.Projects
.Table
(Project
).Library_Kind
=
367 Add_Str_To_Name_Buffer
(Fil
.Append_To
(Lib_Name
, Archive_Ext
));
369 Add_Str_To_Name_Buffer
(Fil
.Append_To
(Lib_Name
, DLL_Ext
));
375 end Library_File_Name_For
;
381 function Object_Ext
return String is
390 function PIC_Option
return String is
395 -----------------------------------------------
396 -- Standalone_Library_Auto_Init_Is_Supported --
397 -----------------------------------------------
399 function Standalone_Library_Auto_Init_Is_Supported
return Boolean is
402 end Standalone_Library_Auto_Init_Is_Supported
;
404 ---------------------------
405 -- Support_For_Libraries --
406 ---------------------------
408 function Support_For_Libraries
return Library_Support
is
411 end Support_For_Libraries
;