OSDN Git Service

PR c++/27714
[pf3gnuchains/gcc-fork.git] / gcc / ada / mlib-tgt-solaris.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             M L I B . T G T                              --
6 --                            (Solaris Version)                             --
7 --                                                                          --
8 --                                 B o d y                                  --
9 --                                                                          --
10 --              Copyright (C) 2002-2005 Free Software Foundation, 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 and shared libraries.
30
31 --  This is the Solaris version of the body
32
33 with MLib.Fil;
34 with MLib.Utl;
35 with Namet;  use Namet;
36 with Opt;
37 with Output; use Output;
38 with Prj.Com;
39 with System;
40
41 package body MLib.Tgt is
42
43    ---------------------
44    -- Archive_Builder --
45    ---------------------
46
47    function Archive_Builder return String is
48    begin
49       return "ar";
50    end Archive_Builder;
51
52    -----------------------------
53    -- Archive_Builder_Options --
54    -----------------------------
55
56    function Archive_Builder_Options return String_List_Access is
57    begin
58       return new String_List'(1 => new String'("cr"));
59    end Archive_Builder_Options;
60
61    -----------------
62    -- Archive_Ext --
63    -----------------
64
65    function Archive_Ext return  String is
66    begin
67       return "a";
68    end Archive_Ext;
69
70    ---------------------
71    -- Archive_Indexer --
72    ---------------------
73
74    function Archive_Indexer return String is
75    begin
76       return "ranlib";
77    end Archive_Indexer;
78
79    -----------------------------
80    -- Archive_Indexer_Options --
81    -----------------------------
82
83    function Archive_Indexer_Options return String_List_Access is
84    begin
85       return new String_List (1 .. 0);
86    end Archive_Indexer_Options;
87
88    ---------------------------
89    -- Build_Dynamic_Library --
90    ---------------------------
91
92    procedure Build_Dynamic_Library
93      (Ofiles       : Argument_List;
94       Foreign      : Argument_List;
95       Afiles       : Argument_List;
96       Options      : Argument_List;
97       Options_2    : Argument_List;
98       Interfaces   : Argument_List;
99       Lib_Filename : String;
100       Lib_Dir      : String;
101       Symbol_Data  : Symbol_Record;
102       Driver_Name  : Name_Id := No_Name;
103       Lib_Version  : String  := "";
104       Auto_Init    : Boolean := False)
105    is
106       pragma Unreferenced (Foreign);
107       pragma Unreferenced (Afiles);
108       pragma Unreferenced (Interfaces);
109       pragma Unreferenced (Symbol_Data);
110       pragma Unreferenced (Auto_Init);
111
112       Lib_File : constant String :=
113                    Lib_Dir & Directory_Separator & "lib" &
114                    Fil.Ext_To (Lib_Filename, DLL_Ext);
115
116       Version_Arg          : String_Access;
117       Symbolic_Link_Needed : Boolean := False;
118
119    begin
120       if Opt.Verbose_Mode then
121          Write_Str ("building relocatable shared library ");
122          Write_Line (Lib_File);
123       end if;
124
125       if Lib_Version = "" then
126          Utl.Gcc
127            (Output_File => Lib_File,
128             Objects     => Ofiles,
129             Options     => Options,
130             Options_2   => Options_2,
131             Driver_Name => Driver_Name);
132
133       else
134          Version_Arg := new String'("-Wl,-h," & Lib_Version);
135
136          if Is_Absolute_Path (Lib_Version) then
137             Utl.Gcc
138               (Output_File => Lib_Version,
139                Objects     => Ofiles,
140                Options     => Options & Version_Arg,
141                Options_2   => Options_2,
142                Driver_Name => Driver_Name);
143             Symbolic_Link_Needed := Lib_Version /= Lib_File;
144
145          else
146             Utl.Gcc
147               (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
148                Objects     => Ofiles,
149                Options     => Options & Version_Arg,
150                Options_2   => Options_2,
151                Driver_Name => Driver_Name);
152             Symbolic_Link_Needed :=
153               Lib_Dir & Directory_Separator & Lib_Version /= Lib_File;
154          end if;
155
156          if Symbolic_Link_Needed then
157             declare
158                Success : Boolean;
159                Oldpath : String (1 .. Lib_Version'Length + 1);
160                Newpath : String (1 .. Lib_File'Length + 1);
161
162                Result : Integer;
163                pragma Unreferenced (Result);
164
165                function Symlink
166                  (Oldpath : System.Address;
167                   Newpath : System.Address)
168                   return    Integer;
169                pragma Import (C, Symlink, "__gnat_symlink");
170
171             begin
172                Oldpath (1 .. Lib_Version'Length) := Lib_Version;
173                Oldpath (Oldpath'Last)            := ASCII.NUL;
174                Newpath (1 .. Lib_File'Length)    := Lib_File;
175                Newpath (Newpath'Last)            := ASCII.NUL;
176
177                Delete_File (Lib_File, Success);
178
179                Result := Symlink (Oldpath'Address, Newpath'Address);
180             end;
181          end if;
182       end if;
183    end Build_Dynamic_Library;
184
185    -------------
186    -- DLL_Ext --
187    -------------
188
189    function DLL_Ext return String is
190    begin
191       return "so";
192    end DLL_Ext;
193
194    ----------------
195    -- DLL_Prefix --
196    ----------------
197
198    function DLL_Prefix return String is
199    begin
200       return "lib";
201    end DLL_Prefix;
202
203    --------------------
204    -- Dynamic_Option --
205    --------------------
206
207    function Dynamic_Option return String is
208    begin
209       return "-shared";
210    end Dynamic_Option;
211
212    -------------------
213    -- Is_Object_Ext --
214    -------------------
215
216    function Is_Object_Ext (Ext : String) return Boolean is
217    begin
218       return Ext = ".o";
219    end Is_Object_Ext;
220
221    --------------
222    -- Is_C_Ext --
223    --------------
224
225    function Is_C_Ext (Ext : String) return Boolean is
226    begin
227       return Ext = ".c";
228    end Is_C_Ext;
229
230    --------------------
231    -- Is_Archive_Ext --
232    --------------------
233
234    function Is_Archive_Ext (Ext : String) return Boolean is
235    begin
236       return Ext = ".a" or else Ext = ".so";
237    end Is_Archive_Ext;
238
239    -------------
240    -- Libgnat --
241    -------------
242
243    function Libgnat return String is
244    begin
245       return "libgnat.a";
246    end Libgnat;
247
248    ------------------------
249    -- Library_Exists_For --
250    ------------------------
251
252    function Library_Exists_For
253      (Project : Project_Id; In_Tree : Project_Tree_Ref) return Boolean
254    is
255    begin
256       if not In_Tree.Projects.Table (Project).Library then
257          Prj.Com.Fail ("INTERNAL ERROR: Library_Exists_For called " &
258                        "for non library project");
259          return False;
260
261       else
262          declare
263             Lib_Dir : constant String :=
264               Get_Name_String
265                 (In_Tree.Projects.Table (Project).Library_Dir);
266             Lib_Name : constant String :=
267               Get_Name_String
268                 (In_Tree.Projects.Table (Project).Library_Name);
269
270          begin
271             if In_Tree.Projects.Table (Project).Library_Kind =
272               Static
273             then
274                return Is_Regular_File
275                  (Lib_Dir & Directory_Separator & "lib" &
276                   Fil.Ext_To (Lib_Name, Archive_Ext));
277
278             else
279                return Is_Regular_File
280                  (Lib_Dir & Directory_Separator & "lib" &
281                   Fil.Ext_To (Lib_Name, DLL_Ext));
282             end if;
283          end;
284       end if;
285    end Library_Exists_For;
286
287    ---------------------------
288    -- Library_File_Name_For --
289    ---------------------------
290
291    function Library_File_Name_For
292      (Project : Project_Id;
293       In_Tree : Project_Tree_Ref) return Name_Id
294    is
295    begin
296       if not In_Tree.Projects.Table (Project).Library then
297          Prj.Com.Fail ("INTERNAL ERROR: Library_File_Name_For called " &
298                        "for non library project");
299          return No_Name;
300
301       else
302          declare
303             Lib_Name : constant String :=
304               Get_Name_String
305                 (In_Tree.Projects.Table (Project).Library_Name);
306
307          begin
308             Name_Len := 3;
309             Name_Buffer (1 .. Name_Len) := "lib";
310
311             if In_Tree.Projects.Table (Project).Library_Kind =
312               Static
313             then
314                Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, Archive_Ext));
315
316             else
317                Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, DLL_Ext));
318             end if;
319
320             return Name_Find;
321          end;
322       end if;
323    end Library_File_Name_For;
324
325    ----------------
326    -- Object_Ext --
327    ----------------
328
329    function Object_Ext return String is
330    begin
331       return "o";
332    end Object_Ext;
333
334    ----------------
335    -- PIC_Option --
336    ----------------
337
338    function PIC_Option return String is
339    begin
340       return "-fPIC";
341    end PIC_Option;
342
343    -----------------------------------------------
344    -- Standalone_Library_Auto_Init_Is_Supported --
345    -----------------------------------------------
346
347    function Standalone_Library_Auto_Init_Is_Supported return Boolean is
348    begin
349       return True;
350    end Standalone_Library_Auto_Init_Is_Supported;
351
352    ---------------------------
353    -- Support_For_Libraries --
354    ---------------------------
355
356    function Support_For_Libraries return Library_Support is
357    begin
358       return Full;
359    end Support_For_Libraries;
360
361 end MLib.Tgt;