* tree-loop-linear.c: Don't include varray.h.
[official-gcc.git] / gcc / ada / mlib-tgt-hpux.adb
blob85e756ce8df4d65aed14e1e599e4b63244812e80
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- M L I B . T G T --
6 -- (HP-UX Version) --
7 -- --
8 -- B o d y --
9 -- --
10 -- Copyright (C) 2003-2005, AdaCore --
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, 51 Franklin Street, Fifth Floor, --
21 -- Boston, MA 02110-1301, 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 ------------------------------------------------------------------------------
28 -- This package provides a set of target dependent routines to build
29 -- libraries (static only on HP-UX).
31 -- This is the HP-UX version of the body
33 with MLib.Fil;
34 with MLib.Utl;
35 with Namet; use Namet;
36 with Opt;
37 with Output; use Output;
38 with Prj.Com;
39 with System;
41 package body MLib.Tgt is
43 ---------------------
44 -- Archive_Builder --
45 ---------------------
47 function Archive_Builder return String is
48 begin
49 return "ar";
50 end Archive_Builder;
52 -----------------------------
53 -- Archive_Builder_Options --
54 -----------------------------
56 function Archive_Builder_Options return String_List_Access is
57 begin
58 return new String_List'(1 => new String'("cr"));
59 end Archive_Builder_Options;
61 -----------------
62 -- Archive_Ext --
63 -----------------
65 function Archive_Ext return String is
66 begin
67 return "a";
68 end Archive_Ext;
70 ---------------------
71 -- Archive_Indexer --
72 ---------------------
74 function Archive_Indexer return String is
75 begin
76 return "ranlib";
77 end Archive_Indexer;
79 -----------------------------
80 -- Archive_Indexer_Options --
81 -----------------------------
83 function Archive_Indexer_Options return String_List_Access is
84 begin
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;
100 Lib_Dir : 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.Ext_To (Lib_Filename, DLL_Ext);
116 Version_Arg : String_Access;
117 Symbolic_Link_Needed : Boolean := False;
119 Common_Options : constant Argument_List :=
120 Options & new String'(PIC_Option);
121 -- Common set of options to the gcc command performing the link.
122 -- On HPUX, this command eventually resorts to collect2, which may
123 -- generate a C file and compile it on the fly. This compilation shall
124 -- also generate position independant code for the final link to
125 -- succeed.
126 begin
127 if Opt.Verbose_Mode then
128 Write_Str ("building relocatable shared library ");
129 Write_Line (Lib_File);
130 end if;
132 if Lib_Version = "" then
133 MLib.Utl.Gcc
134 (Output_File => Lib_File,
135 Objects => Ofiles,
136 Options => Common_Options,
137 Options_2 => Options_2,
138 Driver_Name => Driver_Name);
140 else
141 Version_Arg := new String'("-Wl,+h," & Lib_Version);
143 if Is_Absolute_Path (Lib_Version) then
144 MLib.Utl.Gcc
145 (Output_File => Lib_Version,
146 Objects => Ofiles,
147 Options => Common_Options & Version_Arg,
148 Options_2 => Options_2,
149 Driver_Name => Driver_Name);
150 Symbolic_Link_Needed := Lib_Version /= Lib_File;
152 else
153 MLib.Utl.Gcc
154 (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
155 Objects => Ofiles,
156 Options => Common_Options & Version_Arg,
157 Options_2 => Options_2,
158 Driver_Name => Driver_Name);
159 Symbolic_Link_Needed :=
160 Lib_Dir & Directory_Separator & Lib_Version /= Lib_File;
161 end if;
163 if Symbolic_Link_Needed then
164 declare
165 Success : Boolean;
166 Oldpath : String (1 .. Lib_Version'Length + 1);
167 Newpath : String (1 .. Lib_File'Length + 1);
169 Result : Integer;
170 pragma Unreferenced (Result);
172 function Symlink
173 (Oldpath : System.Address;
174 Newpath : System.Address) return Integer;
175 pragma Import (C, Symlink, "__gnat_symlink");
177 begin
178 Oldpath (1 .. Lib_Version'Length) := Lib_Version;
179 Oldpath (Oldpath'Last) := ASCII.NUL;
180 Newpath (1 .. Lib_File'Length) := Lib_File;
181 Newpath (Newpath'Last) := ASCII.NUL;
183 Delete_File (Lib_File, Success);
185 Result := Symlink (Oldpath'Address, Newpath'Address);
186 end;
187 end if;
188 end if;
189 end Build_Dynamic_Library;
191 -------------
192 -- DLL_Ext --
193 -------------
195 function DLL_Ext return String is
196 begin
197 return "sl";
198 end DLL_Ext;
200 ----------------
201 -- DLL_Prefix --
202 ----------------
204 function DLL_Prefix return String is
205 begin
206 return "lib";
207 end DLL_Prefix;
209 --------------------
210 -- Dynamic_Option --
211 --------------------
213 function Dynamic_Option return String is
214 begin
215 return "-shared";
216 end Dynamic_Option;
218 -------------------
219 -- Is_Object_Ext --
220 -------------------
222 function Is_Object_Ext (Ext : String) return Boolean is
223 begin
224 return Ext = ".o";
225 end Is_Object_Ext;
227 --------------
228 -- Is_C_Ext --
229 --------------
231 function Is_C_Ext (Ext : String) return Boolean is
232 begin
233 return Ext = ".c";
234 end Is_C_Ext;
236 --------------------
237 -- Is_Archive_Ext --
238 --------------------
240 function Is_Archive_Ext (Ext : String) return Boolean is
241 begin
242 return Ext = ".a" or else Ext = ".so";
243 end Is_Archive_Ext;
245 -------------
246 -- Libgnat --
247 -------------
249 function Libgnat return String is
250 begin
251 return "libgnat.a";
252 end Libgnat;
254 ------------------------
255 -- Library_Exists_For --
256 ------------------------
258 function Library_Exists_For
259 (Project : Project_Id; In_Tree : Project_Tree_Ref) return Boolean
261 begin
262 if not In_Tree.Projects.Table (Project).Library then
263 Prj.Com.Fail ("INTERNAL ERROR: Library_Exists_For called " &
264 "for non library project");
265 return False;
267 else
268 declare
269 Lib_Dir : constant String :=
270 Get_Name_String
271 (In_Tree.Projects.Table (Project).Library_Dir);
272 Lib_Name : constant String :=
273 Get_Name_String
274 (In_Tree.Projects.Table (Project).Library_Name);
276 begin
277 if In_Tree.Projects.Table (Project).Library_Kind =
278 Static
279 then
280 return Is_Regular_File
281 (Lib_Dir & Directory_Separator & "lib" &
282 Fil.Ext_To (Lib_Name, Archive_Ext));
284 else
285 return Is_Regular_File
286 (Lib_Dir & Directory_Separator & "lib" &
287 Fil.Ext_To (Lib_Name, DLL_Ext));
288 end if;
289 end;
290 end if;
291 end Library_Exists_For;
293 ---------------------------
294 -- Library_File_Name_For --
295 ---------------------------
297 function Library_File_Name_For
298 (Project : Project_Id;
299 In_Tree : Project_Tree_Ref) return Name_Id
301 begin
302 if not In_Tree.Projects.Table (Project).Library then
303 Prj.Com.Fail ("INTERNAL ERROR: Library_File_Name_For called " &
304 "for non library project");
305 return No_Name;
307 else
308 declare
309 Lib_Name : constant String :=
310 Get_Name_String
311 (In_Tree.Projects.Table (Project).Library_Name);
313 begin
314 Name_Len := 3;
315 Name_Buffer (1 .. Name_Len) := "lib";
317 if In_Tree.Projects.Table (Project).Library_Kind =
318 Static
319 then
320 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, Archive_Ext));
322 else
323 Add_Str_To_Name_Buffer (Fil.Ext_To (Lib_Name, DLL_Ext));
324 end if;
326 return Name_Find;
327 end;
328 end if;
329 end Library_File_Name_For;
331 ----------------
332 -- Object_Ext --
333 ----------------
335 function Object_Ext return String is
336 begin
337 return "o";
338 end Object_Ext;
340 ----------------
341 -- PIC_Option --
342 ----------------
344 function PIC_Option return String is
345 begin
346 return "-fPIC";
347 end PIC_Option;
349 -----------------------------------------------
350 -- Standalone_Library_Auto_Init_Is_Supported --
351 -----------------------------------------------
353 function Standalone_Library_Auto_Init_Is_Supported return Boolean is
354 begin
355 return True;
356 end Standalone_Library_Auto_Init_Is_Supported;
358 ---------------------------
359 -- Support_For_Libraries --
360 ---------------------------
362 function Support_For_Libraries return Library_Support is
363 begin
364 return Full;
365 end Support_For_Libraries;
367 end MLib.Tgt;