Daily bump.
[official-gcc.git] / gcc / ada / mlib-utl.adb
blob5b4f1f0fe4626fca57b97f743e90aea9e026ca00
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- M L I B . U T L --
6 -- --
7 -- B o d y --
8 -- --
9 -- $Revision: 1.3 $
10 -- --
11 -- Copyright (C) 2001, Ada Core Technologies, Inc. --
12 -- --
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. --
23 -- --
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). --
26 -- --
27 ------------------------------------------------------------------------------
29 with MLib.Fil;
30 with MLib.Tgt;
31 with Namet; use Namet;
32 with Opt;
33 with Osint; use Osint;
34 with Output; use Output;
36 package body MLib.Utl is
38 use GNAT;
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;
54 procedure Initialize;
55 -- Look for the tools in the path and record the full path for each one
57 --------
58 -- Ar --
59 --------
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);
68 Success : Boolean;
70 begin
71 Initialize;
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
80 Write_Str (Ar_Name);
82 for J in Arguments'Range loop
83 Write_Char (' ');
84 Write_Str (Arguments (J).all);
85 end loop;
87 Write_Eol;
88 end if;
90 OS_Lib.Spawn (Ar_Exec.all, Arguments, Success);
92 if not Success then
93 Fail (Ar_Name, " execution error.");
94 end if;
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);
101 Write_Char (' ');
102 Write_Line (Arguments (2).all);
103 end if;
105 OS_Lib.Spawn (Ranlib_Exec.all, (1 => Arguments (2)), Success);
107 if not Success then
108 Fail (Ranlib_Name, " execution error.");
109 end if;
110 end if;
111 end Ar;
113 -----------------
114 -- Delete_File --
115 -----------------
117 procedure Delete_File (Filename : in String) is
118 File : constant String := Filename & ASCII.Nul;
119 Success : Boolean;
121 begin
122 OS_Lib.Delete_File (File'Address, Success);
124 if Opt.Verbose_Mode then
125 if Success then
126 Write_Str ("deleted ");
128 else
129 Write_Str ("could not delete ");
130 end if;
132 Write_Line (Filename);
133 end if;
134 end Delete_File;
136 ---------
137 -- Gcc --
138 ---------
140 procedure Gcc
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);
149 A : Natural := 0;
150 Success : Boolean;
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);
156 begin
157 Initialize;
159 if Lib_Opt'Length /= 0 then
160 A := A + 1;
161 Arguments (A) := Lib_Opt;
162 end if;
164 A := A + 1;
165 Arguments (A) := Out_Opt;
166 A := A + 1;
167 Arguments (A) := Out_V;
169 A := A + 1;
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);
181 for J in 1 .. A loop
182 Write_Char (' ');
183 Write_Str (Arguments (J).all);
184 end loop;
186 Write_Eol;
187 end if;
189 OS_Lib.Spawn (Gcc_Exec.all, Arguments (1 .. A), Success);
191 if not Success then
192 Fail (Gcc_Name, " execution error");
193 end if;
194 end Gcc;
196 ----------------
197 -- Initialize --
198 ----------------
200 procedure Initialize is
201 use type OS_Lib.String_Access;
203 begin
204 if not Initialized then
205 Initialized := True;
207 -- gcc
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);
218 end if;
220 -- ar
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);
231 end if;
233 -- ranlib
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);
240 end if;
242 end if;
244 end Initialize;
246 -------------------
247 -- Lib_Directory --
248 -------------------
250 function Lib_Directory return String is
251 Libgnat : constant String := Target.Libgnat;
253 begin
254 Name_Len := Libgnat'Length;
255 Name_Buffer (1 .. Name_Len) := Libgnat;
256 Get_Name_String (Find_File (Name_Enter, Library));
258 -- Remove libgnat.a
260 return Name_Buffer (1 .. Name_Len - Libgnat'Length);
261 end Lib_Directory;
263 end MLib.Utl;