Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / gcc / ada / mlib-tgt-aix.adb
blob004cab8b9ade20d393e61d3f7e13fbb9f316001e
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- M L I B . T G T --
6 -- (AIX Version) --
7 -- --
8 -- B o d y --
9 -- --
10 -- Copyright (C) 2003-2004, 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, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, 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 or relocatable libraries.
31 -- This is the AIX version of the body.
33 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
34 with GNAT.OS_Lib; use GNAT.OS_Lib;
36 with MLib.Fil;
37 with MLib.Utl;
38 with Namet; use Namet;
39 with Osint; use Osint;
40 with Opt;
41 with Output; use Output;
42 with Prj.Com;
43 with Prj.Util; use Prj.Util;
45 package body MLib.Tgt is
47 No_Arguments : aliased Argument_List := (1 .. 0 => null);
48 Empty_Argument_List : constant Argument_List_Access := No_Arguments'Access;
50 Wl_Initfini_String : constant String := "-Wl,-binitfini:";
52 Init_Fini_List : constant Argument_List_Access :=
53 new Argument_List'(1 => null);
54 -- Used to put switch for automatic elaboration/finalization
56 Bexpall : aliased String := "-Wl,-bexpall";
57 Bexpall_Option : constant String_Access := Bexpall'Access;
58 -- The switch to export all symbols
60 Lpthreads : aliased String := "-lpthreads";
61 Native_Thread_Options : aliased Argument_List := (1 => Lpthreads'Access);
62 -- The switch to use when linking a library against libgnarl when using
63 -- Native threads.
65 Lgthreads : aliased String := "-lgthreads";
66 Lmalloc : aliased String := "-lmalloc";
67 FSU_Thread_Options : aliased Argument_List :=
68 (1 => Lgthreads'Access, 2 => Lmalloc'Access);
69 -- The switches to use when linking a library against libgnarl when using
70 -- FSU threads.
72 Thread_Options : Argument_List_Access := Empty_Argument_List;
73 -- Designate the thread switches to used when linking a library against
74 -- libgnarl. Depends on the thread library (Native or FSU). Resolved for
75 -- the first library linked against libgnarl.
77 ---------------------
78 -- Archive_Builder --
79 ---------------------
81 function Archive_Builder return String is
82 begin
83 return "ar";
84 end Archive_Builder;
86 -----------------------------
87 -- Archive_Builder_Options --
88 -----------------------------
90 function Archive_Builder_Options return String_List_Access is
91 begin
92 return new String_List'(1 => new String'("cr"));
93 end Archive_Builder_Options;
95 -----------------
96 -- Archive_Ext --
97 -----------------
99 function Archive_Ext return String is
100 begin
101 return "a";
102 end Archive_Ext;
104 ---------------------
105 -- Archive_Indexer --
106 ---------------------
108 function Archive_Indexer return String is
109 begin
110 return "ranlib";
111 end Archive_Indexer;
113 -----------------------------
114 -- Archive_Indexer_Options --
115 -----------------------------
117 function Archive_Indexer_Options return String_List_Access is
118 begin
119 return new String_List (1 .. 0);
120 end Archive_Indexer_Options;
122 ---------------------------
123 -- Build_Dynamic_Library --
124 ---------------------------
126 procedure Build_Dynamic_Library
127 (Ofiles : Argument_List;
128 Foreign : Argument_List;
129 Afiles : Argument_List;
130 Options : Argument_List;
131 Options_2 : Argument_List;
132 Interfaces : Argument_List;
133 Lib_Filename : String;
134 Lib_Dir : String;
135 Symbol_Data : Symbol_Record;
136 Driver_Name : Name_Id := No_Name;
137 Lib_Version : String := "";
138 Auto_Init : Boolean := False)
140 pragma Unreferenced (Foreign);
141 pragma Unreferenced (Afiles);
142 pragma Unreferenced (Interfaces);
143 pragma Unreferenced (Symbol_Data);
144 pragma Unreferenced (Lib_Version);
146 Lib_File : constant String :=
147 Lib_Dir & Directory_Separator & "lib" &
148 MLib.Fil.Ext_To (Lib_Filename, DLL_Ext);
149 -- The file name of the library
151 Init_Fini : Argument_List_Access := Empty_Argument_List;
152 -- The switch for automatic initialization of Stand-Alone Libraries.
153 -- Changed to a real switch when Auto_Init is True.
155 Thread_Opts : Argument_List_Access := Empty_Argument_List;
156 -- Set to Thread_Options if -lgnarl is found in the Options
158 begin
159 if Opt.Verbose_Mode then
160 Write_Str ("building relocatable shared library ");
161 Write_Line (Lib_File);
162 end if;
164 -- If specified, add automatic elaboration/finalization
166 if Auto_Init then
167 Init_Fini := Init_Fini_List;
168 Init_Fini (1) :=
169 new String'(Wl_Initfini_String & Lib_Filename & "init:" &
170 Lib_Filename & "final");
171 end if;
173 -- Look for -lgnarl in Options. If found, set the thread options.
175 for J in Options'Range loop
176 if Options (J).all = "-lgnarl" then
178 -- If Thread_Options is null, read s-osinte.ads to discover the
179 -- thread library and set Thread_Options accordingly.
181 if Thread_Options = null then
182 declare
183 File : Text_File;
184 Line : String (1 .. 100);
185 Last : Natural;
187 begin
188 Open
189 (File, Include_Dir_Default_Prefix & "/s-osinte.ads");
191 while not End_Of_File (File) loop
192 Get_Line (File, Line, Last);
194 if Index (Line (1 .. Last), "-lpthreads") /= 0 then
195 Thread_Options := Native_Thread_Options'Access;
196 exit;
198 elsif Index (Line (1 .. Last), "-lgthreads") /= 0 then
199 Thread_Options := FSU_Thread_Options'Access;
200 exit;
201 end if;
202 end loop;
204 Close (File);
206 if Thread_Options = null then
207 Prj.Com.Fail ("cannot find the thread library in use");
208 end if;
210 exception
211 when others =>
212 Prj.Com.Fail ("cannot open s-osinte.ads");
213 end;
214 end if;
216 Thread_Opts := Thread_Options;
217 exit;
218 end if;
219 end loop;
221 -- Finally, call GCC (or the driver specified) to build the library
223 MLib.Utl.Gcc
224 (Output_File => Lib_File,
225 Objects => Ofiles,
226 Options => Options & Bexpall_Option & Init_Fini.all,
227 Driver_Name => Driver_Name,
228 Options_2 => Options_2 & Thread_Opts.all);
229 end Build_Dynamic_Library;
231 -------------
232 -- DLL_Ext --
233 -------------
235 function DLL_Ext return String is
236 begin
237 return "a";
238 end DLL_Ext;
240 --------------------
241 -- Dynamic_Option --
242 --------------------
244 function Dynamic_Option return String is
245 begin
246 return "-shared";
247 end Dynamic_Option;
249 -------------------
250 -- Is_Object_Ext --
251 -------------------
253 function Is_Object_Ext (Ext : String) return Boolean is
254 begin
255 return Ext = ".o";
256 end Is_Object_Ext;
258 --------------
259 -- Is_C_Ext --
260 --------------
262 function Is_C_Ext (Ext : String) return Boolean is
263 begin
264 return Ext = ".c";
265 end Is_C_Ext;
267 --------------------
268 -- Is_Archive_Ext --
269 --------------------
271 function Is_Archive_Ext (Ext : String) return Boolean is
272 begin
273 return Ext = ".a";
274 end Is_Archive_Ext;
276 -------------
277 -- Libgnat --
278 -------------
280 function Libgnat return String is
281 begin
282 return "libgnat.a";
283 end Libgnat;
285 ------------------------
286 -- Library_Exists_For --
287 ------------------------
289 function Library_Exists_For (Project : Project_Id) return Boolean is
290 begin
291 if not 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 (Projects.Table (Project).Library_Dir);
301 Lib_Name : constant String :=
302 Get_Name_String
303 (Projects.Table (Project).Library_Name);
305 begin
306 if Projects.Table (Project).Library_Kind = Static then
307 return Is_Regular_File
308 (Lib_Dir & Directory_Separator & "lib" &
309 Fil.Ext_To (Lib_Name, Archive_Ext));
311 else
312 return Is_Regular_File
313 (Lib_Dir & Directory_Separator & "lib" &
314 Fil.Ext_To (Lib_Name, DLL_Ext));
315 end if;
316 end;
317 end if;
318 end Library_Exists_For;
320 ---------------------------
321 -- Library_File_Name_For --
322 ---------------------------
324 function Library_File_Name_For (Project : Project_Id) return Name_Id is
325 begin
326 if not Projects.Table (Project).Library then
327 Prj.Com.Fail ("INTERNAL ERROR: Library_File_Name_For called " &
328 "for non library project");
329 return No_Name;
331 else
332 declare
333 Lib_Name : constant String :=
334 Get_Name_String (Projects.Table (Project).Library_Name);
336 begin
337 Name_Len := 3;
338 Name_Buffer (1 .. Name_Len) := "lib";
340 if Projects.Table (Project).Library_Kind = Static then
341 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, Archive_Ext));
343 else
344 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, DLL_Ext));
345 end if;
347 return Name_Find;
348 end;
349 end if;
350 end Library_File_Name_For;
352 ----------------
353 -- Object_Ext --
354 ----------------
356 function Object_Ext return String is
357 begin
358 return "o";
359 end Object_Ext;
361 ----------------
362 -- PIC_Option --
363 ----------------
365 function PIC_Option return String is
366 begin
367 return "-fPIC";
368 end PIC_Option;
370 -----------------------------------------------
371 -- Standalone_Library_Auto_Init_Is_Supported --
372 -----------------------------------------------
374 function Standalone_Library_Auto_Init_Is_Supported return Boolean is
375 begin
376 return True;
377 end Standalone_Library_Auto_Init_Is_Supported;
379 ---------------------------
380 -- Support_For_Libraries --
381 ---------------------------
383 function Support_For_Libraries return Library_Support is
384 begin
385 return Full;
386 end Support_For_Libraries;
388 end MLib.Tgt;