1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
6 -- (GNU/Linux Version) --
10 -- Copyright (C) 2001, Ada Core Technologies, 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 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
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.
33 with Ada
.Characters
.Handling
; use Ada
.Characters
.Handling
;
34 with GNAT
.Directory_Operations
; use GNAT
.Directory_Operations
;
37 with Namet
; use Namet
;
39 with Osint
; use Osint
;
40 with Output
; use Output
;
43 package body MLib
.Tgt
is
48 -- ??? serious lack of comments below, all these declarations need to
49 -- be commented, none are:
51 package Files
renames MLib
.Fil
;
52 package Tools
renames MLib
.Utl
;
54 Args
: Argument_List_Access
:= new Argument_List
(1 .. 20);
55 Last_Arg
: Natural := 0;
57 Cp
: constant String_Access
:= Locate_Exec_On_Path
("cp");
58 Force
: constant String_Access
:= new String'("-f");
60 procedure Add_Arg (Arg : String);
66 procedure Add_Arg (Arg : String) is
68 if Last_Arg = Args'Last then
70 New_Args : constant Argument_List_Access :=
71 new Argument_List (1 .. Args'Last * 2);
74 New_Args (Args'Range) := Args.all;
79 Last_Arg := Last_Arg + 1;
80 Args (Last_Arg) := new String'(Arg
);
87 function Archive_Ext
return String is
96 function Base_Option
return String is
101 ---------------------------
102 -- Build_Dynamic_Library --
103 ---------------------------
105 procedure Build_Dynamic_Library
106 (Ofiles
: Argument_List
;
107 Foreign
: Argument_List
;
108 Afiles
: Argument_List
;
109 Options
: Argument_List
;
110 Lib_Filename
: String;
112 Lib_Address
: String := "";
113 Lib_Version
: String := "";
114 Relocatable
: Boolean := False)
116 Lib_File
: constant String :=
117 Lib_Dir
& Directory_Separator
& "lib" &
118 Files
.Ext_To
(Lib_Filename
, DLL_Ext
);
120 use type Argument_List
;
121 use type String_Access
;
123 Version_Arg
: String_Access
;
125 Symbolic_Link_Needed
: Boolean := False;
128 if Opt
.Verbose_Mode
then
129 Write_Str
("building relocatable shared library ");
130 Write_Line
(Lib_File
);
133 if Lib_Version
= "" then
135 (Output_File
=> Lib_File
,
140 Version_Arg
:= new String'("-Wl,-soname," & Lib_Version);
142 if Is_Absolute_Path (Lib_Version) then
144 (Output_File => Lib_Version,
146 Options => Options & Version_Arg);
147 Symbolic_Link_Needed := Lib_Version /= Lib_File;
151 (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
153 Options => Options & Version_Arg);
154 Symbolic_Link_Needed :=
155 Lib_Dir & Directory_Separator & Lib_Version /= Lib_File;
158 if Symbolic_Link_Needed then
161 Oldpath : String (1 .. Lib_Version'Length + 1);
162 Newpath : String (1 .. Lib_File'Length + 1);
166 (Oldpath : System.Address;
167 Newpath : System.Address)
169 pragma Import (C, Symlink, "__gnat_symlink");
172 Oldpath (1 .. Lib_Version'Length) := Lib_Version;
173 Oldpath (Oldpath'Last) := ASCII.NUL;
174 Newpath (1 .. Lib_File'Length) := Lib_File;
175 Newpath (Newpath'Last) := ASCII.NUL;
177 Delete_File (Lib_File, Success);
179 Result := Symlink (Oldpath'Address, Newpath'Address);
183 end Build_Dynamic_Library;
189 procedure Copy_ALI_Files
194 Name : String (1 .. 1_000);
197 From_Dir : constant String := Get_Name_String (From);
198 To_Dir : constant String_Access :=
199 new String'(Get_Name_String
(To
));
203 Open
(Dir
, From_Dir
);
206 Read
(Dir
, Name
, Last
);
211 To_Lower
(Name
(Last
- 3 .. Last
)) = ".ali"
213 Add_Arg
(From_Dir
& Directory_Separator
& Name
(1 .. Last
));
217 if Last_Arg
/= 0 then
218 if not Opt
.Quiet_Output
then
219 Write_Str
("cp -f ");
221 for J
in 1 .. Last_Arg
loop
222 Write_Str
(Args
(J
).all);
226 Write_Line
(To_Dir
.all);
230 Force
& Args
(1 .. Last_Arg
) & To_Dir
,
234 Fail
("could not copy ALI files to library dir");
239 -------------------------
240 -- Default_DLL_Address --
241 -------------------------
243 function Default_DLL_Address
return String is
246 end Default_DLL_Address
;
252 function DLL_Ext
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 -- Libraries_Are_Supported --
304 -----------------------------
306 function Libraries_Are_Supported
return Boolean is
309 end Libraries_Are_Supported
;
311 --------------------------------
312 -- Linker_Library_Path_Option --
313 --------------------------------
315 function Linker_Library_Path_Option
320 return new String'("-Wl,-rpath," & Directory);
321 end Linker_Library_Path_Option;
327 function Object_Ext return String is
336 function PIC_Option return String is