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.
29 -- There are several versions for the body of this package
31 -- In the default version, libraries are not supported, so function
32 -- Support_For_Libraries return None.
38 function Support_For_Libraries return Library_Support;
39 -- Indicates how building libraries by gnatmake is supported by the GNAT
40 -- implementation for the platform.
42 function Standalone_Library_Auto_Init_Is_Supported return Boolean;
43 -- Indicates if when building a dynamic Standalone Library,
44 -- automatic initialization is supported. If it is, then it is the default,
45 -- unless attribute Library_Auto_Init has the value "false".
47 function Archive_Builder return String;
48 -- Returns the name of the archive builder program, usually "ar"
50 function Archive_Builder_Options return String_List_Access;
51 -- A list of options to invoke the Archive_Builder, usually "cr" for "ar"
53 function Archive_Builder_Append_Options return String_List_Access;
54 -- A list of options to use with the archive builder to append object
55 -- files ("q", for example).
57 function Archive_Indexer return String;
58 -- Returns the name of the program, if any, that generates an index to the
59 -- contents of an archive, usually "ranlib". If there is no archive indexer
60 -- to be used, returns an empty string.
62 function Archive_Indexer_Options return String_List_Access;
63 -- A list of options to invoke the Archive_Indexer, usually empty
65 function Dynamic_Option return String;
66 -- gcc option to create a dynamic library.
67 -- For Unix, returns "-shared", for Windows returns "-mdll".
69 function Libgnat return String;
70 -- System dependent static GNAT library
72 function Archive_Ext return String;
73 -- System dependent static library extension, without leading dot.
74 -- For Unix and Windows, return "a".
76 function Object_Ext return String;
77 -- System dependent object extension, without leading dot.
78 -- On Unix, returns "o".
80 function DLL_Prefix return String;
81 -- System dependent dynamic library prefix.
82 -- On Windows, returns "". On other platforms, returns "lib".
84 function DLL_Ext return String;
85 -- System dependent dynamic library extension, without leading dot.
86 -- On Windows, returns "dll". On Unix, usually returns "so", but not
87 -- always, e.g. on HP-UX the extension for shared libraries is "sl".
89 function PIC_Option return String;
90 -- Position independent code option
92 function Is_Object_Ext (Ext : String) return Boolean;
93 -- Returns True iff Ext is an object file extension
95 function Is_C_Ext (Ext : String) return Boolean;
96 -- Returns True iff Ext is a C file extension
98 function Is_Archive_Ext (Ext : String) return Boolean;
99 -- Returns True iff Ext is an extension for a library
101 function Default_Symbol_File_Name return String;
102 -- Returns the name of the symbol file when Library_Symbol_File is not
103 -- specified. Return the empty string when symbol files are not supported.
105 procedure Build_Dynamic_Library
106 (Ofiles : Argument_List;
107 Options : Argument_List;
108 Interfaces : Argument_List;
109 Lib_Filename : String;
111 Symbol_Data : Symbol_Record;
112 Driver_Name : Name_Id := No_Name;
113 Lib_Version : String := "";
114 Auto_Init : Boolean := False);
115 -- Build a dynamic/relocatable library
117 -- Ofiles is the list of all object files in the library
119 -- Options is a list of options to be passed to the tool
120 -- (gcc or other) that effectively builds the dynamic library.
122 -- Interfaces is the list of ALI files for the interfaces of a SAL.
123 -- It is empty if the library is not a SAL.
125 -- Lib_Filename is the name of the library, without any prefix or
126 -- extension. For example, on Unix, if Lib_Filename is "toto", the
127 -- name of the library file will be "libtoto.so".
129 -- Lib_Dir is the directory path where the library will be located
131 -- For OSes that support symbolic links, Lib_Version, if non null,
132 -- is the actual file name of the library. For example on Unix, if
133 -- Lib_Filename is "toto" and Lib_Version is "libtoto.so.2.1",
134 -- "libtoto.so" will be a symbolic link to "libtoto.so.2.1" which
135 -- will be the actual library file.
137 -- Symbol_Data is used for some patforms, including VMS, to generate
138 -- the symbols to be exported by the library.
140 -- Note: Depending on the OS, some of the parameters may not be taken into
141 -- account. For example, on Linux, Interfaces, Symbol_Data and Auto_Init
144 function Library_Exists_For
145 (Project : Project_Id; In_Tree : Project_Tree_Ref) return Boolean;
146 -- Return True if the library file for a library project already exists.
147 -- This function can only be called for library projects.
149 function Library_File_Name_For
150 (Project : Project_Id;
151 In_Tree : Project_Tree_Ref) return File_Name_Type;
152 -- Returns the file name of the library file of a library project.
153 -- This function can only be called for library projects.
155 function Library_Major_Minor_Id_Supported return Boolean;
156 -- Indicates if major and minor ids are supported for libraries.
157 -- If they are supported, then a Library_Version such as libtoto.so.1.2
158 -- will have a major id of 1 and a minor id of 2. Then litoto.so,
159 -- libtoto.so.1 and libtoto.so.1.2 will be created, all three designating
163 No_Argument_List : constant Argument_List := (1 .. 0 => null);
165 -- Access to subprogram types for indirection
167 type String_Function is access function return String;
168 type Is_Ext_Function is access function (Ext : String) return Boolean;
169 type String_List_Access_Function is access function
170 return String_List_Access;
171 type Build_Dynamic_Library_Function is access procedure
172 (Ofiles : Argument_List;
173 Options : Argument_List;
174 Interfaces : Argument_List;
175 Lib_Filename : String;
177 Symbol_Data : Symbol_Record;
178 Driver_Name : Name_Id := No_Name;
179 Lib_Version : String := "";
180 Auto_Init : Boolean := False);
181 type Library_Exists_For_Function is access function
182 (Project : Project_Id; In_Tree : Project_Tree_Ref) return Boolean;
183 type Library_File_Name_For_Function is access function
184 (Project : Project_Id;
185 In_Tree : Project_Tree_Ref) return File_Name_Type;
186 type Boolean_Function is access function return Boolean;
187 type Library_Support_Function is access function return Library_Support;
189 function Archive_Builder_Default return String;
190 Archive_Builder_Ptr : String_Function := Archive_Builder_Default'Access;
192 function Archive_Builder_Options_Default return String_List_Access;
193 Archive_Builder_Options_Ptr : String_List_Access_Function :=
194 Archive_Builder_Options_Default'Access;
196 function Archive_Builder_Append_Options_Default return String_List_Access;
197 Archive_Builder_Append_Options_Ptr : String_List_Access_Function :=
198 Archive_Builder_Append_Options_Default'Access;
200 function Archive_Ext_Default return String;
201 Archive_Ext_Ptr : String_Function := Archive_Ext_Default'Access;
203 function Archive_Indexer_Default return String;
204 Archive_Indexer_Ptr : String_Function := Archive_Indexer_Default'Access;
206 function Archive_Indexer_Options_Default return String_List_Access;
207 Archive_Indexer_Options_Ptr : String_List_Access_Function :=
208 Archive_Indexer_Options_Default'Access;
210 function Default_Symbol_File_Name_Default return String;
211 Default_Symbol_File_Name_Ptr : String_Function :=
212 Default_Symbol_File_Name_Default'Access;
214 Build_Dynamic_Library_Ptr : Build_Dynamic_Library_Function;
216 function DLL_Ext_Default return String;
217 DLL_Ext_Ptr : String_Function := DLL_Ext_Default'Access;
219 function DLL_Prefix_Default return String;
220 DLL_Prefix_Ptr : String_Function := DLL_Prefix_Default'Access;
222 function Dynamic_Option_Default return String;
223 Dynamic_Option_Ptr : String_Function := Dynamic_Option_Default'Access;
225 function Is_Object_Ext_Default (Ext : String) return Boolean;
226 Is_Object_Ext_Ptr : Is_Ext_Function := Is_Object_Ext_Default'Access;
228 function Is_C_Ext_Default (Ext : String) return Boolean;
229 Is_C_Ext_Ptr : Is_Ext_Function := Is_C_Ext_Default'Access;
231 function Is_Archive_Ext_Default (Ext : String) return Boolean;
232 Is_Archive_Ext_Ptr : Is_Ext_Function := Is_Archive_Ext_Default'Access;
234 function Libgnat_Default return String;
235 Libgnat_Ptr : String_Function := Libgnat_Default'Access;
237 function Library_Exists_For_Default
238 (Project : Project_Id; In_Tree : Project_Tree_Ref) return Boolean;
239 Library_Exists_For_Ptr : Library_Exists_For_Function :=
240 Library_Exists_For_Default'Access;
242 function Library_File_Name_For_Default
243 (Project : Project_Id;
244 In_Tree : Project_Tree_Ref) return File_Name_Type;
245 Library_File_Name_For_Ptr : Library_File_Name_For_Function :=
246 Library_File_Name_For_Default'Access;
248 function Object_Ext_Default return String;
249 Object_Ext_Ptr : String_Function := Object_Ext_Default'Access;
251 function PIC_Option_Default return String;
252 PIC_Option_Ptr : String_Function := PIC_Option_Default'Access;
254 function Standalone_Library_Auto_Init_Is_Supported_Default return Boolean;
255 Standalone_Library_Auto_Init_Is_Supported_Ptr : Boolean_Function :=
256 Standalone_Library_Auto_Init_Is_Supported_Default'Access;
258 function Support_For_Libraries_Default return Library_Support;
259 Support_For_Libraries_Ptr : Library_Support_Function :=
260 Support_For_Libraries_Default'Access;
262 function Library_Major_Minor_Id_Supported_Default return Boolean;
263 Library_Major_Minor_Id_Supported_Ptr : Boolean_Function :=
264 Library_Major_Minor_Id_Supported_Default'Access;