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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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
;
32 with Snames
; use Snames
;
34 with Types
; use Types
;
38 package body Makeutl
is
40 type Mark_Key
is record
41 File
: File_Name_Type
;
44 -- Identify either a mono-unit source (when Index = 0) or a specific unit
45 -- in a multi-unit source.
47 -- There follow many global undocumented declarations, comments needed ???
49 Max_Mask_Num
: constant := 2048;
51 subtype Mark_Num
is Union_Id
range 0 .. Max_Mask_Num
- 1;
53 function Hash
(Key
: Mark_Key
) return Mark_Num
;
55 package Marks
is new System
.HTable
.Simple_HTable
56 (Header_Num
=> Mark_Num
,
62 -- A hash table to keep tracks of the marked units.
64 type Linker_Options_Data
is record
66 Options
: String_List_Id
;
69 Linker_Option_Initial_Count
: constant := 20;
71 Linker_Options_Buffer
: String_List_Access
:=
72 new String_List
(1 .. Linker_Option_Initial_Count
);
74 Last_Linker_Option
: Natural := 0;
76 package Linker_Opts
is new Table
.Table
(
77 Table_Component_Type
=> Linker_Options_Data
,
78 Table_Index_Type
=> Integer,
81 Table_Increment
=> 100,
82 Table_Name
=> "Make.Linker_Opts");
84 procedure Add_Linker_Option
(Option
: String);
86 -----------------------
87 -- Add_Linker_Option --
88 -----------------------
90 procedure Add_Linker_Option
(Option
: String) is
92 if Option
'Length > 0 then
93 if Last_Linker_Option
= Linker_Options_Buffer
'Last then
95 New_Buffer
: constant String_List_Access
:=
97 (1 .. Linker_Options_Buffer
'Last +
98 Linker_Option_Initial_Count
);
100 New_Buffer
(Linker_Options_Buffer
'Range) :=
101 Linker_Options_Buffer
.all;
102 Linker_Options_Buffer
.all := (others => null);
103 Free
(Linker_Options_Buffer
);
104 Linker_Options_Buffer
:= New_Buffer
;
108 Last_Linker_Option
:= Last_Linker_Option
+ 1;
109 Linker_Options_Buffer
(Last_Linker_Option
) := new String'(Option);
111 end Add_Linker_Option;
113 ----------------------
114 -- Delete_All_Marks --
115 ----------------------
117 procedure Delete_All_Marks is
120 end Delete_All_Marks;
126 function Hash (Key : Mark_Key) return Mark_Num is
128 return Union_Id (Key.File) mod Max_Mask_Num;
131 ----------------------------
132 -- Is_External_Assignment --
133 ----------------------------
135 function Is_External_Assignment (Argv : String) return Boolean is
136 Start : Positive := 3;
137 Finish : Natural := Argv'Last;
141 if Argv'Last < 5 then
144 elsif Argv (3) = '"' then
145 if Argv (Argv'Last) /= '"' or else Argv'Last < 7 then
149 Finish := Argv'Last - 1;
155 while Equal_Pos <= Finish and then Argv (Equal_Pos) /= '=' loop
156 Equal_Pos := Equal_Pos + 1;
160 or else Equal_Pos >= Finish
165 (External_Name => Argv (Start .. Equal_Pos - 1),
166 Value => Argv (Equal_Pos + 1 .. Finish));
169 end Is_External_Assignment;
176 (Source_File : File_Name_Type;
177 Index : Int := 0) return Boolean
180 return Marks.Get (K => (File => Source_File, Index => Index));
183 -----------------------------
184 -- Linker_Options_Switches --
185 -----------------------------
187 function Linker_Options_Switches
188 (Project : Project_Id;
189 In_Tree : Project_Tree_Ref) return String_List
191 procedure Recursive_Add_Linker_Options (Proj : Project_Id);
192 -- The recursive routine used to add linker options
194 ----------------------------------
195 -- Recursive_Add_Linker_Options --
196 ----------------------------------
198 procedure Recursive_Add_Linker_Options (Proj : Project_Id) is
200 Linker_Package : Package_Id;
201 Options : Variable_Value;
202 Imported : Project_List;
205 if Proj /= No_Project then
206 Data := In_Tree.Projects.Table (Proj);
208 if not Data.Seen then
209 In_Tree.Projects.Table (Proj).Seen := True;
210 Imported := Data.Imported_Projects;
212 while Imported /= Empty_Project_List loop
213 Recursive_Add_Linker_Options
214 (In_Tree.Project_Lists.Table
216 Imported := In_Tree.Project_Lists.Table
220 if Proj /= Project then
223 (Name => Name_Linker,
224 In_Packages => Data.Decl.Packages,
230 Attribute_Or_Array_Name => Name_Linker_Options,
231 In_Package => Linker_Package,
234 -- If attribute is present, add the project with
235 -- the attribute to table Linker_Opts.
237 if Options /= Nil_Variable_Value then
238 Linker_Opts.Increment_Last;
239 Linker_Opts.Table (Linker_Opts.Last) :=
240 (Project => Proj, Options => Options.Values);
245 end Recursive_Add_Linker_Options;
247 -- Start of processing for Linker_Options_Switches
252 for Index in Project_Table.First ..
253 Project_Table.Last (In_Tree.Projects)
255 In_Tree.Projects.Table (Index).Seen := False;
258 Recursive_Add_Linker_Options (Project);
260 Last_Linker_Option := 0;
262 for Index in reverse 1 .. Linker_Opts.Last loop
264 Options : String_List_Id := Linker_Opts.Table (Index).Options;
265 Proj : constant Project_Id :=
266 Linker_Opts.Table (Index).Project;
270 -- If Dir_Path has not been computed for this project, do it now
272 if In_Tree.Projects.Table (Proj).Dir_Path = null then
273 In_Tree.Projects.Table (Proj).Dir_Path :=
276 (In_Tree
.Projects
.Table
280 while Options
/= Nil_String
loop
282 In_Tree
.String_Elements
.Table
(Options
).Value
;
284 In_Tree
.String_Elements
.Table
(Options
).Next
;
285 Add_Linker_Option
(Get_Name_String
(Option
));
287 -- Object files and -L switches specified with
288 -- relative paths and must be converted to
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);
301 return Linker_Options_Buffer
(1 .. Last_Linker_Option
);
302 end Linker_Options_Switches
;
308 package body Mains
is
310 package Names
is new Table
.Table
311 (Table_Component_Type
=> File_Name_Type
,
312 Table_Index_Type
=> Integer,
313 Table_Low_Bound
=> 1,
315 Table_Increment
=> 100,
316 Table_Name
=> "Makeutl.Mains.Names");
317 -- The table that stores the mains
319 Current
: Natural := 0;
320 -- The index of the last main retrieved from the table
326 procedure Add_Main
(Name
: String) is
329 Add_Str_To_Name_Buffer
(Name
);
330 Names
.Increment_Last
;
331 Names
.Table
(Names
.Last
) := Name_Find
;
348 function Next_Main
return String is
350 if Current
>= Names
.Last
then
354 Current
:= Current
+ 1;
355 return Get_Name_String
(Names
.Table
(Current
));
359 ---------------------
360 -- Number_Of_Mains --
361 ---------------------
363 function Number_Of_Mains
return Natural is
383 procedure Mark
(Source_File
: File_Name_Type
; Index
: Int
:= 0) is
385 Marks
.Set
(K
=> (File
=> Source_File
, Index
=> Index
), E
=> True);
388 ---------------------------
389 -- Test_If_Relative_Path --
390 ---------------------------
392 procedure Test_If_Relative_Path
393 (Switch
: in out String_Access
;
394 Parent
: String_Access
;
395 Including_L_Switch
: Boolean := True)
398 if Switch
/= null then
400 Sw
: String (1 .. Switch
'Length);
408 and then (Sw
(2) = 'A'
410 or else (Including_L_Switch
and then Sw
(2) = 'L'))
419 and then (Sw
(2 .. 3) = "aL"
420 or else Sw
(2 .. 3) = "aO"
421 or else Sw
(2 .. 3) = "aI")
429 -- Because relative path arguments to --RTS= may be relative
430 -- to the search directory prefix, those relative path
431 -- arguments are not converted.
433 if not Is_Absolute_Path
(Sw
(Start
.. Sw
'Last)) then
434 if Parent
= null or else Parent
'Length = 0 then
436 ("relative search path switches (""",
438 """) are not allowed");
443 (Sw (1 .. Start - 1) &
445 Directory_Separator &
446 Sw (Start .. Sw'Last));
451 if not Is_Absolute_Path (Sw) then
452 if Parent = null or else Parent'Length = 0 then
454 ("relative paths (""", Sw, """) are not allowed");
458 new String'(Parent
.all & Directory_Separator
& Sw
);
464 end Test_If_Relative_Path
;
470 function Unit_Index_Of
(ALI_File
: File_Name_Type
) return Int
is
476 Get_Name_String
(ALI_File
);
478 -- First, find the last dot
482 while Finish
>= 1 and then Name_Buffer
(Finish
) /= '.' loop
483 Finish
:= Finish
- 1;
490 -- Now check that the dot is preceded by digits
493 Finish
:= Finish
- 1;
495 while Start
>= 1 and then Name_Buffer
(Start
- 1) in '0' .. '9' loop
499 -- If there is no difits, or if the digits are not preceded by
500 -- the character that precedes a unit index, this is not the ALI file
501 -- of a unit in a multi-unit source.
505 or else Name_Buffer
(Start
- 1) /= Multi_Unit_Index_Character
510 -- Build the index from the digit(s)
512 while Start
<= Finish
loop
513 Result
:= Result
* 10 +
514 Character'Pos (Name_Buffer
(Start
)) - Character'Pos ('0');