1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2002, Ada Core Technologies, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
25 ------------------------------------------------------------------------------
29 with Namet
; use Namet
;
31 with Osint
; use Osint
;
32 with Output
; use Output
;
34 package body MLib
.Utl
is
38 package Files
renames MLib
.Fil
;
39 package Target
renames MLib
.Tgt
;
41 Initialized
: Boolean := False;
43 Gcc_Name
: constant String := "gcc";
44 Gcc_Exec
: OS_Lib
.String_Access
;
46 Ar_Name
: constant String := "ar";
47 Ar_Exec
: OS_Lib
.String_Access
;
49 Ranlib_Name
: constant String := "ranlib";
50 Ranlib_Exec
: OS_Lib
.String_Access
;
53 -- Look for the tools in the path and record the full path for each one
59 procedure Ar
(Output_File
: String; Objects
: Argument_List
) is
60 Create_Add_Opt
: OS_Lib
.String_Access
:= new String' ("cr");
62 Full_Output_File : constant String :=
63 Files.Ext_To (Output_File, Target.Archive_Ext);
65 Arguments : OS_Lib.Argument_List (1 .. 2 + Objects'Length);
71 Arguments (1) := Create_Add_Opt; -- "ar cr ..."
72 Arguments (2) := new String'(Full_Output_File
);
73 Arguments
(3 .. Arguments
'Last) := Objects
;
75 Delete_File
(Full_Output_File
);
77 if not Opt
.Quiet_Output
then
80 for J
in Arguments
'Range loop
82 Write_Str
(Arguments
(J
).all);
88 OS_Lib
.Spawn
(Ar_Exec
.all, Arguments
, Success
);
91 Fail
(Ar_Name
, " execution error.");
94 -- If we have found ranlib, run it over the library
96 if Ranlib_Exec
/= null then
97 if not Opt
.Quiet_Output
then
98 Write_Str
(Ranlib_Name
);
100 Write_Line
(Arguments
(2).all);
103 OS_Lib
.Spawn
(Ranlib_Exec
.all, (1 => Arguments
(2)), Success
);
106 Fail
(Ranlib_Name
, " execution error.");
115 procedure Delete_File
(Filename
: in String) is
116 File
: constant String := Filename
& ASCII
.Nul
;
120 OS_Lib
.Delete_File
(File
'Address, Success
);
122 if Opt
.Verbose_Mode
then
124 Write_Str
("deleted ");
127 Write_Str
("could not delete ");
130 Write_Line
(Filename
);
139 (Output_File
: String;
140 Objects
: Argument_List
;
141 Options
: Argument_List
)
143 Arguments
: OS_Lib
.Argument_List
144 (1 .. 7 + Objects
'Length + Options
'Length);
148 Out_Opt
: OS_Lib
.String_Access
:= new String' ("-o");
149 Out_V : OS_Lib.String_Access := new String' (Output_File
);
150 Lib_Dir
: OS_Lib
.String_Access
:= new String' ("-L" & Lib_Directory);
151 Lib_Opt : OS_Lib.String_Access := new String' (Target
.Dynamic_Option
);
156 if Lib_Opt
'Length /= 0 then
158 Arguments
(A
) := Lib_Opt
;
162 Arguments
(A
) := Out_Opt
;
165 Arguments
(A
) := Out_V
;
168 Arguments
(A
) := Lib_Dir
;
170 A
:= A
+ Options
'Length;
171 Arguments
(A
- Options
'Length + 1 .. A
) := Options
;
173 A
:= A
+ Objects
'Length;
174 Arguments
(A
- Objects
'Length + 1 .. A
) := Objects
;
176 if not Opt
.Quiet_Output
then
177 Write_Str
(Gcc_Exec
.all);
181 Write_Str
(Arguments
(J
).all);
187 OS_Lib
.Spawn
(Gcc_Exec
.all, Arguments
(1 .. A
), Success
);
190 Fail
(Gcc_Name
, " execution error");
198 procedure Initialize
is
199 use type OS_Lib
.String_Access
;
202 if not Initialized
then
207 Gcc_Exec
:= OS_Lib
.Locate_Exec_On_Path
(Gcc_Name
);
209 if Gcc_Exec
= null then
211 Fail
(Gcc_Name
, " not found in path");
213 elsif Opt
.Verbose_Mode
then
214 Write_Str
("found ");
215 Write_Line
(Gcc_Exec
.all);
220 Ar_Exec
:= OS_Lib
.Locate_Exec_On_Path
(Ar_Name
);
222 if Ar_Exec
= null then
224 Fail
(Ar_Name
, " not found in path");
226 elsif Opt
.Verbose_Mode
then
227 Write_Str
("found ");
228 Write_Line
(Ar_Exec
.all);
233 Ranlib_Exec
:= OS_Lib
.Locate_Exec_On_Path
(Ranlib_Name
);
235 if Ranlib_Exec
/= null and then Opt
.Verbose_Mode
then
236 Write_Str
("found ");
237 Write_Line
(Ranlib_Exec
.all);
248 function Lib_Directory
return String is
249 Libgnat
: constant String := Target
.Libgnat
;
252 Name_Len
:= Libgnat
'Length;
253 Name_Buffer
(1 .. Name_Len
) := Libgnat
;
254 Get_Name_String
(Find_File
(Name_Enter
, Library
));
258 return Name_Buffer
(1 .. Name_Len
- Libgnat
'Length);