OSDN Git Service

2007-04-20 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 . S P E C I F I C                     --
6 --                             (True64 Version)                             --
7 --                                                                          --
8 --                                 B o d y                                  --
9 --                                                                          --
10 --          Copyright (C) 2002-2007, 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 is the True64 version of the body
29
30 with MLib.Fil;
31 with MLib.Utl;
32 with Opt;
33 with Output; use Output;
34 with System;
35
36 package body MLib.Tgt.Specific is
37
38    use MLib;
39
40    --  Non default subprogram
41
42    procedure Build_Dynamic_Library
43      (Ofiles       : Argument_List;
44       Foreign      : Argument_List;
45       Afiles       : Argument_List;
46       Options      : Argument_List;
47       Options_2    : Argument_List;
48       Interfaces   : Argument_List;
49       Lib_Filename : String;
50       Lib_Dir      : String;
51       Symbol_Data  : Symbol_Record;
52       Driver_Name  : Name_Id := No_Name;
53       Lib_Version  : String  := "";
54       Auto_Init    : Boolean := False);
55
56    function Is_Archive_Ext (Ext : String) return Boolean;
57
58    function PIC_Option return String;
59
60    --  Local variables
61
62    Expect_Unresolved : aliased String := "-Wl,-expect_unresolved,*";
63
64    ---------------------------
65    -- Build_Dynamic_Library --
66    ---------------------------
67
68    procedure Build_Dynamic_Library
69      (Ofiles       : Argument_List;
70       Foreign      : Argument_List;
71       Afiles       : Argument_List;
72       Options      : Argument_List;
73       Options_2    : Argument_List;
74       Interfaces   : Argument_List;
75       Lib_Filename : String;
76       Lib_Dir      : String;
77       Symbol_Data  : Symbol_Record;
78       Driver_Name  : Name_Id := No_Name;
79       Lib_Version  : String  := "";
80       Auto_Init    : Boolean := False)
81    is
82       pragma Unreferenced (Foreign);
83       pragma Unreferenced (Afiles);
84       pragma Unreferenced (Interfaces);
85       pragma Unreferenced (Symbol_Data);
86       pragma Unreferenced (Auto_Init);
87       --  Initialization is done through the contructor mechanism
88
89       Lib_File : constant String :=
90                    Lib_Dir & Directory_Separator & "lib" &
91                    Fil.Append_To (Lib_Filename, DLL_Ext);
92
93       Version_Arg          : String_Access;
94       Symbolic_Link_Needed : Boolean := False;
95
96    begin
97       if Opt.Verbose_Mode then
98          Write_Str ("building relocatable shared library ");
99          Write_Line (Lib_File);
100       end if;
101
102       --  If specified, add automatic elaboration/finalization
103
104       if Lib_Version = "" then
105          Utl.Gcc
106            (Output_File => Lib_File,
107             Objects     => Ofiles,
108             Options     => Options & Expect_Unresolved'Access,
109             Options_2   => Options_2,
110             Driver_Name => Driver_Name);
111
112       else
113          Version_Arg := new String'("-Wl,-soname," & Lib_Version);
114
115          if Is_Absolute_Path (Lib_Version) then
116             Utl.Gcc
117               (Output_File => Lib_Version,
118                Objects     => Ofiles,
119                Options     =>
120                  Options & Version_Arg & Expect_Unresolved'Access,
121                Options_2   => Options_2,
122                Driver_Name => Driver_Name);
123             Symbolic_Link_Needed := Lib_Version /= Lib_File;
124
125          else
126             Utl.Gcc
127               (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
128                Objects     => Ofiles,
129                Options     =>
130                  Options & Version_Arg & Expect_Unresolved'Access,
131                Options_2   => Options_2,
132                Driver_Name => Driver_Name);
133             Symbolic_Link_Needed :=
134               Lib_Dir & Directory_Separator & Lib_Version /= Lib_File;
135          end if;
136
137          if Symbolic_Link_Needed then
138             declare
139                Success : Boolean;
140                Oldpath : String (1 .. Lib_Version'Length + 1);
141                Newpath : String (1 .. Lib_File'Length + 1);
142
143                Result : Integer;
144                pragma Unreferenced (Result);
145
146                function Symlink
147                  (Oldpath : System.Address;
148                   Newpath : System.Address)
149                   return    Integer;
150                pragma Import (C, Symlink, "__gnat_symlink");
151
152             begin
153                Oldpath (1 .. Lib_Version'Length) := Lib_Version;
154                Oldpath (Oldpath'Last)            := ASCII.NUL;
155                Newpath (1 .. Lib_File'Length)    := Lib_File;
156                Newpath (Newpath'Last)            := ASCII.NUL;
157
158                Delete_File (Lib_File, Success);
159
160                Result := Symlink (Oldpath'Address, Newpath'Address);
161             end;
162          end if;
163       end if;
164    end Build_Dynamic_Library;
165
166    --------------------
167    -- Is_Archive_Ext --
168    --------------------
169
170    function Is_Archive_Ext (Ext : String) return Boolean is
171    begin
172       return Ext = ".a" or else Ext = ".so";
173    end Is_Archive_Ext;
174
175    ----------------
176    -- PIC_Option --
177    ----------------
178
179    function PIC_Option return String is
180    begin
181       return "";
182    end PIC_Option;
183
184 begin
185    Build_Dynamic_Library_Ptr := Build_Dynamic_Library'Access;
186    Is_Archive_Ext_Ptr := Is_Archive_Ext'Access;
187    PIC_Option_Ptr := PIC_Option'Access;
188 end MLib.Tgt.Specific;