OSDN Git Service

2007-08-14 Robert Dewar <dewar@adacore.com>
[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 . S P E C I F I C                    --
6 --                              (AIX Version)                               --
7 --                                                                          --
8 --                                 B o d y                                  --
9 --                                                                          --
10 --                     Copyright (C) 2003-2007, AdaCore                     --
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 is the AIX version of the body
29
30 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
31
32 with MLib.Fil;
33 with MLib.Utl;
34 with Opt;
35 with Output;   use Output;
36 with Prj.Com;
37 with Prj.Util; use Prj.Util;
38
39 package body MLib.Tgt.Specific is
40
41    --  Non default subprograms
42
43    procedure Build_Dynamic_Library
44      (Ofiles       : Argument_List;
45       Options      : Argument_List;
46       Interfaces   : Argument_List;
47       Lib_Filename : String;
48       Lib_Dir      : String;
49       Symbol_Data  : Symbol_Record;
50       Driver_Name  : Name_Id := No_Name;
51       Lib_Version  : String  := "";
52       Auto_Init    : Boolean := False);
53
54    function DLL_Ext return String;
55
56    function Library_Major_Minor_Id_Supported return Boolean;
57
58    function Support_For_Libraries return Library_Support;
59
60    --  Local variables
61
62    No_Arguments        : aliased Argument_List         := (1 .. 0 => null);
63    Empty_Argument_List : constant Argument_List_Access := No_Arguments'Access;
64
65    Bexpall : aliased String := "-Wl,-bexpall";
66    Bexpall_Option : constant String_Access := Bexpall'Access;
67    --  The switch to export all symbols
68
69    Lpthreads : aliased String := "-lpthreads";
70    Native_Thread_Options : aliased Argument_List := (1 => Lpthreads'Access);
71    --  The switch to use when linking a library against libgnarl when using
72    --  Native threads.
73
74    Lgthreads : aliased String := "-lgthreads";
75    Lmalloc   : aliased String := "-lmalloc";
76    FSU_Thread_Options : aliased Argument_List :=
77                           (1 => Lgthreads'Access, 2 => Lmalloc'Access);
78    --  The switches to use when linking a library against libgnarl when using
79    --  FSU threads.
80
81    Thread_Options : Argument_List_Access := Empty_Argument_List;
82    --  Designate the thread switches to used when linking a library against
83    --  libgnarl. Depends on the thread library (Native or FSU). Resolved for
84    --  the first library linked against libgnarl.
85
86    ---------------------------
87    -- Build_Dynamic_Library --
88    ---------------------------
89
90    procedure Build_Dynamic_Library
91      (Ofiles       : Argument_List;
92       Options      : Argument_List;
93       Interfaces   : Argument_List;
94       Lib_Filename : String;
95       Lib_Dir      : String;
96       Symbol_Data  : Symbol_Record;
97       Driver_Name  : Name_Id := No_Name;
98       Lib_Version  : String  := "";
99       Auto_Init    : Boolean := False)
100    is
101       pragma Unreferenced (Interfaces);
102       pragma Unreferenced (Symbol_Data);
103       pragma Unreferenced (Lib_Version);
104       pragma Unreferenced (Auto_Init);
105
106       Lib_File : constant String :=
107                    Lib_Dir & Directory_Separator & "lib" &
108                    MLib.Fil.Append_To (Lib_Filename, DLL_Ext);
109       --  The file name of the library
110
111       Thread_Opts : Argument_List_Access := Empty_Argument_List;
112       --  Set to Thread_Options if -lgnarl is found in the Options
113
114    begin
115       if Opt.Verbose_Mode then
116          Write_Str ("building relocatable shared library ");
117          Write_Line (Lib_File);
118       end if;
119
120       --  Look for -lgnarl in Options. If found, set the thread options
121
122       for J in Options'Range loop
123          if Options (J).all = "-lgnarl" then
124
125             --  If Thread_Options is null, read s-osinte.ads to discover the
126             --  thread library and set Thread_Options accordingly.
127
128             if Thread_Options = null then
129                declare
130                   File : Text_File;
131                   Line : String (1 .. 100);
132                   Last : Natural;
133
134                begin
135                   Open
136                     (File, Include_Dir_Default_Prefix & "/s-osinte.ads");
137
138                   while not End_Of_File (File) loop
139                      Get_Line (File, Line, Last);
140
141                      if Index (Line (1 .. Last), "-lpthreads") /= 0 then
142                         Thread_Options := Native_Thread_Options'Access;
143                         exit;
144
145                      elsif Index (Line (1 .. Last), "-lgthreads") /= 0 then
146                         Thread_Options := FSU_Thread_Options'Access;
147                         exit;
148                      end if;
149                   end loop;
150
151                   Close (File);
152
153                   if Thread_Options = null then
154                      Prj.Com.Fail ("cannot find the thread library in use");
155                   end if;
156
157                exception
158                   when others =>
159                      Prj.Com.Fail ("cannot open s-osinte.ads");
160                end;
161             end if;
162
163             Thread_Opts := Thread_Options;
164             exit;
165          end if;
166       end loop;
167
168       --  Finally, call GCC (or the driver specified) to build the library
169
170       MLib.Utl.Gcc
171         (Output_File => Lib_File,
172          Objects     => Ofiles,
173          Options     => Options & Bexpall_Option,
174          Driver_Name => Driver_Name,
175          Options_2   => Thread_Opts.all);
176    end Build_Dynamic_Library;
177
178    -------------
179    -- DLL_Ext --
180    -------------
181
182    function DLL_Ext return String is
183    begin
184       return "a";
185    end DLL_Ext;
186
187    --------------------------------------
188    -- Library_Major_Minor_Id_Supported --
189    --------------------------------------
190
191    function Library_Major_Minor_Id_Supported return Boolean is
192    begin
193       return False;
194    end Library_Major_Minor_Id_Supported;
195
196    ---------------------------
197    -- Support_For_Libraries --
198    ---------------------------
199
200    function Support_For_Libraries return Library_Support is
201    begin
202       return Static_Only;
203    end Support_For_Libraries;
204
205 begin
206    Build_Dynamic_Library_Ptr := Build_Dynamic_Library'Access;
207    DLL_Ext_Ptr := DLL_Ext'Access;
208    Library_Major_Minor_Id_Supported_Ptr :=
209                                 Library_Major_Minor_Id_Supported'Access;
210    Support_For_Libraries_Ptr := Support_For_Libraries'Access;
211
212 end MLib.Tgt.Specific;