1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2004-2005 Free Software Foundation, 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Namet
; use Namet
;
28 with Osint
; use Osint
;
31 with Snames
; use Snames
;
36 package body Makeutl
is
38 type Mark_Key
is record
39 File
: File_Name_Type
;
42 -- Identify either a mono-unit source (when Index = 0) or a specific unit
43 -- in a multi-unit source.
45 -- There follow many global undocumented declarations, comments needed ???
47 Max_Mask_Num
: constant := 2048;
49 subtype Mark_Num
is Union_Id
range 0 .. Max_Mask_Num
- 1;
51 function Hash
(Key
: Mark_Key
) return Mark_Num
;
53 package Marks
is new System
.HTable
.Simple_HTable
54 (Header_Num
=> Mark_Num
,
60 -- A hash table to keep tracks of the marked units
62 type Linker_Options_Data
is record
64 Options
: String_List_Id
;
67 Linker_Option_Initial_Count
: constant := 20;
69 Linker_Options_Buffer
: String_List_Access
:=
70 new String_List
(1 .. Linker_Option_Initial_Count
);
72 Last_Linker_Option
: Natural := 0;
74 package Linker_Opts
is new Table
.Table
(
75 Table_Component_Type
=> Linker_Options_Data
,
76 Table_Index_Type
=> Integer,
79 Table_Increment
=> 100,
80 Table_Name
=> "Make.Linker_Opts");
82 procedure Add_Linker_Option
(Option
: String);
84 -----------------------
85 -- Add_Linker_Option --
86 -----------------------
88 procedure Add_Linker_Option
(Option
: String) is
90 if Option
'Length > 0 then
91 if Last_Linker_Option
= Linker_Options_Buffer
'Last then
93 New_Buffer
: constant String_List_Access
:=
95 (1 .. Linker_Options_Buffer
'Last +
96 Linker_Option_Initial_Count
);
98 New_Buffer
(Linker_Options_Buffer
'Range) :=
99 Linker_Options_Buffer
.all;
100 Linker_Options_Buffer
.all := (others => null);
101 Free
(Linker_Options_Buffer
);
102 Linker_Options_Buffer
:= New_Buffer
;
106 Last_Linker_Option
:= Last_Linker_Option
+ 1;
107 Linker_Options_Buffer
(Last_Linker_Option
) := new String'(Option);
109 end Add_Linker_Option;
111 ----------------------
112 -- Delete_All_Marks --
113 ----------------------
115 procedure Delete_All_Marks is
118 end Delete_All_Marks;
124 function Hash (Key : Mark_Key) return Mark_Num is
126 return Union_Id (Key.File) mod Max_Mask_Num;
129 ----------------------------
130 -- Is_External_Assignment --
131 ----------------------------
133 function Is_External_Assignment (Argv : String) return Boolean is
134 Start : Positive := 3;
135 Finish : Natural := Argv'Last;
139 if Argv'Last < 5 then
142 elsif Argv (3) = '"' then
143 if Argv (Argv'Last) /= '"' or else Argv'Last < 7 then
147 Finish := Argv'Last - 1;
153 while Equal_Pos <= Finish and then Argv (Equal_Pos) /= '=' loop
154 Equal_Pos := Equal_Pos + 1;
158 or else Equal_Pos >= Finish
163 (External_Name => Argv (Start .. Equal_Pos - 1),
164 Value => Argv (Equal_Pos + 1 .. Finish));
167 end Is_External_Assignment;
174 (Source_File : File_Name_Type;
175 Index : Int := 0) return Boolean
178 return Marks.Get (K => (File => Source_File, Index => Index));
181 -----------------------------
182 -- Linker_Options_Switches --
183 -----------------------------
185 function Linker_Options_Switches
186 (Project : Project_Id;
187 In_Tree : Project_Tree_Ref) return String_List
189 procedure Recursive_Add_Linker_Options (Proj : Project_Id);
190 -- The recursive routine used to add linker options
192 ----------------------------------
193 -- Recursive_Add_Linker_Options --
194 ----------------------------------
196 procedure Recursive_Add_Linker_Options (Proj : Project_Id) is
198 Linker_Package : Package_Id;
199 Options : Variable_Value;
200 Imported : Project_List;
203 if Proj /= No_Project then
204 Data := In_Tree.Projects.Table (Proj);
206 if not Data.Seen then
207 In_Tree.Projects.Table (Proj).Seen := True;
208 Imported := Data.Imported_Projects;
210 while Imported /= Empty_Project_List loop
211 Recursive_Add_Linker_Options
212 (In_Tree.Project_Lists.Table
214 Imported := In_Tree.Project_Lists.Table
218 if Proj /= Project then
221 (Name => Name_Linker,
222 In_Packages => Data.Decl.Packages,
228 Attribute_Or_Array_Name => Name_Linker_Options,
229 In_Package => Linker_Package,
232 -- If attribute is present, add the project with
233 -- the attribute to table Linker_Opts.
235 if Options /= Nil_Variable_Value then
236 Linker_Opts.Increment_Last;
237 Linker_Opts.Table (Linker_Opts.Last) :=
238 (Project => Proj, Options => Options.Values);
243 end Recursive_Add_Linker_Options;
245 -- Start of processing for Linker_Options_Switches
250 for Index in Project_Table.First ..
251 Project_Table.Last (In_Tree.Projects)
253 In_Tree.Projects.Table (Index).Seen := False;
256 Recursive_Add_Linker_Options (Project);
258 Last_Linker_Option := 0;
260 for Index in reverse 1 .. Linker_Opts.Last loop
262 Options : String_List_Id := Linker_Opts.Table (Index).Options;
263 Proj : constant Project_Id :=
264 Linker_Opts.Table (Index).Project;
268 -- If Dir_Path has not been computed for this project, do it now
270 if In_Tree.Projects.Table (Proj).Dir_Path = null then
271 In_Tree.Projects.Table (Proj).Dir_Path :=
274 (In_Tree
.Projects
.Table
278 while Options
/= Nil_String
loop
280 In_Tree
.String_Elements
.Table
(Options
).Value
;
282 In_Tree
.String_Elements
.Table
(Options
).Next
;
283 Add_Linker_Option
(Get_Name_String
(Option
));
285 -- Object files and -L switches specified with
286 -- relative paths and must be converted to
289 Test_If_Relative_Path
291 Linker_Options_Buffer
(Last_Linker_Option
),
293 In_Tree
.Projects
.Table
(Proj
).Dir_Path
,
294 Including_L_Switch
=> True);
299 return Linker_Options_Buffer
(1 .. Last_Linker_Option
);
300 end Linker_Options_Switches
;
306 package body Mains
is
308 package Names
is new Table
.Table
309 (Table_Component_Type
=> File_Name_Type
,
310 Table_Index_Type
=> Integer,
311 Table_Low_Bound
=> 1,
313 Table_Increment
=> 100,
314 Table_Name
=> "Makeutl.Mains.Names");
315 -- The table that stores the mains
317 Current
: Natural := 0;
318 -- The index of the last main retrieved from the table
324 procedure Add_Main
(Name
: String) is
327 Add_Str_To_Name_Buffer
(Name
);
328 Names
.Increment_Last
;
329 Names
.Table
(Names
.Last
) := Name_Find
;
346 function Next_Main
return String is
348 if Current
>= Names
.Last
then
352 Current
:= Current
+ 1;
353 return Get_Name_String
(Names
.Table
(Current
));
357 ---------------------
358 -- Number_Of_Mains --
359 ---------------------
361 function Number_Of_Mains
return Natural is
381 procedure Mark
(Source_File
: File_Name_Type
; Index
: Int
:= 0) is
383 Marks
.Set
(K
=> (File
=> Source_File
, Index
=> Index
), E
=> True);
386 ---------------------------
387 -- Test_If_Relative_Path --
388 ---------------------------
390 procedure Test_If_Relative_Path
391 (Switch
: in out String_Access
;
392 Parent
: String_Access
;
393 Including_L_Switch
: Boolean := True)
396 if Switch
/= null then
398 Sw
: String (1 .. Switch
'Length);
406 and then (Sw
(2) = 'A'
408 or else (Including_L_Switch
and then Sw
(2) = 'L'))
417 and then (Sw
(2 .. 3) = "aL"
418 or else Sw
(2 .. 3) = "aO"
419 or else Sw
(2 .. 3) = "aI")
427 -- Because relative path arguments to --RTS= may be relative
428 -- to the search directory prefix, those relative path
429 -- arguments are not converted.
431 if not Is_Absolute_Path
(Sw
(Start
.. Sw
'Last)) then
432 if Parent
= null or else Parent
'Length = 0 then
434 ("relative search path switches (""",
436 """) are not allowed");
441 (Sw (1 .. Start - 1) &
443 Directory_Separator &
444 Sw (Start .. Sw'Last));
449 if not Is_Absolute_Path (Sw) then
450 if Parent = null or else Parent'Length = 0 then
452 ("relative paths (""", Sw, """) are not allowed");
456 new String'(Parent
.all & Directory_Separator
& Sw
);
462 end Test_If_Relative_Path
;
468 function Unit_Index_Of
(ALI_File
: File_Name_Type
) return Int
is
474 Get_Name_String
(ALI_File
);
476 -- First, find the last dot
480 while Finish
>= 1 and then Name_Buffer
(Finish
) /= '.' loop
481 Finish
:= Finish
- 1;
488 -- Now check that the dot is preceded by digits
491 Finish
:= Finish
- 1;
493 while Start
>= 1 and then Name_Buffer
(Start
- 1) in '0' .. '9' loop
497 -- If there is no difits, or if the digits are not preceded by
498 -- the character that precedes a unit index, this is not the ALI file
499 -- of a unit in a multi-unit source.
503 or else Name_Buffer
(Start
- 1) /= Multi_Unit_Index_Character
508 -- Build the index from the digit(s)
510 while Start
<= Finish
loop
511 Result
:= Result
* 10 +
512 Character'Pos (Name_Buffer
(Start
)) - Character'Pos ('0');