* gimplify.c (find_single_pointer_decl_1): New static function.
[official-gcc.git] / gcc / ada / mlib-tgt-irix.adb
blob7a77bff749377716086f2b3f8cd2f07d36695f7f
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, Ada Core Technologies, Inc. --
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 -- Dynamic_Option --
240 --------------------
242 function Dynamic_Option return String is
243 begin
244 return "-shared";
245 end Dynamic_Option;
247 -------------------
248 -- Is_Object_Ext --
249 -------------------
251 function Is_Object_Ext (Ext : String) return Boolean is
252 begin
253 return Ext = ".o";
254 end Is_Object_Ext;
256 --------------
257 -- Is_C_Ext --
258 --------------
260 function Is_C_Ext (Ext : String) return Boolean is
261 begin
262 return Ext = ".c";
263 end Is_C_Ext;
265 --------------------
266 -- Is_Archive_Ext --
267 --------------------
269 function Is_Archive_Ext (Ext : String) return Boolean is
270 begin
271 return Ext = ".a" or else Ext = ".so";
272 end Is_Archive_Ext;
274 -------------
275 -- Libgnat --
276 -------------
278 function Libgnat return String is
279 begin
280 return "libgnat.a";
281 end Libgnat;
283 ------------------------
284 -- Library_Exists_For --
285 ------------------------
287 function Library_Exists_For
288 (Project : Project_Id; In_Tree : Project_Tree_Ref) return Boolean
290 begin
291 if not In_Tree.Projects.Table (Project).Library then
292 Prj.Com.Fail ("INTERNAL ERROR: Library_Exists_For called " &
293 "for non library project");
294 return False;
296 else
297 declare
298 Lib_Dir : constant String :=
299 Get_Name_String
300 (In_Tree.Projects.Table (Project).Library_Dir);
301 Lib_Name : constant String :=
302 Get_Name_String
303 (In_Tree.Projects.Table (Project).Library_Name);
305 begin
306 if In_Tree.Projects.Table (Project).Library_Kind =
307 Static
308 then
309 return Is_Regular_File
310 (Lib_Dir & Directory_Separator & "lib" &
311 Fil.Ext_To (Lib_Name, Archive_Ext));
313 else
314 return Is_Regular_File
315 (Lib_Dir & Directory_Separator & "lib" &
316 Fil.Ext_To (Lib_Name, DLL_Ext));
317 end if;
318 end;
319 end if;
320 end Library_Exists_For;
322 ---------------------------
323 -- Library_File_Name_For --
324 ---------------------------
326 function Library_File_Name_For
327 (Project : Project_Id;
328 In_Tree : Project_Tree_Ref) return Name_Id
330 begin
331 if not In_Tree.Projects.Table (Project).Library then
332 Prj.Com.Fail ("INTERNAL ERROR: Library_File_Name_For called " &
333 "for non library project");
334 return No_Name;
336 else
337 declare
338 Lib_Name : constant String :=
339 Get_Name_String
340 (In_Tree.Projects.Table (Project).Library_Name);
342 begin
343 Name_Len := 3;
344 Name_Buffer (1 .. Name_Len) := "lib";
346 if In_Tree.Projects.Table (Project).Library_Kind =
347 Static
348 then
349 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, Archive_Ext));
351 else
352 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, DLL_Ext));
353 end if;
355 return Name_Find;
356 end;
357 end if;
358 end Library_File_Name_For;
360 ----------------
361 -- Object_Ext --
362 ----------------
364 function Object_Ext return String is
365 begin
366 return "o";
367 end Object_Ext;
369 ----------------
370 -- PIC_Option --
371 ----------------
373 function PIC_Option return String is
374 begin
375 return "-fPIC";
376 end PIC_Option;
378 -----------------------------------------------
379 -- Standalone_Library_Auto_Init_Is_Supported --
380 -----------------------------------------------
382 function Standalone_Library_Auto_Init_Is_Supported return Boolean is
383 begin
384 return True;
385 end Standalone_Library_Auto_Init_Is_Supported;
387 ---------------------------
388 -- Support_For_Libraries --
389 ---------------------------
391 function Support_For_Libraries return Library_Support is
392 begin
393 return Full;
394 end Support_For_Libraries;
396 end MLib.Tgt;