OSDN Git Service

2007-08-14 Vincent Celier <celier@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / mlib-tgt-solaris.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 --                            (Solaris 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 Solaris 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 subprograms
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" & 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    begin
81       if Opt.Verbose_Mode then
82          Write_Str ("building relocatable shared library ");
83          Write_Line (Lib_Path);
84       end if;
85
86       if Lib_Version = "" then
87          Utl.Gcc
88            (Output_File => Lib_Path,
89             Objects     => Ofiles,
90             Options     => Options,
91             Options_2   => No_Argument_List,
92             Driver_Name => Driver_Name);
93
94       else
95          declare
96             Maj_Version : constant String :=
97                             Major_Id_Name (Lib_File, Lib_Version);
98          begin
99             if Maj_Version'Length /= 0 then
100                Version_Arg := new String'("-Wl,-h," & Maj_Version);
101
102             else
103                Version_Arg := new String'("-Wl,-h," & Lib_Version);
104             end if;
105
106             if Is_Absolute_Path (Lib_Version) then
107                Utl.Gcc
108                  (Output_File => Lib_Version,
109                   Objects     => Ofiles,
110                   Options     => Options & Version_Arg,
111                   Options_2   => No_Argument_List,
112                   Driver_Name => Driver_Name);
113                Symbolic_Link_Needed := Lib_Version /= Lib_Path;
114
115             else
116                Utl.Gcc
117                  (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
118                   Objects     => Ofiles,
119                   Options     => Options & Version_Arg,
120                   Options_2   => No_Argument_List,
121                   Driver_Name => Driver_Name);
122                Symbolic_Link_Needed :=
123                  Lib_Dir & Directory_Separator & Lib_Version /= Lib_Path;
124             end if;
125
126             if Symbolic_Link_Needed then
127                Create_Sym_Links
128                  (Lib_Path, Lib_Version, Lib_Dir, Maj_Version);
129             end if;
130          end;
131       end if;
132    end Build_Dynamic_Library;
133
134    --------------------
135    -- Is_Archive_Ext --
136    --------------------
137
138    function Is_Archive_Ext (Ext : String) return Boolean is
139    begin
140       return Ext = ".a" or else Ext = ".so";
141    end Is_Archive_Ext;
142
143 begin
144    Build_Dynamic_Library_Ptr := Build_Dynamic_Library'Access;
145    Is_Archive_Ext_Ptr := Is_Archive_Ext'Access;
146 end MLib.Tgt.Specific;