OSDN Git Service

* genemit.c (gen_insn): Call gen_exp with a non-null used
[pf3gnuchains/gcc-fork.git] / gcc / ada / mlib-tgt-hpux.adb
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-2006, 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 ------------------------------------------------------------------------------
27
28 --  This package provides a set of target dependent routines to build
29 --  libraries (static only on HP-UX).
30
31 --  This is the HP-UX version of the body
32
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;
40
41 package body MLib.Tgt is
42
43    ---------------------
44    -- Archive_Builder --
45    ---------------------
46
47    function Archive_Builder return String is
48    begin
49       return "ar";
50    end Archive_Builder;
51
52    -----------------------------
53    -- Archive_Builder_Options --
54    -----------------------------
55
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;
60
61    -----------------
62    -- Archive_Ext --
63    -----------------
64
65    function Archive_Ext return String is
66    begin
67       return "a";
68    end Archive_Ext;
69
70    ---------------------
71    -- Archive_Indexer --
72    ---------------------
73
74    function Archive_Indexer return String is
75    begin
76       return "ranlib";
77    end Archive_Indexer;
78
79    -----------------------------
80    -- Archive_Indexer_Options --
81    -----------------------------
82
83    function Archive_Indexer_Options return String_List_Access is
84    begin
85       return new String_List (1 .. 0);
86    end Archive_Indexer_Options;
87
88    ---------------------------
89    -- Build_Dynamic_Library --
90    ---------------------------
91
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)
105    is
106       pragma Unreferenced (Foreign);
107       pragma Unreferenced (Afiles);
108       pragma Unreferenced (Interfaces);
109       pragma Unreferenced (Symbol_Data);
110       pragma Unreferenced (Auto_Init);
111
112       Lib_File : constant String :=
113                    Lib_Dir & Directory_Separator & "lib" &
114                    MLib.Fil.Append_To (Lib_Filename, DLL_Ext);
115
116       Version_Arg          : String_Access;
117       Symbolic_Link_Needed : Boolean := False;
118
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;
131
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);
139
140       else
141          Version_Arg := new String'("-Wl,+h," & Lib_Version);
142
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;
151
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;
162
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);
168
169                Result : Integer;
170                pragma Unreferenced (Result);
171
172                function Symlink
173                  (Oldpath : System.Address;
174                   Newpath : System.Address) return Integer;
175                pragma Import (C, Symlink, "__gnat_symlink");
176
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;
182
183                Delete_File (Lib_File, Success);
184
185                Result := Symlink (Oldpath'Address, Newpath'Address);
186             end;
187          end if;
188       end if;
189    end Build_Dynamic_Library;
190
191    -------------
192    -- DLL_Ext --
193    -------------
194
195    function DLL_Ext return String is
196    begin
197       return "sl";
198    end DLL_Ext;
199
200    ----------------
201    -- DLL_Prefix --
202    ----------------
203
204    function DLL_Prefix return String is
205    begin
206       return "lib";
207    end DLL_Prefix;
208
209    --------------------
210    -- Dynamic_Option --
211    --------------------
212
213    function Dynamic_Option return String is
214    begin
215       return "-shared";
216    end Dynamic_Option;
217
218    -------------------
219    -- Is_Object_Ext --
220    -------------------
221
222    function Is_Object_Ext (Ext : String) return Boolean is
223    begin
224       return Ext = ".o";
225    end Is_Object_Ext;
226
227    --------------
228    -- Is_C_Ext --
229    --------------
230
231    function Is_C_Ext (Ext : String) return Boolean is
232    begin
233       return Ext = ".c";
234    end Is_C_Ext;
235
236    --------------------
237    -- Is_Archive_Ext --
238    --------------------
239
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;
244
245    -------------
246    -- Libgnat --
247    -------------
248
249    function Libgnat return String is
250    begin
251       return "libgnat.a";
252    end Libgnat;
253
254    ------------------------
255    -- Library_Exists_For --
256    ------------------------
257
258    function Library_Exists_For
259      (Project : Project_Id;
260       In_Tree : Project_Tree_Ref) return Boolean
261    is
262    begin
263       if not In_Tree.Projects.Table (Project).Library then
264          Prj.Com.Fail ("INTERNAL ERROR: Library_Exists_For called " &
265                        "for non library project");
266          return False;
267
268       else
269          declare
270             Lib_Dir  : constant String :=
271                          Get_Name_String
272                            (In_Tree.Projects.Table (Project).Library_Dir);
273             Lib_Name : constant String :=
274                          Get_Name_String
275                            (In_Tree.Projects.Table (Project).Library_Name);
276
277          begin
278             if In_Tree.Projects.Table (Project).Library_Kind = Static then
279                return Is_Regular_File
280                  (Lib_Dir & Directory_Separator & "lib" &
281                   Fil.Append_To (Lib_Name, Archive_Ext));
282
283             else
284                return Is_Regular_File
285                  (Lib_Dir & Directory_Separator & "lib" &
286                   Fil.Append_To (Lib_Name, DLL_Ext));
287             end if;
288          end;
289       end if;
290    end Library_Exists_For;
291
292    ---------------------------
293    -- Library_File_Name_For --
294    ---------------------------
295
296    function Library_File_Name_For
297      (Project : Project_Id;
298       In_Tree : Project_Tree_Ref) return Name_Id
299    is
300    begin
301       if not In_Tree.Projects.Table (Project).Library then
302          Prj.Com.Fail ("INTERNAL ERROR: Library_File_Name_For called " &
303                        "for non library project");
304          return No_Name;
305
306       else
307          declare
308             Lib_Name : constant String :=
309                          Get_Name_String
310                            (In_Tree.Projects.Table (Project).Library_Name);
311
312          begin
313             Name_Len := 3;
314             Name_Buffer (1 .. Name_Len) := "lib";
315
316             if In_Tree.Projects.Table (Project).Library_Kind =
317               Static
318             then
319                Add_Str_To_Name_Buffer (Fil.Append_To (Lib_Name, Archive_Ext));
320             else
321                Add_Str_To_Name_Buffer (Fil.Append_To (Lib_Name, DLL_Ext));
322             end if;
323
324             return Name_Find;
325          end;
326       end if;
327    end Library_File_Name_For;
328
329    ----------------
330    -- Object_Ext --
331    ----------------
332
333    function Object_Ext return String is
334    begin
335       return "o";
336    end Object_Ext;
337
338    ----------------
339    -- PIC_Option --
340    ----------------
341
342    function PIC_Option return String is
343    begin
344       return "-fPIC";
345    end PIC_Option;
346
347    -----------------------------------------------
348    -- Standalone_Library_Auto_Init_Is_Supported --
349    -----------------------------------------------
350
351    function Standalone_Library_Auto_Init_Is_Supported return Boolean is
352    begin
353       return True;
354    end Standalone_Library_Auto_Init_Is_Supported;
355
356    ---------------------------
357    -- Support_For_Libraries --
358    ---------------------------
359
360    function Support_For_Libraries return Library_Support is
361    begin
362       return Full;
363    end Support_For_Libraries;
364
365 end MLib.Tgt;