OSDN Git Service

2007-08-14 Robert Dewar <dewar@adacore.com>
[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
35 package body MLib.Tgt.Specific is
36
37    --  Non default subprogram
38
39    procedure Build_Dynamic_Library
40      (Ofiles       : Argument_List;
41       Options      : Argument_List;
42       Interfaces   : Argument_List;
43       Lib_Filename : String;
44       Lib_Dir      : String;
45       Symbol_Data  : Symbol_Record;
46       Driver_Name  : Name_Id := No_Name;
47       Lib_Version  : String  := "";
48       Auto_Init    : Boolean := False);
49
50    function Is_Archive_Ext (Ext : String) return Boolean;
51
52    ---------------------------
53    -- Build_Dynamic_Library --
54    ---------------------------
55
56    procedure Build_Dynamic_Library
57      (Ofiles       : Argument_List;
58       Options      : Argument_List;
59       Interfaces   : Argument_List;
60       Lib_Filename : String;
61       Lib_Dir      : String;
62       Symbol_Data  : Symbol_Record;
63       Driver_Name  : Name_Id := No_Name;
64       Lib_Version  : String  := "";
65       Auto_Init    : Boolean := False)
66    is
67       pragma Unreferenced (Interfaces);
68       pragma Unreferenced (Symbol_Data);
69       pragma Unreferenced (Auto_Init);
70
71       Lib_File : constant String :=
72                    "lib" & MLib.Fil.Append_To (Lib_Filename, DLL_Ext);
73
74       Lib_Path : constant String :=
75                    Lib_Dir & Directory_Separator & Lib_File;
76
77       Version_Arg          : String_Access;
78       Symbolic_Link_Needed : Boolean := False;
79
80       N_Options    : Argument_List := Options;
81       Options_Last : Natural := N_Options'Last;
82       --  After moving -lxxx to Options_2, N_Options up to index Options_Last
83       --  will contain the Options to pass to MLib.Utl.Gcc.
84
85       Real_Options_2 : Argument_List (1 .. Options'Length);
86       Real_Options_2_Last : Natural := 0;
87       --  Real_Options_2 up to index Real_Options_2_Last will contain the
88       --  Options_2 to pass to MLib.Utl.Gcc.
89
90    begin
91       if Opt.Verbose_Mode then
92          Write_Str ("building relocatable shared library ");
93          Write_Line (Lib_Path);
94       end if;
95
96       --  Move all -lxxx to Options_2
97
98       declare
99          Index : Natural := N_Options'First;
100          Arg   : String_Access;
101
102       begin
103          while Index <= Options_Last loop
104             Arg := N_Options (Index);
105
106             if Arg'Length > 2
107               and then Arg (Arg'First .. Arg'First + 1) = "-l"
108             then
109                Real_Options_2_Last := Real_Options_2_Last + 1;
110                Real_Options_2 (Real_Options_2_Last) := Arg;
111                N_Options (Index .. Options_Last - 1) :=
112                  N_Options (Index + 1 .. Options_Last);
113                Options_Last := Options_Last - 1;
114
115             else
116                Index := Index + 1;
117             end if;
118          end loop;
119       end;
120
121       if Lib_Version = "" then
122          MLib.Utl.Gcc
123            (Output_File => Lib_Path,
124             Objects     => Ofiles,
125             Options     => N_Options (N_Options'First .. Options_Last),
126             Driver_Name => Driver_Name,
127             Options_2   => Real_Options_2 (1 .. Real_Options_2_Last));
128
129       else
130          declare
131             Maj_Version : constant String :=
132                             Major_Id_Name (Lib_File, Lib_Version);
133          begin
134             if Maj_Version'Length /= 0 then
135                Version_Arg := new String'("-Wl,-soname," & Maj_Version);
136
137             else
138                Version_Arg := new String'("-Wl,-soname," & Lib_Version);
139             end if;
140
141             if Is_Absolute_Path (Lib_Version) then
142                MLib.Utl.Gcc
143                  (Output_File => Lib_Version,
144                   Objects     => Ofiles,
145                   Options     => N_Options (N_Options'First .. Options_Last) &
146                   Version_Arg,
147                   Driver_Name => Driver_Name,
148                   Options_2   => Real_Options_2 (1 .. Real_Options_2_Last));
149                Symbolic_Link_Needed := Lib_Version /= Lib_Path;
150
151             else
152                MLib.Utl.Gcc
153                  (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
154                   Objects     => Ofiles,
155                   Options     => N_Options (N_Options'First .. Options_Last) &
156                   Version_Arg,
157                   Driver_Name => Driver_Name,
158                   Options_2   => Real_Options_2 (1 .. Real_Options_2_Last));
159                Symbolic_Link_Needed :=
160                  Lib_Dir & Directory_Separator & Lib_Version /= Lib_Path;
161             end if;
162
163             if Symbolic_Link_Needed then
164                Create_Sym_Links
165                  (Lib_Path, Lib_Version, Lib_Dir, Maj_Version);
166             end if;
167          end;
168       end if;
169    end Build_Dynamic_Library;
170
171    --------------------
172    -- Is_Archive_Ext --
173    --------------------
174
175    function Is_Archive_Ext (Ext : String) return Boolean is
176    begin
177       return Ext = ".a" or else Ext = ".so";
178    end Is_Archive_Ext;
179
180 begin
181    Build_Dynamic_Library_Ptr := Build_Dynamic_Library'Access;
182    Is_Archive_Ext_Ptr := Is_Archive_Ext'Access;
183 end MLib.Tgt.Specific;