OSDN Git Service

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