OSDN Git Service

2007-08-14 Robert Dewar <dewar@adacore.com>
[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 . S P E C I F I C                    --
6 --                             (HP-UX Version)                              --
7 --                                                                          --
8 --                                 B o d y                                  --
9 --                                                                          --
10 --                     Copyright (C) 2003-2007, 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 is the HP-UX version of the body
29
30 with MLib.Fil;
31 with MLib.Utl;
32 with Opt;
33 with Output; use Output;
34
35 package body MLib.Tgt.Specific is
36
37    --  Non default subprograms
38
39    procedure Build_Dynamic_Library
40      (Ofiles       : Argument_List;
41       Options      : Argument_List;
42       Interfaces   : Argument_List;
43       Lib_Filename : String;
44       Lib_Dir      : String;
45       Symbol_Data  : Symbol_Record;
46       Driver_Name  : Name_Id := No_Name;
47       Lib_Version  : String  := "";
48       Auto_Init    : Boolean := False);
49
50    function DLL_Ext return String;
51
52    function Is_Archive_Ext (Ext : String) return Boolean;
53
54    ---------------------------
55    -- Build_Dynamic_Library --
56    ---------------------------
57
58    procedure Build_Dynamic_Library
59      (Ofiles       : Argument_List;
60       Options      : Argument_List;
61       Interfaces   : Argument_List;
62       Lib_Filename : String;
63       Lib_Dir      : String;
64       Symbol_Data  : Symbol_Record;
65       Driver_Name  : Name_Id := No_Name;
66       Lib_Version  : String  := "";
67       Auto_Init    : Boolean := False)
68    is
69       pragma Unreferenced (Interfaces);
70       pragma Unreferenced (Symbol_Data);
71       pragma Unreferenced (Auto_Init);
72
73       Lib_File : constant String :=
74                    "lib" & Fil.Append_To (Lib_Filename, DLL_Ext);
75
76       Lib_Path : constant String :=
77                    Lib_Dir & Directory_Separator & Lib_File;
78
79       Version_Arg          : String_Access;
80       Symbolic_Link_Needed : Boolean := False;
81
82       Common_Options : constant Argument_List :=
83                          Options & new String'(PIC_Option);
84       --  Common set of options to the gcc command performing the link.
85       --  On HPUX, this command eventually resorts to collect2, which may
86       --  generate a C file and compile it on the fly. This compilation shall
87       --  also generate position independant code for the final link to
88       --  succeed.
89    begin
90       if Opt.Verbose_Mode then
91          Write_Str ("building relocatable shared library ");
92          Write_Line (Lib_Path);
93       end if;
94
95       if Lib_Version = "" then
96          MLib.Utl.Gcc
97            (Output_File => Lib_Path,
98             Objects     => Ofiles,
99             Options     => Common_Options,
100             Options_2   => No_Argument_List,
101             Driver_Name => Driver_Name);
102
103       else
104          declare
105             Maj_Version : constant String :=
106                             Major_Id_Name (Lib_File, Lib_Version);
107          begin
108             if Maj_Version'Length /= 0 then
109                Version_Arg := new String'("-Wl,+h," & Maj_Version);
110
111             else
112                Version_Arg := new String'("-Wl,+h," & Lib_Version);
113             end if;
114
115             if Is_Absolute_Path (Lib_Version) then
116                MLib.Utl.Gcc
117                  (Output_File => Lib_Version,
118                   Objects     => Ofiles,
119                   Options     => Common_Options & Version_Arg,
120                   Options_2   => No_Argument_List,
121                   Driver_Name => Driver_Name);
122                Symbolic_Link_Needed := Lib_Version /= Lib_Path;
123
124             else
125                MLib.Utl.Gcc
126                  (Output_File => Lib_Dir & Directory_Separator & Lib_Version,
127                   Objects     => Ofiles,
128                   Options     => Common_Options & Version_Arg,
129                   Options_2   => No_Argument_List,
130                   Driver_Name => Driver_Name);
131                Symbolic_Link_Needed :=
132                  Lib_Dir & Directory_Separator & Lib_Version /= Lib_Path;
133             end if;
134
135             if Symbolic_Link_Needed then
136                Create_Sym_Links
137                  (Lib_Path, Lib_Version, Lib_Dir, Maj_Version);
138             end if;
139          end;
140       end if;
141    end Build_Dynamic_Library;
142
143    -------------
144    -- DLL_Ext --
145    -------------
146
147    function DLL_Ext return String is
148    begin
149       return "sl";
150    end DLL_Ext;
151
152    --------------------
153    -- Is_Archive_Ext --
154    --------------------
155
156    function Is_Archive_Ext (Ext : String) return Boolean is
157    begin
158       return Ext = ".a" or else Ext = ".so";
159    end Is_Archive_Ext;
160
161 begin
162    Build_Dynamic_Library_Ptr := Build_Dynamic_Library'Access;
163    DLL_Ext_Ptr := DLL_Ext'Access;
164    Is_Archive_Ext_Ptr := Is_Archive_Ext'Access;
165 end MLib.Tgt.Specific;