s-tposen.adb (Service_Entry): The object must be always unlocked at the end of this...
[platform/upstream/gcc.git] / gcc / ada / mlib-tgt-mingw.adb
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 ------------------------------------------------------------------------------
27
28 --  This package provides a set of target dependent routines to build
29 --  static, dynamic and shared libraries.
30
31 --  This is the Windows version of the body. Works only with GCC versions
32 --  supporting the "-shared" option.
33
34 with Namet;  use Namet;
35 with Opt;
36 with Output; use Output;
37 with Prj.Com;
38
39 with GNAT.OS_Lib; use GNAT.OS_Lib;
40
41 with MLib.Fil;
42 with MLib.Utl;
43
44 package body MLib.Tgt is
45
46    package Files renames MLib.Fil;
47    package Tools renames MLib.Utl;
48
49    ---------------------
50    -- Archive_Builder --
51    ---------------------
52
53    function Archive_Builder return String is
54    begin
55       return "ar";
56    end Archive_Builder;
57
58    -----------------------------
59    -- Archive_Builder_Options --
60    -----------------------------
61
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;
66
67    -----------------
68    -- Archive_Ext --
69    -----------------
70
71    function Archive_Ext return  String is
72    begin
73       return "a";
74    end Archive_Ext;
75
76    ---------------------
77    -- Archive_Indexer --
78    ---------------------
79
80    function Archive_Indexer return String is
81    begin
82       return "ranlib";
83    end Archive_Indexer;
84
85    ---------------------------
86    -- Build_Dynamic_Library --
87    ---------------------------
88
89    procedure Build_Dynamic_Library
90      (Ofiles       : Argument_List;
91       Foreign      : Argument_List;
92       Afiles       : Argument_List;
93       Options      : Argument_List;
94       Interfaces   : Argument_List;
95       Lib_Filename : String;
96       Lib_Dir      : String;
97       Symbol_Data  : Symbol_Record;
98       Driver_Name  : Name_Id := No_Name;
99       Lib_Version  : String  := "";
100       Auto_Init    : Boolean := False)
101    is
102       pragma Unreferenced (Foreign);
103       pragma Unreferenced (Afiles);
104       pragma Unreferenced (Auto_Init);
105       pragma Unreferenced (Symbol_Data);
106       pragma Unreferenced (Interfaces);
107       pragma Unreferenced (Lib_Version);
108
109       Lib_File : constant String :=
110                    Lib_Dir & Directory_Separator &
111                    Files.Ext_To (Lib_Filename, DLL_Ext);
112
113    --  Start of processing for Build_Dynamic_Library
114
115    begin
116       if Opt.Verbose_Mode then
117          Write_Str ("building relocatable shared library ");
118          Write_Line (Lib_File);
119       end if;
120
121       Tools.Gcc
122         (Output_File => Lib_File,
123          Objects     => Ofiles,
124          Options     => Tools.No_Argument_List,
125          Options_2   => Options,
126          Driver_Name => Driver_Name);
127    end Build_Dynamic_Library;
128
129    -------------
130    -- DLL_Ext --
131    -------------
132
133    function DLL_Ext return String is
134    begin
135       return "dll";
136    end DLL_Ext;
137
138    --------------------
139    -- Dynamic_Option --
140    --------------------
141
142    function Dynamic_Option return String is
143    begin
144       return "-shared";
145    end Dynamic_Option;
146
147    -------------------
148    -- Is_Object_Ext --
149    -------------------
150
151    function Is_Object_Ext (Ext : String) return Boolean is
152    begin
153       return Ext = ".o";
154    end Is_Object_Ext;
155
156    --------------
157    -- Is_C_Ext --
158    --------------
159
160    function Is_C_Ext (Ext : String) return Boolean is
161    begin
162       return Ext = ".c";
163    end Is_C_Ext;
164
165    --------------------
166    -- Is_Archive_Ext --
167    --------------------
168
169    function Is_Archive_Ext (Ext : String) return Boolean is
170    begin
171       return Ext = ".a" or else Ext = ".dll";
172    end Is_Archive_Ext;
173
174    -------------
175    -- Libgnat --
176    -------------
177
178    function Libgnat return String is
179    begin
180       return "libgnat.a";
181    end Libgnat;
182
183    ------------------------
184    -- Library_Exists_For --
185    ------------------------
186
187    function Library_Exists_For (Project : Project_Id) return Boolean is
188    begin
189       if not Projects.Table (Project).Library then
190          Prj.Com.Fail ("INTERNAL ERROR: Library_Exists_For called " &
191                        "for non library project");
192          return False;
193
194       else
195          declare
196             Lib_Dir : constant String :=
197                         Get_Name_String
198                           (Projects.Table (Project).Library_Dir);
199             Lib_Name : constant String :=
200                          Get_Name_String
201                            (Projects.Table (Project).Library_Name);
202
203          begin
204             if Projects.Table (Project).Library_Kind = Static then
205                return Is_Regular_File
206                  (Lib_Dir & Directory_Separator & "lib" &
207                   MLib.Fil.Ext_To (Lib_Name, Archive_Ext));
208
209             else
210                return Is_Regular_File
211                  (Lib_Dir & Directory_Separator &
212                   MLib.Fil.Ext_To (Lib_Name, DLL_Ext));
213             end if;
214          end;
215       end if;
216    end Library_Exists_For;
217
218    ---------------------------
219    -- Library_File_Name_For --
220    ---------------------------
221
222    function Library_File_Name_For (Project : Project_Id) return Name_Id is
223    begin
224       if not Projects.Table (Project).Library then
225          Prj.Com.Fail ("INTERNAL ERROR: Library_File_Name_For called " &
226                        "for non library project");
227          return No_Name;
228
229       else
230          declare
231             Lib_Name : constant String :=
232               Get_Name_String (Projects.Table (Project).Library_Name);
233
234          begin
235             if Projects.Table (Project).Library_Kind = Static then
236                Name_Len := 3;
237                Name_Buffer (1 .. Name_Len) := "lib";
238                Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, Archive_Ext));
239
240             else
241                Name_Len := 0;
242                Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, DLL_Ext));
243             end if;
244
245             return Name_Find;
246          end;
247       end if;
248    end Library_File_Name_For;
249
250    ----------------
251    -- Object_Ext --
252    ----------------
253
254    function Object_Ext return String is
255    begin
256       return "o";
257    end Object_Ext;
258
259    ----------------
260    -- PIC_Option --
261    ----------------
262
263    function PIC_Option return String is
264    begin
265       return "";
266    end PIC_Option;
267
268    -----------------------------------------------
269    -- Standalone_Library_Auto_Init_Is_Supported --
270    -----------------------------------------------
271
272    function Standalone_Library_Auto_Init_Is_Supported return Boolean is
273    begin
274       return False;
275    end Standalone_Library_Auto_Init_Is_Supported;
276
277    ---------------------------
278    -- Support_For_Libraries --
279    ---------------------------
280
281    function Support_For_Libraries return Library_Support is
282    begin
283       return Full;
284    end Support_For_Libraries;
285
286 end MLib.Tgt;