1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
6 -- (GNU/Linux Version) --
10 -- Copyright (C) 2001-2004, 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 GNU/Linux 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;
51 Wl_Fini_String
: aliased String := "-Wl,-fini";
52 Wl_Fini
: constant String_Access
:= Wl_Fini_String
'Access;
54 Init_Fini_List
: constant Argument_List_Access
:=
55 new Argument_List
'(1 => Wl_Init,
59 -- Used to put switches for automatic elaboration/finalization
65 function Archive_Builder return String is
70 -----------------------------
71 -- Archive_Builder_Options --
72 -----------------------------
74 function Archive_Builder_Options return String_List_Access is
76 return new String_List'(1 => new String'("cr"));
77 end Archive_Builder_Options;
83 function Archive_Ext return String is
92 function Archive_Indexer return String is
97 -----------------------------
98 -- Archive_Indexer_Options --
99 -----------------------------
101 function Archive_Indexer_Options return String_List_Access is
103 return new String_List (1 .. 0);
104 end Archive_Indexer_Options;
106 ---------------------------
107 -- Build_Dynamic_Library --
108 ---------------------------
110 procedure Build_Dynamic_Library
111 (Ofiles : Argument_List;
112 Foreign : Argument_List;
113 Afiles : Argument_List;
114 Options : Argument_List;
115 Options_2 : Argument_List;
116 Interfaces : Argument_List;
117 Lib_Filename : String;
119 Symbol_Data : Symbol_Record;
120 Driver_Name : Name_Id := No_Name;
121 Lib_Version : String := "";
122 Auto_Init : Boolean := False)
124 pragma Unreferenced (Foreign);
125 pragma Unreferenced (Afiles);
126 pragma Unreferenced (Interfaces);
127 pragma Unreferenced (Symbol_Data);
129 Lib_File : constant String :=
130 Lib_Dir & Directory_Separator & "lib" &
131 Fil.Ext_To (Lib_Filename, DLL_Ext);
133 Version_Arg : String_Access;
134 Symbolic_Link_Needed : Boolean := False;
136 Init_Fini : Argument_List_Access := Empty_Argument_List;
139 if Opt.Verbose_Mode then
140 Write_Str ("building relocatable shared library ");
141 Write_Line (Lib_File);
144 -- If specified, add automatic elaboration/finalization
147 Init_Fini := Init_Fini_List;
148 Init_Fini (2) := new String'("-Wl," & Lib_Filename
& "init");
149 Init_Fini
(4) := new String'("-Wl," & Lib_Filename & "final");
152 if Lib_Version = "" then
154 (Output_File => Lib_File,
156 Options => Options & Init_Fini.all,
157 Driver_Name => Driver_Name,
158 Options_2 => Options_2);
161 Version_Arg := new String'("-Wl,-soname," & Lib_Version
);
163 if Is_Absolute_Path
(Lib_Version
) then
165 (Output_File
=> Lib_Version
,
167 Options
=> Options
& Version_Arg
& Init_Fini
.all,
168 Driver_Name
=> Driver_Name
,
169 Options_2
=> Options_2
);
170 Symbolic_Link_Needed
:= Lib_Version
/= Lib_File
;
174 (Output_File
=> Lib_Dir
& Directory_Separator
& Lib_Version
,
176 Options
=> Options
& Version_Arg
& Init_Fini
.all,
177 Driver_Name
=> Driver_Name
,
178 Options_2
=> Options_2
);
179 Symbolic_Link_Needed
:=
180 Lib_Dir
& Directory_Separator
& Lib_Version
/= Lib_File
;
183 if Symbolic_Link_Needed
then
186 Oldpath
: String (1 .. Lib_Version
'Length + 1);
187 Newpath
: String (1 .. Lib_File
'Length + 1);
190 pragma Unreferenced
(Result
);
193 (Oldpath
: System
.Address
;
194 Newpath
: System
.Address
) return Integer;
195 pragma Import
(C
, Symlink
, "__gnat_symlink");
198 Oldpath
(1 .. Lib_Version
'Length) := Lib_Version
;
199 Oldpath
(Oldpath
'Last) := ASCII
.NUL
;
200 Newpath
(1 .. Lib_File
'Length) := Lib_File
;
201 Newpath
(Newpath
'Last) := ASCII
.NUL
;
203 Delete_File
(Lib_File
, Success
);
205 Result
:= Symlink
(Oldpath
'Address, Newpath
'Address);
209 end Build_Dynamic_Library
;
215 function DLL_Ext
return String is
224 function Dynamic_Option
return String is
233 function Is_Object_Ext
(Ext
: String) return Boolean is
242 function Is_C_Ext
(Ext
: String) return Boolean is
251 function Is_Archive_Ext
(Ext
: String) return Boolean is
253 return Ext
= ".a" or else Ext
= ".so";
260 function Libgnat
return String is
265 ------------------------
266 -- Library_Exists_For --
267 ------------------------
269 function Library_Exists_For
(Project
: Project_Id
) return Boolean is
271 if not Projects
.Table
(Project
).Library
then
272 Prj
.Com
.Fail
("INTERNAL ERROR: Library_Exists_For called " &
273 "for non library project");
278 Lib_Dir
: constant String :=
279 Get_Name_String
(Projects
.Table
(Project
).Library_Dir
);
280 Lib_Name
: constant String :=
281 Get_Name_String
(Projects
.Table
(Project
).Library_Name
);
284 if Projects
.Table
(Project
).Library_Kind
= Static
then
285 return Is_Regular_File
286 (Lib_Dir
& Directory_Separator
& "lib" &
287 Fil
.Ext_To
(Lib_Name
, Archive_Ext
));
290 return Is_Regular_File
291 (Lib_Dir
& Directory_Separator
& "lib" &
292 Fil
.Ext_To
(Lib_Name
, DLL_Ext
));
296 end Library_Exists_For
;
298 ---------------------------
299 -- Library_File_Name_For --
300 ---------------------------
302 function Library_File_Name_For
(Project
: Project_Id
) return Name_Id
is
304 if not 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 :=
312 Get_Name_String
(Projects
.Table
(Project
).Library_Name
);
316 Name_Buffer
(1 .. Name_Len
) := "lib";
318 if Projects
.Table
(Project
).Library_Kind
= Static
then
319 Add_Str_To_Name_Buffer
(Fil
.Ext_To
(Lib_Name
, Archive_Ext
));
322 Add_Str_To_Name_Buffer
(Fil
.Ext_To
(Lib_Name
, DLL_Ext
));
328 end Library_File_Name_For
;
334 function Object_Ext
return String is
343 function PIC_Option
return String is
348 -----------------------------------------------
349 -- Standalone_Library_Auto_Init_Is_Supported --
350 -----------------------------------------------
352 function Standalone_Library_Auto_Init_Is_Supported
return Boolean is
355 end Standalone_Library_Auto_Init_Is_Supported
;
357 ---------------------------
358 -- Support_For_Libraries --
359 ---------------------------
361 function Support_For_Libraries
return Library_Support
is
364 end Support_For_Libraries
;