1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 2001, Ada Core Technologies, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
31 with Namet; use Namet;
33 with Osint; use Osint;
34 with Output; use Output;
36 package body MLib.Utl is
40 package Files renames MLib.Fil;
41 package Target renames MLib.Tgt;
43 Initialized : Boolean := False;
45 Gcc_Name : constant String := "gcc";
46 Gcc_Exec : OS_Lib.String_Access;
48 Ar_Name : constant String := "ar";
49 Ar_Exec : OS_Lib.String_Access;
51 Ranlib_Name : constant String := "ranlib";
52 Ranlib_Exec : OS_Lib.String_Access;
55 -- Look for the tools in the path and record the full path for each one
61 procedure Ar (Output_File : String; Objects : Argument_List) is
62 Create_Add_Opt : OS_Lib.String_Access := new String' ("cr");
64 Full_Output_File : constant String :=
65 Files.Ext_To (Output_File, Target.Archive_Ext);
67 Arguments : OS_Lib.Argument_List (1 .. 2 + Objects'Length);
73 Arguments (1) := Create_Add_Opt; -- "ar cr ..."
74 Arguments (2) := new String'(Full_Output_File);
75 Arguments (3 .. Arguments'Last) := Objects;
77 Delete_File (Full_Output_File);
79 if not Opt.Quiet_Output then
82 for J in Arguments'Range loop
84 Write_Str (Arguments (J).all);
90 OS_Lib.Spawn (Ar_Exec.all, Arguments, Success);
93 Fail (Ar_Name, " execution error.");
96 -- If we have found ranlib, run it over the library
98 if Ranlib_Exec /= null then
99 if not Opt.Quiet_Output then
100 Write_Str (Ranlib_Name);
102 Write_Line (Arguments (2).all);
105 OS_Lib.Spawn (Ranlib_Exec.all, (1 => Arguments (2)), Success);
108 Fail (Ranlib_Name, " execution error.");
117 procedure Delete_File (Filename : in String) is
118 File : constant String := Filename & ASCII.Nul;
122 OS_Lib.Delete_File (File'Address, Success);
124 if Opt.Verbose_Mode then
126 Write_Str ("deleted ");
129 Write_Str ("could not delete ");
132 Write_Line (Filename);
141 (Output_File : String;
142 Objects : Argument_List;
143 Options : Argument_List;
144 Base_File : String := "")
146 Arguments : OS_Lib.Argument_List
147 (1 .. 7 + Objects'Length + Options'Length);
151 Out_Opt : OS_Lib.String_Access := new String' ("-o");
152 Out_V : OS_Lib.String_Access := new String' (Output_File);
153 Lib_Dir : OS_Lib.String_Access := new String' ("-L" & Lib_Directory);
154 Lib_Opt : OS_Lib.String_Access := new String' (Target.Dynamic_Option);
159 if Lib_Opt'Length /= 0 then
161 Arguments (A) := Lib_Opt;
165 Arguments (A) := Out_Opt;
167 Arguments (A) := Out_V;
170 Arguments (A) := Lib_Dir;
172 A := A + Options'Length;
173 Arguments (A - Options'Length + 1 .. A) := Options;
175 A := A + Objects'Length;
176 Arguments (A - Objects'Length + 1 .. A) := Objects;
178 if not Opt.Quiet_Output then
179 Write_Str (Gcc_Exec.all);
183 Write_Str (Arguments (J).all);
189 OS_Lib.Spawn (Gcc_Exec.all, Arguments (1 .. A), Success);
192 Fail (Gcc_Name, " execution error");
200 procedure Initialize is
201 use type OS_Lib.String_Access;
204 if not Initialized then
209 Gcc_Exec := OS_Lib.Locate_Exec_On_Path (Gcc_Name);
211 if Gcc_Exec = null then
213 Fail (Gcc_Name, " not found in path");
215 elsif Opt.Verbose_Mode then
216 Write_Str ("found ");
217 Write_Line (Gcc_Exec.all);
222 Ar_Exec := OS_Lib.Locate_Exec_On_Path (Ar_Name);
224 if Ar_Exec = null then
226 Fail (Ar_Name, " not found in path");
228 elsif Opt.Verbose_Mode then
229 Write_Str ("found ");
230 Write_Line (Ar_Exec.all);
235 Ranlib_Exec := OS_Lib.Locate_Exec_On_Path (Ranlib_Name);
237 if Ranlib_Exec /= null and then Opt.Verbose_Mode then
238 Write_Str ("found ");
239 Write_Line (Ranlib_Exec.all);
250 function Lib_Directory return String is
251 Libgnat : constant String := Target.Libgnat;
254 Name_Len := Libgnat'Length;
255 Name_Buffer (1 .. Name_Len) := Libgnat;
256 Get_Name_String (Find_File (Name_Enter, Library));
260 return Name_Buffer (1 .. Name_Len - Libgnat'Length);