OSDN Git Service

2007-08-16 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / mlib-tgt-linux.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 --                           (GNU/Linux Version)                            --
7 --                                                                          --
8 --                                 B o d y                                  --
9 --                                                                          --
10 --          Copyright (C) 2001-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 GNU/Linux 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    use MLib;
38
39    --  Non default subprograms
40
41    procedure Build_Dynamic_Library
42      (Ofiles       : Argument_List;
43       Options      : Argument_List;
44       Interfaces   : Argument_List;
45       Lib_Filename : String;
46       Lib_Dir      : String;
47       Symbol_Data  : Symbol_Record;
48       Driver_Name  : Name_Id := No_Name;
49       Lib_Version  : String  := "";
50       Auto_Init    : Boolean := False);
51
52    function Is_Archive_Ext (Ext : String) return Boolean;
53
54    ---------------------------
55    -- Build_Dynamic_Library --
56    ---------------------------
57
58    procedure Build_Dynamic_Library
59      (Ofiles       : Argument_List;
60       Options      : Argument_List;
61       Interfaces   : Argument_List;
62       Lib_Filename : String;
63       Lib_Dir      : String;
64       Symbol_Data  : Symbol_Record;
65       Driver_Name  : Name_Id := No_Name;
66       Lib_Version  : String  := "";
67       Auto_Init    : Boolean := False)
68    is
69       pragma Unreferenced (Interfaces);
70       pragma Unreferenced (Symbol_Data);
71       pragma Unreferenced (Auto_Init);
72       --  Initialization is done through the contructor mechanism
73
74       Lib_File : constant String :=
75                    "lib" & Fil.Append_To (Lib_Filename, DLL_Ext);
76
77       Lib_Path : constant String :=
78                    Lib_Dir & Directory_Separator & Lib_File;
79
80       Version_Arg          : String_Access;
81       Symbolic_Link_Needed : Boolean := False;
82
83    begin
84       if Opt.Verbose_Mode then
85          Write_Str ("building relocatable shared library ");
86          Write_Line (Lib_Path);
87       end if;
88
89       if Lib_Version = "" then
90          Utl.Gcc
91            (Output_File => Lib_Path,
92             Objects     => Ofiles,
93             Options     => Options,
94             Driver_Name => Driver_Name,
95             Options_2   => No_Argument_List);
96
97       else
98          declare
99             Maj_Version : constant String :=
100                             Major_Id_Name (Lib_File, Lib_Version);
101          begin
102             if Maj_Version'Length /= 0 then
103                Version_Arg := new String'("-Wl,-soname," & Maj_Version);
104
105             else
106                Version_Arg := new String'("-Wl,-soname," & Lib_Version);
107             end if;
108
109             if Is_Absolute_Path (Lib_Version) then
110                Utl.Gcc
111                  (Output_File => Lib_Version,
112                   Objects     => Ofiles,
113                   Options     => Options & Version_Arg,
114                   Driver_Name => Driver_Name,
115                   Options_2   => No_Argument_List);
116                Symbolic_Link_Needed := Lib_Version /= Lib_Path;
117
118             else
119                Utl.Gcc
120                  (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
121                   Objects     => Ofiles,
122                   Options     => Options & Version_Arg,
123                   Driver_Name => Driver_Name,
124                   Options_2   => No_Argument_List);
125                Symbolic_Link_Needed :=
126                  Lib_Dir & Directory_Separator & Lib_Version /= Lib_Path;
127             end if;
128
129             if Symbolic_Link_Needed then
130                Create_Sym_Links
131                  (Lib_Path, Lib_Version, Lib_Dir, Maj_Version);
132             end if;
133          end;
134       end if;
135    end Build_Dynamic_Library;
136
137    --------------------
138    -- Is_Archive_Ext --
139    --------------------
140
141    function Is_Archive_Ext (Ext : String) return Boolean is
142    begin
143       return Ext = ".a" or else Ext = ".so";
144    end Is_Archive_Ext;
145
146 begin
147    Build_Dynamic_Library_Ptr := Build_Dynamic_Library'Access;
148    Is_Archive_Ext_Ptr := Is_Archive_Ext'Access;
149 end MLib.Tgt.Specific;