2013-11-25 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / ada / mlib-tgt-specific-darwin.adb
blobbc54dbfb918948259826fc2e0f66e94c84cf9105
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-2011, 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 ------------------------------------------------------------------------------
27 -- This is the Darwin version of the body
29 with MLib; use MLib;
30 with MLib.Fil;
31 with MLib.Utl;
32 with Opt; use Opt;
33 with Output; use Output;
35 package body MLib.Tgt.Specific is
37 -- Non default subprograms
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);
50 function DLL_Ext return String;
52 function Dynamic_Option return String;
54 function Is_Archive_Ext (Ext : String) return Boolean;
56 -- Local objects
58 Shared_Libgcc : aliased String := "-shared-libgcc";
60 Shared_Options : constant Argument_List :=
61 (1 => Shared_Libgcc'Access);
63 ---------------------------
64 -- Build_Dynamic_Library --
65 ---------------------------
67 procedure Build_Dynamic_Library
68 (Ofiles : Argument_List;
69 Options : Argument_List;
70 Interfaces : Argument_List;
71 Lib_Filename : String;
72 Lib_Dir : String;
73 Symbol_Data : Symbol_Record;
74 Driver_Name : Name_Id := No_Name;
75 Lib_Version : String := "";
76 Auto_Init : Boolean := False)
78 pragma Unreferenced (Interfaces);
79 pragma Unreferenced (Symbol_Data);
80 pragma Unreferenced (Auto_Init);
82 Lib_File : constant String :=
83 "lib" & Fil.Append_To (Lib_Filename, DLL_Ext);
85 Lib_Path : constant String :=
86 Lib_Dir & Directory_Separator & Lib_File;
88 Symbolic_Link_Needed : Boolean := False;
90 begin
91 if Opt.Verbose_Mode then
92 Write_Str ("building relocatable shared library ");
93 Write_Line (Lib_File);
94 end if;
96 -- If specified, add automatic elaboration/finalization
98 if Lib_Version = "" then
99 Utl.Gcc
100 (Output_File => Lib_Path,
101 Objects => Ofiles,
102 Options => Options & Shared_Options,
103 Driver_Name => Driver_Name,
104 Options_2 => No_Argument_List);
106 else
107 declare
108 Maj_Version : constant String :=
109 Major_Id_Name (Lib_File, Lib_Version);
110 begin
111 if Is_Absolute_Path (Lib_Version) then
112 Utl.Gcc
113 (Output_File => Lib_Version,
114 Objects => Ofiles,
115 Options => Options & Shared_Options,
116 Driver_Name => Driver_Name,
117 Options_2 => No_Argument_List);
118 Symbolic_Link_Needed := Lib_Version /= Lib_Path;
120 else
121 Utl.Gcc
122 (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
123 Objects => Ofiles,
124 Options => Options & Shared_Options,
125 Driver_Name => Driver_Name,
126 Options_2 => No_Argument_List);
127 Symbolic_Link_Needed :=
128 Lib_Dir & Directory_Separator & Lib_Version /= Lib_Path;
129 end if;
131 if Symbolic_Link_Needed then
132 Create_Sym_Links
133 (Lib_Path, Lib_Version, Lib_Dir, Maj_Version);
134 end if;
135 end;
136 end if;
137 end Build_Dynamic_Library;
139 -------------
140 -- DLL_Ext --
141 -------------
143 function DLL_Ext return String is
144 begin
145 return "dylib";
146 end DLL_Ext;
148 --------------------
149 -- Dynamic_Option --
150 --------------------
152 function Dynamic_Option return String is
153 begin
154 return "-dynamiclib";
155 end Dynamic_Option;
157 --------------------
158 -- Is_Archive_Ext --
159 --------------------
161 function Is_Archive_Ext (Ext : String) return Boolean is
162 begin
163 return Ext = ".dylib" or else Ext = ".a";
164 end Is_Archive_Ext;
166 begin
167 Build_Dynamic_Library_Ptr := Build_Dynamic_Library'Access;
168 DLL_Ext_Ptr := DLL_Ext'Access;
169 Dynamic_Option_Ptr := Dynamic_Option'Access;
170 Is_Archive_Ext_Ptr := Is_Archive_Ext'Access;
171 end MLib.Tgt.Specific;