OSDN Git Service

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