1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
6 -- (GNU/Linux Version) --
12 -- Copyright (C) 2001, Ada Core Technologies, Inc. --
14 -- GNAT is free software; you can redistribute it and/or modify it under --
15 -- terms of the GNU General Public License as published by the Free Soft- --
16 -- ware Foundation; either version 2, or (at your option) any later ver- --
17 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
18 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
19 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
20 -- for more details. You should have received a copy of the GNU General --
21 -- Public License distributed with GNAT; see file COPYING. If not, write --
22 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
23 -- MA 02111-1307, USA. --
25 -- GNAT was originally developed by the GNAT team at New York University. --
26 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
28 ------------------------------------------------------------------------------
30 -- This package provides a set of target dependent routines to build
31 -- static, dynamic and shared libraries.
33 -- This is the GNU/Linux version of the body.
35 with Ada
.Characters
.Handling
; use Ada
.Characters
.Handling
;
36 with GNAT
.Directory_Operations
; use GNAT
.Directory_Operations
;
39 with Namet
; use Namet
;
41 with Osint
; use Osint
;
42 with Output
; use Output
;
45 package body MLib
.Tgt
is
50 -- ??? serious lack of comments below, all these declarations need to
51 -- be commented, none are:
53 package Files
renames MLib
.Fil
;
54 package Tools
renames MLib
.Utl
;
56 Args
: Argument_List_Access
:= new Argument_List
(1 .. 20);
57 Last_Arg
: Natural := 0;
59 Cp
: constant String_Access
:= Locate_Exec_On_Path
("cp");
60 Force
: constant String_Access
:= new String'("-f");
62 procedure Add_Arg (Arg : String);
68 procedure Add_Arg (Arg : String) is
70 if Last_Arg = Args'Last then
72 New_Args : constant Argument_List_Access :=
73 new Argument_List (1 .. Args'Last * 2);
76 New_Args (Args'Range) := Args.all;
81 Last_Arg := Last_Arg + 1;
82 Args (Last_Arg) := new String'(Arg
);
89 function Archive_Ext
return String is
98 function Base_Option
return String is
103 ---------------------------
104 -- Build_Dynamic_Library --
105 ---------------------------
107 procedure Build_Dynamic_Library
108 (Ofiles
: Argument_List
;
109 Foreign
: Argument_List
;
110 Afiles
: Argument_List
;
111 Options
: Argument_List
;
112 Lib_Filename
: String;
114 Lib_Address
: String := "";
115 Lib_Version
: String := "";
116 Relocatable
: Boolean := False)
118 Lib_File
: constant String :=
119 Lib_Dir
& Directory_Separator
& "lib" &
120 Files
.Ext_To
(Lib_Filename
, DLL_Ext
);
122 use type Argument_List
;
123 use type String_Access
;
125 Version_Arg
: String_Access
;
127 Symbolic_Link_Needed
: Boolean := False;
130 if Opt
.Verbose_Mode
then
131 Write_Str
("building relocatable shared library ");
132 Write_Line
(Lib_File
);
135 if Lib_Version
= "" then
137 (Output_File
=> Lib_File
,
142 Version_Arg
:= new String'("-Wl,-soname," & Lib_Version);
144 if Is_Absolute_Path (Lib_Version) then
146 (Output_File => Lib_Version,
148 Options => Options & Version_Arg);
149 Symbolic_Link_Needed := Lib_Version /= Lib_File;
153 (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
155 Options => Options & Version_Arg);
156 Symbolic_Link_Needed :=
157 Lib_Dir & Directory_Separator & Lib_Version /= Lib_File;
160 if Symbolic_Link_Needed then
163 Oldpath : String (1 .. Lib_Version'Length + 1);
164 Newpath : String (1 .. Lib_File'Length + 1);
168 (Oldpath : System.Address;
169 Newpath : System.Address)
171 pragma Import (C, Symlink, "__gnat_symlink");
174 Oldpath (1 .. Lib_Version'Length) := Lib_Version;
175 Oldpath (Oldpath'Last) := ASCII.NUL;
176 Newpath (1 .. Lib_File'Length) := Lib_File;
177 Newpath (Newpath'Last) := ASCII.NUL;
179 Delete_File (Lib_File, Success);
181 Result := Symlink (Oldpath'Address, Newpath'Address);
185 end Build_Dynamic_Library;
191 procedure Copy_ALI_Files
196 Name : String (1 .. 1_000);
199 From_Dir : constant String := Get_Name_String (From);
200 To_Dir : constant String_Access :=
201 new String'(Get_Name_String
(To
));
205 Open
(Dir
, From_Dir
);
208 Read
(Dir
, Name
, Last
);
213 To_Lower
(Name
(Last
- 3 .. Last
)) = ".ali"
215 Add_Arg
(From_Dir
& Directory_Separator
& Name
(1 .. Last
));
219 if Last_Arg
/= 0 then
220 if not Opt
.Quiet_Output
then
221 Write_Str
("cp -f ");
223 for J
in 1 .. Last_Arg
loop
224 Write_Str
(Args
(J
).all);
228 Write_Line
(To_Dir
.all);
232 Force
& Args
(1 .. Last_Arg
) & To_Dir
,
236 Fail
("could not copy ALI files to library dir");
241 -------------------------
242 -- Default_DLL_Address --
243 -------------------------
245 function Default_DLL_Address
return String is
248 end Default_DLL_Address
;
254 function DLL_Ext
return String is
263 function Dynamic_Option
return String is
272 function Is_Object_Ext
(Ext
: String) return Boolean is
281 function Is_C_Ext
(Ext
: String) return Boolean is
290 function Is_Archive_Ext
(Ext
: String) return Boolean is
292 return Ext
= ".a" or else Ext
= ".so";
299 function Libgnat
return String is
304 -----------------------------
305 -- Libraries_Are_Supported --
306 -----------------------------
308 function Libraries_Are_Supported
return Boolean is
311 end Libraries_Are_Supported
;
313 --------------------------------
314 -- Linker_Library_Path_Option --
315 --------------------------------
317 function Linker_Library_Path_Option
322 return new String'("-Wl,-rpath," & Directory);
323 end Linker_Library_Path_Option;
329 function Object_Ext return String is
338 function PIC_Option return String is