OSDN Git Service

./:
[pf3gnuchains/gcc-fork.git] / gcc / ada / mlib-tgt-irix.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 --                              (IRIX 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 IRIX 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    --  Non default subprogram
39
40    procedure Build_Dynamic_Library
41      (Ofiles       : Argument_List;
42       Foreign      : Argument_List;
43       Afiles       : Argument_List;
44       Options      : Argument_List;
45       Options_2    : 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 Is_Archive_Ext (Ext : String) return Boolean;
55
56    ---------------------------
57    -- Build_Dynamic_Library --
58    ---------------------------
59
60    procedure Build_Dynamic_Library
61      (Ofiles       : Argument_List;
62       Foreign      : Argument_List;
63       Afiles       : Argument_List;
64       Options      : Argument_List;
65       Options_2    : Argument_List;
66       Interfaces   : Argument_List;
67       Lib_Filename : String;
68       Lib_Dir      : String;
69       Symbol_Data  : Symbol_Record;
70       Driver_Name  : Name_Id := No_Name;
71       Lib_Version  : String  := "";
72       Auto_Init    : Boolean := False)
73    is
74       pragma Unreferenced (Foreign);
75       pragma Unreferenced (Afiles);
76       pragma Unreferenced (Interfaces);
77       pragma Unreferenced (Symbol_Data);
78       pragma Unreferenced (Auto_Init);
79
80       Lib_File : constant String :=
81                    Lib_Dir & Directory_Separator & "lib" &
82                    MLib.Fil.Append_To (Lib_Filename, DLL_Ext);
83
84       Version_Arg          : String_Access;
85       Symbolic_Link_Needed : Boolean := False;
86
87       N_Options    : Argument_List := Options;
88       Options_Last : Natural := N_Options'Last;
89       --  After moving -lxxx to Options_2, N_Options up to index Options_Last
90       --  will contain the Options to pass to MLib.Utl.Gcc.
91
92       Real_Options_2 : Argument_List (1 .. Options'Length + Options_2'Length);
93       Real_Options_2_Last : Natural := 0;
94       --  Real_Options_2 up to index Real_Options_2_Last will contain the
95       --  Options_2 to pass to MLib.Utl.Gcc.
96
97    begin
98       if Opt.Verbose_Mode then
99          Write_Str ("building relocatable shared library ");
100          Write_Line (Lib_File);
101       end if;
102
103       --  Move all -lxxx to Options_2
104
105       declare
106          Index : Natural := N_Options'First;
107          Arg   : String_Access;
108
109       begin
110          while Index <= Options_Last loop
111             Arg := N_Options (Index);
112
113             if Arg'Length > 2
114               and then Arg (Arg'First .. Arg'First + 1) = "-l"
115             then
116                Real_Options_2_Last := Real_Options_2_Last + 1;
117                Real_Options_2 (Real_Options_2_Last) := Arg;
118                N_Options (Index .. Options_Last - 1) :=
119                  N_Options (Index + 1 .. Options_Last);
120                Options_Last := Options_Last - 1;
121
122             else
123                Index := Index + 1;
124             end if;
125          end loop;
126       end;
127
128       --  Add to Real_Options_2 the argument Options_2
129
130       Real_Options_2
131         (Real_Options_2_Last + 1 .. Real_Options_2_Last + Options_2'Length) :=
132         Options_2;
133       Real_Options_2_Last := Real_Options_2_Last + Options_2'Length;
134
135       if Lib_Version = "" then
136          MLib.Utl.Gcc
137            (Output_File => Lib_File,
138             Objects     => Ofiles,
139             Options     => N_Options (N_Options'First .. Options_Last),
140             Driver_Name => Driver_Name,
141             Options_2   => Real_Options_2 (1 .. Real_Options_2_Last));
142
143       else
144          Version_Arg := new String'("-Wl,-soname," & Lib_Version);
145
146          if Is_Absolute_Path (Lib_Version) then
147             MLib.Utl.Gcc
148               (Output_File => Lib_Version,
149                Objects     => Ofiles,
150                Options     => N_Options (N_Options'First .. Options_Last) &
151                               Version_Arg,
152                Driver_Name => Driver_Name,
153                Options_2   => Real_Options_2 (1 .. Real_Options_2_Last));
154             Symbolic_Link_Needed := Lib_Version /= Lib_File;
155
156          else
157             MLib.Utl.Gcc
158               (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
159                Objects     => Ofiles,
160                Options     => N_Options (N_Options'First .. Options_Last) &
161                               Version_Arg,
162                Driver_Name => Driver_Name,
163                Options_2   => Real_Options_2 (1 .. Real_Options_2_Last));
164             Symbolic_Link_Needed :=
165               Lib_Dir & Directory_Separator & Lib_Version /= Lib_File;
166          end if;
167
168          if Symbolic_Link_Needed then
169             declare
170                Success : Boolean;
171                Oldpath : String (1 .. Lib_Version'Length + 1);
172                Newpath : String (1 .. Lib_File'Length + 1);
173
174                Result : Integer;
175                pragma Unreferenced (Result);
176
177                function Symlink
178                  (Oldpath : System.Address;
179                   Newpath : System.Address)
180                   return    Integer;
181                pragma Import (C, Symlink, "__gnat_symlink");
182
183             begin
184                Oldpath (1 .. Lib_Version'Length) := Lib_Version;
185                Oldpath (Oldpath'Last)            := ASCII.NUL;
186                Newpath (1 .. Lib_File'Length)    := Lib_File;
187                Newpath (Newpath'Last)            := ASCII.NUL;
188
189                Delete_File (Lib_File, Success);
190
191                Result := Symlink (Oldpath'Address, Newpath'Address);
192             end;
193          end if;
194       end if;
195    end Build_Dynamic_Library;
196
197    --------------------
198    -- Is_Archive_Ext --
199    --------------------
200
201    function Is_Archive_Ext (Ext : String) return Boolean is
202    begin
203       return Ext = ".a" or else Ext = ".so";
204    end Is_Archive_Ext;
205
206 begin
207    Build_Dynamic_Library_Ptr := Build_Dynamic_Library'Access;
208    Is_Archive_Ext_Ptr := Is_Archive_Ext'Access;
209 end MLib.Tgt.Specific;