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-2008, 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 3,  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 COPYING3.  If not, go to --
20-- http://www.gnu.org/licenses for a complete copy of the license.          --
21--                                                                          --
22-- GNAT was originally developed  by the GNAT team at  New York University. --
23-- Extensive contributions were provided by Ada Core Technologies Inc.      --
24--                                                                          --
25------------------------------------------------------------------------------
26
27--  This is the GNU/Linux version of the body
28
29with MLib.Fil;
30with MLib.Utl;
31with Opt;
32with Output; use Output;
33
34package body MLib.Tgt.Specific is
35
36   use MLib;
37
38   --  Non default subprograms
39
40   procedure Build_Dynamic_Library
41     (Ofiles       : Argument_List;
42      Options      : Argument_List;
43      Interfaces   : Argument_List;
44      Lib_Filename : String;
45      Lib_Dir      : String;
46      Symbol_Data  : Symbol_Record;
47      Driver_Name  : Name_Id := No_Name;
48      Lib_Version  : String  := "";
49      Auto_Init    : Boolean := False);
50
51   function Is_Archive_Ext (Ext : String) return Boolean;
52
53   ---------------------------
54   -- Build_Dynamic_Library --
55   ---------------------------
56
57   procedure Build_Dynamic_Library
58     (Ofiles       : Argument_List;
59      Options      : Argument_List;
60      Interfaces   : Argument_List;
61      Lib_Filename : String;
62      Lib_Dir      : String;
63      Symbol_Data  : Symbol_Record;
64      Driver_Name  : Name_Id := No_Name;
65      Lib_Version  : String  := "";
66      Auto_Init    : Boolean := False)
67   is
68      pragma Unreferenced (Interfaces);
69      pragma Unreferenced (Symbol_Data);
70      pragma Unreferenced (Auto_Init);
71      --  Initialization is done through the constructor mechanism
72
73      Lib_File : constant String :=
74                   "lib" & Fil.Append_To (Lib_Filename, DLL_Ext);
75
76      Lib_Path : constant String :=
77                   Lib_Dir & Directory_Separator & Lib_File;
78
79      Version_Arg          : String_Access;
80      Symbolic_Link_Needed : Boolean := False;
81
82   begin
83      if Opt.Verbose_Mode then
84         Write_Str ("building relocatable shared library ");
85         Write_Line (Lib_Path);
86      end if;
87
88      if Lib_Version = "" then
89         Utl.Gcc
90           (Output_File => Lib_Path,
91            Objects     => Ofiles,
92            Options     => Options,
93            Driver_Name => Driver_Name,
94            Options_2   => No_Argument_List);
95
96      else
97         declare
98            Maj_Version : constant String :=
99                            Major_Id_Name (Lib_File, Lib_Version);
100         begin
101            if Maj_Version'Length /= 0 then
102               Version_Arg := new String'("-Wl,-soname," & Maj_Version);
103
104            else
105               Version_Arg := new String'("-Wl,-soname," & Lib_Version);
106            end if;
107
108            if Is_Absolute_Path (Lib_Version) then
109               Utl.Gcc
110                 (Output_File => Lib_Version,
111                  Objects     => Ofiles,
112                  Options     => Options & Version_Arg,
113                  Driver_Name => Driver_Name,
114                  Options_2   => No_Argument_List);
115               Symbolic_Link_Needed := Lib_Version /= Lib_Path;
116
117            else
118               Utl.Gcc
119                 (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
120                  Objects     => Ofiles,
121                  Options     => Options & Version_Arg,
122                  Driver_Name => Driver_Name,
123                  Options_2   => No_Argument_List);
124               Symbolic_Link_Needed :=
125                 Lib_Dir & Directory_Separator & Lib_Version /= Lib_Path;
126            end if;
127
128            if Symbolic_Link_Needed then
129               Create_Sym_Links
130                 (Lib_Path, Lib_Version, Lib_Dir, Maj_Version);
131            end if;
132         end;
133      end if;
134   end Build_Dynamic_Library;
135
136   --------------------
137   -- Is_Archive_Ext --
138   --------------------
139
140   function Is_Archive_Ext (Ext : String) return Boolean is
141   begin
142      return Ext = ".a" or else Ext = ".so";
143   end Is_Archive_Ext;
144
145begin
146   Build_Dynamic_Library_Ptr := Build_Dynamic_Library'Access;
147   Is_Archive_Ext_Ptr := Is_Archive_Ext'Access;
148end MLib.Tgt.Specific;
149