1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2004-2006, 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;
138 pragma Assert (Argv'First = 1);
139 pragma Assert (Argv (1 .. 2) = "-X");
142 if Argv'Last < 5 then
145 elsif Argv (3) = '"' then
146 if Argv (Argv'Last) /= '"' or else Argv'Last < 7 then
150 Finish := Argv'Last - 1;
156 while Equal_Pos <= Finish and then Argv (Equal_Pos) /= '=' loop
157 Equal_Pos := Equal_Pos + 1;
161 or else Equal_Pos >= Finish
166 (External_Name => Argv (Start .. Equal_Pos - 1),
167 Value => Argv (Equal_Pos + 1 .. Finish));
170 end Is_External_Assignment;
177 (Source_File : File_Name_Type;
178 Index : Int := 0) return Boolean
181 return Marks.Get (K => (File => Source_File, Index => Index));
184 -----------------------------
185 -- Linker_Options_Switches --
186 -----------------------------
188 function Linker_Options_Switches
189 (Project : Project_Id;
190 In_Tree : Project_Tree_Ref) return String_List
192 procedure Recursive_Add_Linker_Options (Proj : Project_Id);
193 -- The recursive routine used to add linker options
195 ----------------------------------
196 -- Recursive_Add_Linker_Options --
197 ----------------------------------
199 procedure Recursive_Add_Linker_Options (Proj : Project_Id) is
201 Linker_Package : Package_Id;
202 Options : Variable_Value;
203 Imported : Project_List;
206 if Proj /= No_Project then
207 Data := In_Tree.Projects.Table (Proj);
209 if not Data.Seen then
210 In_Tree.Projects.Table (Proj).Seen := True;
211 Imported := Data.Imported_Projects;
213 while Imported /= Empty_Project_List loop
214 Recursive_Add_Linker_Options
215 (In_Tree.Project_Lists.Table
217 Imported := In_Tree.Project_Lists.Table
221 if Proj /= Project then
224 (Name => Name_Linker,
225 In_Packages => Data.Decl.Packages,
231 Attribute_Or_Array_Name => Name_Linker_Options,
232 In_Package => Linker_Package,
235 -- If attribute is present, add the project with
236 -- the attribute to table Linker_Opts.
238 if Options /= Nil_Variable_Value then
239 Linker_Opts.Increment_Last;
240 Linker_Opts.Table (Linker_Opts.Last) :=
241 (Project => Proj, Options => Options.Values);
246 end Recursive_Add_Linker_Options;
248 -- Start of processing for Linker_Options_Switches
253 for Index in Project_Table.First ..
254 Project_Table.Last (In_Tree.Projects)
256 In_Tree.Projects.Table (Index).Seen := False;
259 Recursive_Add_Linker_Options (Project);
261 Last_Linker_Option := 0;
263 for Index in reverse 1 .. Linker_Opts.Last loop
265 Options : String_List_Id := Linker_Opts.Table (Index).Options;
266 Proj : constant Project_Id :=
267 Linker_Opts.Table (Index).Project;
271 -- If Dir_Path has not been computed for this project, do it now
273 if In_Tree.Projects.Table (Proj).Dir_Path = null then
274 In_Tree.Projects.Table (Proj).Dir_Path :=
277 (In_Tree
.Projects
.Table
281 while Options
/= Nil_String
loop
283 In_Tree
.String_Elements
.Table
(Options
).Value
;
284 Get_Name_String
(Option
);
286 -- Do not consider empty linker options
288 if Name_Len
/= 0 then
289 Add_Linker_Option
(Name_Buffer
(1 .. Name_Len
));
291 -- Object files and -L switches specified with relative
292 -- paths must be converted to absolute paths.
294 Test_If_Relative_Path
296 Linker_Options_Buffer
(Last_Linker_Option
),
298 In_Tree
.Projects
.Table
(Proj
).Dir_Path
,
299 Including_L_Switch
=> True);
303 In_Tree
.String_Elements
.Table
(Options
).Next
;
308 return Linker_Options_Buffer
(1 .. Last_Linker_Option
);
309 end Linker_Options_Switches
;
315 package body Mains
is
317 package Names
is new Table
.Table
318 (Table_Component_Type
=> File_Name_Type
,
319 Table_Index_Type
=> Integer,
320 Table_Low_Bound
=> 1,
322 Table_Increment
=> 100,
323 Table_Name
=> "Makeutl.Mains.Names");
324 -- The table that stores the mains
326 Current
: Natural := 0;
327 -- The index of the last main retrieved from the table
333 procedure Add_Main
(Name
: String) is
336 Add_Str_To_Name_Buffer
(Name
);
337 Names
.Increment_Last
;
338 Names
.Table
(Names
.Last
) := Name_Find
;
355 function Next_Main
return String is
357 if Current
>= Names
.Last
then
361 Current
:= Current
+ 1;
362 return Get_Name_String
(Names
.Table
(Current
));
366 ---------------------
367 -- Number_Of_Mains --
368 ---------------------
370 function Number_Of_Mains
return Natural is
390 procedure Mark
(Source_File
: File_Name_Type
; Index
: Int
:= 0) is
392 Marks
.Set
(K
=> (File
=> Source_File
, Index
=> Index
), E
=> True);
395 ---------------------------
396 -- Test_If_Relative_Path --
397 ---------------------------
399 procedure Test_If_Relative_Path
400 (Switch
: in out String_Access
;
401 Parent
: String_Access
;
402 Including_L_Switch
: Boolean := True)
405 if Switch
/= null then
407 Sw
: String (1 .. Switch
'Length);
415 and then (Sw
(2) = 'A'
417 or else (Including_L_Switch
and then Sw
(2) = 'L'))
426 and then (Sw
(2 .. 3) = "aL"
427 or else Sw
(2 .. 3) = "aO"
428 or else Sw
(2 .. 3) = "aI")
436 -- Because relative path arguments to --RTS= may be relative
437 -- to the search directory prefix, those relative path
438 -- arguments are not converted.
440 if not Is_Absolute_Path
(Sw
(Start
.. Sw
'Last)) then
441 if Parent
= null or else Parent
'Length = 0 then
443 ("relative search path switches (""",
445 """) are not allowed");
450 (Sw (1 .. Start - 1) &
452 Directory_Separator &
453 Sw (Start .. Sw'Last));
458 if not Is_Absolute_Path (Sw) then
459 if Parent = null or else Parent'Length = 0 then
461 ("relative paths (""", Sw, """) are not allowed");
465 new String'(Parent
.all & Directory_Separator
& Sw
);
471 end Test_If_Relative_Path
;
477 function Unit_Index_Of
(ALI_File
: File_Name_Type
) return Int
is
483 Get_Name_String
(ALI_File
);
485 -- First, find the last dot
489 while Finish
>= 1 and then Name_Buffer
(Finish
) /= '.' loop
490 Finish
:= Finish
- 1;
497 -- Now check that the dot is preceded by digits
500 Finish
:= Finish
- 1;
502 while Start
>= 1 and then Name_Buffer
(Start
- 1) in '0' .. '9' loop
506 -- If there is no difits, or if the digits are not preceded by
507 -- the character that precedes a unit index, this is not the ALI file
508 -- of a unit in a multi-unit source.
512 or else Name_Buffer
(Start
- 1) /= Multi_Unit_Index_Character
517 -- Build the index from the digit(s)
519 while Start
<= Finish
loop
520 Result
:= Result
* 10 +
521 Character'Pos (Name_Buffer
(Start
)) - Character'Pos ('0');