1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 2003-2006, AdaCore --
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, 51 Franklin Street, Fifth Floor, --
21 -- Boston, MA 02110-1301, 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 IRIX version of the body
35 with Namet; use Namet;
37 with Output; use Output;
41 package body MLib.Tgt is
47 function Archive_Builder return String is
52 -----------------------------
53 -- Archive_Builder_Options --
54 -----------------------------
56 function Archive_Builder_Options return String_List_Access is
58 return new String_List'(1 => new String'("cr"));
59 end Archive_Builder_Options;
65 function Archive_Ext return String is
74 function Archive_Indexer return String is
79 -----------------------------
80 -- Archive_Indexer_Options --
81 -----------------------------
83 function Archive_Indexer_Options return String_List_Access is
85 return new String_List (1 .. 0);
86 end Archive_Indexer_Options;
88 ---------------------------
89 -- Build_Dynamic_Library --
90 ---------------------------
92 procedure Build_Dynamic_Library
93 (Ofiles : Argument_List;
94 Foreign : Argument_List;
95 Afiles : Argument_List;
96 Options : Argument_List;
97 Options_2 : Argument_List;
98 Interfaces : Argument_List;
99 Lib_Filename : String;
101 Symbol_Data : Symbol_Record;
102 Driver_Name : Name_Id := No_Name;
103 Lib_Version : String := "";
104 Auto_Init : Boolean := False)
106 pragma Unreferenced (Foreign);
107 pragma Unreferenced (Afiles);
108 pragma Unreferenced (Interfaces);
109 pragma Unreferenced (Symbol_Data);
110 pragma Unreferenced (Auto_Init);
112 Lib_File : constant String :=
113 Lib_Dir & Directory_Separator & "lib" &
114 MLib.Fil.Append_To (Lib_Filename, DLL_Ext);
116 Version_Arg : String_Access;
117 Symbolic_Link_Needed : Boolean := False;
119 N_Options : Argument_List := Options;
120 Options_Last : Natural := N_Options'Last;
121 -- After moving -lxxx to Options_2, N_Options up to index Options_Last
122 -- will contain the Options to pass to MLib.Utl.Gcc.
124 Real_Options_2 : Argument_List (1 .. Options'Length + Options_2'Length);
125 Real_Options_2_Last : Natural := 0;
126 -- Real_Options_2 up to index Real_Options_2_Last will contain the
127 -- Options_2 to pass to MLib.Utl.Gcc.
130 if Opt.Verbose_Mode then
131 Write_Str ("building relocatable shared library ");
132 Write_Line (Lib_File);
135 -- Move all -lxxx to Options_2
138 Index : Natural := N_Options'First;
142 while Index <= Options_Last loop
143 Arg := N_Options (Index);
146 and then Arg (Arg'First .. Arg'First + 1) = "-l"
148 Real_Options_2_Last := Real_Options_2_Last + 1;
149 Real_Options_2 (Real_Options_2_Last) := Arg;
150 N_Options (Index .. Options_Last - 1) :=
151 N_Options (Index + 1 .. Options_Last);
152 Options_Last := Options_Last - 1;
160 -- Add to Real_Options_2 the argument Options_2
163 (Real_Options_2_Last + 1 .. Real_Options_2_Last + Options_2'Length) :=
165 Real_Options_2_Last := Real_Options_2_Last + Options_2'Length;
167 if Lib_Version = "" then
169 (Output_File => Lib_File,
171 Options => N_Options (N_Options'First .. Options_Last),
172 Driver_Name => Driver_Name,
173 Options_2 => Real_Options_2 (1 .. Real_Options_2_Last));
176 Version_Arg := new String'("-Wl,-soname," & Lib_Version);
178 if Is_Absolute_Path (Lib_Version) then
180 (Output_File => Lib_Version,
182 Options => N_Options (N_Options'First .. Options_Last) &
184 Driver_Name => Driver_Name,
185 Options_2 => Real_Options_2 (1 .. Real_Options_2_Last));
186 Symbolic_Link_Needed := Lib_Version /= Lib_File;
190 (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
192 Options => N_Options (N_Options'First .. Options_Last) &
194 Driver_Name => Driver_Name,
195 Options_2 => Real_Options_2 (1 .. Real_Options_2_Last));
196 Symbolic_Link_Needed :=
197 Lib_Dir & Directory_Separator & Lib_Version /= Lib_File;
200 if Symbolic_Link_Needed then
203 Oldpath : String (1 .. Lib_Version'Length + 1);
204 Newpath : String (1 .. Lib_File'Length + 1);
207 pragma Unreferenced (Result);
210 (Oldpath : System.Address;
211 Newpath : System.Address)
213 pragma Import (C, Symlink, "__gnat_symlink");
216 Oldpath (1 .. Lib_Version'Length) := Lib_Version;
217 Oldpath (Oldpath'Last) := ASCII.NUL;
218 Newpath (1 .. Lib_File'Length) := Lib_File;
219 Newpath (Newpath'Last) := ASCII.NUL;
221 Delete_File (Lib_File, Success);
223 Result := Symlink (Oldpath'Address, Newpath'Address);
227 end Build_Dynamic_Library;
233 function DLL_Ext return String is
242 function DLL_Prefix return String is
251 function Dynamic_Option return String is
260 function Is_Object_Ext (Ext : String) return Boolean is
269 function Is_C_Ext (Ext : String) return Boolean is
278 function Is_Archive_Ext (Ext : String) return Boolean is
280 return Ext = ".a" or else Ext = ".so";
287 function Libgnat return String is
292 ------------------------
293 -- Library_Exists_For --
294 ------------------------
296 function Library_Exists_For
297 (Project : Project_Id;
298 In_Tree : Project_Tree_Ref) return Boolean
301 if not In_Tree.Projects.Table (Project).Library then
302 Prj.Com.Fail ("INTERNAL ERROR: Library_Exists_For called " &
303 "for non library project");
308 Lib_Dir : constant String :=
310 (In_Tree.Projects.Table (Project).Library_Dir);
311 Lib_Name : constant String :=
313 (In_Tree.Projects.Table (Project).Library_Name);
316 if In_Tree.Projects.Table (Project).Library_Kind = Static then
317 return Is_Regular_File
318 (Lib_Dir & Directory_Separator & "lib" &
319 Fil.Append_To (Lib_Name, Archive_Ext));
322 return Is_Regular_File
323 (Lib_Dir & Directory_Separator & "lib" &
324 Fil.Append_To (Lib_Name, DLL_Ext));
328 end Library_Exists_For;
330 ---------------------------
331 -- Library_File_Name_For --
332 ---------------------------
334 function Library_File_Name_For
335 (Project : Project_Id;
336 In_Tree : Project_Tree_Ref) return Name_Id
339 if not In_Tree.Projects.Table (Project).Library then
340 Prj.Com.Fail ("INTERNAL ERROR: Library_File_Name_For called " &
341 "for non library project");
346 Lib_Name : constant String :=
348 (In_Tree.Projects.Table (Project).Library_Name);
352 Name_Buffer (1 .. Name_Len) := "lib";
354 if In_Tree.Projects.Table (Project).Library_Kind =
357 Add_Str_To_Name_Buffer (Fil.Append_To (Lib_Name, Archive_Ext));
359 Add_Str_To_Name_Buffer (Fil.Append_To (Lib_Name, DLL_Ext));
365 end Library_File_Name_For;
371 function Object_Ext return String is
380 function PIC_Option return String is
385 -----------------------------------------------
386 -- Standalone_Library_Auto_Init_Is_Supported --
387 -----------------------------------------------
389 function Standalone_Library_Auto_Init_Is_Supported return Boolean is
392 end Standalone_Library_Auto_Init_Is_Supported;
394 ---------------------------
395 -- Support_For_Libraries --
396 ---------------------------
398 function Support_For_Libraries return Library_Support is
401 end Support_For_Libraries;