1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 2002, Ada Core Technologies, Inc. --
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, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
26 ------------------------------------------------------------------------------
30 with Namet
; use Namet
;
32 with Osint
; use Osint
;
33 with Output
; use Output
;
35 package body MLib
.Utl
is
39 package Files
renames MLib
.Fil
;
40 package Target
renames MLib
.Tgt
;
42 Initialized
: Boolean := False;
44 Gcc_Name
: constant String := "gcc";
45 Gcc_Exec
: OS_Lib
.String_Access
;
47 Ar_Name
: constant String := "ar";
48 Ar_Exec
: OS_Lib
.String_Access
;
50 Ranlib_Name
: constant String := "ranlib";
51 Ranlib_Exec
: OS_Lib
.String_Access
;
54 -- Look for the tools in the path and record the full path for each one
60 procedure Ar
(Output_File
: String; Objects
: Argument_List
) is
61 Create_Add_Opt
: OS_Lib
.String_Access
:= new String' ("cr");
63 Full_Output_File : constant String :=
64 Files.Ext_To (Output_File, Target.Archive_Ext);
66 Arguments : OS_Lib.Argument_List (1 .. 2 + Objects'Length);
72 Arguments (1) := Create_Add_Opt; -- "ar cr ..."
73 Arguments (2) := new String'(Full_Output_File
);
74 Arguments
(3 .. Arguments
'Last) := Objects
;
76 Delete_File
(Full_Output_File
);
78 if not Opt
.Quiet_Output
then
81 for J
in Arguments
'Range loop
83 Write_Str
(Arguments
(J
).all);
89 OS_Lib
.Spawn
(Ar_Exec
.all, Arguments
, Success
);
92 Fail
(Ar_Name
, " execution error.");
95 -- If we have found ranlib, run it over the library
97 if Ranlib_Exec
/= null then
98 if not Opt
.Quiet_Output
then
99 Write_Str
(Ranlib_Name
);
101 Write_Line
(Arguments
(2).all);
104 OS_Lib
.Spawn
(Ranlib_Exec
.all, (1 => Arguments
(2)), Success
);
107 Fail
(Ranlib_Name
, " execution error.");
116 procedure Delete_File
(Filename
: in String) is
117 File
: constant String := Filename
& ASCII
.Nul
;
121 OS_Lib
.Delete_File
(File
'Address, Success
);
123 if Opt
.Verbose_Mode
then
125 Write_Str
("deleted ");
128 Write_Str
("could not delete ");
131 Write_Line
(Filename
);
140 (Output_File
: String;
141 Objects
: Argument_List
;
142 Options
: Argument_List
)
144 Arguments
: OS_Lib
.Argument_List
145 (1 .. 7 + Objects
'Length + Options
'Length);
149 Out_Opt
: OS_Lib
.String_Access
:= new String' ("-o");
150 Out_V : OS_Lib.String_Access := new String' (Output_File
);
151 Lib_Dir
: OS_Lib
.String_Access
:= new String' ("-L" & Lib_Directory);
152 Lib_Opt : OS_Lib.String_Access := new String' (Target
.Dynamic_Option
);
157 if Lib_Opt
'Length /= 0 then
159 Arguments
(A
) := Lib_Opt
;
163 Arguments
(A
) := Out_Opt
;
166 Arguments
(A
) := Out_V
;
169 Arguments
(A
) := Lib_Dir
;
171 A
:= A
+ Options
'Length;
172 Arguments
(A
- Options
'Length + 1 .. A
) := Options
;
174 A
:= A
+ Objects
'Length;
175 Arguments
(A
- Objects
'Length + 1 .. A
) := Objects
;
177 if not Opt
.Quiet_Output
then
178 Write_Str
(Gcc_Exec
.all);
182 Write_Str
(Arguments
(J
).all);
188 OS_Lib
.Spawn
(Gcc_Exec
.all, Arguments
(1 .. A
), Success
);
191 Fail
(Gcc_Name
, " execution error");
199 procedure Initialize
is
200 use type OS_Lib
.String_Access
;
203 if not Initialized
then
208 Gcc_Exec
:= OS_Lib
.Locate_Exec_On_Path
(Gcc_Name
);
210 if Gcc_Exec
= null then
212 Fail
(Gcc_Name
, " not found in path");
214 elsif Opt
.Verbose_Mode
then
215 Write_Str
("found ");
216 Write_Line
(Gcc_Exec
.all);
221 Ar_Exec
:= OS_Lib
.Locate_Exec_On_Path
(Ar_Name
);
223 if Ar_Exec
= null then
225 Fail
(Ar_Name
, " not found in path");
227 elsif Opt
.Verbose_Mode
then
228 Write_Str
("found ");
229 Write_Line
(Ar_Exec
.all);
234 Ranlib_Exec
:= OS_Lib
.Locate_Exec_On_Path
(Ranlib_Name
);
236 if Ranlib_Exec
/= null and then Opt
.Verbose_Mode
then
237 Write_Str
("found ");
238 Write_Line
(Ranlib_Exec
.all);
249 function Lib_Directory
return String is
250 Libgnat
: constant String := Target
.Libgnat
;
253 Name_Len
:= Libgnat
'Length;
254 Name_Buffer
(1 .. Name_Len
) := Libgnat
;
255 Get_Name_String
(Find_File
(Name_Enter
, Library
));
259 return Name_Buffer
(1 .. Name_Len
- Libgnat
'Length);