1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- M L I B . T G T . S P E C I F I C --
10 -- Copyright (C) 2001-2007, Free Software Foundation, Inc. --
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. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc. --
26 ------------------------------------------------------------------------------
28 -- This is the Darwin version of the body
34 with Output; use Output;
36 package body MLib.Tgt.Specific is
38 -- Non default subprograms
40 function Archive_Indexer_Options return String_List_Access;
42 procedure Build_Dynamic_Library
43 (Ofiles : Argument_List;
44 Options : Argument_List;
45 Interfaces : Argument_List;
46 Lib_Filename : String;
48 Symbol_Data : Symbol_Record;
49 Driver_Name : Name_Id := No_Name;
50 Lib_Version : String := "";
51 Auto_Init : Boolean := False);
53 function DLL_Ext return String;
55 function Dynamic_Option return String;
57 function Is_Archive_Ext (Ext : String) return Boolean;
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.
65 Shared_Libgcc : aliased String := "-shared-libgcc";
67 Shared_Options : constant Argument_List :=
68 (1 => Flat_Namespace'Access,
69 2 => Shared_Libgcc'Access);
71 -----------------------------
72 -- Archive_Indexer_Options --
73 -----------------------------
75 function Archive_Indexer_Options return String_List_Access is
77 return new String_List'(1 => new String'("-c"));
78 end Archive_Indexer_Options;
80 ---------------------------
81 -- Build_Dynamic_Library --
82 ---------------------------
84 procedure Build_Dynamic_Library
85 (Ofiles : Argument_List;
86 Options : Argument_List;
87 Interfaces : Argument_List;
88 Lib_Filename : String;
90 Symbol_Data : Symbol_Record;
91 Driver_Name : Name_Id := No_Name;
92 Lib_Version : String := "";
93 Auto_Init : Boolean := False)
95 pragma Unreferenced (Interfaces);
96 pragma Unreferenced (Symbol_Data);
97 pragma Unreferenced (Auto_Init);
99 Lib_File : constant String :=
100 "lib" & Fil.Append_To (Lib_Filename, DLL_Ext);
102 Lib_Path : constant String :=
103 Lib_Dir & Directory_Separator & Lib_File;
105 Symbolic_Link_Needed : Boolean := False;
108 if Opt.Verbose_Mode then
109 Write_Str ("building relocatable shared library ");
110 Write_Line (Lib_File);
113 -- If specified, add automatic elaboration/finalization
115 if Lib_Version = "" then
117 (Output_File => Lib_File,
119 Options => Options & Shared_Options,
120 Driver_Name => Driver_Name,
121 Options_2 => No_Argument_List);
125 Maj_Version : constant String :=
126 Major_Id_Name (Lib_File, Lib_Version);
128 if Is_Absolute_Path (Lib_Version) then
130 (Output_File => Lib_Version,
132 Options => Options & Shared_Options,
133 Driver_Name => Driver_Name,
134 Options_2 => No_Argument_List);
135 Symbolic_Link_Needed := Lib_Version /= Lib_File;
139 (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
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;
148 if Symbolic_Link_Needed then
150 (Lib_Path, Lib_Version, Lib_Dir, Maj_Version);
154 end Build_Dynamic_Library;
160 function DLL_Ext return String is
169 function Dynamic_Option return String is
171 return "-dynamiclib";
178 function Is_Archive_Ext (Ext : String) return Boolean is
180 return Ext = ".dylib" or else Ext = ".a";
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;