1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
6 -- (Windows Version) --
10 -- Copyright (C) 2002-2003, Ada Core Technologies, 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, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, 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 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.
33 with Namet; use Namet;
35 with Output; use Output;
38 with GNAT.OS_Lib; use GNAT.OS_Lib;
44 package body MLib.Tgt is
50 function Archive_Builder return String is
55 -----------------------------
56 -- Archive_Builder_Options --
57 -----------------------------
59 function Archive_Builder_Options return String_List_Access is
61 return new String_List'(1 => new String'("cr"));
62 end Archive_Builder_Options;
68 function Archive_Ext return String is
77 function Archive_Indexer return String is
82 ---------------------------
83 -- Build_Dynamic_Library --
84 ---------------------------
86 procedure Build_Dynamic_Library
87 (Ofiles : Argument_List;
88 Foreign : Argument_List;
89 Afiles : Argument_List;
90 Options : Argument_List;
91 Interfaces : Argument_List;
92 Lib_Filename : String;
94 Symbol_Data : Symbol_Record;
95 Driver_Name : Name_Id := No_Name;
96 Lib_Address : String := "";
97 Lib_Version : String := "";
98 Relocatable : Boolean := False;
99 Auto_Init : Boolean := False)
101 pragma Unreferenced (Ofiles);
102 pragma Unreferenced (Interfaces);
103 pragma Unreferenced (Symbol_Data);
104 pragma Unreferenced (Driver_Name);
105 pragma Unreferenced (Lib_Version);
106 pragma Unreferenced (Auto_Init);
108 Imp_File : constant String :=
109 "lib" & MLib.Fil.Ext_To (Lib_Filename, Archive_Ext);
110 -- Name of the import library
112 DLL_File : constant String := MLib.Fil.Ext_To (Lib_Filename, DLL_Ext);
113 -- Name of the DLL file
115 Lib_File : constant String := Lib_Dir & Directory_Separator & DLL_File;
116 -- Full path of the DLL file
121 if Opt.Verbose_Mode then
123 Write_Str ("building relocatable shared library ");
125 Write_Str ("building non-relocatable shared library ");
128 Write_Line (Lib_File);
131 MDLL.Verbose := Opt.Verbose_Mode;
132 MDLL.Quiet := not MDLL.Verbose;
136 MDLL.Build_Dynamic_Library
138 MDLL.Null_Argument_List, MDLL.Null_Argument_List, Options,
139 Lib_Filename, Lib_Filename & ".def",
140 Lib_Address, True, Relocatable);
142 -- Move the DLL and import library in the lib directory
144 Copy_File (DLL_File, Lib_Dir, Success, Mode => Overwrite);
147 Fail ("could not copy DLL to library dir");
150 Copy_File (Imp_File, Lib_Dir, Success, Mode => Overwrite);
153 Fail ("could not copy import library to library dir");
158 Delete_File (DLL_File, Success);
161 Fail ("could not delete DLL from build dir");
164 Delete_File (Imp_File, Success);
167 Fail ("could not delete import library from build dir");
169 end Build_Dynamic_Library;
171 -------------------------
172 -- Default_DLL_Address --
173 -------------------------
175 function Default_DLL_Address return String is
178 end Default_DLL_Address;
184 function DLL_Ext return String is
193 function Dynamic_Option return String is
202 function Is_Object_Ext (Ext : String) return Boolean is
211 function Is_C_Ext (Ext : String) return Boolean is
220 function Is_Archive_Ext (Ext : String) return Boolean is
229 function Libgnat return String is
234 ------------------------
235 -- Library_Exists_For --
236 ------------------------
238 function Library_Exists_For (Project : Project_Id) return Boolean is
240 if not Projects.Table (Project).Library then
241 Prj.Com.Fail ("INTERNAL ERROR: Library_Exists_For called " &
242 "for non library project");
247 Lib_Dir : constant String :=
248 Get_Name_String (Projects.Table (Project).Library_Dir);
249 Lib_Name : constant String :=
250 Get_Name_String (Projects.Table (Project).Library_Name);
253 if Projects.Table (Project).Library_Kind = Static then
255 -- Static libraries are named : lib<name>.a
257 return Is_Regular_File
258 (Lib_Dir & Directory_Separator & "lib" &
259 MLib.Fil.Ext_To (Lib_Name, Archive_Ext));
262 -- Shared libraries are named : <name>.dll
264 return Is_Regular_File
265 (Lib_Dir & Directory_Separator &
266 MLib.Fil.Ext_To (Lib_Name, DLL_Ext));
270 end Library_Exists_For;
272 ---------------------------
273 -- Library_File_Name_For --
274 ---------------------------
276 function Library_File_Name_For (Project : Project_Id) return Name_Id is
278 if not Projects.Table (Project).Library then
279 Prj.Com.Fail ("INTERNAL ERROR: Library_File_Name_For called " &
280 "for non library project");
285 Lib_Name : constant String :=
287 (Projects.Table (Project).Library_Name);
290 if Projects.Table (Project).Library_Kind = Static then
292 -- Static libraries are named : lib<name>.a
295 Name_Buffer (1 .. Name_Len) := "lib";
297 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, Archive_Ext));
300 -- Shared libraries are named : <name>.dll
303 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, DLL_Ext));
309 end Library_File_Name_For;
311 --------------------------------
312 -- Linker_Library_Path_Option --
313 --------------------------------
315 function Linker_Library_Path_Option return String_Access is
318 end Linker_Library_Path_Option;
324 function Object_Ext return String is
333 function PIC_Option return String is
338 -----------------------------------------------
339 -- Standalone_Library_Auto_Init_Is_Supported --
340 -----------------------------------------------
342 function Standalone_Library_Auto_Init_Is_Supported return Boolean is
345 end Standalone_Library_Auto_Init_Is_Supported;
347 ---------------------------
348 -- Support_For_Libraries --
349 ---------------------------
351 function Support_For_Libraries return Library_Support is
354 end Support_For_Libraries;