]>
Commit | Line | Data |
---|---|---|
8f9df7d8 VC |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT COMPILER COMPONENTS -- | |
4 | -- -- | |
5 | -- M A K E U T L -- | |
6 | -- -- | |
7 | -- B o d y -- | |
8 | -- -- | |
c0e538ad | 9 | -- Copyright (C) 2004-2011, Free Software Foundation, Inc. -- |
8f9df7d8 VC |
10 | -- -- |
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- -- | |
b5c84c3c | 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- |
8f9df7d8 VC |
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 -- | |
b5c84c3c RD |
18 | -- Public License distributed with GNAT; see file COPYING3. If not, go to -- |
19 | -- http://www.gnu.org/licenses for a complete copy of the license. -- | |
8f9df7d8 VC |
20 | -- -- |
21 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
22 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- | |
23 | -- -- | |
24 | ------------------------------------------------------------------------------ | |
25 | ||
38990220 | 26 | with ALI; use ALI; |
7d903840 | 27 | with Debug; |
fdfcc663 | 28 | with Fname; |
88b17d45 | 29 | with Hostparm; |
5950a3ac | 30 | with Osint; use Osint; |
2cd44f5a | 31 | with Output; use Output; |
f7e71125 | 32 | with Opt; use Opt; |
8f9df7d8 VC |
33 | with Prj.Ext; |
34 | with Prj.Util; | |
5950a3ac | 35 | with Snames; use Snames; |
8f9df7d8 | 36 | with Table; |
a113c55d | 37 | with Tempdir; |
8f9df7d8 | 38 | |
7d903840 AC |
39 | with Ada.Command_Line; use Ada.Command_Line; |
40 | ||
3ce5ca75 | 41 | with GNAT.Case_Util; use GNAT.Case_Util; |
1c218ac3 | 42 | with GNAT.Directory_Operations; use GNAT.Directory_Operations; |
55c1c66d | 43 | with GNAT.HTable; |
aa720a54 | 44 | |
8f9df7d8 VC |
45 | package body Makeutl is |
46 | ||
aa720a54 AC |
47 | type Mark_Key is record |
48 | File : File_Name_Type; | |
49 | Index : Int; | |
50 | end record; | |
51 | -- Identify either a mono-unit source (when Index = 0) or a specific unit | |
7d903840 | 52 | -- (index = 1's origin index of unit) in a multi-unit source. |
aa720a54 | 53 | |
5950a3ac AC |
54 | -- There follow many global undocumented declarations, comments needed ??? |
55 | ||
aa720a54 AC |
56 | Max_Mask_Num : constant := 2048; |
57 | ||
58 | subtype Mark_Num is Union_Id range 0 .. Max_Mask_Num - 1; | |
59 | ||
60 | function Hash (Key : Mark_Key) return Mark_Num; | |
61 | ||
55c1c66d | 62 | package Marks is new GNAT.HTable.Simple_HTable |
aa720a54 AC |
63 | (Header_Num => Mark_Num, |
64 | Element => Boolean, | |
65 | No_Element => False, | |
66 | Key => Mark_Key, | |
67 | Hash => Hash, | |
68 | Equal => "="); | |
9de61fcb | 69 | -- A hash table to keep tracks of the marked units |
aa720a54 | 70 | |
8f9df7d8 VC |
71 | type Linker_Options_Data is record |
72 | Project : Project_Id; | |
73 | Options : String_List_Id; | |
74 | end record; | |
75 | ||
76 | Linker_Option_Initial_Count : constant := 20; | |
77 | ||
78 | Linker_Options_Buffer : String_List_Access := | |
79 | new String_List (1 .. Linker_Option_Initial_Count); | |
80 | ||
81 | Last_Linker_Option : Natural := 0; | |
82 | ||
83 | package Linker_Opts is new Table.Table ( | |
84 | Table_Component_Type => Linker_Options_Data, | |
85 | Table_Index_Type => Integer, | |
86 | Table_Low_Bound => 1, | |
87 | Table_Initial => 10, | |
88 | Table_Increment => 100, | |
89 | Table_Name => "Make.Linker_Opts"); | |
90 | ||
91 | procedure Add_Linker_Option (Option : String); | |
92 | ||
2cd44f5a VC |
93 | --------- |
94 | -- Add -- | |
95 | --------- | |
96 | ||
97 | procedure Add | |
98 | (Option : String_Access; | |
99 | To : in out String_List_Access; | |
100 | Last : in out Natural) | |
101 | is | |
102 | begin | |
103 | if Last = To'Last then | |
104 | declare | |
105 | New_Options : constant String_List_Access := | |
106 | new String_List (1 .. To'Last * 2); | |
74744c7b | 107 | |
2cd44f5a VC |
108 | begin |
109 | New_Options (To'Range) := To.all; | |
110 | ||
111 | -- Set all elements of the original options to null to avoid | |
112 | -- deallocation of copies. | |
113 | ||
114 | To.all := (others => null); | |
115 | ||
116 | Free (To); | |
117 | To := New_Options; | |
118 | end; | |
119 | end if; | |
120 | ||
121 | Last := Last + 1; | |
122 | To (Last) := Option; | |
123 | end Add; | |
124 | ||
125 | procedure Add | |
126 | (Option : String; | |
127 | To : in out String_List_Access; | |
128 | Last : in out Natural) | |
129 | is | |
130 | begin | |
131 | Add (Option => new String'(Option), To => To, Last => Last); | |
132 | end Add; | |
133 | ||
8f9df7d8 VC |
134 | ----------------------- |
135 | -- Add_Linker_Option -- | |
136 | ----------------------- | |
137 | ||
138 | procedure Add_Linker_Option (Option : String) is | |
139 | begin | |
140 | if Option'Length > 0 then | |
141 | if Last_Linker_Option = Linker_Options_Buffer'Last then | |
142 | declare | |
143 | New_Buffer : constant String_List_Access := | |
5950a3ac AC |
144 | new String_List |
145 | (1 .. Linker_Options_Buffer'Last + | |
146 | Linker_Option_Initial_Count); | |
8f9df7d8 VC |
147 | begin |
148 | New_Buffer (Linker_Options_Buffer'Range) := | |
149 | Linker_Options_Buffer.all; | |
150 | Linker_Options_Buffer.all := (others => null); | |
151 | Free (Linker_Options_Buffer); | |
152 | Linker_Options_Buffer := New_Buffer; | |
153 | end; | |
154 | end if; | |
155 | ||
156 | Last_Linker_Option := Last_Linker_Option + 1; | |
157 | Linker_Options_Buffer (Last_Linker_Option) := new String'(Option); | |
158 | end if; | |
159 | end Add_Linker_Option; | |
160 | ||
c9df623a AC |
161 | ------------------------- |
162 | -- Base_Name_Index_For -- | |
163 | ------------------------- | |
164 | ||
165 | function Base_Name_Index_For | |
166 | (Main : String; | |
167 | Main_Index : Int; | |
168 | Index_Separator : Character) return File_Name_Type | |
169 | is | |
170 | Result : File_Name_Type; | |
c8c41617 | 171 | |
c9df623a AC |
172 | begin |
173 | Name_Len := 0; | |
174 | Add_Str_To_Name_Buffer (Base_Name (Main)); | |
175 | ||
c8c41617 RD |
176 | -- Remove the extension, if any, that is the last part of the base name |
177 | -- starting with a dot and following some characters. | |
c9df623a AC |
178 | |
179 | for J in reverse 2 .. Name_Len loop | |
180 | if Name_Buffer (J) = '.' then | |
181 | Name_Len := J - 1; | |
182 | exit; | |
183 | end if; | |
184 | end loop; | |
185 | ||
186 | -- Add the index info, if index is different from 0 | |
187 | ||
188 | if Main_Index > 0 then | |
189 | Add_Char_To_Name_Buffer (Index_Separator); | |
190 | ||
191 | declare | |
192 | Img : constant String := Main_Index'Img; | |
193 | begin | |
194 | Add_Str_To_Name_Buffer (Img (2 .. Img'Last)); | |
195 | end; | |
196 | end if; | |
c8c41617 | 197 | |
c9df623a AC |
198 | Result := Name_Find; |
199 | return Result; | |
200 | end Base_Name_Index_For; | |
201 | ||
38990220 EB |
202 | ------------------------------ |
203 | -- Check_Source_Info_In_ALI -- | |
204 | ------------------------------ | |
205 | ||
72e9f2b9 AC |
206 | function Check_Source_Info_In_ALI |
207 | (The_ALI : ALI_Id; | |
208 | Tree : Project_Tree_Ref) return Boolean | |
209 | is | |
38990220 | 210 | Unit_Name : Name_Id; |
8d12c865 | 211 | |
38990220 | 212 | begin |
8d12c865 RD |
213 | -- Loop through units |
214 | ||
215 | for U in ALIs.Table (The_ALI).First_Unit .. | |
216 | ALIs.Table (The_ALI).Last_Unit | |
38990220 | 217 | loop |
8d12c865 | 218 | -- Check if the file name is one of the source of the unit |
38990220 EB |
219 | |
220 | Get_Name_String (Units.Table (U).Uname); | |
221 | Name_Len := Name_Len - 2; | |
222 | Unit_Name := Name_Find; | |
223 | ||
224 | if File_Not_A_Source_Of (Unit_Name, Units.Table (U).Sfile) then | |
225 | return False; | |
226 | end if; | |
227 | ||
8d12c865 | 228 | -- Loop to do same check for each of the withed units |
38990220 | 229 | |
38990220 EB |
230 | for W in Units.Table (U).First_With .. Units.Table (U).Last_With loop |
231 | declare | |
232 | WR : ALI.With_Record renames Withs.Table (W); | |
8d12c865 | 233 | |
38990220 EB |
234 | begin |
235 | if WR.Sfile /= No_File then | |
236 | Get_Name_String (WR.Uname); | |
237 | Name_Len := Name_Len - 2; | |
238 | Unit_Name := Name_Find; | |
239 | ||
240 | if File_Not_A_Source_Of (Unit_Name, WR.Sfile) then | |
241 | return False; | |
242 | end if; | |
243 | end if; | |
244 | end; | |
8d12c865 RD |
245 | end loop; |
246 | end loop; | |
38990220 | 247 | |
72e9f2b9 | 248 | -- Loop to check subunits and replaced sources |
38990220 | 249 | |
8d12c865 RD |
250 | for D in ALIs.Table (The_ALI).First_Sdep .. |
251 | ALIs.Table (The_ALI).Last_Sdep | |
38990220 EB |
252 | loop |
253 | declare | |
254 | SD : Sdep_Record renames Sdep.Table (D); | |
8d12c865 | 255 | |
38990220 EB |
256 | begin |
257 | Unit_Name := SD.Subunit_Name; | |
258 | ||
72e9f2b9 AC |
259 | if Unit_Name = No_Name then |
260 | -- Check if this source file has been replaced by a source with | |
261 | -- a different file name. | |
262 | ||
263 | if Tree /= null and then Tree.Replaced_Source_Number > 0 then | |
264 | declare | |
265 | Replacement : constant File_Name_Type := | |
266 | Replaced_Source_HTable.Get | |
267 | (Tree.Replaced_Sources, SD.Sfile); | |
268 | ||
269 | begin | |
270 | if Replacement /= No_File then | |
271 | if Verbose_Mode then | |
272 | Write_Line | |
273 | ("source file" & | |
274 | Get_Name_String (SD.Sfile) & | |
275 | " has been replaced by " & | |
276 | Get_Name_String (Replacement)); | |
277 | end if; | |
278 | ||
279 | return False; | |
280 | end if; | |
281 | end; | |
282 | end if; | |
8d12c865 | 283 | |
72e9f2b9 | 284 | else |
38990220 | 285 | -- For separates, the file is no longer associated with the |
fdfcc663 AC |
286 | -- unit ("proc-sep.adb" is not associated with unit "proc.sep") |
287 | -- so we need to check whether the source file still exists in | |
38990220 EB |
288 | -- the source tree: it will if it matches the naming scheme |
289 | -- (and then will be for the same unit). | |
290 | ||
291 | if Find_Source | |
76b84bf0 AC |
292 | (In_Tree => Project_Tree, |
293 | Project => No_Project, | |
294 | Base_Name => SD.Sfile) = No_Source | |
38990220 | 295 | then |
fdfcc663 AC |
296 | -- If this is not a runtime file or if, when gnatmake switch |
297 | -- -a is used, we are not able to find this subunit in the | |
298 | -- source directories, then recompilation is needed. | |
299 | ||
300 | if not Fname.Is_Internal_File_Name (SD.Sfile) | |
301 | or else | |
76b84bf0 | 302 | (Check_Readonly_Files |
c5fdd4ad | 303 | and then Full_Source_Name (SD.Sfile) = No_File) |
38990220 EB |
304 | then |
305 | if Verbose_Mode then | |
306 | Write_Line | |
fdfcc663 | 307 | ("While parsing ALI file, file " |
38990220 | 308 | & Get_Name_String (SD.Sfile) |
fdfcc663 AC |
309 | & " is indicated as containing subunit " |
310 | & Get_Name_String (Unit_Name) | |
38990220 EB |
311 | & " but this does not match what was found while" |
312 | & " parsing the project. Will recompile"); | |
313 | end if; | |
76b84bf0 | 314 | |
38990220 EB |
315 | return False; |
316 | end if; | |
317 | end if; | |
318 | end if; | |
319 | end; | |
8d12c865 | 320 | end loop; |
38990220 EB |
321 | |
322 | return True; | |
323 | end Check_Source_Info_In_ALI; | |
324 | ||
a113c55d AC |
325 | -------------------------------- |
326 | -- Create_Binder_Mapping_File -- | |
327 | -------------------------------- | |
328 | ||
329 | function Create_Binder_Mapping_File return Path_Name_Type is | |
330 | Mapping_Path : Path_Name_Type := No_Path; | |
331 | ||
332 | Mapping_FD : File_Descriptor := Invalid_FD; | |
333 | -- A File Descriptor for an eventual mapping file | |
334 | ||
335 | ALI_Unit : Unit_Name_Type := No_Unit_Name; | |
336 | -- The unit name of an ALI file | |
337 | ||
338 | ALI_Name : File_Name_Type := No_File; | |
339 | -- The file name of the ALI file | |
340 | ||
341 | ALI_Project : Project_Id := No_Project; | |
342 | -- The project of the ALI file | |
343 | ||
344 | Bytes : Integer; | |
345 | OK : Boolean := False; | |
346 | Unit : Unit_Index; | |
347 | ||
348 | Status : Boolean; | |
349 | -- For call to Close | |
350 | ||
351 | begin | |
352 | Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path); | |
353 | Record_Temp_File (Project_Tree, Mapping_Path); | |
354 | ||
355 | if Mapping_FD /= Invalid_FD then | |
356 | OK := True; | |
357 | ||
358 | -- Traverse all units | |
359 | ||
360 | Unit := Units_Htable.Get_First (Project_Tree.Units_HT); | |
361 | while Unit /= No_Unit_Index loop | |
362 | if Unit.Name /= No_Name then | |
363 | ||
364 | -- If there is a body, put it in the mapping | |
365 | ||
366 | if Unit.File_Names (Impl) /= No_Source | |
367 | and then Unit.File_Names (Impl).Project /= No_Project | |
368 | then | |
369 | Get_Name_String (Unit.Name); | |
370 | Add_Str_To_Name_Buffer ("%b"); | |
371 | ALI_Unit := Name_Find; | |
372 | ALI_Name := | |
373 | Lib_File_Name (Unit.File_Names (Impl).Display_File); | |
374 | ALI_Project := Unit.File_Names (Impl).Project; | |
375 | ||
376 | -- Otherwise, if there is a spec, put it in the mapping | |
377 | ||
378 | elsif Unit.File_Names (Spec) /= No_Source | |
379 | and then Unit.File_Names (Spec).Project /= No_Project | |
380 | then | |
381 | Get_Name_String (Unit.Name); | |
382 | Add_Str_To_Name_Buffer ("%s"); | |
383 | ALI_Unit := Name_Find; | |
384 | ALI_Name := | |
385 | Lib_File_Name (Unit.File_Names (Spec).Display_File); | |
386 | ALI_Project := Unit.File_Names (Spec).Project; | |
387 | ||
388 | else | |
389 | ALI_Name := No_File; | |
390 | end if; | |
391 | ||
392 | -- If we have something to put in the mapping then do it now. | |
393 | -- However, if the project is extended, we don't put anything | |
394 | -- in the mapping file, since we don't know where the ALI file | |
395 | -- is: it might be in the extended project object directory as | |
396 | -- well as in the extending project object directory. | |
397 | ||
398 | if ALI_Name /= No_File | |
399 | and then ALI_Project.Extended_By = No_Project | |
400 | and then ALI_Project.Extends = No_Project | |
401 | then | |
402 | -- First check if the ALI file exists. If it does not, do | |
403 | -- not put the unit in the mapping file. | |
404 | ||
405 | declare | |
406 | ALI : constant String := Get_Name_String (ALI_Name); | |
407 | ||
408 | begin | |
409 | -- For library projects, use the library ALI directory, | |
410 | -- for other projects, use the object directory. | |
411 | ||
412 | if ALI_Project.Library then | |
413 | Get_Name_String | |
414 | (ALI_Project.Library_ALI_Dir.Display_Name); | |
415 | else | |
416 | Get_Name_String | |
417 | (ALI_Project.Object_Directory.Display_Name); | |
418 | end if; | |
419 | ||
a113c55d AC |
420 | Add_Str_To_Name_Buffer (ALI); |
421 | Add_Char_To_Name_Buffer (ASCII.LF); | |
422 | ||
423 | declare | |
424 | ALI_Path_Name : constant String := | |
23685ae6 | 425 | Name_Buffer (1 .. Name_Len); |
a113c55d AC |
426 | |
427 | begin | |
428 | if Is_Regular_File | |
429 | (ALI_Path_Name (1 .. ALI_Path_Name'Last - 1)) | |
430 | then | |
431 | -- First line is the unit name | |
432 | ||
433 | Get_Name_String (ALI_Unit); | |
434 | Add_Char_To_Name_Buffer (ASCII.LF); | |
435 | Bytes := | |
436 | Write | |
437 | (Mapping_FD, | |
438 | Name_Buffer (1)'Address, | |
439 | Name_Len); | |
440 | OK := Bytes = Name_Len; | |
441 | ||
442 | exit when not OK; | |
443 | ||
444 | -- Second line it the ALI file name | |
445 | ||
446 | Get_Name_String (ALI_Name); | |
447 | Add_Char_To_Name_Buffer (ASCII.LF); | |
448 | Bytes := | |
449 | Write | |
450 | (Mapping_FD, | |
451 | Name_Buffer (1)'Address, | |
452 | Name_Len); | |
453 | OK := (Bytes = Name_Len); | |
454 | ||
455 | exit when not OK; | |
456 | ||
457 | -- Third line it the ALI path name | |
458 | ||
459 | Bytes := | |
460 | Write | |
461 | (Mapping_FD, | |
462 | ALI_Path_Name (1)'Address, | |
463 | ALI_Path_Name'Length); | |
464 | OK := (Bytes = ALI_Path_Name'Length); | |
465 | ||
466 | -- If OK is False, it means we were unable to | |
467 | -- write a line. No point in continuing with the | |
468 | -- other units. | |
469 | ||
470 | exit when not OK; | |
471 | end if; | |
472 | end; | |
473 | end; | |
474 | end if; | |
475 | end if; | |
476 | ||
477 | Unit := Units_Htable.Get_Next (Project_Tree.Units_HT); | |
478 | end loop; | |
479 | ||
480 | Close (Mapping_FD, Status); | |
481 | ||
482 | OK := OK and Status; | |
483 | end if; | |
484 | ||
485 | -- If the creation of the mapping file was successful, we add the switch | |
486 | -- to the arguments of gnatbind. | |
487 | ||
488 | if OK then | |
489 | return Mapping_Path; | |
490 | ||
491 | else | |
492 | return No_Path; | |
493 | end if; | |
494 | end Create_Binder_Mapping_File; | |
495 | ||
2cd44f5a VC |
496 | ----------------- |
497 | -- Create_Name -- | |
498 | ----------------- | |
499 | ||
500 | function Create_Name (Name : String) return File_Name_Type is | |
501 | begin | |
502 | Name_Len := 0; | |
503 | Add_Str_To_Name_Buffer (Name); | |
504 | return Name_Find; | |
505 | end Create_Name; | |
506 | ||
507 | function Create_Name (Name : String) return Name_Id is | |
508 | begin | |
509 | Name_Len := 0; | |
510 | Add_Str_To_Name_Buffer (Name); | |
511 | return Name_Find; | |
512 | end Create_Name; | |
513 | ||
514 | function Create_Name (Name : String) return Path_Name_Type is | |
515 | begin | |
516 | Name_Len := 0; | |
517 | Add_Str_To_Name_Buffer (Name); | |
518 | return Name_Find; | |
519 | end Create_Name; | |
520 | ||
aa720a54 AC |
521 | ---------------------- |
522 | -- Delete_All_Marks -- | |
523 | ---------------------- | |
524 | ||
525 | procedure Delete_All_Marks is | |
526 | begin | |
527 | Marks.Reset; | |
528 | end Delete_All_Marks; | |
529 | ||
958a816e VC |
530 | ---------------------------- |
531 | -- Executable_Prefix_Path -- | |
532 | ---------------------------- | |
533 | ||
534 | function Executable_Prefix_Path return String is | |
535 | Exec_Name : constant String := Command_Name; | |
536 | ||
537 | function Get_Install_Dir (S : String) return String; | |
74744c7b AC |
538 | -- S is the executable name preceded by the absolute or relative path, |
539 | -- e.g. "c:\usr\bin\gcc.exe". Returns the absolute directory where "bin" | |
540 | -- lies (in the example "C:\usr"). If the executable is not in a "bin" | |
541 | -- directory, return "". | |
958a816e VC |
542 | |
543 | --------------------- | |
544 | -- Get_Install_Dir -- | |
545 | --------------------- | |
546 | ||
547 | function Get_Install_Dir (S : String) return String is | |
548 | Exec : String := S; | |
549 | Path_Last : Integer := 0; | |
550 | ||
551 | begin | |
552 | for J in reverse Exec'Range loop | |
553 | if Exec (J) = Directory_Separator then | |
554 | Path_Last := J - 1; | |
555 | exit; | |
556 | end if; | |
557 | end loop; | |
558 | ||
559 | if Path_Last >= Exec'First + 2 then | |
560 | To_Lower (Exec (Path_Last - 2 .. Path_Last)); | |
561 | end if; | |
562 | ||
563 | if Path_Last < Exec'First + 2 | |
564 | or else Exec (Path_Last - 2 .. Path_Last) /= "bin" | |
565 | or else (Path_Last - 3 >= Exec'First | |
566 | and then Exec (Path_Last - 3) /= Directory_Separator) | |
567 | then | |
568 | return ""; | |
569 | end if; | |
570 | ||
5fd3fd79 | 571 | return Normalize_Pathname |
d56e7acd AC |
572 | (Exec (Exec'First .. Path_Last - 4), |
573 | Resolve_Links => Opt.Follow_Links_For_Dirs) | |
659819b9 | 574 | & Directory_Separator; |
958a816e VC |
575 | end Get_Install_Dir; |
576 | ||
577 | -- Beginning of Executable_Prefix_Path | |
578 | ||
579 | begin | |
88b17d45 AC |
580 | -- For VMS, the path returned is always /gnu/ |
581 | ||
582 | if Hostparm.OpenVMS then | |
583 | return "/gnu/"; | |
584 | end if; | |
585 | ||
958a816e VC |
586 | -- First determine if a path prefix was placed in front of the |
587 | -- executable name. | |
588 | ||
589 | for J in reverse Exec_Name'Range loop | |
590 | if Exec_Name (J) = Directory_Separator then | |
591 | return Get_Install_Dir (Exec_Name); | |
592 | end if; | |
593 | end loop; | |
594 | ||
595 | -- If we get here, the user has typed the executable name with no | |
596 | -- directory prefix. | |
597 | ||
67d7b0ab | 598 | declare |
659819b9 | 599 | Path : String_Access := Locate_Exec_On_Path (Exec_Name); |
67d7b0ab VC |
600 | begin |
601 | if Path = null then | |
602 | return ""; | |
67d7b0ab | 603 | else |
659819b9 AC |
604 | declare |
605 | Dir : constant String := Get_Install_Dir (Path.all); | |
606 | begin | |
607 | Free (Path); | |
608 | return Dir; | |
609 | end; | |
67d7b0ab VC |
610 | end if; |
611 | end; | |
958a816e VC |
612 | end Executable_Prefix_Path; |
613 | ||
f7e71125 AC |
614 | -------------------------- |
615 | -- File_Not_A_Source_Of -- | |
616 | -------------------------- | |
617 | ||
618 | function File_Not_A_Source_Of | |
619 | (Uname : Name_Id; | |
620 | Sfile : File_Name_Type) return Boolean | |
621 | is | |
622 | Unit : constant Unit_Index := | |
623 | Units_Htable.Get (Project_Tree.Units_HT, Uname); | |
624 | ||
625 | At_Least_One_File : Boolean := False; | |
626 | ||
627 | begin | |
628 | if Unit /= No_Unit_Index then | |
629 | for F in Unit.File_Names'Range loop | |
630 | if Unit.File_Names (F) /= null then | |
631 | At_Least_One_File := True; | |
632 | if Unit.File_Names (F).File = Sfile then | |
633 | return False; | |
634 | end if; | |
635 | end if; | |
636 | end loop; | |
637 | ||
638 | if not At_Least_One_File then | |
639 | ||
640 | -- The unit was probably created initially for a separate unit | |
641 | -- (which are initially created as IMPL when both suffixes are the | |
642 | -- same). Later on, Override_Kind changed the type of the file, | |
643 | -- and the unit is no longer valid in fact. | |
644 | ||
645 | return False; | |
646 | end if; | |
647 | ||
648 | Verbose_Msg (Uname, "sources do not include ", Name_Id (Sfile)); | |
649 | return True; | |
650 | end if; | |
651 | ||
652 | return False; | |
653 | end File_Not_A_Source_Of; | |
654 | ||
aa720a54 AC |
655 | ---------- |
656 | -- Hash -- | |
657 | ---------- | |
658 | ||
659 | function Hash (Key : Mark_Key) return Mark_Num is | |
660 | begin | |
661 | return Union_Id (Key.File) mod Max_Mask_Num; | |
662 | end Hash; | |
663 | ||
2cd44f5a VC |
664 | ------------ |
665 | -- Inform -- | |
666 | ------------ | |
667 | ||
668 | procedure Inform (N : File_Name_Type; Msg : String) is | |
669 | begin | |
670 | Inform (Name_Id (N), Msg); | |
671 | end Inform; | |
672 | ||
673 | procedure Inform (N : Name_Id := No_Name; Msg : String) is | |
674 | begin | |
675 | Osint.Write_Program_Name; | |
676 | ||
677 | Write_Str (": "); | |
678 | ||
679 | if N /= No_Name then | |
680 | Write_Str (""""); | |
7d903840 AC |
681 | |
682 | declare | |
683 | Name : constant String := Get_Name_String (N); | |
684 | begin | |
685 | if Debug.Debug_Flag_F and then Is_Absolute_Path (Name) then | |
686 | Write_Str (File_Name (Name)); | |
687 | else | |
688 | Write_Str (Name); | |
689 | end if; | |
690 | end; | |
691 | ||
2cd44f5a VC |
692 | Write_Str (""" "); |
693 | end if; | |
694 | ||
695 | Write_Str (Msg); | |
696 | Write_Eol; | |
697 | end Inform; | |
698 | ||
8f9df7d8 VC |
699 | ---------------------------- |
700 | -- Is_External_Assignment -- | |
701 | ---------------------------- | |
702 | ||
daa72421 | 703 | function Is_External_Assignment |
804fe3c4 | 704 | (Env : Prj.Tree.Environment; |
daa72421 AC |
705 | Argv : String) return Boolean |
706 | is | |
8f9df7d8 VC |
707 | Start : Positive := 3; |
708 | Finish : Natural := Argv'Last; | |
8f9df7d8 | 709 | |
bfc8aa81 RD |
710 | pragma Assert (Argv'First = 1); |
711 | pragma Assert (Argv (1 .. 2) = "-X"); | |
712 | ||
8f9df7d8 VC |
713 | begin |
714 | if Argv'Last < 5 then | |
715 | return False; | |
716 | ||
717 | elsif Argv (3) = '"' then | |
718 | if Argv (Argv'Last) /= '"' or else Argv'Last < 7 then | |
719 | return False; | |
720 | else | |
721 | Start := 4; | |
722 | Finish := Argv'Last - 1; | |
723 | end if; | |
724 | end if; | |
725 | ||
d9b4a5d3 | 726 | return Prj.Ext.Check |
804fe3c4 | 727 | (Self => Env.External, |
d9b4a5d3 | 728 | Declaration => Argv (Start .. Finish)); |
8f9df7d8 VC |
729 | end Is_External_Assignment; |
730 | ||
aa720a54 AC |
731 | --------------- |
732 | -- Is_Marked -- | |
733 | --------------- | |
734 | ||
735 | function Is_Marked | |
736 | (Source_File : File_Name_Type; | |
5950a3ac | 737 | Index : Int := 0) return Boolean |
aa720a54 AC |
738 | is |
739 | begin | |
740 | return Marks.Get (K => (File => Source_File, Index => Index)); | |
741 | end Is_Marked; | |
742 | ||
8f9df7d8 VC |
743 | ----------------------------- |
744 | -- Linker_Options_Switches -- | |
745 | ----------------------------- | |
746 | ||
747 | function Linker_Options_Switches | |
7e98a4c6 VC |
748 | (Project : Project_Id; |
749 | In_Tree : Project_Tree_Ref) return String_List | |
8f9df7d8 | 750 | is |
8b9890fa | 751 | procedure Recursive_Add (Proj : Project_Id; Dummy : in out Boolean); |
5950a3ac | 752 | -- The recursive routine used to add linker options |
8f9df7d8 | 753 | |
8b9890fa EB |
754 | ------------------- |
755 | -- Recursive_Add -- | |
756 | ------------------- | |
8f9df7d8 | 757 | |
8b9890fa EB |
758 | procedure Recursive_Add (Proj : Project_Id; Dummy : in out Boolean) is |
759 | pragma Unreferenced (Dummy); | |
74744c7b | 760 | |
8f9df7d8 | 761 | Linker_Package : Package_Id; |
5950a3ac | 762 | Options : Variable_Value; |
5950a3ac | 763 | |
8f9df7d8 | 764 | begin |
8b9890fa EB |
765 | Linker_Package := |
766 | Prj.Util.Value_Of | |
767 | (Name => Name_Linker, | |
66713d62 | 768 | In_Packages => Proj.Decl.Packages, |
8b9890fa | 769 | In_Tree => In_Tree); |
74744c7b | 770 | |
8b9890fa EB |
771 | Options := |
772 | Prj.Util.Value_Of | |
773 | (Name => Name_Ada, | |
774 | Index => 0, | |
775 | Attribute_Or_Array_Name => Name_Linker_Options, | |
776 | In_Package => Linker_Package, | |
777 | In_Tree => In_Tree); | |
778 | ||
779 | -- If attribute is present, add the project with | |
780 | -- the attribute to table Linker_Opts. | |
781 | ||
782 | if Options /= Nil_Variable_Value then | |
783 | Linker_Opts.Increment_Last; | |
784 | Linker_Opts.Table (Linker_Opts.Last) := | |
785 | (Project => Proj, Options => Options.Values); | |
8f9df7d8 | 786 | end if; |
8b9890fa EB |
787 | end Recursive_Add; |
788 | ||
789 | procedure For_All_Projects is | |
790 | new For_Every_Project_Imported (Boolean, Recursive_Add); | |
74744c7b | 791 | |
8b9890fa | 792 | Dummy : Boolean := False; |
8f9df7d8 | 793 | |
5950a3ac AC |
794 | -- Start of processing for Linker_Options_Switches |
795 | ||
8f9df7d8 VC |
796 | begin |
797 | Linker_Opts.Init; | |
798 | ||
66713d62 | 799 | For_All_Projects (Project, Dummy, Imported_First => True); |
8f9df7d8 VC |
800 | |
801 | Last_Linker_Option := 0; | |
802 | ||
803 | for Index in reverse 1 .. Linker_Opts.Last loop | |
804 | declare | |
66713d62 | 805 | Options : String_List_Id; |
8f9df7d8 | 806 | Proj : constant Project_Id := |
74744c7b | 807 | Linker_Opts.Table (Index).Project; |
8f9df7d8 | 808 | Option : Name_Id; |
2324b3fd | 809 | Dir_Path : constant String := |
66713d62 | 810 | Get_Name_String (Proj.Directory.Name); |
8f9df7d8 VC |
811 | |
812 | begin | |
66713d62 | 813 | Options := Linker_Opts.Table (Index).Options; |
8f9df7d8 | 814 | while Options /= Nil_String loop |
74744c7b | 815 | Option := In_Tree.String_Elements.Table (Options).Value; |
f2c573b1 VC |
816 | Get_Name_String (Option); |
817 | ||
818 | -- Do not consider empty linker options | |
819 | ||
820 | if Name_Len /= 0 then | |
821 | Add_Linker_Option (Name_Buffer (1 .. Name_Len)); | |
822 | ||
823 | -- Object files and -L switches specified with relative | |
824 | -- paths must be converted to absolute paths. | |
825 | ||
826 | Test_If_Relative_Path | |
74744c7b | 827 | (Switch => Linker_Options_Buffer (Last_Linker_Option), |
2324b3fd | 828 | Parent => Dir_Path, |
f2c573b1 VC |
829 | Including_L_Switch => True); |
830 | end if; | |
831 | ||
66713d62 | 832 | Options := In_Tree.String_Elements.Table (Options).Next; |
8f9df7d8 VC |
833 | end loop; |
834 | end; | |
835 | end loop; | |
836 | ||
837 | return Linker_Options_Buffer (1 .. Last_Linker_Option); | |
838 | end Linker_Options_Switches; | |
839 | ||
840 | ----------- | |
841 | -- Mains -- | |
842 | ----------- | |
843 | ||
844 | package body Mains is | |
845 | ||
1e887886 VC |
846 | type File_And_Loc is record |
847 | File_Name : File_Name_Type; | |
c9df623a | 848 | Index : Int := 0; |
1e887886 VC |
849 | Location : Source_Ptr := No_Location; |
850 | end record; | |
851 | ||
8f9df7d8 | 852 | package Names is new Table.Table |
1e887886 | 853 | (Table_Component_Type => File_And_Loc, |
8f9df7d8 VC |
854 | Table_Index_Type => Integer, |
855 | Table_Low_Bound => 1, | |
856 | Table_Initial => 10, | |
857 | Table_Increment => 100, | |
858 | Table_Name => "Makeutl.Mains.Names"); | |
859 | -- The table that stores the mains | |
860 | ||
861 | Current : Natural := 0; | |
862 | -- The index of the last main retrieved from the table | |
863 | ||
864 | -------------- | |
865 | -- Add_Main -- | |
866 | -------------- | |
867 | ||
868 | procedure Add_Main (Name : String) is | |
869 | begin | |
870 | Name_Len := 0; | |
871 | Add_Str_To_Name_Buffer (Name); | |
872 | Names.Increment_Last; | |
c9df623a | 873 | Names.Table (Names.Last) := (Name_Find, 0, No_Location); |
8f9df7d8 VC |
874 | end Add_Main; |
875 | ||
876 | ------------ | |
877 | -- Delete -- | |
878 | ------------ | |
879 | ||
880 | procedure Delete is | |
881 | begin | |
882 | Names.Set_Last (0); | |
7e98a4c6 | 883 | Mains.Reset; |
8f9df7d8 VC |
884 | end Delete; |
885 | ||
c9df623a AC |
886 | --------------- |
887 | -- Get_Index -- | |
888 | --------------- | |
889 | ||
890 | function Get_Index return Int is | |
891 | begin | |
892 | if Current in Names.First .. Names.Last then | |
893 | return Names.Table (Current).Index; | |
894 | else | |
895 | return 0; | |
896 | end if; | |
897 | end Get_Index; | |
898 | ||
1e887886 VC |
899 | ------------------ |
900 | -- Get_Location -- | |
901 | ------------------ | |
902 | ||
903 | function Get_Location return Source_Ptr is | |
904 | begin | |
a573518c TQ |
905 | if Current in Names.First .. Names.Last then |
906 | return Names.Table (Current).Location; | |
1e887886 | 907 | else |
a573518c | 908 | return No_Location; |
1e887886 VC |
909 | end if; |
910 | end Get_Location; | |
911 | ||
8f9df7d8 VC |
912 | --------------- |
913 | -- Next_Main -- | |
914 | --------------- | |
915 | ||
916 | function Next_Main return String is | |
917 | begin | |
918 | if Current >= Names.Last then | |
919 | return ""; | |
8f9df7d8 VC |
920 | else |
921 | Current := Current + 1; | |
1e887886 | 922 | return Get_Name_String (Names.Table (Current).File_Name); |
8f9df7d8 VC |
923 | end if; |
924 | end Next_Main; | |
925 | ||
926 | --------------------- | |
927 | -- Number_Of_Mains -- | |
928 | --------------------- | |
929 | ||
930 | function Number_Of_Mains return Natural is | |
931 | begin | |
932 | return Names.Last; | |
933 | end Number_Of_Mains; | |
934 | ||
935 | ----------- | |
936 | -- Reset -- | |
937 | ----------- | |
938 | ||
939 | procedure Reset is | |
940 | begin | |
941 | Current := 0; | |
942 | end Reset; | |
943 | ||
c9df623a AC |
944 | --------------- |
945 | -- Set_Index -- | |
946 | --------------- | |
947 | ||
948 | procedure Set_Index (Index : Int) is | |
949 | begin | |
950 | if Names.Last > 0 then | |
951 | Names.Table (Names.Last).Index := Index; | |
952 | end if; | |
953 | end Set_Index; | |
954 | ||
1e887886 VC |
955 | ------------------ |
956 | -- Set_Location -- | |
957 | ------------------ | |
958 | ||
959 | procedure Set_Location (Location : Source_Ptr) is | |
960 | begin | |
961 | if Names.Last > 0 then | |
962 | Names.Table (Names.Last).Location := Location; | |
963 | end if; | |
964 | end Set_Location; | |
965 | ||
966 | ----------------- | |
967 | -- Update_Main -- | |
968 | ----------------- | |
969 | ||
970 | procedure Update_Main (Name : String) is | |
971 | begin | |
a573518c | 972 | if Current in Names.First .. Names.Last then |
1e887886 VC |
973 | Name_Len := 0; |
974 | Add_Str_To_Name_Buffer (Name); | |
975 | Names.Table (Current).File_Name := Name_Find; | |
976 | end if; | |
977 | end Update_Main; | |
8f9df7d8 VC |
978 | end Mains; |
979 | ||
aa720a54 AC |
980 | ---------- |
981 | -- Mark -- | |
982 | ---------- | |
983 | ||
984 | procedure Mark (Source_File : File_Name_Type; Index : Int := 0) is | |
985 | begin | |
986 | Marks.Set (K => (File => Source_File, Index => Index), E => True); | |
987 | end Mark; | |
988 | ||
7d903840 AC |
989 | ----------------------- |
990 | -- Path_Or_File_Name -- | |
991 | ----------------------- | |
992 | ||
993 | function Path_Or_File_Name (Path : Path_Name_Type) return String is | |
994 | Path_Name : constant String := Get_Name_String (Path); | |
995 | begin | |
996 | if Debug.Debug_Flag_F then | |
997 | return File_Name (Path_Name); | |
998 | else | |
999 | return Path_Name; | |
1000 | end if; | |
1001 | end Path_Or_File_Name; | |
1002 | ||
8f9df7d8 VC |
1003 | --------------------------- |
1004 | -- Test_If_Relative_Path -- | |
1005 | --------------------------- | |
1006 | ||
1007 | procedure Test_If_Relative_Path | |
1086c39b | 1008 | (Switch : in out String_Access; |
2324b3fd | 1009 | Parent : String; |
1086c39b | 1010 | Including_L_Switch : Boolean := True; |
35debead EB |
1011 | Including_Non_Switch : Boolean := True; |
1012 | Including_RTS : Boolean := False) | |
8f9df7d8 VC |
1013 | is |
1014 | begin | |
1015 | if Switch /= null then | |
8f9df7d8 | 1016 | declare |
74744c7b | 1017 | Sw : String (1 .. Switch'Length); |
8f9df7d8 VC |
1018 | Start : Positive; |
1019 | ||
1020 | begin | |
1021 | Sw := Switch.all; | |
1022 | ||
1023 | if Sw (1) = '-' then | |
1024 | if Sw'Length >= 3 | |
1025 | and then (Sw (2) = 'A' | |
74744c7b AC |
1026 | or else Sw (2) = 'I' |
1027 | or else (Including_L_Switch and then Sw (2) = 'L')) | |
8f9df7d8 VC |
1028 | then |
1029 | Start := 3; | |
1030 | ||
1031 | if Sw = "-I-" then | |
1032 | return; | |
1033 | end if; | |
1034 | ||
1035 | elsif Sw'Length >= 4 | |
1036 | and then (Sw (2 .. 3) = "aL" | |
74744c7b AC |
1037 | or else Sw (2 .. 3) = "aO" |
1038 | or else Sw (2 .. 3) = "aI") | |
8f9df7d8 VC |
1039 | then |
1040 | Start := 4; | |
1041 | ||
35debead EB |
1042 | elsif Including_RTS |
1043 | and then Sw'Length >= 7 | |
1044 | and then Sw (2 .. 6) = "-RTS=" | |
1045 | then | |
1046 | Start := 7; | |
1047 | ||
8f9df7d8 VC |
1048 | else |
1049 | return; | |
1050 | end if; | |
1051 | ||
1052 | -- Because relative path arguments to --RTS= may be relative | |
1053 | -- to the search directory prefix, those relative path | |
35debead EB |
1054 | -- arguments are converted only when they include directory |
1055 | -- information. | |
8f9df7d8 VC |
1056 | |
1057 | if not Is_Absolute_Path (Sw (Start .. Sw'Last)) then | |
2324b3fd | 1058 | if Parent'Length = 0 then |
8f9df7d8 | 1059 | Do_Fail |
3dd9959c AC |
1060 | ("relative search path switches (""" |
1061 | & Sw | |
1062 | & """) are not allowed"); | |
8f9df7d8 | 1063 | |
35debead EB |
1064 | elsif Including_RTS then |
1065 | for J in Start .. Sw'Last loop | |
1066 | if Sw (J) = Directory_Separator then | |
1067 | Switch := | |
1068 | new String' | |
1069 | (Sw (1 .. Start - 1) & | |
1070 | Parent & | |
1071 | Directory_Separator & | |
1072 | Sw (Start .. Sw'Last)); | |
1073 | return; | |
1074 | end if; | |
1075 | end loop; | |
1076 | ||
8f9df7d8 VC |
1077 | else |
1078 | Switch := | |
1079 | new String' | |
1080 | (Sw (1 .. Start - 1) & | |
2324b3fd | 1081 | Parent & |
8f9df7d8 VC |
1082 | Directory_Separator & |
1083 | Sw (Start .. Sw'Last)); | |
1084 | end if; | |
1085 | end if; | |
1086 | ||
1086c39b | 1087 | elsif Including_Non_Switch then |
8f9df7d8 | 1088 | if not Is_Absolute_Path (Sw) then |
2324b3fd | 1089 | if Parent'Length = 0 then |
8f9df7d8 | 1090 | Do_Fail |
3dd9959c | 1091 | ("relative paths (""" & Sw & """) are not allowed"); |
8f9df7d8 | 1092 | else |
2324b3fd | 1093 | Switch := new String'(Parent & Directory_Separator & Sw); |
8f9df7d8 VC |
1094 | end if; |
1095 | end if; | |
1096 | end if; | |
1097 | end; | |
1098 | end if; | |
1099 | end Test_If_Relative_Path; | |
1100 | ||
aa720a54 AC |
1101 | ------------------- |
1102 | -- Unit_Index_Of -- | |
1103 | ------------------- | |
1104 | ||
1105 | function Unit_Index_Of (ALI_File : File_Name_Type) return Int is | |
1106 | Start : Natural; | |
1107 | Finish : Natural; | |
1108 | Result : Int := 0; | |
5950a3ac | 1109 | |
aa720a54 AC |
1110 | begin |
1111 | Get_Name_String (ALI_File); | |
1112 | ||
1113 | -- First, find the last dot | |
1114 | ||
1115 | Finish := Name_Len; | |
1116 | ||
1117 | while Finish >= 1 and then Name_Buffer (Finish) /= '.' loop | |
1118 | Finish := Finish - 1; | |
1119 | end loop; | |
1120 | ||
1121 | if Finish = 1 then | |
1122 | return 0; | |
1123 | end if; | |
1124 | ||
1125 | -- Now check that the dot is preceded by digits | |
1126 | ||
1127 | Start := Finish; | |
1128 | Finish := Finish - 1; | |
1129 | ||
1130 | while Start >= 1 and then Name_Buffer (Start - 1) in '0' .. '9' loop | |
1131 | Start := Start - 1; | |
1132 | end loop; | |
1133 | ||
74744c7b AC |
1134 | -- If there are no digits, or if the digits are not preceded by the |
1135 | -- character that precedes a unit index, this is not the ALI file of | |
1136 | -- a unit in a multi-unit source. | |
aa720a54 | 1137 | |
5950a3ac AC |
1138 | if Start > Finish |
1139 | or else Start = 1 | |
1140 | or else Name_Buffer (Start - 1) /= Multi_Unit_Index_Character | |
aa720a54 AC |
1141 | then |
1142 | return 0; | |
1143 | end if; | |
1144 | ||
1145 | -- Build the index from the digit(s) | |
1146 | ||
1147 | while Start <= Finish loop | |
5950a3ac AC |
1148 | Result := Result * 10 + |
1149 | Character'Pos (Name_Buffer (Start)) - Character'Pos ('0'); | |
aa720a54 AC |
1150 | Start := Start + 1; |
1151 | end loop; | |
1152 | ||
1153 | return Result; | |
1154 | end Unit_Index_Of; | |
1155 | ||
f7e71125 AC |
1156 | ----------------- |
1157 | -- Verbose_Msg -- | |
1158 | ----------------- | |
1159 | ||
1160 | procedure Verbose_Msg | |
1161 | (N1 : Name_Id; | |
1162 | S1 : String; | |
1163 | N2 : Name_Id := No_Name; | |
1164 | S2 : String := ""; | |
1165 | Prefix : String := " -> "; | |
1166 | Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low) | |
1167 | is | |
1168 | begin | |
1169 | if not Opt.Verbose_Mode | |
1170 | or else Minimum_Verbosity > Opt.Verbosity_Level | |
1171 | then | |
1172 | return; | |
1173 | end if; | |
1174 | ||
1175 | Write_Str (Prefix); | |
1176 | Write_Str (""""); | |
1177 | Write_Name (N1); | |
1178 | Write_Str (""" "); | |
1179 | Write_Str (S1); | |
1180 | ||
1181 | if N2 /= No_Name then | |
1182 | Write_Str (" """); | |
1183 | Write_Name (N2); | |
1184 | Write_Str (""" "); | |
1185 | end if; | |
1186 | ||
1187 | Write_Str (S2); | |
1188 | Write_Eol; | |
1189 | end Verbose_Msg; | |
1190 | ||
1191 | procedure Verbose_Msg | |
1192 | (N1 : File_Name_Type; | |
1193 | S1 : String; | |
1194 | N2 : File_Name_Type := No_File; | |
1195 | S2 : String := ""; | |
1196 | Prefix : String := " -> "; | |
1197 | Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low) | |
1198 | is | |
1199 | begin | |
1200 | Verbose_Msg | |
1201 | (Name_Id (N1), S1, Name_Id (N2), S2, Prefix, Minimum_Verbosity); | |
1202 | end Verbose_Msg; | |
1203 | ||
8f9df7d8 | 1204 | end Makeutl; |