* gnu/regexp/CharIndexedReader.java: Removed.
[official-gcc.git] / gcc / ada / mlib-tgt-aix.adb
blobc95d64893a4370ec5874e9879e7776a080ff4ba5
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 := null;
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 -- Build_Dynamic_Library --
115 ---------------------------
117 procedure Build_Dynamic_Library
118 (Ofiles : Argument_List;
119 Foreign : Argument_List;
120 Afiles : Argument_List;
121 Options : Argument_List;
122 Interfaces : Argument_List;
123 Lib_Filename : String;
124 Lib_Dir : String;
125 Symbol_Data : Symbol_Record;
126 Driver_Name : Name_Id := No_Name;
127 Lib_Address : String := "";
128 Lib_Version : String := "";
129 Relocatable : Boolean := False;
130 Auto_Init : Boolean := False)
132 pragma Unreferenced (Foreign);
133 pragma Unreferenced (Afiles);
134 pragma Unreferenced (Interfaces);
135 pragma Unreferenced (Symbol_Data);
136 pragma Unreferenced (Lib_Address);
137 pragma Unreferenced (Lib_Version);
138 pragma Unreferenced (Relocatable);
140 Lib_File : constant String :=
141 Lib_Dir & Directory_Separator & "lib" &
142 MLib.Fil.Ext_To (Lib_Filename, DLL_Ext);
143 -- The file name of the library
145 Init_Fini : Argument_List_Access := Empty_Argument_List;
146 -- The switch for automatic initialization of Stand-Alone Libraries.
147 -- Changed to a real switch when Auto_Init is True.
149 Options_2 : Argument_List_Access := Empty_Argument_List;
150 -- Changed to the thread options, if -lgnarl is specified
152 begin
153 if Opt.Verbose_Mode then
154 Write_Str ("building relocatable shared library ");
155 Write_Line (Lib_File);
156 end if;
158 -- If specified, add automatic elaboration/finalization
160 if Auto_Init then
161 Init_Fini := Init_Fini_List;
162 Init_Fini (1) :=
163 new String'(Wl_Initfini_String & Lib_Filename & "init:" &
164 Lib_Filename & "final");
165 end if;
167 -- Look for -lgnarl in Options. If found, set the thread options.
169 for J in Options'Range loop
170 if Options (J).all = "-lgnarl" then
172 -- If Thread_Options is null, read s-osinte.ads to discover the
173 -- thread library and set Thread_Options accordingly.
175 if Thread_Options = null then
176 declare
177 File : Text_File;
178 Line : String (1 .. 100);
179 Last : Natural;
181 begin
182 Open
183 (File, Include_Dir_Default_Prefix & "/s-osinte.ads");
185 while not End_Of_File (File) loop
186 Get_Line (File, Line, Last);
188 if Index (Line (1 .. Last), "-lpthreads") /= 0 then
189 Thread_Options := Native_Thread_Options'Access;
190 exit;
192 elsif Index (Line (1 .. Last), "-lgthreads") /= 0 then
193 Thread_Options := FSU_Thread_Options'Access;
194 exit;
195 end if;
196 end loop;
198 Close (File);
200 if Thread_Options = null then
201 Prj.Com.Fail ("cannot find the thread library in use");
202 end if;
204 exception
205 when others =>
206 Prj.Com.Fail ("cannot open s-osinte.ads");
207 end;
208 end if;
210 Options_2 := Thread_Options;
211 exit;
212 end if;
213 end loop;
215 -- Finally, call GCC (or the driver specified) to build the library
217 MLib.Utl.Gcc
218 (Output_File => Lib_File,
219 Objects => Ofiles,
220 Options => Options & Bexpall_Option & Init_Fini.all,
221 Driver_Name => Driver_Name,
222 Options_2 => Options_2.all);
223 end Build_Dynamic_Library;
225 -------------------------
226 -- Default_DLL_Address --
227 -------------------------
229 function Default_DLL_Address return String is
230 begin
231 return "";
232 end Default_DLL_Address;
234 -------------
235 -- DLL_Ext --
236 -------------
238 function DLL_Ext return String is
239 begin
240 return "a";
241 end DLL_Ext;
243 --------------------
244 -- Dynamic_Option --
245 --------------------
247 function Dynamic_Option return String is
248 begin
249 return "-shared";
250 end Dynamic_Option;
252 -------------------
253 -- Is_Object_Ext --
254 -------------------
256 function Is_Object_Ext (Ext : String) return Boolean is
257 begin
258 return Ext = ".o";
259 end Is_Object_Ext;
261 --------------
262 -- Is_C_Ext --
263 --------------
265 function Is_C_Ext (Ext : String) return Boolean is
266 begin
267 return Ext = ".c";
268 end Is_C_Ext;
270 --------------------
271 -- Is_Archive_Ext --
272 --------------------
274 function Is_Archive_Ext (Ext : String) return Boolean is
275 begin
276 return Ext = ".a";
277 end Is_Archive_Ext;
279 -------------
280 -- Libgnat --
281 -------------
283 function Libgnat return String is
284 begin
285 return "libgnat.a";
286 end Libgnat;
288 ------------------------
289 -- Library_Exists_For --
290 ------------------------
292 function Library_Exists_For (Project : Project_Id) return Boolean is
293 begin
294 if not Projects.Table (Project).Library then
295 Prj.Com.Fail ("INTERNAL ERROR: Library_Exists_For called " &
296 "for non library project");
297 return False;
299 else
300 declare
301 Lib_Dir : constant String :=
302 Get_Name_String
303 (Projects.Table (Project).Library_Dir);
304 Lib_Name : constant String :=
305 Get_Name_String
306 (Projects.Table (Project).Library_Name);
308 begin
309 if Projects.Table (Project).Library_Kind = Static then
310 return Is_Regular_File
311 (Lib_Dir & Directory_Separator & "lib" &
312 Fil.Ext_To (Lib_Name, Archive_Ext));
314 else
315 return Is_Regular_File
316 (Lib_Dir & Directory_Separator & "lib" &
317 Fil.Ext_To (Lib_Name, DLL_Ext));
318 end if;
319 end;
320 end if;
321 end Library_Exists_For;
323 ---------------------------
324 -- Library_File_Name_For --
325 ---------------------------
327 function Library_File_Name_For (Project : Project_Id) return Name_Id is
328 begin
329 if not Projects.Table (Project).Library then
330 Prj.Com.Fail ("INTERNAL ERROR: Library_File_Name_For called " &
331 "for non library project");
332 return No_Name;
334 else
335 declare
336 Lib_Name : constant String :=
337 Get_Name_String (Projects.Table (Project).Library_Name);
339 begin
340 Name_Len := 3;
341 Name_Buffer (1 .. Name_Len) := "lib";
343 if Projects.Table (Project).Library_Kind = Static then
344 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, Archive_Ext));
346 else
347 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, DLL_Ext));
348 end if;
350 return Name_Find;
351 end;
352 end if;
353 end Library_File_Name_For;
355 ----------------
356 -- Object_Ext --
357 ----------------
359 function Object_Ext return String is
360 begin
361 return "o";
362 end Object_Ext;
364 ----------------
365 -- PIC_Option --
366 ----------------
368 function PIC_Option return String is
369 begin
370 return "-fPIC";
371 end PIC_Option;
373 -----------------------------------------------
374 -- Standalone_Library_Auto_Init_Is_Supported --
375 -----------------------------------------------
377 function Standalone_Library_Auto_Init_Is_Supported return Boolean is
378 begin
379 return True;
380 end Standalone_Library_Auto_Init_Is_Supported;
382 ---------------------------
383 -- Support_For_Libraries --
384 ---------------------------
386 function Support_For_Libraries return Library_Support is
387 begin
388 return Full;
389 end Support_For_Libraries;
391 end MLib.Tgt;