Add x prefix to v850e case for handling --with-cpu=v850e.
[official-gcc.git] / gcc / ada / 5lml-tgt.adb
blobbdabc5bc64e21eef163ffa5ec552f44aee683892
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- M L I B . T G T --
6 -- (GNU/Linux Version) --
7 -- --
8 -- B o d y --
9 -- --
10 -- --
11 -- Copyright (C) 2001, Ada Core Technologies, Inc. --
12 -- --
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. --
23 -- --
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). --
26 -- --
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;
36 with MLib.Fil;
37 with MLib.Utl;
38 with Namet; use Namet;
39 with Opt;
40 with Osint; use Osint;
41 with Output; use Output;
42 with System;
44 package body MLib.Tgt is
46 use GNAT;
47 use MLib;
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);
63 -------------
64 -- Add_Arg --
65 -------------
67 procedure Add_Arg (Arg : String) is
68 begin
69 if Last_Arg = Args'Last then
70 declare
71 New_Args : constant Argument_List_Access :=
72 new Argument_List (1 .. Args'Last * 2);
74 begin
75 New_Args (Args'Range) := Args.all;
76 Args := New_Args;
77 end;
78 end if;
80 Last_Arg := Last_Arg + 1;
81 Args (Last_Arg) := new String'(Arg);
82 end Add_Arg;
84 -----------------
85 -- Archive_Ext --
86 -----------------
88 function Archive_Ext return String is
89 begin
90 return "a";
91 end Archive_Ext;
93 -----------------
94 -- Base_Option --
95 -----------------
97 function Base_Option return String is
98 begin
99 return "";
100 end Base_Option;
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;
112 Lib_Dir : 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;
128 begin
129 if Opt.Verbose_Mode then
130 Write_Str ("building relocatable shared library ");
131 Write_Line (Lib_File);
132 end if;
134 if Lib_Version = "" then
135 Tools.Gcc
136 (Output_File => Lib_File,
137 Objects => Ofiles,
138 Options => Options);
140 else
141 Version_Arg := new String'("-Wl,-soname," & Lib_Version);
143 if Is_Absolute_Path (Lib_Version) then
144 Tools.Gcc
145 (Output_File => Lib_Version,
146 Objects => Ofiles,
147 Options => Options & Version_Arg);
148 Symbolic_Link_Needed := Lib_Version /= Lib_File;
150 else
151 Tools.Gcc
152 (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
153 Objects => Ofiles,
154 Options => Options & Version_Arg);
155 Symbolic_Link_Needed :=
156 Lib_Dir & Directory_Separator & Lib_Version /= Lib_File;
157 end if;
159 if Symbolic_Link_Needed then
160 declare
161 Success : Boolean;
162 Oldpath : String (1 .. Lib_Version'Length + 1);
163 Newpath : String (1 .. Lib_File'Length + 1);
164 Result : Integer;
166 function Symlink
167 (Oldpath : System.Address;
168 Newpath : System.Address)
169 return Integer;
170 pragma Import (C, Symlink, "__gnat_symlink");
172 begin
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);
181 end;
182 end if;
183 end if;
184 end Build_Dynamic_Library;
186 --------------------
187 -- Copy_ALI_Files --
188 --------------------
190 procedure Copy_ALI_Files
191 (From : Name_Id;
192 To : Name_Id)
194 Dir : Dir_Type;
195 Name : String (1 .. 1_000);
196 Last : Natural;
197 Success : Boolean;
198 From_Dir : constant String := Get_Name_String (From);
199 To_Dir : constant String_Access :=
200 new String'(Get_Name_String (To));
202 begin
203 Last_Arg := 0;
204 Open (Dir, From_Dir);
206 loop
207 Read (Dir, Name, Last);
208 exit when Last = 0;
209 if Last > 4
211 and then
212 To_Lower (Name (Last - 3 .. Last)) = ".ali"
213 then
214 Add_Arg (From_Dir & Directory_Separator & Name (1 .. Last));
215 end if;
216 end loop;
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);
224 Write_Char (' ');
225 end loop;
227 Write_Line (To_Dir.all);
228 end if;
230 Spawn (Cp.all,
231 Force & Args (1 .. Last_Arg) & To_Dir,
232 Success);
234 if not Success then
235 Fail ("could not copy ALI files to library dir");
236 end if;
237 end if;
238 end Copy_ALI_Files;
240 -------------------------
241 -- Default_DLL_Address --
242 -------------------------
244 function Default_DLL_Address return String is
245 begin
246 return "";
247 end Default_DLL_Address;
249 -------------
250 -- DLL_Ext --
251 -------------
253 function DLL_Ext return String is
254 begin
255 return "so";
256 end DLL_Ext;
258 --------------------
259 -- Dynamic_Option --
260 --------------------
262 function Dynamic_Option return String is
263 begin
264 return "-shared";
265 end Dynamic_Option;
267 -------------------
268 -- Is_Object_Ext --
269 -------------------
271 function Is_Object_Ext (Ext : String) return Boolean is
272 begin
273 return Ext = ".o";
274 end Is_Object_Ext;
276 --------------
277 -- Is_C_Ext --
278 --------------
280 function Is_C_Ext (Ext : String) return Boolean is
281 begin
282 return Ext = ".c";
283 end Is_C_Ext;
285 --------------------
286 -- Is_Archive_Ext --
287 --------------------
289 function Is_Archive_Ext (Ext : String) return Boolean is
290 begin
291 return Ext = ".a" or else Ext = ".so";
292 end Is_Archive_Ext;
294 -------------
295 -- Libgnat --
296 -------------
298 function Libgnat return String is
299 begin
300 return "libgnat.a";
301 end Libgnat;
303 -----------------------------
304 -- Libraries_Are_Supported --
305 -----------------------------
307 function Libraries_Are_Supported return Boolean is
308 begin
309 return True;
310 end Libraries_Are_Supported;
312 --------------------------------
313 -- Linker_Library_Path_Option --
314 --------------------------------
316 function Linker_Library_Path_Option
317 (Directory : String)
318 return String_Access
320 begin
321 return new String'("-Wl,-rpath," & Directory);
322 end Linker_Library_Path_Option;
324 ----------------
325 -- Object_Ext --
326 ----------------
328 function Object_Ext return String is
329 begin
330 return "o";
331 end Object_Ext;
333 ----------------
334 -- PIC_Option --
335 ----------------
337 function PIC_Option return String is
338 begin
339 return "-fPIC";
340 end PIC_Option;
342 end MLib.Tgt;