1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2007, AdaCore --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This package provides a set of target dependent routines to build
27 -- static, dynamic and shared libraries. There are several packages
28 -- providing the actual routines; this package calls them indirectly
29 -- by means of access-to-subprogram values; each target-dependent
30 -- package initializes these values in its elaboration block.
36 function Support_For_Libraries
return Library_Support
;
37 -- Indicates how building libraries by gnatmake is supported by the GNAT
38 -- implementation for the platform.
40 function Standalone_Library_Auto_Init_Is_Supported
return Boolean;
41 -- Indicates if when building a dynamic Standalone Library,
42 -- automatic initialization is supported. If it is, then it is the default,
43 -- unless attribute Library_Auto_Init has the value "false".
45 function Archive_Builder
return String;
46 -- Returns the name of the archive builder program, usually "ar"
48 function Archive_Builder_Options
return String_List_Access
;
49 -- A list of options to invoke the Archive_Builder, usually "cr" for "ar"
51 function Archive_Builder_Append_Options
return String_List_Access
;
52 -- A list of options to use with the archive builder to append object
53 -- files ("q", for example).
55 function Archive_Indexer
return String;
56 -- Returns the name of the program, if any, that generates an index to the
57 -- contents of an archive, usually "ranlib". If there is no archive indexer
58 -- to be used, returns an empty string.
60 function Archive_Indexer_Options
return String_List_Access
;
61 -- A list of options to invoke the Archive_Indexer, usually empty
63 function Dynamic_Option
return String;
64 -- gcc option to create a dynamic library.
65 -- For Unix, returns "-shared", for Windows returns "-mdll".
67 function Libgnat
return String;
68 -- System dependent static GNAT library
70 function Archive_Ext
return String;
71 -- System dependent static library extension, without leading dot.
72 -- For Unix and Windows, return "a".
74 function Object_Ext
return String;
75 -- System dependent object extension, without leading dot.
76 -- On Unix, returns "o".
78 function DLL_Prefix
return String;
79 -- System dependent dynamic library prefix.
80 -- On Windows, returns "". On other platforms, returns "lib".
82 function DLL_Ext
return String;
83 -- System dependent dynamic library extension, without leading dot.
84 -- On Windows, returns "dll". On Unix, usually returns "so", but not
85 -- always, e.g. on HP-UX the extension for shared libraries is "sl".
87 function PIC_Option
return String;
88 -- Position independent code option
90 function Is_Object_Ext
(Ext
: String) return Boolean;
91 -- Returns True iff Ext is an object file extension
93 function Is_C_Ext
(Ext
: String) return Boolean;
94 -- Returns True iff Ext is a C file extension
96 function Is_Archive_Ext
(Ext
: String) return Boolean;
97 -- Returns True iff Ext is an extension for a library
99 function Default_Symbol_File_Name
return String;
100 -- Returns the name of the symbol file when Library_Symbol_File is not
101 -- specified. Return the empty string when symbol files are not supported.
103 procedure Build_Dynamic_Library
104 (Ofiles
: Argument_List
;
105 Options
: Argument_List
;
106 Interfaces
: Argument_List
;
107 Lib_Filename
: String;
109 Symbol_Data
: Symbol_Record
;
110 Driver_Name
: Name_Id
:= No_Name
;
111 Lib_Version
: String := "";
112 Auto_Init
: Boolean := False);
113 -- Build a dynamic/relocatable library
115 -- Ofiles is the list of all object files in the library
117 -- Options is a list of options to be passed to the tool
118 -- (gcc or other) that effectively builds the dynamic library.
120 -- Interfaces is the list of ALI files for the interfaces of a SAL.
121 -- It is empty if the library is not a SAL.
123 -- Lib_Filename is the name of the library, without any prefix or
124 -- extension. For example, on Unix, if Lib_Filename is "toto", the
125 -- name of the library file will be "libtoto.so".
127 -- Lib_Dir is the directory path where the library will be located
129 -- For OSes that support symbolic links, Lib_Version, if non null,
130 -- is the actual file name of the library. For example on Unix, if
131 -- Lib_Filename is "toto" and Lib_Version is "libtoto.so.2.1",
132 -- "libtoto.so" will be a symbolic link to "libtoto.so.2.1" which
133 -- will be the actual library file.
135 -- Symbol_Data is used for some patforms, including VMS, to generate
136 -- the symbols to be exported by the library.
138 -- Note: Depending on the OS, some of the parameters may not be taken into
139 -- account. For example, on Linux, Interfaces, Symbol_Data and Auto_Init
142 function Library_Exists_For
143 (Project
: Project_Id
; In_Tree
: Project_Tree_Ref
) return Boolean;
144 -- Return True if the library file for a library project already exists.
145 -- This function can only be called for library projects.
147 function Library_File_Name_For
148 (Project
: Project_Id
;
149 In_Tree
: Project_Tree_Ref
) return File_Name_Type
;
150 -- Returns the file name of the library file of a library project.
151 -- This function can only be called for library projects.
153 function Library_Major_Minor_Id_Supported
return Boolean;
154 -- Indicates if major and minor ids are supported for libraries.
155 -- If they are supported, then a Library_Version such as libtoto.so.1.2
156 -- will have a major id of 1 and a minor id of 2. Then litoto.so,
157 -- libtoto.so.1 and libtoto.so.1.2 will be created, all three designating
161 No_Argument_List
: constant Argument_List
:= (1 .. 0 => null);
163 -- Access to subprogram types for indirection
165 type String_Function
is access function return String;
166 type Is_Ext_Function
is access function (Ext
: String) return Boolean;
167 type String_List_Access_Function
is access function
168 return String_List_Access
;
169 type Build_Dynamic_Library_Function
is access procedure
170 (Ofiles
: Argument_List
;
171 Options
: Argument_List
;
172 Interfaces
: Argument_List
;
173 Lib_Filename
: String;
175 Symbol_Data
: Symbol_Record
;
176 Driver_Name
: Name_Id
:= No_Name
;
177 Lib_Version
: String := "";
178 Auto_Init
: Boolean := False);
179 type Library_Exists_For_Function
is access function
180 (Project
: Project_Id
; In_Tree
: Project_Tree_Ref
) return Boolean;
181 type Library_File_Name_For_Function
is access function
182 (Project
: Project_Id
;
183 In_Tree
: Project_Tree_Ref
) return File_Name_Type
;
184 type Boolean_Function
is access function return Boolean;
185 type Library_Support_Function
is access function return Library_Support
;
187 function Archive_Builder_Default
return String;
188 Archive_Builder_Ptr
: String_Function
:= Archive_Builder_Default
'Access;
190 function Archive_Builder_Options_Default
return String_List_Access
;
191 Archive_Builder_Options_Ptr
: String_List_Access_Function
:=
192 Archive_Builder_Options_Default
'Access;
194 function Archive_Builder_Append_Options_Default
return String_List_Access
;
195 Archive_Builder_Append_Options_Ptr
: String_List_Access_Function
:=
196 Archive_Builder_Append_Options_Default
'Access;
198 function Archive_Ext_Default
return String;
199 Archive_Ext_Ptr
: String_Function
:= Archive_Ext_Default
'Access;
201 function Archive_Indexer_Default
return String;
202 Archive_Indexer_Ptr
: String_Function
:= Archive_Indexer_Default
'Access;
204 function Archive_Indexer_Options_Default
return String_List_Access
;
205 Archive_Indexer_Options_Ptr
: String_List_Access_Function
:=
206 Archive_Indexer_Options_Default
'Access;
208 function Default_Symbol_File_Name_Default
return String;
209 Default_Symbol_File_Name_Ptr
: String_Function
:=
210 Default_Symbol_File_Name_Default
'Access;
212 Build_Dynamic_Library_Ptr
: Build_Dynamic_Library_Function
;
214 function DLL_Ext_Default
return String;
215 DLL_Ext_Ptr
: String_Function
:= DLL_Ext_Default
'Access;
217 function DLL_Prefix_Default
return String;
218 DLL_Prefix_Ptr
: String_Function
:= DLL_Prefix_Default
'Access;
220 function Dynamic_Option_Default
return String;
221 Dynamic_Option_Ptr
: String_Function
:= Dynamic_Option_Default
'Access;
223 function Is_Object_Ext_Default
(Ext
: String) return Boolean;
224 Is_Object_Ext_Ptr
: Is_Ext_Function
:= Is_Object_Ext_Default
'Access;
226 function Is_C_Ext_Default
(Ext
: String) return Boolean;
227 Is_C_Ext_Ptr
: Is_Ext_Function
:= Is_C_Ext_Default
'Access;
229 function Is_Archive_Ext_Default
(Ext
: String) return Boolean;
230 Is_Archive_Ext_Ptr
: Is_Ext_Function
:= Is_Archive_Ext_Default
'Access;
232 function Libgnat_Default
return String;
233 Libgnat_Ptr
: String_Function
:= Libgnat_Default
'Access;
235 function Library_Exists_For_Default
236 (Project
: Project_Id
; In_Tree
: Project_Tree_Ref
) return Boolean;
237 Library_Exists_For_Ptr
: Library_Exists_For_Function
:=
238 Library_Exists_For_Default
'Access;
240 function Library_File_Name_For_Default
241 (Project
: Project_Id
;
242 In_Tree
: Project_Tree_Ref
) return File_Name_Type
;
243 Library_File_Name_For_Ptr
: Library_File_Name_For_Function
:=
244 Library_File_Name_For_Default
'Access;
246 function Object_Ext_Default
return String;
247 Object_Ext_Ptr
: String_Function
:= Object_Ext_Default
'Access;
249 function PIC_Option_Default
return String;
250 PIC_Option_Ptr
: String_Function
:= PIC_Option_Default
'Access;
252 function Standalone_Library_Auto_Init_Is_Supported_Default
return Boolean;
253 Standalone_Library_Auto_Init_Is_Supported_Ptr
: Boolean_Function
:=
254 Standalone_Library_Auto_Init_Is_Supported_Default
'Access;
256 function Support_For_Libraries_Default
return Library_Support
;
257 Support_For_Libraries_Ptr
: Library_Support_Function
:=
258 Support_For_Libraries_Default
'Access;
260 function Library_Major_Minor_Id_Supported_Default
return Boolean;
261 Library_Major_Minor_Id_Supported_Ptr
: Boolean_Function
:=
262 Library_Major_Minor_Id_Supported_Default
'Access;