Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / gcc / ada / mlib-tgt-mingw.adb
blob140bbccff997c1a53191858abe615f8ddc78cc45
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-2004, 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, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, 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 Namet; use Namet;
35 with Opt;
36 with Output; use Output;
37 with Prj.Com;
39 with GNAT.OS_Lib; use GNAT.OS_Lib;
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 ---------------------
50 -- Archive_Builder --
51 ---------------------
53 function Archive_Builder return String is
54 begin
55 return "ar";
56 end Archive_Builder;
58 -----------------------------
59 -- Archive_Builder_Options --
60 -----------------------------
62 function Archive_Builder_Options return String_List_Access is
63 begin
64 return new String_List'(1 => new String'("cr"));
65 end Archive_Builder_Options;
67 -----------------
68 -- Archive_Ext --
69 -----------------
71 function Archive_Ext return String is
72 begin
73 return "a";
74 end Archive_Ext;
76 ---------------------
77 -- Archive_Indexer --
78 ---------------------
80 function Archive_Indexer return String is
81 begin
82 return "ranlib";
83 end Archive_Indexer;
85 -----------------------------
86 -- Archive_Indexer_Options --
87 -----------------------------
89 function Archive_Indexer_Options return String_List_Access is
90 begin
91 return new String_List (1 .. 0);
92 end Archive_Indexer_Options;
94 ---------------------------
95 -- Build_Dynamic_Library --
96 ---------------------------
98 procedure Build_Dynamic_Library
99 (Ofiles : Argument_List;
100 Foreign : Argument_List;
101 Afiles : Argument_List;
102 Options : Argument_List;
103 Options_2 : Argument_List;
104 Interfaces : Argument_List;
105 Lib_Filename : String;
106 Lib_Dir : String;
107 Symbol_Data : Symbol_Record;
108 Driver_Name : Name_Id := No_Name;
109 Lib_Version : String := "";
110 Auto_Init : Boolean := False)
112 pragma Unreferenced (Foreign);
113 pragma Unreferenced (Afiles);
114 pragma Unreferenced (Auto_Init);
115 pragma Unreferenced (Symbol_Data);
116 pragma Unreferenced (Interfaces);
117 pragma Unreferenced (Lib_Version);
119 Lib_File : constant String :=
120 Lib_Dir & Directory_Separator &
121 Files.Ext_To (Lib_Filename, DLL_Ext);
123 -- Start of processing for Build_Dynamic_Library
125 begin
126 if Opt.Verbose_Mode then
127 Write_Str ("building relocatable shared library ");
128 Write_Line (Lib_File);
129 end if;
131 Tools.Gcc
132 (Output_File => Lib_File,
133 Objects => Ofiles,
134 Options => Tools.No_Argument_List,
135 Options_2 => Options & Options_2,
136 Driver_Name => Driver_Name);
137 end Build_Dynamic_Library;
139 -------------
140 -- DLL_Ext --
141 -------------
143 function DLL_Ext return String is
144 begin
145 return "dll";
146 end DLL_Ext;
148 --------------------
149 -- Dynamic_Option --
150 --------------------
152 function Dynamic_Option return String is
153 begin
154 return "-shared";
155 end Dynamic_Option;
157 -------------------
158 -- Is_Object_Ext --
159 -------------------
161 function Is_Object_Ext (Ext : String) return Boolean is
162 begin
163 return Ext = ".o";
164 end Is_Object_Ext;
166 --------------
167 -- Is_C_Ext --
168 --------------
170 function Is_C_Ext (Ext : String) return Boolean is
171 begin
172 return Ext = ".c";
173 end Is_C_Ext;
175 --------------------
176 -- Is_Archive_Ext --
177 --------------------
179 function Is_Archive_Ext (Ext : String) return Boolean is
180 begin
181 return Ext = ".a" or else Ext = ".dll";
182 end Is_Archive_Ext;
184 -------------
185 -- Libgnat --
186 -------------
188 function Libgnat return String is
189 begin
190 return "libgnat.a";
191 end Libgnat;
193 ------------------------
194 -- Library_Exists_For --
195 ------------------------
197 function Library_Exists_For (Project : Project_Id) return Boolean is
198 begin
199 if not Projects.Table (Project).Library then
200 Prj.Com.Fail ("INTERNAL ERROR: Library_Exists_For called " &
201 "for non library project");
202 return False;
204 else
205 declare
206 Lib_Dir : constant String :=
207 Get_Name_String
208 (Projects.Table (Project).Library_Dir);
209 Lib_Name : constant String :=
210 Get_Name_String
211 (Projects.Table (Project).Library_Name);
213 begin
214 if Projects.Table (Project).Library_Kind = Static then
215 return Is_Regular_File
216 (Lib_Dir & Directory_Separator & "lib" &
217 MLib.Fil.Ext_To (Lib_Name, Archive_Ext));
219 else
220 return Is_Regular_File
221 (Lib_Dir & Directory_Separator &
222 MLib.Fil.Ext_To (Lib_Name, DLL_Ext));
223 end if;
224 end;
225 end if;
226 end Library_Exists_For;
228 ---------------------------
229 -- Library_File_Name_For --
230 ---------------------------
232 function Library_File_Name_For (Project : Project_Id) return Name_Id is
233 begin
234 if not Projects.Table (Project).Library then
235 Prj.Com.Fail ("INTERNAL ERROR: Library_File_Name_For called " &
236 "for non library project");
237 return No_Name;
239 else
240 declare
241 Lib_Name : constant String :=
242 Get_Name_String (Projects.Table (Project).Library_Name);
244 begin
245 if Projects.Table (Project).Library_Kind = Static then
246 Name_Len := 3;
247 Name_Buffer (1 .. Name_Len) := "lib";
248 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, Archive_Ext));
250 else
251 Name_Len := 0;
252 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, DLL_Ext));
253 end if;
255 return Name_Find;
256 end;
257 end if;
258 end Library_File_Name_For;
260 ----------------
261 -- Object_Ext --
262 ----------------
264 function Object_Ext return String is
265 begin
266 return "o";
267 end Object_Ext;
269 ----------------
270 -- PIC_Option --
271 ----------------
273 function PIC_Option return String is
274 begin
275 return "";
276 end PIC_Option;
278 -----------------------------------------------
279 -- Standalone_Library_Auto_Init_Is_Supported --
280 -----------------------------------------------
282 function Standalone_Library_Auto_Init_Is_Supported return Boolean is
283 begin
284 return False;
285 end Standalone_Library_Auto_Init_Is_Supported;
287 ---------------------------
288 -- Support_For_Libraries --
289 ---------------------------
291 function Support_For_Libraries return Library_Support is
292 begin
293 return Full;
294 end Support_For_Libraries;
296 end MLib.Tgt;