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;
38 package body MLib.Tgt.Specific is
40 -- Non default subprograms
42 function Archive_Indexer_Options return String_List_Access;
44 procedure Build_Dynamic_Library
45 (Ofiles : Argument_List;
46 Foreign : Argument_List;
47 Afiles : Argument_List;
48 Options : Argument_List;
49 Options_2 : Argument_List;
50 Interfaces : Argument_List;
51 Lib_Filename : String;
53 Symbol_Data : Symbol_Record;
54 Driver_Name : Name_Id := No_Name;
55 Lib_Version : String := "";
56 Auto_Init : Boolean := False);
58 function DLL_Ext return String;
60 function Dynamic_Option return String;
62 function Is_Archive_Ext (Ext : String) return Boolean;
66 Flat_Namespace : aliased String := "-Wl,-flat_namespace";
67 -- Instruct the linker to build the shared library as a flat
68 -- namespace image. The default is a two-level namespace image.
70 Shared_Libgcc : aliased String := "-shared-libgcc";
72 Shared_Options : constant Argument_List :=
73 (1 => Flat_Namespace'Access,
74 2 => Shared_Libgcc'Access);
76 -----------------------------
77 -- Archive_Indexer_Options --
78 -----------------------------
80 function Archive_Indexer_Options return String_List_Access is
82 return new String_List'(1 => new String'("-c"));
83 end Archive_Indexer_Options;
85 ---------------------------
86 -- Build_Dynamic_Library --
87 ---------------------------
89 procedure Build_Dynamic_Library
90 (Ofiles : Argument_List;
91 Foreign : Argument_List;
92 Afiles : Argument_List;
93 Options : Argument_List;
94 Options_2 : Argument_List;
95 Interfaces : Argument_List;
96 Lib_Filename : String;
98 Symbol_Data : Symbol_Record;
99 Driver_Name : Name_Id := No_Name;
100 Lib_Version : String := "";
101 Auto_Init : Boolean := False)
103 pragma Unreferenced (Foreign);
104 pragma Unreferenced (Afiles);
105 pragma Unreferenced (Interfaces);
106 pragma Unreferenced (Symbol_Data);
107 pragma Unreferenced (Auto_Init);
109 Lib_File : constant String :=
110 Lib_Dir & Directory_Separator & "lib" &
111 Fil.Append_To (Lib_Filename, DLL_Ext);
113 Symbolic_Link_Needed : Boolean := False;
116 if Opt.Verbose_Mode then
117 Write_Str ("building relocatable shared library ");
118 Write_Line (Lib_File);
121 -- If specified, add automatic elaboration/finalization
123 if Lib_Version = "" then
125 (Output_File => Lib_File,
127 Options => Options & Shared_Options,
128 Driver_Name => Driver_Name,
129 Options_2 => Options_2);
133 if Is_Absolute_Path (Lib_Version) then
135 (Output_File => Lib_Version,
137 Options => Options & Shared_Options,
138 Driver_Name => Driver_Name,
139 Options_2 => Options_2);
140 Symbolic_Link_Needed := Lib_Version /= Lib_File;
144 (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
146 Options => Options & Shared_Options,
147 Driver_Name => Driver_Name,
148 Options_2 => Options_2);
149 Symbolic_Link_Needed :=
150 Lib_Dir & Directory_Separator & Lib_Version /= Lib_File;
153 if Symbolic_Link_Needed then
156 Oldpath : String (1 .. Lib_Version'Length + 1);
157 Newpath : String (1 .. Lib_File'Length + 1);
160 pragma Unreferenced (Result);
163 (Oldpath : System.Address;
164 Newpath : System.Address) return Integer;
165 pragma Import (C, Symlink, "__gnat_symlink");
168 Oldpath (1 .. Lib_Version'Length) := Lib_Version;
169 Oldpath (Oldpath'Last) := ASCII.NUL;
170 Newpath (1 .. Lib_File'Length) := Lib_File;
171 Newpath (Newpath'Last) := ASCII.NUL;
173 Delete_File (Lib_File, Success);
175 Result := Symlink (Oldpath'Address, Newpath'Address);
179 end Build_Dynamic_Library;
185 function DLL_Ext return String is
194 function Dynamic_Option return String is
196 return "-dynamiclib";
203 function Is_Archive_Ext (Ext : String) return Boolean is
205 return Ext = ".dylib" or else Ext = ".a";
209 Archive_Indexer_Options_Ptr := Archive_Indexer_Options'Access;
210 Build_Dynamic_Library_Ptr := Build_Dynamic_Library'Access;
211 DLL_Ext_Ptr := DLL_Ext'Access;
212 Dynamic_Option_Ptr := Dynamic_Option'Access;
213 Is_Archive_Ext_Ptr := Is_Archive_Ext'Access;
214 end MLib.Tgt.Specific;