OSDN Git Service

PR target/50678
[pf3gnuchains/gcc-fork.git] / gcc / ada / mlib-tgt-specific-darwin.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 --                             (Darwin 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 Darwin version of the body
28
29 with MLib;     use MLib;
30 with MLib.Fil;
31 with MLib.Utl;
32 with Opt;      use 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 DLL_Ext return String;
51
52    function Dynamic_Option return String;
53
54    function Is_Archive_Ext (Ext : String) return Boolean;
55
56    --  Local objects
57
58    Flat_Namespace : aliased String := "-Wl,-flat_namespace";
59    --  Instruct the linker to build the shared library as a flat
60    --  namespace image. The default is a two-level namespace image.
61
62    Shared_Libgcc  : aliased String := "-shared-libgcc";
63
64    Shared_Options : constant Argument_List :=
65                       (1 => Flat_Namespace'Access,
66                        2 => Shared_Libgcc'Access);
67
68    ---------------------------
69    -- Build_Dynamic_Library --
70    ---------------------------
71
72    procedure Build_Dynamic_Library
73      (Ofiles       : Argument_List;
74       Options      : Argument_List;
75       Interfaces   : Argument_List;
76       Lib_Filename : String;
77       Lib_Dir      : String;
78       Symbol_Data  : Symbol_Record;
79       Driver_Name  : Name_Id := No_Name;
80       Lib_Version  : String  := "";
81       Auto_Init    : Boolean := False)
82    is
83       pragma Unreferenced (Interfaces);
84       pragma Unreferenced (Symbol_Data);
85       pragma Unreferenced (Auto_Init);
86
87       Lib_File : constant String :=
88                    "lib" & Fil.Append_To (Lib_Filename, DLL_Ext);
89
90       Lib_Path : constant String :=
91                    Lib_Dir & Directory_Separator & Lib_File;
92
93       Symbolic_Link_Needed : Boolean := False;
94
95    begin
96       if Opt.Verbose_Mode then
97          Write_Str ("building relocatable shared library ");
98          Write_Line (Lib_File);
99       end if;
100
101       --  If specified, add automatic elaboration/finalization
102
103       if Lib_Version = "" then
104          Utl.Gcc
105            (Output_File => Lib_Path,
106             Objects     => Ofiles,
107             Options     => Options & Shared_Options,
108             Driver_Name => Driver_Name,
109             Options_2   => No_Argument_List);
110
111       else
112          declare
113             Maj_Version : constant String :=
114                             Major_Id_Name (Lib_File, Lib_Version);
115          begin
116             if Is_Absolute_Path (Lib_Version) then
117                Utl.Gcc
118                  (Output_File => Lib_Version,
119                   Objects     => Ofiles,
120                   Options     => Options & Shared_Options,
121                   Driver_Name => Driver_Name,
122                   Options_2   => No_Argument_List);
123                Symbolic_Link_Needed := Lib_Version /= Lib_Path;
124
125             else
126                Utl.Gcc
127                  (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
128                   Objects     => Ofiles,
129                   Options     => Options & Shared_Options,
130                   Driver_Name => Driver_Name,
131                   Options_2   => No_Argument_List);
132                Symbolic_Link_Needed :=
133                  Lib_Dir & Directory_Separator & Lib_Version /= Lib_Path;
134             end if;
135
136             if Symbolic_Link_Needed then
137                Create_Sym_Links
138                  (Lib_Path, Lib_Version, Lib_Dir, Maj_Version);
139             end if;
140          end;
141       end if;
142    end Build_Dynamic_Library;
143
144    -------------
145    -- DLL_Ext --
146    -------------
147
148    function DLL_Ext return String is
149    begin
150       return "dylib";
151    end DLL_Ext;
152
153    --------------------
154    -- Dynamic_Option --
155    --------------------
156
157    function Dynamic_Option return String is
158    begin
159       return "-dynamiclib";
160    end Dynamic_Option;
161
162    --------------------
163    -- Is_Archive_Ext --
164    --------------------
165
166    function Is_Archive_Ext (Ext : String) return Boolean is
167    begin
168       return Ext = ".dylib" or else Ext = ".a";
169    end Is_Archive_Ext;
170
171 begin
172    Build_Dynamic_Library_Ptr := Build_Dynamic_Library'Access;
173    DLL_Ext_Ptr := DLL_Ext'Access;
174    Dynamic_Option_Ptr := Dynamic_Option'Access;
175    Is_Archive_Ext_Ptr := Is_Archive_Ext'Access;
176 end MLib.Tgt.Specific;