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
;
281 Get_Name_String
(Option
);
283 -- Do not consider empty linker options
285 if Name_Len
/= 0 then
286 Add_Linker_Option
(Name_Buffer
(1 .. Name_Len
));
288 -- Object files and -L switches specified with relative
289 -- paths must be converted to absolute paths.
291 Test_If_Relative_Path
293 Linker_Options_Buffer
(Last_Linker_Option
),
295 In_Tree
.Projects
.Table
(Proj
).Dir_Path
,
296 Including_L_Switch
=> True);
300 In_Tree
.String_Elements
.Table
(Options
).Next
;
305 return Linker_Options_Buffer
(1 .. Last_Linker_Option
);
306 end Linker_Options_Switches
;
312 package body Mains
is
314 package Names
is new Table
.Table
315 (Table_Component_Type
=> File_Name_Type
,
316 Table_Index_Type
=> Integer,
317 Table_Low_Bound
=> 1,
319 Table_Increment
=> 100,
320 Table_Name
=> "Makeutl.Mains.Names");
321 -- The table that stores the mains
323 Current
: Natural := 0;
324 -- The index of the last main retrieved from the table
330 procedure Add_Main
(Name
: String) is
333 Add_Str_To_Name_Buffer
(Name
);
334 Names
.Increment_Last
;
335 Names
.Table
(Names
.Last
) := Name_Find
;
352 function Next_Main
return String is
354 if Current
>= Names
.Last
then
358 Current
:= Current
+ 1;
359 return Get_Name_String
(Names
.Table
(Current
));
363 ---------------------
364 -- Number_Of_Mains --
365 ---------------------
367 function Number_Of_Mains
return Natural is
387 procedure Mark
(Source_File
: File_Name_Type
; Index
: Int
:= 0) is
389 Marks
.Set
(K
=> (File
=> Source_File
, Index
=> Index
), E
=> True);
392 ---------------------------
393 -- Test_If_Relative_Path --
394 ---------------------------
396 procedure Test_If_Relative_Path
397 (Switch
: in out String_Access
;
398 Parent
: String_Access
;
399 Including_L_Switch
: Boolean := True)
402 if Switch
/= null then
404 Sw
: String (1 .. Switch
'Length);
412 and then (Sw
(2) = 'A'
414 or else (Including_L_Switch
and then Sw
(2) = 'L'))
423 and then (Sw
(2 .. 3) = "aL"
424 or else Sw
(2 .. 3) = "aO"
425 or else Sw
(2 .. 3) = "aI")
433 -- Because relative path arguments to --RTS= may be relative
434 -- to the search directory prefix, those relative path
435 -- arguments are not converted.
437 if not Is_Absolute_Path
(Sw
(Start
.. Sw
'Last)) then
438 if Parent
= null or else Parent
'Length = 0 then
440 ("relative search path switches (""",
442 """) are not allowed");
447 (Sw (1 .. Start - 1) &
449 Directory_Separator &
450 Sw (Start .. Sw'Last));
455 if not Is_Absolute_Path (Sw) then
456 if Parent = null or else Parent'Length = 0 then
458 ("relative paths (""", Sw, """) are not allowed");
462 new String'(Parent
.all & Directory_Separator
& Sw
);
468 end Test_If_Relative_Path
;
474 function Unit_Index_Of
(ALI_File
: File_Name_Type
) return Int
is
480 Get_Name_String
(ALI_File
);
482 -- First, find the last dot
486 while Finish
>= 1 and then Name_Buffer
(Finish
) /= '.' loop
487 Finish
:= Finish
- 1;
494 -- Now check that the dot is preceded by digits
497 Finish
:= Finish
- 1;
499 while Start
>= 1 and then Name_Buffer
(Start
- 1) in '0' .. '9' loop
503 -- If there is no difits, or if the digits are not preceded by
504 -- the character that precedes a unit index, this is not the ALI file
505 -- of a unit in a multi-unit source.
509 or else Name_Buffer
(Start
- 1) /= Multi_Unit_Index_Character
514 -- Build the index from the digit(s)
516 while Start
<= Finish
loop
517 Result
:= Result
* 10 +
518 Character'Pos (Name_Buffer
(Start
)) - Character'Pos ('0');