* testsuite/libgomp.fortran/vla7.f90: Add -w to options.
[official-gcc.git] / gcc / ada / mlib-tgt-irix.adb
blobd7749a9cd97083ad06c9dfd8db8cd5fd152476cb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- M L I B . T G T --
6 -- (IRIX Version) --
7 -- --
8 -- B o d y --
9 -- --
10 -- Copyright (C) 2003-2005, AdaCore --
11 -- --
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, 51 Franklin Street, Fifth Floor, --
21 -- Boston, MA 02110-1301, USA. --
22 -- --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 -- --
26 ------------------------------------------------------------------------------
28 -- This package provides a set of target dependent routines to build
29 -- static, dynamic and shared libraries.
31 -- This is the IRIX version of the body
33 with MLib.Fil;
34 with MLib.Utl;
35 with Namet; use Namet;
36 with Opt;
37 with Output; use Output;
38 with Prj.Com;
39 with System;
41 package body MLib.Tgt is
43 ---------------------
44 -- Archive_Builder --
45 ---------------------
47 function Archive_Builder return String is
48 begin
49 return "ar";
50 end Archive_Builder;
52 -----------------------------
53 -- Archive_Builder_Options --
54 -----------------------------
56 function Archive_Builder_Options return String_List_Access is
57 begin
58 return new String_List'(1 => new String'("cr"));
59 end Archive_Builder_Options;
61 -----------------
62 -- Archive_Ext --
63 -----------------
65 function Archive_Ext return String is
66 begin
67 return "a";
68 end Archive_Ext;
70 ---------------------
71 -- Archive_Indexer --
72 ---------------------
74 function Archive_Indexer return String is
75 begin
76 return "ranlib";
77 end Archive_Indexer;
79 -----------------------------
80 -- Archive_Indexer_Options --
81 -----------------------------
83 function Archive_Indexer_Options return String_List_Access is
84 begin
85 return new String_List (1 .. 0);
86 end Archive_Indexer_Options;
88 ---------------------------
89 -- Build_Dynamic_Library --
90 ---------------------------
92 procedure Build_Dynamic_Library
93 (Ofiles : Argument_List;
94 Foreign : Argument_List;
95 Afiles : Argument_List;
96 Options : Argument_List;
97 Options_2 : Argument_List;
98 Interfaces : Argument_List;
99 Lib_Filename : String;
100 Lib_Dir : String;
101 Symbol_Data : Symbol_Record;
102 Driver_Name : Name_Id := No_Name;
103 Lib_Version : String := "";
104 Auto_Init : Boolean := False)
106 pragma Unreferenced (Foreign);
107 pragma Unreferenced (Afiles);
108 pragma Unreferenced (Interfaces);
109 pragma Unreferenced (Symbol_Data);
110 pragma Unreferenced (Auto_Init);
112 Lib_File : constant String :=
113 Lib_Dir & Directory_Separator & "lib" &
114 MLib.Fil.Ext_To (Lib_Filename, DLL_Ext);
116 Version_Arg : String_Access;
117 Symbolic_Link_Needed : Boolean := False;
119 N_Options : Argument_List := Options;
120 Options_Last : Natural := N_Options'Last;
121 -- After moving -lxxx to Options_2, N_Options up to index Options_Last
122 -- will contain the Options to pass to MLib.Utl.Gcc.
124 Real_Options_2 : Argument_List (1 .. Options'Length + Options_2'Length);
125 Real_Options_2_Last : Natural := 0;
126 -- Real_Options_2 up to index Real_Options_2_Last will contain the
127 -- Options_2 to pass to MLib.Utl.Gcc.
129 begin
130 if Opt.Verbose_Mode then
131 Write_Str ("building relocatable shared library ");
132 Write_Line (Lib_File);
133 end if;
135 -- Move all -lxxx to Options_2
137 declare
138 Index : Natural := N_Options'First;
139 Arg : String_Access;
141 begin
142 while Index <= Options_Last loop
143 Arg := N_Options (Index);
145 if Arg'Length > 2
146 and then Arg (Arg'First .. Arg'First + 1) = "-l"
147 then
148 Real_Options_2_Last := Real_Options_2_Last + 1;
149 Real_Options_2 (Real_Options_2_Last) := Arg;
150 N_Options (Index .. Options_Last - 1) :=
151 N_Options (Index + 1 .. Options_Last);
152 Options_Last := Options_Last - 1;
154 else
155 Index := Index + 1;
156 end if;
157 end loop;
158 end;
160 -- Add to Real_Options_2 the argument Options_2
162 Real_Options_2
163 (Real_Options_2_Last + 1 .. Real_Options_2_Last + Options_2'Length) :=
164 Options_2;
165 Real_Options_2_Last := Real_Options_2_Last + Options_2'Length;
167 if Lib_Version = "" then
168 MLib.Utl.Gcc
169 (Output_File => Lib_File,
170 Objects => Ofiles,
171 Options => N_Options (N_Options'First .. Options_Last),
172 Driver_Name => Driver_Name,
173 Options_2 => Real_Options_2 (1 .. Real_Options_2_Last));
175 else
176 Version_Arg := new String'("-Wl,-soname," & Lib_Version);
178 if Is_Absolute_Path (Lib_Version) then
179 MLib.Utl.Gcc
180 (Output_File => Lib_Version,
181 Objects => Ofiles,
182 Options => N_Options (N_Options'First .. Options_Last) &
183 Version_Arg,
184 Driver_Name => Driver_Name,
185 Options_2 => Real_Options_2 (1 .. Real_Options_2_Last));
186 Symbolic_Link_Needed := Lib_Version /= Lib_File;
188 else
189 MLib.Utl.Gcc
190 (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
191 Objects => Ofiles,
192 Options => N_Options (N_Options'First .. Options_Last) &
193 Version_Arg,
194 Driver_Name => Driver_Name,
195 Options_2 => Real_Options_2 (1 .. Real_Options_2_Last));
196 Symbolic_Link_Needed :=
197 Lib_Dir & Directory_Separator & Lib_Version /= Lib_File;
198 end if;
200 if Symbolic_Link_Needed then
201 declare
202 Success : Boolean;
203 Oldpath : String (1 .. Lib_Version'Length + 1);
204 Newpath : String (1 .. Lib_File'Length + 1);
206 Result : Integer;
207 pragma Unreferenced (Result);
209 function Symlink
210 (Oldpath : System.Address;
211 Newpath : System.Address)
212 return Integer;
213 pragma Import (C, Symlink, "__gnat_symlink");
215 begin
216 Oldpath (1 .. Lib_Version'Length) := Lib_Version;
217 Oldpath (Oldpath'Last) := ASCII.NUL;
218 Newpath (1 .. Lib_File'Length) := Lib_File;
219 Newpath (Newpath'Last) := ASCII.NUL;
221 Delete_File (Lib_File, Success);
223 Result := Symlink (Oldpath'Address, Newpath'Address);
224 end;
225 end if;
226 end if;
227 end Build_Dynamic_Library;
229 -------------
230 -- DLL_Ext --
231 -------------
233 function DLL_Ext return String is
234 begin
235 return "so";
236 end DLL_Ext;
238 ----------------
239 -- DLL_Prefix --
240 ----------------
242 function DLL_Prefix return String is
243 begin
244 return "lib";
245 end DLL_Prefix;
247 --------------------
248 -- Dynamic_Option --
249 --------------------
251 function Dynamic_Option return String is
252 begin
253 return "-shared";
254 end Dynamic_Option;
256 -------------------
257 -- Is_Object_Ext --
258 -------------------
260 function Is_Object_Ext (Ext : String) return Boolean is
261 begin
262 return Ext = ".o";
263 end Is_Object_Ext;
265 --------------
266 -- Is_C_Ext --
267 --------------
269 function Is_C_Ext (Ext : String) return Boolean is
270 begin
271 return Ext = ".c";
272 end Is_C_Ext;
274 --------------------
275 -- Is_Archive_Ext --
276 --------------------
278 function Is_Archive_Ext (Ext : String) return Boolean is
279 begin
280 return Ext = ".a" or else Ext = ".so";
281 end Is_Archive_Ext;
283 -------------
284 -- Libgnat --
285 -------------
287 function Libgnat return String is
288 begin
289 return "libgnat.a";
290 end Libgnat;
292 ------------------------
293 -- Library_Exists_For --
294 ------------------------
296 function Library_Exists_For
297 (Project : Project_Id; In_Tree : Project_Tree_Ref) return Boolean
299 begin
300 if not In_Tree.Projects.Table (Project).Library then
301 Prj.Com.Fail ("INTERNAL ERROR: Library_Exists_For called " &
302 "for non library project");
303 return False;
305 else
306 declare
307 Lib_Dir : constant String :=
308 Get_Name_String
309 (In_Tree.Projects.Table (Project).Library_Dir);
310 Lib_Name : constant String :=
311 Get_Name_String
312 (In_Tree.Projects.Table (Project).Library_Name);
314 begin
315 if In_Tree.Projects.Table (Project).Library_Kind =
316 Static
317 then
318 return Is_Regular_File
319 (Lib_Dir & Directory_Separator & "lib" &
320 Fil.Ext_To (Lib_Name, Archive_Ext));
322 else
323 return Is_Regular_File
324 (Lib_Dir & Directory_Separator & "lib" &
325 Fil.Ext_To (Lib_Name, DLL_Ext));
326 end if;
327 end;
328 end if;
329 end Library_Exists_For;
331 ---------------------------
332 -- Library_File_Name_For --
333 ---------------------------
335 function Library_File_Name_For
336 (Project : Project_Id;
337 In_Tree : Project_Tree_Ref) return Name_Id
339 begin
340 if not In_Tree.Projects.Table (Project).Library then
341 Prj.Com.Fail ("INTERNAL ERROR: Library_File_Name_For called " &
342 "for non library project");
343 return No_Name;
345 else
346 declare
347 Lib_Name : constant String :=
348 Get_Name_String
349 (In_Tree.Projects.Table (Project).Library_Name);
351 begin
352 Name_Len := 3;
353 Name_Buffer (1 .. Name_Len) := "lib";
355 if In_Tree.Projects.Table (Project).Library_Kind =
356 Static
357 then
358 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, Archive_Ext));
360 else
361 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, DLL_Ext));
362 end if;
364 return Name_Find;
365 end;
366 end if;
367 end Library_File_Name_For;
369 ----------------
370 -- Object_Ext --
371 ----------------
373 function Object_Ext return String is
374 begin
375 return "o";
376 end Object_Ext;
378 ----------------
379 -- PIC_Option --
380 ----------------
382 function PIC_Option return String is
383 begin
384 return "-fPIC";
385 end PIC_Option;
387 -----------------------------------------------
388 -- Standalone_Library_Auto_Init_Is_Supported --
389 -----------------------------------------------
391 function Standalone_Library_Auto_Init_Is_Supported return Boolean is
392 begin
393 return True;
394 end Standalone_Library_Auto_Init_Is_Supported;
396 ---------------------------
397 -- Support_For_Libraries --
398 ---------------------------
400 function Support_For_Libraries return Library_Support is
401 begin
402 return Full;
403 end Support_For_Libraries;
405 end MLib.Tgt;