OSDN Git Service

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