OSDN Git Service

* gcc.dg/attr-weakref-1.c: Add exit (0) to avoid spurious
[pf3gnuchains/gcc-fork.git] / gcc / ada / mlib-tgt-aix.adb
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-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 ------------------------------------------------------------------------------
27
28 --  This package provides a set of target dependent routines to build
29 --  static, dynamic or relocatable libraries.
30
31 --  This is the AIX version of the body.
32
33 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
34 with GNAT.OS_Lib;       use GNAT.OS_Lib;
35
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;
44
45 package body MLib.Tgt is
46
47    No_Arguments        : aliased Argument_List         := (1 .. 0 => null);
48    Empty_Argument_List : constant Argument_List_Access := No_Arguments'Access;
49
50    Bexpall : aliased String := "-Wl,-bexpall";
51    Bexpall_Option : constant String_Access := Bexpall'Access;
52    --  The switch to export all symbols
53
54    Lpthreads : aliased String := "-lpthreads";
55    Native_Thread_Options : aliased Argument_List := (1 => Lpthreads'Access);
56    --  The switch to use when linking a library against libgnarl when using
57    --  Native threads.
58
59    Lgthreads : aliased String := "-lgthreads";
60    Lmalloc   : aliased String := "-lmalloc";
61    FSU_Thread_Options : aliased Argument_List :=
62                           (1 => Lgthreads'Access, 2 => Lmalloc'Access);
63    --  The switches to use when linking a library against libgnarl when using
64    --  FSU threads.
65
66    Thread_Options : Argument_List_Access := Empty_Argument_List;
67    --  Designate the thread switches to used when linking a library against
68    --  libgnarl. Depends on the thread library (Native or FSU). Resolved for
69    --  the first library linked against libgnarl.
70
71    ---------------------
72    -- Archive_Builder --
73    ---------------------
74
75    function Archive_Builder return String is
76    begin
77       return "ar";
78    end Archive_Builder;
79
80    -----------------------------
81    -- Archive_Builder_Options --
82    -----------------------------
83
84    function Archive_Builder_Options return String_List_Access is
85    begin
86       return new String_List'(1 => new String'("cr"));
87    end Archive_Builder_Options;
88
89    -----------------
90    -- Archive_Ext --
91    -----------------
92
93    function Archive_Ext return String is
94    begin
95       return "a";
96    end Archive_Ext;
97
98    ---------------------
99    -- Archive_Indexer --
100    ---------------------
101
102    function Archive_Indexer return String is
103    begin
104       return "ranlib";
105    end Archive_Indexer;
106
107    -----------------------------
108    -- Archive_Indexer_Options --
109    -----------------------------
110
111    function Archive_Indexer_Options return String_List_Access is
112    begin
113       return new String_List (1 .. 0);
114    end Archive_Indexer_Options;
115
116    ---------------------------
117    -- Build_Dynamic_Library --
118    ---------------------------
119
120    procedure Build_Dynamic_Library
121      (Ofiles       : Argument_List;
122       Foreign      : Argument_List;
123       Afiles       : Argument_List;
124       Options      : Argument_List;
125       Options_2    : Argument_List;
126       Interfaces   : Argument_List;
127       Lib_Filename : String;
128       Lib_Dir      : String;
129       Symbol_Data  : Symbol_Record;
130       Driver_Name  : Name_Id := No_Name;
131       Lib_Version  : String  := "";
132       Auto_Init    : Boolean := False)
133    is
134       pragma Unreferenced (Foreign);
135       pragma Unreferenced (Afiles);
136       pragma Unreferenced (Interfaces);
137       pragma Unreferenced (Symbol_Data);
138       pragma Unreferenced (Lib_Version);
139       pragma Unreferenced (Auto_Init);
140
141       Lib_File : constant String :=
142                    Lib_Dir & Directory_Separator & "lib" &
143                    MLib.Fil.Ext_To (Lib_Filename, DLL_Ext);
144       --  The file name of the library
145
146       Thread_Opts : Argument_List_Access := Empty_Argument_List;
147       --  Set to Thread_Options if -lgnarl is found in the Options
148
149    begin
150       if Opt.Verbose_Mode then
151          Write_Str ("building relocatable shared library ");
152          Write_Line (Lib_File);
153       end if;
154
155       --  Look for -lgnarl in Options. If found, set the thread options.
156
157       for J in Options'Range loop
158          if Options (J).all = "-lgnarl" then
159
160             --  If Thread_Options is null, read s-osinte.ads to discover the
161             --  thread library and set Thread_Options accordingly.
162
163             if Thread_Options = null then
164                declare
165                   File : Text_File;
166                   Line : String (1 .. 100);
167                   Last : Natural;
168
169                begin
170                   Open
171                     (File, Include_Dir_Default_Prefix & "/s-osinte.ads");
172
173                   while not End_Of_File (File) loop
174                      Get_Line (File, Line, Last);
175
176                      if Index (Line (1 .. Last), "-lpthreads") /= 0 then
177                         Thread_Options := Native_Thread_Options'Access;
178                         exit;
179
180                      elsif Index (Line (1 .. Last), "-lgthreads") /= 0 then
181                         Thread_Options := FSU_Thread_Options'Access;
182                         exit;
183                      end if;
184                   end loop;
185
186                   Close (File);
187
188                   if Thread_Options = null then
189                      Prj.Com.Fail ("cannot find the thread library in use");
190                   end if;
191
192                exception
193                   when others =>
194                      Prj.Com.Fail ("cannot open s-osinte.ads");
195                end;
196             end if;
197
198             Thread_Opts := Thread_Options;
199             exit;
200          end if;
201       end loop;
202
203       --  Finally, call GCC (or the driver specified) to build the library
204
205       MLib.Utl.Gcc
206         (Output_File => Lib_File,
207          Objects     => Ofiles,
208          Options     => Options & Bexpall_Option,
209          Driver_Name => Driver_Name,
210          Options_2   => Options_2 & Thread_Opts.all);
211    end Build_Dynamic_Library;
212
213    -------------
214    -- DLL_Ext --
215    -------------
216
217    function DLL_Ext return String is
218    begin
219       return "a";
220    end DLL_Ext;
221
222    --------------------
223    -- Dynamic_Option --
224    --------------------
225
226    function Dynamic_Option return String is
227    begin
228       return "-shared";
229    end Dynamic_Option;
230
231    -------------------
232    -- Is_Object_Ext --
233    -------------------
234
235    function Is_Object_Ext (Ext : String) return Boolean is
236    begin
237       return Ext = ".o";
238    end Is_Object_Ext;
239
240    --------------
241    -- Is_C_Ext --
242    --------------
243
244    function Is_C_Ext (Ext : String) return Boolean is
245    begin
246       return Ext = ".c";
247    end Is_C_Ext;
248
249    --------------------
250    -- Is_Archive_Ext --
251    --------------------
252
253    function Is_Archive_Ext (Ext : String) return Boolean is
254    begin
255       return Ext = ".a";
256    end Is_Archive_Ext;
257
258    -------------
259    -- Libgnat --
260    -------------
261
262    function Libgnat return String is
263    begin
264       return "libgnat.a";
265    end Libgnat;
266
267    ------------------------
268    -- Library_Exists_For --
269    ------------------------
270
271    function Library_Exists_For
272      (Project : Project_Id; In_Tree : Project_Tree_Ref) return Boolean
273    is
274    begin
275       if not In_Tree.Projects.Table (Project).Library then
276          Prj.Com.Fail ("INTERNAL ERROR: Library_Exists_For called " &
277                        "for non library project");
278          return False;
279
280       else
281          declare
282             Lib_Dir  : constant String :=
283               Get_Name_String
284                 (In_Tree.Projects.Table (Project).Library_Dir);
285
286             Lib_Name : constant String :=
287               Get_Name_String
288                 (In_Tree.Projects.Table (Project).Library_Name);
289
290          begin
291             if In_Tree.Projects.Table (Project).Library_Kind =
292               Static
293             then
294                return Is_Regular_File
295                  (Lib_Dir & Directory_Separator & "lib" &
296                   Fil.Ext_To (Lib_Name, Archive_Ext));
297
298             else
299                return Is_Regular_File
300                  (Lib_Dir & Directory_Separator & "lib" &
301                   Fil.Ext_To (Lib_Name, DLL_Ext));
302             end if;
303          end;
304       end if;
305    end Library_Exists_For;
306
307    ---------------------------
308    -- Library_File_Name_For --
309    ---------------------------
310
311    function Library_File_Name_For
312      (Project : Project_Id;
313       In_Tree : Project_Tree_Ref) return Name_Id
314    is
315    begin
316       if not In_Tree.Projects.Table (Project).Library then
317          Prj.Com.Fail ("INTERNAL ERROR: Library_File_Name_For called " &
318                        "for non library project");
319          return No_Name;
320
321       else
322          declare
323             Lib_Name : constant String :=
324               Get_Name_String
325                 (In_Tree.Projects.Table (Project).Library_Name);
326
327          begin
328             Name_Len := 3;
329             Name_Buffer (1 .. Name_Len) := "lib";
330
331             if In_Tree.Projects.Table (Project).Library_Kind =
332               Static
333             then
334                Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, Archive_Ext));
335
336             else
337                Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, DLL_Ext));
338             end if;
339
340             return Name_Find;
341          end;
342       end if;
343    end Library_File_Name_For;
344
345    ----------------
346    -- Object_Ext --
347    ----------------
348
349    function Object_Ext return String is
350    begin
351       return "o";
352    end Object_Ext;
353
354    ----------------
355    -- PIC_Option --
356    ----------------
357
358    function PIC_Option return String is
359    begin
360       return "-fPIC";
361    end PIC_Option;
362
363    -----------------------------------------------
364    -- Standalone_Library_Auto_Init_Is_Supported --
365    -----------------------------------------------
366
367    function Standalone_Library_Auto_Init_Is_Supported return Boolean is
368    begin
369       return True;
370    end Standalone_Library_Auto_Init_Is_Supported;
371
372    ---------------------------
373    -- Support_For_Libraries --
374    ---------------------------
375
376    function Support_For_Libraries return Library_Support is
377    begin
378       return Static_Only;
379    end Support_For_Libraries;
380
381 end MLib.Tgt;