OSDN Git Service

New out of ssa Coalescer.
[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                              --
6 --                              (IRIX Version)                              --
7 --                                                                          --
8 --                                 B o d y                                  --
9 --                                                                          --
10 --                     Copyright (C) 2003-2006, 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 package provides a set of target dependent routines to build
29 --  static, dynamic and shared libraries.
30
31 --  This is the IRIX 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                    MLib.Fil.Append_To (Lib_Filename, DLL_Ext);
115
116       Version_Arg          : String_Access;
117       Symbolic_Link_Needed : Boolean := False;
118
119       N_Options    : Argument_List := Options;
120       Options_Last : Natural := N_Options'Last;
121       --  After moving -lxxx to Options_2, N_Options up to index Options_Last
122       --  will contain the Options to pass to MLib.Utl.Gcc.
123
124       Real_Options_2 : Argument_List (1 .. Options'Length + Options_2'Length);
125       Real_Options_2_Last : Natural := 0;
126       --  Real_Options_2 up to index Real_Options_2_Last will contain the
127       --  Options_2 to pass to MLib.Utl.Gcc.
128
129    begin
130       if Opt.Verbose_Mode then
131          Write_Str ("building relocatable shared library ");
132          Write_Line (Lib_File);
133       end if;
134
135       --  Move all -lxxx to Options_2
136
137       declare
138          Index : Natural := N_Options'First;
139          Arg   : String_Access;
140
141       begin
142          while Index <= Options_Last loop
143             Arg := N_Options (Index);
144
145             if Arg'Length > 2
146               and then Arg (Arg'First .. Arg'First + 1) = "-l"
147             then
148                Real_Options_2_Last := Real_Options_2_Last + 1;
149                Real_Options_2 (Real_Options_2_Last) := Arg;
150                N_Options (Index .. Options_Last - 1) :=
151                  N_Options (Index + 1 .. Options_Last);
152                Options_Last := Options_Last - 1;
153
154             else
155                Index := Index + 1;
156             end if;
157          end loop;
158       end;
159
160       --  Add to Real_Options_2 the argument Options_2
161
162       Real_Options_2
163         (Real_Options_2_Last + 1 .. Real_Options_2_Last + Options_2'Length) :=
164         Options_2;
165       Real_Options_2_Last := Real_Options_2_Last + Options_2'Length;
166
167       if Lib_Version = "" then
168          MLib.Utl.Gcc
169            (Output_File => Lib_File,
170             Objects     => Ofiles,
171             Options     => N_Options (N_Options'First .. Options_Last),
172             Driver_Name => Driver_Name,
173             Options_2   => Real_Options_2 (1 .. Real_Options_2_Last));
174
175       else
176          Version_Arg := new String'("-Wl,-soname," & Lib_Version);
177
178          if Is_Absolute_Path (Lib_Version) then
179             MLib.Utl.Gcc
180               (Output_File => Lib_Version,
181                Objects     => Ofiles,
182                Options     => N_Options (N_Options'First .. Options_Last) &
183                               Version_Arg,
184                Driver_Name => Driver_Name,
185                Options_2   => Real_Options_2 (1 .. Real_Options_2_Last));
186             Symbolic_Link_Needed := Lib_Version /= Lib_File;
187
188          else
189             MLib.Utl.Gcc
190               (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
191                Objects     => Ofiles,
192                Options     => N_Options (N_Options'First .. Options_Last) &
193                               Version_Arg,
194                Driver_Name => Driver_Name,
195                Options_2   => Real_Options_2 (1 .. Real_Options_2_Last));
196             Symbolic_Link_Needed :=
197               Lib_Dir & Directory_Separator & Lib_Version /= Lib_File;
198          end if;
199
200          if Symbolic_Link_Needed then
201             declare
202                Success : Boolean;
203                Oldpath : String (1 .. Lib_Version'Length + 1);
204                Newpath : String (1 .. Lib_File'Length + 1);
205
206                Result : Integer;
207                pragma Unreferenced (Result);
208
209                function Symlink
210                  (Oldpath : System.Address;
211                   Newpath : System.Address)
212                   return    Integer;
213                pragma Import (C, Symlink, "__gnat_symlink");
214
215             begin
216                Oldpath (1 .. Lib_Version'Length) := Lib_Version;
217                Oldpath (Oldpath'Last)            := ASCII.NUL;
218                Newpath (1 .. Lib_File'Length)    := Lib_File;
219                Newpath (Newpath'Last)            := ASCII.NUL;
220
221                Delete_File (Lib_File, Success);
222
223                Result := Symlink (Oldpath'Address, Newpath'Address);
224             end;
225          end if;
226       end if;
227    end Build_Dynamic_Library;
228
229    -------------
230    -- DLL_Ext --
231    -------------
232
233    function DLL_Ext return String is
234    begin
235       return "so";
236    end DLL_Ext;
237
238    ----------------
239    -- DLL_Prefix --
240    ----------------
241
242    function DLL_Prefix return String is
243    begin
244       return "lib";
245    end DLL_Prefix;
246
247    --------------------
248    -- Dynamic_Option --
249    --------------------
250
251    function Dynamic_Option return String is
252    begin
253       return "-shared";
254    end Dynamic_Option;
255
256    -------------------
257    -- Is_Object_Ext --
258    -------------------
259
260    function Is_Object_Ext (Ext : String) return Boolean is
261    begin
262       return Ext = ".o";
263    end Is_Object_Ext;
264
265    --------------
266    -- Is_C_Ext --
267    --------------
268
269    function Is_C_Ext (Ext : String) return Boolean is
270    begin
271       return Ext = ".c";
272    end Is_C_Ext;
273
274    --------------------
275    -- Is_Archive_Ext --
276    --------------------
277
278    function Is_Archive_Ext (Ext : String) return Boolean is
279    begin
280       return Ext = ".a" or else Ext = ".so";
281    end Is_Archive_Ext;
282
283    -------------
284    -- Libgnat --
285    -------------
286
287    function Libgnat return String is
288    begin
289       return "libgnat.a";
290    end Libgnat;
291
292    ------------------------
293    -- Library_Exists_For --
294    ------------------------
295
296    function Library_Exists_For
297      (Project : Project_Id;
298       In_Tree : Project_Tree_Ref) return Boolean
299    is
300    begin
301       if not In_Tree.Projects.Table (Project).Library then
302          Prj.Com.Fail ("INTERNAL ERROR: Library_Exists_For called " &
303                        "for non library project");
304          return False;
305
306       else
307          declare
308             Lib_Dir  : constant String :=
309                          Get_Name_String
310                            (In_Tree.Projects.Table (Project).Library_Dir);
311             Lib_Name : constant String :=
312                          Get_Name_String
313                            (In_Tree.Projects.Table (Project).Library_Name);
314
315          begin
316             if In_Tree.Projects.Table (Project).Library_Kind = Static then
317                return Is_Regular_File
318                  (Lib_Dir & Directory_Separator & "lib" &
319                   Fil.Append_To (Lib_Name, Archive_Ext));
320
321             else
322                return Is_Regular_File
323                  (Lib_Dir & Directory_Separator & "lib" &
324                   Fil.Append_To (Lib_Name, DLL_Ext));
325             end if;
326          end;
327       end if;
328    end Library_Exists_For;
329
330    ---------------------------
331    -- Library_File_Name_For --
332    ---------------------------
333
334    function Library_File_Name_For
335      (Project : Project_Id;
336       In_Tree : Project_Tree_Ref) return Name_Id
337    is
338    begin
339       if not In_Tree.Projects.Table (Project).Library then
340          Prj.Com.Fail ("INTERNAL ERROR: Library_File_Name_For called " &
341                        "for non library project");
342          return No_Name;
343
344       else
345          declare
346             Lib_Name : constant String :=
347                          Get_Name_String
348                            (In_Tree.Projects.Table (Project).Library_Name);
349
350          begin
351             Name_Len := 3;
352             Name_Buffer (1 .. Name_Len) := "lib";
353
354             if In_Tree.Projects.Table (Project).Library_Kind =
355               Static
356             then
357                Add_Str_To_Name_Buffer (Fil.Append_To (Lib_Name, Archive_Ext));
358             else
359                Add_Str_To_Name_Buffer (Fil.Append_To (Lib_Name, DLL_Ext));
360             end if;
361
362             return Name_Find;
363          end;
364       end if;
365    end Library_File_Name_For;
366
367    ----------------
368    -- Object_Ext --
369    ----------------
370
371    function Object_Ext return String is
372    begin
373       return "o";
374    end Object_Ext;
375
376    ----------------
377    -- PIC_Option --
378    ----------------
379
380    function PIC_Option return String is
381    begin
382       return "-fPIC";
383    end PIC_Option;
384
385    -----------------------------------------------
386    -- Standalone_Library_Auto_Init_Is_Supported --
387    -----------------------------------------------
388
389    function Standalone_Library_Auto_Init_Is_Supported return Boolean is
390    begin
391       return True;
392    end Standalone_Library_Auto_Init_Is_Supported;
393
394    ---------------------------
395    -- Support_For_Libraries --
396    ---------------------------
397
398    function Support_For_Libraries return Library_Support is
399    begin
400       return Full;
401    end Support_For_Libraries;
402
403 end MLib.Tgt;