OSDN Git Service

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