1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
6 -- (GNU/Linux Version) --
11 -- Copyright (C) 2001, Ada Core Technologies, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
29 -- This package provides a set of target dependent routines to build
30 -- static, dynamic and shared libraries.
32 -- This is the GNU/Linux version of the body.
34 with Ada.Characters.Handling; use Ada.Characters.Handling;
35 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
38 with Namet; use Namet;
40 with Osint; use Osint;
41 with Output; use Output;
44 package body MLib.Tgt is
49 -- ??? serious lack of comments below, all these declarations need to
50 -- be commented, none are:
52 package Files renames MLib.Fil;
53 package Tools renames MLib.Utl;
55 Args : Argument_List_Access := new Argument_List (1 .. 20);
56 Last_Arg : Natural := 0;
58 Cp : constant String_Access := Locate_Exec_On_Path ("cp");
59 Force : constant String_Access := new String'("-f");
61 procedure Add_Arg (Arg : String);
67 procedure Add_Arg (Arg : String) is
69 if Last_Arg = Args'Last then
71 New_Args : constant Argument_List_Access :=
72 new Argument_List (1 .. Args'Last * 2);
75 New_Args (Args'Range) := Args.all;
80 Last_Arg := Last_Arg + 1;
81 Args (Last_Arg) := new String'(Arg);
88 function Archive_Ext return String is
97 function Base_Option return String is
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 Lib_Filename : String;
113 Lib_Address : String := "";
114 Lib_Version : String := "";
115 Relocatable : Boolean := False)
117 Lib_File : constant String :=
118 Lib_Dir & Directory_Separator & "lib" &
119 Files.Ext_To (Lib_Filename, DLL_Ext);
121 use type Argument_List;
122 use type String_Access;
124 Version_Arg : String_Access;
126 Symbolic_Link_Needed : Boolean := False;
129 if Opt.Verbose_Mode then
130 Write_Str ("building relocatable shared library ");
131 Write_Line (Lib_File);
134 if Lib_Version = "" then
136 (Output_File => Lib_File,
141 Version_Arg := new String'("-Wl,-soname," & Lib_Version);
143 if Is_Absolute_Path (Lib_Version) then
145 (Output_File => Lib_Version,
147 Options => Options & Version_Arg);
148 Symbolic_Link_Needed := Lib_Version /= Lib_File;
152 (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
154 Options => Options & Version_Arg);
155 Symbolic_Link_Needed :=
156 Lib_Dir & Directory_Separator & Lib_Version /= Lib_File;
159 if Symbolic_Link_Needed then
162 Oldpath : String (1 .. Lib_Version'Length + 1);
163 Newpath : String (1 .. Lib_File'Length + 1);
167 (Oldpath : System.Address;
168 Newpath : System.Address)
170 pragma Import (C, Symlink, "__gnat_symlink");
173 Oldpath (1 .. Lib_Version'Length) := Lib_Version;
174 Oldpath (Oldpath'Last) := ASCII.NUL;
175 Newpath (1 .. Lib_File'Length) := Lib_File;
176 Newpath (Newpath'Last) := ASCII.NUL;
178 Delete_File (Lib_File, Success);
180 Result := Symlink (Oldpath'Address, Newpath'Address);
184 end Build_Dynamic_Library;
190 procedure Copy_ALI_Files
195 Name : String (1 .. 1_000);
198 From_Dir : constant String := Get_Name_String (From);
199 To_Dir : constant String_Access :=
200 new String'(Get_Name_String (To));
204 Open (Dir, From_Dir);
207 Read (Dir, Name, Last);
212 To_Lower (Name (Last - 3 .. Last)) = ".ali"
214 Add_Arg (From_Dir & Directory_Separator & Name (1 .. Last));
218 if Last_Arg /= 0 then
219 if not Opt.Quiet_Output then
220 Write_Str ("cp -f ");
222 for J in 1 .. Last_Arg loop
223 Write_Str (Args (J).all);
227 Write_Line (To_Dir.all);
231 Force & Args (1 .. Last_Arg) & To_Dir,
235 Fail ("could not copy ALI files to library dir");
240 -------------------------
241 -- Default_DLL_Address --
242 -------------------------
244 function Default_DLL_Address return String is
247 end Default_DLL_Address;
253 function DLL_Ext return String is
262 function Dynamic_Option return String is
271 function Is_Object_Ext (Ext : String) return Boolean is
280 function Is_C_Ext (Ext : String) return Boolean is
289 function Is_Archive_Ext (Ext : String) return Boolean is
291 return Ext = ".a" or else Ext = ".so";
298 function Libgnat return String is
303 -----------------------------
304 -- Libraries_Are_Supported --
305 -----------------------------
307 function Libraries_Are_Supported return Boolean is
310 end Libraries_Are_Supported;
312 --------------------------------
313 -- Linker_Library_Path_Option --
314 --------------------------------
316 function Linker_Library_Path_Option
321 return new String'("-Wl,-rpath," & Directory);
322 end Linker_Library_Path_Option;
328 function Object_Ext return String is
337 function PIC_Option return String is