1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 2003, Ada Core Technologies, Inc. --
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. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc. --
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 Ada.Text_IO; use Ada.Text_IO;
37 with Namet; use Namet;
39 with Output; use Output;
43 package body MLib.Tgt is
45 No_Arguments : aliased Argument_List := (1 .. 0 => null);
46 Empty_Argument_List : constant Argument_List_Access := No_Arguments'Access;
48 Wl_Initfini_String : constant String := "-Wl,-binitfini:";
50 Init_Fini_List : constant Argument_List_Access :=
51 new Argument_List'(1 => null);
52 -- Used to put switch for automatic elaboration/finalization
54 Bexpall : aliased String := "-Wl,-bexpall";
55 Bexpall_Option : constant String_Access := Bexpall'Access;
56 -- The switch to export all symbols
58 Lpthreads : aliased String := "-lpthreads";
59 Native_Thread_Options : aliased Argument_List := (1 => Lpthreads'Access);
60 -- The switch to use when linking a library against libgnarl when using
63 Lgthreads : aliased String := "-lgthreads";
64 Lmalloc : aliased String := "-lmalloc";
65 FSU_Thread_Options : aliased Argument_List :=
66 (1 => Lgthreads'Access, 2 => Lmalloc'Access);
67 -- The switches to use when linking a library against libgnarl when using
70 Thread_Options : Argument_List_Access := null;
71 -- Designate the thread switches to used when linking a library against
72 -- libgnarl. Depends on the thread library (Native or FSU). Resolved for
73 -- the first library linked against libgnarl.
79 function Archive_Builder return String is
84 -----------------------------
85 -- Archive_Builder_Options --
86 -----------------------------
88 function Archive_Builder_Options return String_List_Access is
90 return new String_List'(1 => new String'("cr"));
91 end Archive_Builder_Options;
97 function Archive_Ext return String is
102 ---------------------
103 -- Archive_Indexer --
104 ---------------------
106 function Archive_Indexer return String is
111 ---------------------------
112 -- Build_Dynamic_Library --
113 ---------------------------
115 procedure Build_Dynamic_Library
116 (Ofiles : Argument_List;
117 Foreign : Argument_List;
118 Afiles : Argument_List;
119 Options : Argument_List;
120 Interfaces : Argument_List;
121 Lib_Filename : String;
123 Driver_Name : Name_Id := No_Name;
124 Lib_Address : String := "";
125 Lib_Version : String := "";
126 Relocatable : Boolean := False;
127 Auto_Init : Boolean := False)
129 pragma Unreferenced (Foreign);
130 pragma Unreferenced (Afiles);
131 pragma Unreferenced (Interfaces);
132 pragma Unreferenced (Lib_Address);
133 pragma Unreferenced (Lib_Version);
134 pragma Unreferenced (Relocatable);
136 Lib_File : constant String :=
137 Lib_Dir & Directory_Separator & "lib" &
138 MLib.Fil.Ext_To (Lib_Filename, DLL_Ext);
139 -- The file name of the library
141 Init_Fini : Argument_List_Access := Empty_Argument_List;
142 -- The switch for automatic initialization of Stand-Alone Libraries.
143 -- Changed to a real switch when Auto_Init is True.
145 Options_2 : Argument_List_Access := Empty_Argument_List;
146 -- Changed to the thread options, if -lgnarl is specified
149 if Opt.Verbose_Mode then
150 Write_Str ("building relocatable shared library ");
151 Write_Line (Lib_File);
154 -- If specified, add automatic elaboration/finalization
157 Init_Fini := Init_Fini_List;
159 new String'(Wl_Initfini_String & Lib_Filename & "init:" &
160 Lib_Filename & "final");
163 -- Look for -lgnarl in Options. If found, set the thread options.
165 for J in Options'Range loop
166 if Options (J).all = "-lgnarl" then
168 -- If Thread_Options is null, read s-osinte.ads to discover the
169 -- thread library and set Thread_Options accordingly.
171 if Thread_Options = null then
173 File : Ada.Text_IO.File_Type;
174 Line : String (1 .. 100);
179 Sdefault.Include_Dir_Default_Name.all &
182 while not End_Of_File (File) loop
183 Get_Line (File, Line, Last);
185 if Index (Line (1 .. Last), "-lpthreads") /= 0 then
186 Thread_Options := Native_Thread_Options'Access;
189 elsif Index (Line (1 .. Last), "-lgthreads") /= 0 then
190 Thread_Options := FSU_Thread_Options'Access;
197 if Thread_Options = null then
198 Prj.Com.Fail ("cannot find the thread library in use");
203 Prj.Com.Fail ("cannot open s-osinte.ads");
207 Options_2 := Thread_Options;
212 -- Finally, call GCC (or the driver specified) to build the library
215 (Output_File => Lib_File,
217 Options => Options & Bexpall_Option & Init_Fini.all,
218 Driver_Name => Driver_Name,
219 Options_2 => Options_2.all);
220 end Build_Dynamic_Library;
222 -------------------------
223 -- Default_DLL_Address --
224 -------------------------
226 function Default_DLL_Address return String is
229 end Default_DLL_Address;
235 function DLL_Ext return String is
244 function Dynamic_Option return String is
253 function Is_Object_Ext (Ext : String) return Boolean is
262 function Is_C_Ext (Ext : String) return Boolean is
271 function Is_Archive_Ext (Ext : String) return Boolean is
280 function Libgnat return String is
285 ------------------------
286 -- Library_Exists_For --
287 ------------------------
289 function Library_Exists_For (Project : Project_Id) return Boolean is
291 if not Projects.Table (Project).Library then
292 Prj.Com.Fail ("INTERNAL ERROR: Library_Exists_For called " &
293 "for non library project");
298 Lib_Dir : constant String :=
299 Get_Name_String (Projects.Table (Project).Library_Dir);
300 Lib_Name : constant String :=
301 Get_Name_String (Projects.Table (Project).Library_Name);
304 if Projects.Table (Project).Library_Kind = Static then
305 return Is_Regular_File
306 (Lib_Dir & Directory_Separator & "lib" &
307 Fil.Ext_To (Lib_Name, Archive_Ext));
310 return Is_Regular_File
311 (Lib_Dir & Directory_Separator & "lib" &
312 Fil.Ext_To (Lib_Name, DLL_Ext));
316 end Library_Exists_For;
318 ---------------------------
319 -- Library_File_Name_For --
320 ---------------------------
322 function Library_File_Name_For (Project : Project_Id) return Name_Id is
324 if not Projects.Table (Project).Library then
325 Prj.Com.Fail ("INTERNAL ERROR: Library_File_Name_For called " &
326 "for non library project");
331 Lib_Name : constant String :=
332 Get_Name_String (Projects.Table (Project).Library_Name);
336 Name_Buffer (1 .. Name_Len) := "lib";
338 if Projects.Table (Project).Library_Kind = Static then
339 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, Archive_Ext));
342 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, DLL_Ext));
348 end Library_File_Name_For;
350 --------------------------------
351 -- Linker_Library_Path_Option --
352 --------------------------------
354 function Linker_Library_Path_Option return String_Access is
356 -- On AIX, any path specify with an -L switch is automatically added
357 -- to the library path. So, nothing is needed here.
360 end Linker_Library_Path_Option;
366 function Object_Ext return String is
375 function PIC_Option return String is
380 -----------------------------------------------
381 -- Standalone_Library_Auto_Init_Is_Supported --
382 -----------------------------------------------
384 function Standalone_Library_Auto_Init_Is_Supported return Boolean is
387 end Standalone_Library_Auto_Init_Is_Supported;
389 ---------------------------
390 -- Support_For_Libraries --
391 ---------------------------
393 function Support_For_Libraries return Library_Support is
396 end Support_For_Libraries;