Merge form mainline (hopefully)
[official-gcc.git] / gcc / ada / mlib-tgt-mingw.adb
blob98a5de88012f851003ffa18e14b8a7f66ac1ef12
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- M L I B . T G T --
6 -- (Windows Version) --
7 -- --
8 -- B o d y --
9 -- --
10 -- Copyright (C) 2002-2005, 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 ------------------------------------------------------------------------------
28 -- This package provides a set of target dependent routines to build
29 -- static, dynamic and shared libraries.
31 -- This is the Windows version of the body. Works only with GCC versions
32 -- supporting the "-shared" option.
34 with GNAT.OS_Lib; use GNAT.OS_Lib;
36 with Namet; use Namet;
37 with Opt;
38 with Output; use Output;
39 with Prj.Com;
41 with MLib.Fil;
42 with MLib.Utl;
44 package body MLib.Tgt is
46 package Files renames MLib.Fil;
47 package Tools renames MLib.Utl;
49 No_Argument_List : constant String_List := (1 .. 0 => null);
50 -- Used as value of parameter Options or Options2 in calls to Gcc
52 ---------------------
53 -- Archive_Builder --
54 ---------------------
56 function Archive_Builder return String is
57 begin
58 return "ar";
59 end Archive_Builder;
61 -----------------------------
62 -- Archive_Builder_Options --
63 -----------------------------
65 function Archive_Builder_Options return String_List_Access is
66 begin
67 return new String_List'(1 => new String'("cr"));
68 end Archive_Builder_Options;
70 -----------------
71 -- Archive_Ext --
72 -----------------
74 function Archive_Ext return String is
75 begin
76 return "a";
77 end Archive_Ext;
79 ---------------------
80 -- Archive_Indexer --
81 ---------------------
83 function Archive_Indexer return String is
84 begin
85 return "ranlib";
86 end Archive_Indexer;
88 -----------------------------
89 -- Archive_Indexer_Options --
90 -----------------------------
92 function Archive_Indexer_Options return String_List_Access is
93 begin
94 return new String_List (1 .. 0);
95 end Archive_Indexer_Options;
97 ---------------------------
98 -- Build_Dynamic_Library --
99 ---------------------------
101 procedure Build_Dynamic_Library
102 (Ofiles : Argument_List;
103 Foreign : Argument_List;
104 Afiles : Argument_List;
105 Options : Argument_List;
106 Options_2 : Argument_List;
107 Interfaces : Argument_List;
108 Lib_Filename : String;
109 Lib_Dir : String;
110 Symbol_Data : Symbol_Record;
111 Driver_Name : Name_Id := No_Name;
112 Lib_Version : String := "";
113 Auto_Init : Boolean := False)
115 pragma Unreferenced (Foreign);
116 pragma Unreferenced (Afiles);
117 pragma Unreferenced (Symbol_Data);
118 pragma Unreferenced (Interfaces);
119 pragma Unreferenced (Lib_Version);
120 pragma Unreferenced (Auto_Init);
122 Lib_File : constant String :=
123 Lib_Dir & Directory_Separator &
124 Files.Ext_To (Lib_Filename, DLL_Ext);
126 -- Start of processing for Build_Dynamic_Library
128 begin
129 if Opt.Verbose_Mode then
130 Write_Str ("building relocatable shared library ");
131 Write_Line (Lib_File);
132 end if;
134 Tools.Gcc
135 (Output_File => Lib_File,
136 Objects => Ofiles,
137 Options => No_Argument_List,
138 Options_2 => Options & Options_2,
139 Driver_Name => Driver_Name);
140 end Build_Dynamic_Library;
142 -------------
143 -- DLL_Ext --
144 -------------
146 function DLL_Ext return String is
147 begin
148 return "dll";
149 end DLL_Ext;
151 --------------------
152 -- Dynamic_Option --
153 --------------------
155 function Dynamic_Option return String is
156 begin
157 return "-shared";
158 end Dynamic_Option;
160 -------------------
161 -- Is_Object_Ext --
162 -------------------
164 function Is_Object_Ext (Ext : String) return Boolean is
165 begin
166 return Ext = ".o";
167 end Is_Object_Ext;
169 --------------
170 -- Is_C_Ext --
171 --------------
173 function Is_C_Ext (Ext : String) return Boolean is
174 begin
175 return Ext = ".c";
176 end Is_C_Ext;
178 --------------------
179 -- Is_Archive_Ext --
180 --------------------
182 function Is_Archive_Ext (Ext : String) return Boolean is
183 begin
184 return Ext = ".a" or else Ext = ".dll";
185 end Is_Archive_Ext;
187 -------------
188 -- Libgnat --
189 -------------
191 function Libgnat return String is
192 begin
193 return "libgnat.a";
194 end Libgnat;
196 ------------------------
197 -- Library_Exists_For --
198 ------------------------
200 function Library_Exists_For
201 (Project : Project_Id; In_Tree : Project_Tree_Ref) return Boolean is
202 begin
203 if not In_Tree.Projects.Table (Project).Library then
204 Prj.Com.Fail ("INTERNAL ERROR: Library_Exists_For called " &
205 "for non library project");
206 return False;
208 else
209 declare
210 Lib_Dir : constant String :=
211 Get_Name_String
212 (In_Tree.Projects.Table (Project).Library_Dir);
213 Lib_Name : constant String :=
214 Get_Name_String
215 (In_Tree.Projects.Table (Project).Library_Name);
217 begin
218 if In_Tree.Projects.Table (Project).Library_Kind =
219 Static
220 then
221 return Is_Regular_File
222 (Lib_Dir & Directory_Separator & "lib" &
223 MLib.Fil.Ext_To (Lib_Name, Archive_Ext));
225 else
226 return Is_Regular_File
227 (Lib_Dir & Directory_Separator &
228 MLib.Fil.Ext_To (Lib_Name, DLL_Ext));
229 end if;
230 end;
231 end if;
232 end Library_Exists_For;
234 ---------------------------
235 -- Library_File_Name_For --
236 ---------------------------
238 function Library_File_Name_For
239 (Project : Project_Id;
240 In_Tree : Project_Tree_Ref) return Name_Id is
241 begin
242 if not In_Tree.Projects.Table (Project).Library then
243 Prj.Com.Fail ("INTERNAL ERROR: Library_File_Name_For called " &
244 "for non library project");
245 return No_Name;
247 else
248 declare
249 Lib_Name : constant String :=
250 Get_Name_String
251 (In_Tree.Projects.Table (Project).Library_Name);
253 begin
254 if In_Tree.Projects.Table (Project).Library_Kind =
255 Static
256 then
257 Name_Len := 3;
258 Name_Buffer (1 .. Name_Len) := "lib";
259 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, Archive_Ext));
261 else
262 Name_Len := 0;
263 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, DLL_Ext));
264 end if;
266 return Name_Find;
267 end;
268 end if;
269 end Library_File_Name_For;
271 ----------------
272 -- Object_Ext --
273 ----------------
275 function Object_Ext return String is
276 begin
277 return "o";
278 end Object_Ext;
280 ----------------
281 -- PIC_Option --
282 ----------------
284 function PIC_Option return String is
285 begin
286 return "";
287 end PIC_Option;
289 -----------------------------------------------
290 -- Standalone_Library_Auto_Init_Is_Supported --
291 -----------------------------------------------
293 function Standalone_Library_Auto_Init_Is_Supported return Boolean is
294 begin
295 return True;
296 end Standalone_Library_Auto_Init_Is_Supported;
298 ---------------------------
299 -- Support_For_Libraries --
300 ---------------------------
302 function Support_For_Libraries return Library_Support is
303 begin
304 return Full;
305 end Support_For_Libraries;
307 end MLib.Tgt;