]> gcc.gnu.org Git - gcc.git/blob - gcc/ada/make.adb
[Ada] Remove AAMP from compiler sources
[gcc.git] / gcc / ada / make.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- M A K E --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2021, Free Software Foundation, Inc. --
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- --
13 -- ware Foundation; either version 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
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
26 with ALI; use ALI;
27 with ALI.Util; use ALI.Util;
28 with Csets;
29 with Debug;
30 with Fmap;
31 with Fname; use Fname;
32 with Fname.SF;
33 with Fname.UF; use Fname.UF;
34 with Gnatvsn; use Gnatvsn;
35 with Hostparm; use Hostparm;
36 with Makeusg;
37 with Make_Util; use Make_Util;
38 with Namet; use Namet;
39 with Opt; use Opt;
40 with Osint.M; use Osint.M;
41 with Osint; use Osint;
42 with Output; use Output;
43 with SFN_Scan;
44 with Sinput;
45 with Snames;
46 with Stringt;
47
48 pragma Warnings (Off);
49 with System.HTable;
50 pragma Warnings (On);
51
52 with Switch; use Switch;
53 with Switch.M; use Switch.M;
54 with Table;
55 with Targparm;
56 with Tempdir;
57 with Types; use Types;
58
59 with Ada.Command_Line; use Ada.Command_Line;
60 with Ada.Directories;
61 with Ada.Exceptions; use Ada.Exceptions;
62
63 with GNAT.Command_Line; use GNAT.Command_Line;
64 with GNAT.Ctrl_C;
65 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
66 with GNAT.OS_Lib; use GNAT.OS_Lib;
67
68 package body Make is
69
70 use ASCII;
71 -- Make control characters visible
72
73 Standard_Library_Package_Body_Name : constant String := "s-stalib.adb";
74 System_Package_Spec_Name : constant String := "system.ads";
75 -- Every program depends on one of these packages: usually the first one,
76 -- or if Supress_Standard_Library is true on the second one. The dependency
77 -- is not always explicit and considering it is important when -f and -a
78 -- are used.
79
80 procedure Sigint_Intercepted;
81 pragma No_Return (Sigint_Intercepted);
82 -- Called when the program is interrupted by Ctrl-C to delete the
83 -- temporary mapping files and configuration pragmas files.
84
85 No_Mapping_File : constant Natural := 0;
86
87 type Compilation_Data is record
88 Pid : Process_Id;
89 Full_Source_File : File_Name_Type;
90 Lib_File : File_Name_Type;
91 Source_Unit : Unit_Name_Type;
92 Full_Lib_File : File_Name_Type;
93 Lib_File_Attr : aliased File_Attributes;
94 Mapping_File : Natural := No_Mapping_File;
95 end record;
96 -- Data recorded for each compilation process spawned
97
98 No_Compilation_Data : constant Compilation_Data :=
99 (Invalid_Pid, No_File, No_File, No_Unit_Name, No_File, Unknown_Attributes,
100 No_Mapping_File);
101
102 type Comp_Data_Arr is array (Positive range <>) of Compilation_Data;
103 type Comp_Data_Ptr is access Comp_Data_Arr;
104 Running_Compile : Comp_Data_Ptr;
105 -- Used to save information about outstanding compilations
106
107 Outstanding_Compiles : Natural := 0;
108 -- Current number of outstanding compiles
109
110 procedure Initialize;
111
112 Project_File_Name_Present : Boolean := False;
113
114 Project_File_Name : String_Access := null;
115
116 -------------------------
117 -- Note on terminology --
118 -------------------------
119
120 -- In this program, we use the phrase "termination" of a file name to refer
121 -- to the suffix that appears after the unit name portion. Very often this
122 -- is simply the extension, but in some cases, the sequence may be more
123 -- complex, for example in main.1.ada, the termination in this name is
124 -- ".1.ada" and in main_.ada the termination is "_.ada".
125
126 Unique_Compile : Boolean := False;
127 -- Set to True if -u or -U is used
128
129 Must_Compile : Boolean := False;
130 -- True if gnatmake is invoked with -f -u and one or several mains on the
131 -- command line.
132
133 Main_On_Command_Line : Boolean := False;
134 -- True if gnatmake is invoked with one or several mains on the command
135 -- line.
136
137 RTS_Specified : String_Access := null;
138 -- Used to detect multiple --RTS= switches
139
140 N_M_Switch : Natural := 0;
141 -- Used to count -mxxx switches that can affect multilib
142
143 -- The 3 following packages are used to store gcc, gnatbind and gnatlink
144 -- switches found in the project files.
145
146 package Gcc_Switches is new Table.Table (
147 Table_Component_Type => String_Access,
148 Table_Index_Type => Integer,
149 Table_Low_Bound => 1,
150 Table_Initial => 20,
151 Table_Increment => 100,
152 Table_Name => "Make.Gcc_Switches");
153
154 package Binder_Switches is new Table.Table (
155 Table_Component_Type => String_Access,
156 Table_Index_Type => Integer,
157 Table_Low_Bound => 1,
158 Table_Initial => 20,
159 Table_Increment => 100,
160 Table_Name => "Make.Binder_Switches");
161
162 package Linker_Switches is new Table.Table (
163 Table_Component_Type => String_Access,
164 Table_Index_Type => Integer,
165 Table_Low_Bound => 1,
166 Table_Initial => 20,
167 Table_Increment => 100,
168 Table_Name => "Make.Linker_Switches");
169
170 package Switches_To_Check is new Table.Table (
171 Table_Component_Type => String_Access,
172 Table_Index_Type => Integer,
173 Table_Low_Bound => 1,
174 Table_Initial => 20,
175 Table_Increment => 100,
176 Table_Name => "Make.Switches_To_Check");
177
178 package Failed_Links is new Table.Table (
179 Table_Component_Type => File_Name_Type,
180 Table_Index_Type => Integer,
181 Table_Low_Bound => 1,
182 Table_Initial => 10,
183 Table_Increment => 100,
184 Table_Name => "Make.Failed_Links");
185
186 package Successful_Links is new Table.Table (
187 Table_Component_Type => File_Name_Type,
188 Table_Index_Type => Integer,
189 Table_Low_Bound => 1,
190 Table_Initial => 10,
191 Table_Increment => 100,
192 Table_Name => "Make.Successful_Links");
193
194 Normalized_Switches : Argument_List_Access := new Argument_List (1 .. 10);
195 Last_Norm_Switch : Natural := 0;
196
197 Map_File : String_Access := null;
198 -- Value of switch --create-map-file
199
200 procedure Add_Library_Search_Dir (Path : String);
201 -- Call Add_Lib_Search_Dir with an absolute directory path. If Path is
202 -- relative path, it is relative to the current working directory.
203
204 procedure Add_Source_Search_Dir (Path : String);
205 -- Call Add_Src_Search_Dir with an absolute directory path. If Path is a
206 -- relative path, it is relative to the current working directory.
207
208 type Bad_Compilation_Info is record
209 File : File_Name_Type;
210 Unit : Unit_Name_Type;
211 Found : Boolean;
212 end record;
213 -- File is the name of the file for which a compilation failed. Unit is for
214 -- gnatdist use in order to easily get the unit name of a file when its
215 -- name is krunched or declared in gnat.adc. Found is False if the
216 -- compilation failed because the file could not be found.
217
218 package Bad_Compilation is new Table.Table (
219 Table_Component_Type => Bad_Compilation_Info,
220 Table_Index_Type => Natural,
221 Table_Low_Bound => 1,
222 Table_Initial => 20,
223 Table_Increment => 100,
224 Table_Name => "Make.Bad_Compilation");
225 -- Full name of all the source files for which compilation fails
226
227 Do_Compile_Step : Boolean := True;
228 Do_Bind_Step : Boolean := True;
229 Do_Link_Step : Boolean := True;
230 -- Flags to indicate what step should be executed. Can be set to False
231 -- with the switches -c, -b and -l. These flags are reset to True for
232 -- each invocation of procedure Gnatmake.
233
234 CodePeer_Mode_String : aliased String := "-P";
235
236 No_Shared_Switch : aliased Argument_List := (1 .. 0 => null);
237 Bind_Shared : Argument_List_Access := No_Shared_Switch'Access;
238 -- Switch to added in front of gnatbind switches. By default no switch is
239 -- added. Switch "-shared" is added if there is a non-static Library
240 -- Project File.
241
242 Shared_Libgcc : aliased String := "-shared-libgcc";
243
244 No_Shared_Libgcc_Switch : aliased Argument_List := (1 .. 0 => null);
245 Shared_Libgcc_Switch : aliased Argument_List :=
246 (1 => Shared_Libgcc'Access);
247 Link_With_Shared_Libgcc : Argument_List_Access :=
248 No_Shared_Libgcc_Switch'Access;
249
250 procedure Make_Failed (S : String);
251 pragma No_Return (Make_Failed);
252 -- Delete all temp files created by Gnatmake and call Osint.Fail, with the
253 -- parameter S (see osint.ads).
254
255 --------------------------
256 -- Obsolete Executables --
257 --------------------------
258
259 Executable_Obsolete : Boolean := False;
260 -- Executable_Obsolete is initially set to False for each executable,
261 -- and is set to True whenever one of the source of the executable is
262 -- compiled, or has already been compiled for another executable.
263
264 Max_Header : constant := 200;
265 -- This needs a proper comment, it used to say "arbitrary" that's not an
266 -- adequate comment ???
267
268 type Header_Num is range 1 .. Max_Header;
269 -- Header_Num for the hash table Obsoleted below
270
271 function Hash (F : File_Name_Type) return Header_Num;
272 -- Hash function for the hash table Obsoleted below
273
274 package Obsoleted is new System.HTable.Simple_HTable
275 (Header_Num => Header_Num,
276 Element => Boolean,
277 No_Element => False,
278 Key => File_Name_Type,
279 Hash => Hash,
280 Equal => "=");
281 -- A hash table to keep all files that have been compiled, to detect
282 -- if an executable is up to date or not.
283
284 procedure Enter_Into_Obsoleted (F : File_Name_Type);
285 -- Enter a file name, without directory information, into the hash table
286 -- Obsoleted.
287
288 function Is_In_Obsoleted (F : File_Name_Type) return Boolean;
289 -- Check if a file name, without directory information, has already been
290 -- entered into the hash table Obsoleted.
291
292 type Dependency is record
293 This : File_Name_Type;
294 Depends_On : File_Name_Type;
295 end record;
296 -- Components of table Dependencies below
297
298 package Dependencies is new Table.Table (
299 Table_Component_Type => Dependency,
300 Table_Index_Type => Integer,
301 Table_Low_Bound => 1,
302 Table_Initial => 20,
303 Table_Increment => 100,
304 Table_Name => "Make.Dependencies");
305 -- A table to keep dependencies, to be able to decide if an executable
306 -- is obsolete. More explanation needed ???
307
308 ----------------------------
309 -- Arguments and Switches --
310 ----------------------------
311
312 Arguments : Argument_List_Access;
313 -- Used to gather the arguments for invocation of the compiler
314
315 Last_Argument : Natural := 0;
316 -- Last index of arguments in Arguments above
317
318 Dummy_Switch : constant String_Access := new String'("- ");
319 -- Used to initialized Prev_Switch in procedure Check
320
321 procedure Add_Arguments (Args : Argument_List);
322 -- Add arguments to global variable Arguments, increasing its size
323 -- if necessary and adjusting Last_Argument.
324
325 -------------------
326 -- Misc Routines --
327 -------------------
328
329 procedure List_Depend;
330 -- Prints to standard output the list of object dependencies. This list
331 -- can be used directly in a Makefile. A call to Compile_Sources must
332 -- precede the call to List_Depend. Also because this routine uses the
333 -- ALI files that were originally loaded and scanned by Compile_Sources,
334 -- no additional ALI files should be scanned between the two calls (i.e.
335 -- between the call to Compile_Sources and List_Depend.)
336
337 procedure List_Bad_Compilations;
338 -- Prints out the list of all files for which the compilation failed
339
340 Usage_Needed : Boolean := True;
341 -- Flag used to make sure Makeusg is call at most once
342
343 procedure Usage;
344 -- Call Makeusg, if Usage_Needed is True.
345 -- Set Usage_Needed to False.
346
347 procedure Debug_Msg (S : String; N : Name_Id);
348 procedure Debug_Msg (S : String; N : File_Name_Type);
349 procedure Debug_Msg (S : String; N : Unit_Name_Type);
350 -- If Debug.Debug_Flag_W is set outputs string S followed by name N
351
352 -----------------------
353 -- Gnatmake Routines --
354 -----------------------
355
356 subtype Lib_Mark_Type is Byte;
357 -- Used in Mark_Directory
358
359 Ada_Lib_Dir : constant Lib_Mark_Type := 1;
360 -- Used to mark a directory as a GNAT lib dir
361
362 -- Note that the notion of GNAT lib dir is no longer used. The code related
363 -- to it has not been removed to give an idea on how to use the directory
364 -- prefix marking mechanism.
365
366 -- An Ada library directory is a directory containing ali and object files
367 -- but no source files for the bodies (the specs can be in the same or some
368 -- other directory). These directories are specified in the Gnatmake
369 -- command line with the switch "-Adir" (to specify the spec location -Idir
370 -- cab be used). Gnatmake skips the missing sources whose ali are in Ada
371 -- library directories. For an explanation of why Gnatmake behaves that
372 -- way, see the spec of Make.Compile_Sources. The directory lookup penalty
373 -- is incurred every single time this routine is called.
374
375 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean;
376 -- Get directory prefix of this file and get lib mark stored in name
377 -- table for this directory. Then check if an Ada lib mark has been set.
378
379 procedure Mark_Directory (Dir : String; Mark : Lib_Mark_Type);
380 -- Store the absolute path from Dir in name table and set lib mark as name
381 -- info to identify Ada libraries.
382 --
383 -- If Dir is a relative path, it is relative to the current working
384 -- directory.
385
386 Output_Is_Object : Boolean := True;
387 -- Set to False when using a switch -S for the compiler
388
389 procedure Check_For_S_Switch;
390 -- Set Output_Is_Object to False when the -S switch is used for the
391 -- compiler.
392
393 procedure Process_Multilib;
394 -- Add appropriate --RTS argument to handle multilib
395
396 procedure Compute_Executable
397 (Main_Source_File : File_Name_Type;
398 Executable : out File_Name_Type;
399 Non_Std_Executable : out Boolean);
400 -- Parse the linker switches and project file to compute the name of the
401 -- executable to generate.
402 --
403 -- When the platform expects a specific extension for the generated binary,
404 -- there is a chance that the linker might not use the right name for the
405 -- it. Non_Std_Executable is set to True in this case.
406
407 procedure Compilation_Phase
408 (Main_Source_File : File_Name_Type;
409 Current_Main_Index : Int := 0;
410 Total_Compilation_Failures : in out Natural;
411 Executable : File_Name_Type := No_File;
412 Stop_Compile : out Boolean);
413 -- Build all source files for a given main file
414 --
415 -- Current_Main_Index, if not zero, is the index of the current main unit
416 -- in its source file.
417 --
418 -- Stand_Alone_Libraries is set to True when there are Stand-Alone
419 -- Libraries, so that gnatbind is invoked with the -F switch to force
420 -- checking of elaboration flags.
421 --
422 -- Stop_Compile is set to true if we should not try to compile any more
423 -- of the main units
424
425 procedure Binding_Phase
426 (Main_ALI_File : File_Name_Type);
427 -- Stand_Alone_Libraries should be set to True when there are Stand-Alone
428 -- Libraries, so that gnatbind is invoked with the -F switch to force
429 -- checking of elaboration flags.
430
431 procedure Linking_Phase
432 (Non_Std_Executable : Boolean := False;
433 Executable : File_Name_Type := No_File;
434 Main_ALI_File : File_Name_Type);
435 -- Perform the link of a single executable. The ali file corresponds
436 -- to Main_ALI_File. Executable is the file name of an executable.
437 -- Non_Std_Executable is set to True when there is a possibility that
438 -- the linker will not choose the correct executable file name.
439
440 ----------------------------------------------------
441 -- Compiler, Binder & Linker Data and Subprograms --
442 ----------------------------------------------------
443
444 Gcc : String_Access := Program_Name ("gcc", "gnatmake");
445 Gnatbind : String_Access := Program_Name ("gnatbind", "gnatmake");
446 Gnatlink : String_Access := Program_Name ("gnatlink", "gnatmake");
447 -- Default compiler, binder, linker programs
448
449 Gcc_Path : String_Access :=
450 GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
451 Gnatbind_Path : String_Access :=
452 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
453 Gnatlink_Path : String_Access :=
454 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
455 -- Path for compiler, binder, linker programs, defaulted now for gnatdist.
456 -- Changed later if overridden on command line.
457
458 Comp_Flag : constant String_Access := new String'("-c");
459 Output_Flag : constant String_Access := new String'("-o");
460 Ada_Flag_1 : constant String_Access := new String'("-x");
461 Ada_Flag_2 : constant String_Access := new String'("ada");
462 AdaSCIL_Flag : constant String_Access := new String'("adascil");
463 GNAT_Flag : constant String_Access := new String'("-gnatg");
464 Do_Not_Check_Flag : constant String_Access := new String'("-x");
465
466 Object_Suffix : constant String := Get_Target_Object_Suffix.all;
467
468 Syntax_Only : Boolean := False;
469 -- Set to True when compiling with -gnats
470
471 Output_File_Name_Seen : Boolean := False;
472 -- Set to True after having scanned the file_name for
473 -- switch "-o file_name"
474
475 Object_Directory_Seen : Boolean := False;
476 -- Set to True after having scanned the object directory for
477 -- switch "-D obj_dir".
478
479 Object_Directory_Path : String_Access := null;
480 -- The path name of the object directory, set with switch -D
481
482 type Make_Program_Type is (None, Compiler, Binder, Linker);
483
484 Program_Args : Make_Program_Type := None;
485 -- Used to indicate if we are scanning gnatmake, gcc, gnatbind, or gnatbind
486 -- options within the gnatmake command line. Used in Scan_Make_Arg only,
487 -- but must be global since value preserved from one call to another.
488
489 procedure Add_Switch
490 (S : String_Access;
491 Program : Make_Program_Type;
492 Append_Switch : Boolean := True);
493 procedure Add_Switch
494 (S : String;
495 Program : Make_Program_Type;
496 Append_Switch : Boolean := True);
497 -- Make invokes one of three programs (the compiler, the binder or the
498 -- linker). For the sake of convenience, some program specific switches
499 -- can be passed directly on the gnatmake command line. This procedure
500 -- records these switches so that gnatmake can pass them to the right
501 -- program. S is the switch to be added at the end of the command line
502 -- for Program if Append_Switch is True. If Append_Switch is False S is
503 -- added at the beginning of the command line.
504
505 procedure Check
506 (Source_File : File_Name_Type;
507 The_Args : Argument_List;
508 Lib_File : File_Name_Type;
509 Full_Lib_File : File_Name_Type;
510 Lib_File_Attr : access File_Attributes;
511 Read_Only : Boolean;
512 ALI : out ALI_Id;
513 O_File : out File_Name_Type;
514 O_Stamp : out Time_Stamp_Type);
515 -- Determines whether the library file Lib_File is up-to-date or not. The
516 -- full name (with path information) of the object file corresponding to
517 -- Lib_File is returned in O_File. Its time stamp is saved in O_Stamp.
518 -- ALI is the ALI_Id corresponding to Lib_File. If Lib_File in not
519 -- up-to-date, then the corresponding source file needs to be recompiled.
520 -- In this case ALI = No_ALI_Id.
521 -- Full_Lib_File must be the result of calling Osint.Full_Lib_File_Name on
522 -- Lib_File. Precomputing it saves system calls. Lib_File_Attr is the
523 -- initialized attributes of that file, which is also used to save on
524 -- system calls (it can safely be initialized to Unknown_Attributes).
525
526 procedure Check_Linker_Options
527 (E_Stamp : Time_Stamp_Type;
528 O_File : out File_Name_Type;
529 O_Stamp : out Time_Stamp_Type);
530 -- Checks all linker options for linker files that are newer
531 -- than E_Stamp. If such objects are found, the youngest object
532 -- is returned in O_File and its stamp in O_Stamp.
533 --
534 -- If no obsolete linker files were found, the first missing
535 -- linker file is returned in O_File and O_Stamp is empty.
536 -- Otherwise O_File is No_File.
537
538 procedure Collect_Arguments (Args : Argument_List);
539 -- Collect all arguments for a source to be compiled.
540
541 procedure Display (Program : String; Args : Argument_List);
542 -- Displays Program followed by the arguments in Args if variable
543 -- Display_Executed_Programs is set. The lower bound of Args must be 1.
544
545 procedure Report_Compilation_Failed;
546 pragma No_Return (Report_Compilation_Failed);
547 -- Delete all temporary files and fail graciously
548
549 -----------------
550 -- Mapping files
551 -----------------
552
553 type Temp_Path_Names is array (Positive range <>) of Path_Name_Type;
554 type Temp_Path_Ptr is access Temp_Path_Names;
555
556 type Free_File_Indexes is array (Positive range <>) of Positive;
557 type Free_Indexes_Ptr is access Free_File_Indexes;
558
559 type Mapping_File_Data is record
560 Mapping_File_Names : Temp_Path_Ptr;
561 -- The name ids of the temporary mapping files used. This is indexed
562 -- on the maximum number of compilation processes we will be spawning
563 -- (-j parameter)
564
565 Last_Mapping_File_Names : Natural;
566 -- Index of the last mapping file created for this project
567
568 Free_Mapping_File_Indexes : Free_Indexes_Ptr;
569 -- Indexes in Mapping_File_Names of the mapping file names that can be
570 -- reused for subsequent compilations.
571
572 Last_Free_Indexes : Natural;
573 -- Number of mapping files that can be reused
574 end record;
575 -- Information necessary when compiling a project
576
577 The_Mapping_Files : Mapping_File_Data;
578
579 Gnatmake_Mapping_File : String_Access := null;
580 -- The path name of a mapping file specified by switch -C=
581
582 procedure Init_Mapping_File (File_Index : out Natural);
583 -- Create a new mapping file or reuse one already created.
584
585 package Temp_File_Paths is new Table.Table
586 (Table_Component_Type => Path_Name_Type,
587 Table_Index_Type => Natural,
588 Table_Low_Bound => 1,
589 Table_Initial => 4,
590 Table_Increment => 100,
591 Table_Name => "Make.Temp_File_Paths",
592 Release_Threshold => 0);
593
594 procedure Record_Temp_File (Path : Path_Name_Type);
595 -- Record the path of a temporary file, so that it can be deleted at the
596 -- end of execution of gnatmake.
597
598 procedure Record_Temp_File (Path : Path_Name_Type) is
599 begin
600 for J in 1 .. Temp_File_Paths.Last loop
601 if Temp_File_Paths.Table (J) = Path then
602 return;
603 end if;
604 end loop;
605
606 Temp_File_Paths.Append (Path);
607 end Record_Temp_File;
608
609 -------------------------------------------------
610 -- Subprogram declarations moved from the spec --
611 -------------------------------------------------
612
613 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List);
614 -- Binds ALI_File. Args are the arguments to pass to the binder.
615 -- Args must have a lower bound of 1.
616
617 -- If a compilation, bind or link failed one of the following 3 exceptions
618 -- is raised. These need to be handled by the calling routines.
619
620 procedure Compile_Sources
621 (Main_Source : File_Name_Type;
622 Args : Argument_List;
623 First_Compiled_File : out File_Name_Type;
624 Most_Recent_Obj_File : out File_Name_Type;
625 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
626 Main_Unit : out Boolean;
627 Compilation_Failures : out Natural;
628 Main_Index : Int := 0;
629 Check_Readonly_Files : Boolean := False;
630 Do_Not_Execute : Boolean := False;
631 Force_Compilations : Boolean := False;
632 Keep_Going : Boolean := False;
633 In_Place_Mode : Boolean := False;
634 Initialize_ALI_Data : Boolean := True;
635 Max_Process : Positive := 1);
636 -- Compile_Sources will recursively compile all the sources needed by
637 -- Main_Source. Before calling this routine make sure Namet has been
638 -- initialized. This routine can be called repeatedly with different
639 -- Main_Source file as long as all the source (-I flags), library
640 -- (-B flags) and ada library (-A flags) search paths between calls are
641 -- *exactly* the same. The default directory must also be the same.
642 --
643 -- Args contains the arguments to use during the compilations.
644 -- The lower bound of Args must be 1.
645 --
646 -- First_Compiled_File is set to the name of the first file that is
647 -- compiled or that needs to be compiled. This is set to No_Name if no
648 -- compilations were needed.
649 --
650 -- Most_Recent_Obj_File is set to the full name of the most recent
651 -- object file found when no compilations are needed, that is when
652 -- First_Compiled_File is set to No_Name. When First_Compiled_File
653 -- is set then Most_Recent_Obj_File is set to No_Name.
654 --
655 -- Most_Recent_Obj_Stamp is the time stamp of Most_Recent_Obj_File.
656 --
657 -- Main_Unit is set to True if Main_Source can be a main unit.
658 -- If Do_Not_Execute is False and First_Compiled_File /= No_Name
659 -- the value of Main_Unit is always False.
660 -- Is this used any more??? It is certainly not used by gnatmake???
661 --
662 -- Compilation_Failures is a count of compilation failures. This count
663 -- is used to extract compilation failure reports with Extract_Failure.
664 --
665 -- Main_Index, when not zero, is the index of the main unit in source
666 -- file Main_Source which is a multi-unit source.
667 -- Zero indicates that Main_Source is a single unit source file.
668 --
669 -- Check_Readonly_Files set it to True to compile source files
670 -- which library files are read-only. When compiling GNAT predefined
671 -- files the "-gnatg" flag is used.
672 --
673 -- Do_Not_Execute set it to True to find out the first source that
674 -- needs to be recompiled, but without recompiling it. This file is
675 -- saved in First_Compiled_File.
676 --
677 -- Force_Compilations forces all compilations no matter what but
678 -- recompiles read-only files only if Check_Readonly_Files
679 -- is set.
680 --
681 -- Keep_Going when True keep compiling even in the presence of
682 -- compilation errors.
683 --
684 -- In_Place_Mode when True save library/object files in their object
685 -- directory if they already exist; otherwise, in the source directory.
686 --
687 -- Initialize_ALI_Data set it to True when you want to initialize ALI
688 -- data-structures. This is what you should do most of the time.
689 -- (especially the first time around when you call this routine).
690 -- This parameter is set to False to preserve previously recorded
691 -- ALI file data.
692 --
693 -- Max_Process is the maximum number of processes that should be spawned
694 -- to carry out compilations.
695 --
696 -- Flags in Package Opt Affecting Compile_Sources
697 -- -----------------------------------------------
698 --
699 -- Check_Object_Consistency set it to False to omit all consistency
700 -- checks between an .ali file and its corresponding object file.
701 -- When this flag is set to true, every time an .ali is read,
702 -- package Osint checks that the corresponding object file
703 -- exists and is more recent than the .ali.
704 --
705 -- Use of Name Table Info
706 -- ----------------------
707 --
708 -- All file names manipulated by Compile_Sources are entered into the
709 -- Names table. The Byte field of a source file is used to mark it.
710 --
711 -- Calling Compile_Sources Several Times
712 -- -------------------------------------
713 --
714 -- Upon return from Compile_Sources all the ALI data structures are left
715 -- intact for further browsing. HOWEVER upon entry to this routine ALI
716 -- data structures are re-initialized if parameter Initialize_ALI_Data
717 -- above is set to true. Typically this is what you want the first time
718 -- you call Compile_Sources. You should not load an ali file, call this
719 -- routine with flag Initialize_ALI_Data set to True and then expect
720 -- that ALI information to be around after the call. Note that the first
721 -- time you call Compile_Sources you better set Initialize_ALI_Data to
722 -- True unless you have called Initialize_ALI yourself.
723 --
724 -- Compile_Sources ALGORITHM : Compile_Sources (Main_Source)
725 -- -------------------------
726 --
727 -- 1. Insert Main_Source in a Queue (Q) and mark it.
728 --
729 -- 2. Let unit.adb be the file at the head of the Q. If unit.adb is
730 -- missing but its corresponding ali file is in an Ada library directory
731 -- (see below) then, remove unit.adb from the Q and goto step 4.
732 -- Otherwise, look at the files under the D (dependency) section of
733 -- unit.ali. If unit.ali does not exist or some of the time stamps do
734 -- not match, (re)compile unit.adb.
735 --
736 -- An Ada library directory is a directory containing Ada specs, ali
737 -- and object files but no source files for the bodies. An Ada library
738 -- directory is communicated to gnatmake by means of some switch so that
739 -- gnatmake can skip the sources whole ali are in that directory.
740 -- There are two reasons for skipping the sources in this case. Firstly,
741 -- Ada libraries typically come without full sources but binding and
742 -- linking against those libraries is still possible. Secondly, it would
743 -- be very wasteful for gnatmake to systematically check the consistency
744 -- of every external Ada library used in a program. The binder is
745 -- already in charge of catching any potential inconsistencies.
746 --
747 -- 3. Look into the W section of unit.ali and insert into the Q all
748 -- unmarked source files. Mark all files newly inserted in the Q.
749 -- Specifically, assuming that the W section looks like
750 --
751 -- W types%s types.adb types.ali
752 -- W unchecked_deallocation%s
753 -- W xref_tab%s xref_tab.adb xref_tab.ali
754 --
755 -- Then xref_tab.adb and types.adb are inserted in the Q if they are not
756 -- already marked.
757 -- Note that there is no file listed under W unchecked_deallocation%s
758 -- so no generic body should ever be explicitly compiled (unless the
759 -- Main_Source at the start was a generic body).
760 --
761 -- 4. Repeat steps 2 and 3 above until the Q is empty
762 --
763 -- Note that the above algorithm works because the units withed in
764 -- subunits are transitively included in the W section (with section) of
765 -- the main unit. Likewise the withed units in a generic body needed
766 -- during a compilation are also transitively included in the W section
767 -- of the originally compiled file.
768
769 procedure Link
770 (ALI_File : File_Name_Type;
771 Args : Argument_List;
772 Success : out Boolean);
773 -- Links ALI_File. Args are the arguments to pass to the linker.
774 -- Args must have a lower bound of 1. Success indicates if the link
775 -- succeeded or not.
776
777 Gnatmake_Switch_Found : Boolean := False;
778
779 procedure Scan_Make_Arg (Argv : String);
780 -- Scan make arguments. Argv is a single argument to be processed.
781
782 -------------------
783 -- Add_Arguments --
784 -------------------
785
786 procedure Add_Arguments (Args : Argument_List) is
787 begin
788 if Arguments = null then
789 Arguments := new Argument_List (1 .. Args'Length + 10);
790
791 else
792 while Last_Argument + Args'Length > Arguments'Last loop
793 declare
794 New_Arguments : constant Argument_List_Access :=
795 new Argument_List (1 .. Arguments'Last * 2);
796 begin
797 New_Arguments (1 .. Last_Argument) :=
798 Arguments (1 .. Last_Argument);
799 Arguments := New_Arguments;
800 end;
801 end loop;
802 end if;
803
804 Arguments (Last_Argument + 1 .. Last_Argument + Args'Length) := Args;
805 Last_Argument := Last_Argument + Args'Length;
806 end Add_Arguments;
807
808 ----------------------------
809 -- Add_Library_Search_Dir --
810 ----------------------------
811
812 procedure Add_Library_Search_Dir (Path : String) is
813 begin
814 Add_Lib_Search_Dir (Normalize_Pathname (Path));
815 end Add_Library_Search_Dir;
816
817 ---------------------------
818 -- Add_Source_Search_Dir --
819 ---------------------------
820
821 procedure Add_Source_Search_Dir (Path : String) is
822 begin
823 Add_Src_Search_Dir (Normalize_Pathname (Path));
824 end Add_Source_Search_Dir;
825
826 ----------------
827 -- Add_Switch --
828 ----------------
829
830 procedure Add_Switch
831 (S : String_Access;
832 Program : Make_Program_Type;
833 Append_Switch : Boolean := True)
834 is
835 generic
836 with package T is new Table.Table (<>);
837 procedure Generic_Position (New_Position : out Integer);
838 -- Generic procedure that chooses a position for S in T at the
839 -- beginning or the end, depending on the boolean Append_Switch.
840 -- Calling this procedure may expand the table.
841
842 ----------------------
843 -- Generic_Position --
844 ----------------------
845
846 procedure Generic_Position (New_Position : out Integer) is
847 begin
848 T.Increment_Last;
849
850 if Append_Switch then
851 New_Position := Integer (T.Last);
852 else
853 for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
854 T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
855 end loop;
856
857 New_Position := Integer (T.First);
858 end if;
859 end Generic_Position;
860
861 procedure Gcc_Switches_Pos is new Generic_Position (Gcc_Switches);
862 procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
863 procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
864
865 New_Position : Integer;
866
867 -- Start of processing for Add_Switch
868
869 begin
870 case Program is
871 when Compiler =>
872 Gcc_Switches_Pos (New_Position);
873 Gcc_Switches.Table (New_Position) := S;
874
875 when Binder =>
876 Binder_Switches_Pos (New_Position);
877 Binder_Switches.Table (New_Position) := S;
878
879 when Linker =>
880 Linker_Switches_Pos (New_Position);
881 Linker_Switches.Table (New_Position) := S;
882
883 when None =>
884 raise Program_Error;
885 end case;
886 end Add_Switch;
887
888 procedure Add_Switch
889 (S : String;
890 Program : Make_Program_Type;
891 Append_Switch : Boolean := True)
892 is
893 begin
894 Add_Switch (S => new String'(S),
895 Program => Program,
896 Append_Switch => Append_Switch);
897 end Add_Switch;
898
899 ----------
900 -- Bind --
901 ----------
902
903 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List) is
904 Bind_Args : Argument_List (1 .. Args'Last + 2);
905 Bind_Last : Integer;
906 Success : Boolean;
907
908 begin
909 pragma Assert (Args'First = 1);
910
911 -- Optimize the simple case where the gnatbind command line looks like
912 -- gnatbind -aO. -I- file.ali
913 -- into
914 -- gnatbind file.adb
915
916 if Args'Length = 2
917 and then Args (Args'First).all = "-aO" & Normalized_CWD
918 and then Args (Args'Last).all = "-I-"
919 and then ALI_File = Strip_Directory (ALI_File)
920 then
921 Bind_Last := Args'First - 1;
922
923 else
924 Bind_Last := Args'Last;
925 Bind_Args (Args'Range) := Args;
926 end if;
927
928 -- It is completely pointless to re-check source file time stamps. This
929 -- has been done already by gnatmake
930
931 Bind_Last := Bind_Last + 1;
932 Bind_Args (Bind_Last) := Do_Not_Check_Flag;
933
934 Get_Name_String (ALI_File);
935
936 Bind_Last := Bind_Last + 1;
937 Bind_Args (Bind_Last) := new String'(Name_Buffer (1 .. Name_Len));
938
939 GNAT.OS_Lib.Normalize_Arguments (Bind_Args (Args'First .. Bind_Last));
940
941 Display (Gnatbind.all, Bind_Args (Args'First .. Bind_Last));
942
943 if Gnatbind_Path = null then
944 Make_Failed ("error, unable to locate " & Gnatbind.all);
945 end if;
946
947 GNAT.OS_Lib.Spawn
948 (Gnatbind_Path.all, Bind_Args (Args'First .. Bind_Last), Success);
949
950 if not Success then
951 Make_Failed ("*** bind failed.");
952 end if;
953 end Bind;
954
955 -----------
956 -- Check --
957 -----------
958
959 procedure Check
960 (Source_File : File_Name_Type;
961 The_Args : Argument_List;
962 Lib_File : File_Name_Type;
963 Full_Lib_File : File_Name_Type;
964 Lib_File_Attr : access File_Attributes;
965 Read_Only : Boolean;
966 ALI : out ALI_Id;
967 O_File : out File_Name_Type;
968 O_Stamp : out Time_Stamp_Type)
969 is
970 function First_New_Spec (A : ALI_Id) return File_Name_Type;
971 -- Looks in the with table entries of A and returns the spec file name
972 -- of the first withed unit (subprogram) for which no spec existed when
973 -- A was generated but for which there exists one now, implying that A
974 -- is now obsolete. If no such unit is found No_File is returned.
975 -- Otherwise the spec file name of the unit is returned.
976 --
977 -- **WARNING** in the event of Uname format modifications, one *MUST*
978 -- make sure this function is also updated.
979 --
980 -- Note: This function should really be in ali.adb and use Uname
981 -- services, but this causes the whole compiler to be dragged along
982 -- for gnatbind and gnatmake.
983
984 --------------------
985 -- First_New_Spec --
986 --------------------
987
988 function First_New_Spec (A : ALI_Id) return File_Name_Type is
989 Spec_File_Name : File_Name_Type := No_File;
990
991 function New_Spec (Uname : Unit_Name_Type) return Boolean;
992 -- Uname is the name of the spec or body of some ada unit. This
993 -- function returns True if the Uname is the name of a body which has
994 -- a spec not mentioned in ALI file A. If True is returned
995 -- Spec_File_Name above is set to the name of this spec file.
996
997 --------------
998 -- New_Spec --
999 --------------
1000
1001 function New_Spec (Uname : Unit_Name_Type) return Boolean is
1002 Spec_Name : Unit_Name_Type;
1003 File_Name : File_Name_Type;
1004
1005 begin
1006 -- Test whether Uname is the name of a body unit (i.e. ends
1007 -- with %b).
1008
1009 Get_Name_String (Uname);
1010 pragma
1011 Assert (Name_Len > 2 and then Name_Buffer (Name_Len - 1) = '%');
1012
1013 if Name_Buffer (Name_Len) /= 'b' then
1014 return False;
1015 end if;
1016
1017 -- Convert unit name into spec name
1018
1019 -- ??? this code seems dubious in presence of pragma
1020 -- Source_File_Name since there is no more direct relationship
1021 -- between unit name and file name.
1022
1023 -- ??? Further, what about alternative subunit naming
1024
1025 Name_Buffer (Name_Len) := 's';
1026 Spec_Name := Name_Find;
1027 File_Name := Get_File_Name (Spec_Name, Subunit => False);
1028
1029 -- Look if File_Name is mentioned in A's sdep list.
1030 -- If not look if the file exists. If it does return True.
1031
1032 for D in
1033 ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep
1034 loop
1035 if Sdep.Table (D).Sfile = File_Name then
1036 return False;
1037 end if;
1038 end loop;
1039
1040 if Full_Source_Name (File_Name) /= No_File then
1041 Spec_File_Name := File_Name;
1042 return True;
1043 end if;
1044
1045 return False;
1046 end New_Spec;
1047
1048 -- Start of processing for First_New_Spec
1049
1050 begin
1051 U_Chk : for U in
1052 ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit
1053 loop
1054 exit U_Chk when Units.Table (U).Utype = Is_Body_Only
1055 and then New_Spec (Units.Table (U).Uname);
1056
1057 for W in Units.Table (U).First_With
1058 ..
1059 Units.Table (U).Last_With
1060 loop
1061 exit U_Chk when
1062 Withs.Table (W).Afile /= No_File
1063 and then New_Spec (Withs.Table (W).Uname);
1064 end loop;
1065 end loop U_Chk;
1066
1067 return Spec_File_Name;
1068 end First_New_Spec;
1069
1070 ---------------------------------
1071 -- Data declarations for Check --
1072 ---------------------------------
1073
1074 Full_Obj_File : File_Name_Type;
1075 -- Full name of the object file corresponding to Lib_File
1076
1077 Lib_Stamp : Time_Stamp_Type;
1078 -- Time stamp of the current ada library file
1079
1080 Obj_Stamp : Time_Stamp_Type;
1081 -- Time stamp of the current object file
1082
1083 Modified_Source : File_Name_Type;
1084 -- The first source in Lib_File whose current time stamp differs from
1085 -- that stored in Lib_File.
1086
1087 New_Spec : File_Name_Type;
1088 -- If Lib_File contains in its W (with) section a body (for a
1089 -- subprogram) for which there exists a spec, and the spec did not
1090 -- appear in the Sdep section of Lib_File, New_Spec contains the file
1091 -- name of this new spec.
1092
1093 Source_Name : File_Name_Type;
1094 Text : Text_Buffer_Ptr;
1095
1096 First_Arg : Arg_Id;
1097 -- Index of the first argument in Args.Table for a given unit
1098
1099 Last_Arg : Arg_Id;
1100 -- Index of the last argument in Args.Table for a given unit
1101
1102 Arg : Arg_Id := Arg_Id'First;
1103 -- Current index in Args.Table for a given unit (init to stop warning)
1104
1105 Number_Of_Switches : Natural;
1106 -- Number of switches recorded for a given unit
1107
1108 Prev_Switch : String_Access;
1109 -- Previous switch processed
1110
1111 Switch_Found : Boolean;
1112 -- True if a given switch has been found
1113
1114 begin
1115 pragma Assert (Lib_File /= No_File);
1116
1117 -- If ALI file is read-only, temporarily set Check_Object_Consistency to
1118 -- False. We don't care if the object file is not there (presumably a
1119 -- library will be used for linking.)
1120
1121 if Read_Only then
1122 declare
1123 Saved_Check_Object_Consistency : constant Boolean :=
1124 Check_Object_Consistency;
1125 begin
1126 Check_Object_Consistency := False;
1127 Text := Read_Library_Info_From_Full (Full_Lib_File, Lib_File_Attr);
1128 Check_Object_Consistency := Saved_Check_Object_Consistency;
1129 end;
1130
1131 else
1132 Text := Read_Library_Info_From_Full (Full_Lib_File, Lib_File_Attr);
1133 end if;
1134
1135 Full_Obj_File := Full_Object_File_Name;
1136 Lib_Stamp := Current_Library_File_Stamp;
1137 Obj_Stamp := Current_Object_File_Stamp;
1138
1139 if Full_Lib_File = No_File then
1140 Verbose_Msg
1141 (Lib_File,
1142 "being checked ...",
1143 Prefix => " ",
1144 Minimum_Verbosity => Opt.Medium);
1145 else
1146 Verbose_Msg
1147 (Full_Lib_File,
1148 "being checked ...",
1149 Prefix => " ",
1150 Minimum_Verbosity => Opt.Medium);
1151 end if;
1152
1153 ALI := No_ALI_Id;
1154 O_File := Full_Obj_File;
1155 O_Stamp := Obj_Stamp;
1156
1157 if Text = null then
1158 if Full_Lib_File = No_File then
1159 Verbose_Msg (Lib_File, "missing.");
1160
1161 elsif Obj_Stamp (Obj_Stamp'First) = ' ' then
1162 Verbose_Msg (Full_Obj_File, "missing.");
1163
1164 else
1165 Verbose_Msg
1166 (Full_Lib_File, "(" & String (Lib_Stamp) & ") newer than",
1167 Full_Obj_File, "(" & String (Obj_Stamp) & ")");
1168 end if;
1169
1170 else
1171 ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
1172 Free (Text);
1173
1174 if ALI = No_ALI_Id then
1175 Verbose_Msg (Full_Lib_File, "incorrectly formatted ALI file");
1176 return;
1177
1178 elsif ALIs.Table (ALI).Ver (1 .. ALIs.Table (ALI).Ver_Len) /=
1179 Verbose_Library_Version
1180 then
1181 Verbose_Msg (Full_Lib_File, "compiled with old GNAT version");
1182 ALI := No_ALI_Id;
1183 return;
1184 end if;
1185
1186 -- Don't take ALI file into account if it was generated with errors
1187
1188 if ALIs.Table (ALI).Compile_Errors then
1189 Verbose_Msg (Full_Lib_File, "had errors, must be recompiled");
1190 ALI := No_ALI_Id;
1191 return;
1192 end if;
1193
1194 -- Don't take ALI file into account if no object was generated
1195
1196 if Operating_Mode /= Check_Semantics
1197 and then ALIs.Table (ALI).No_Object
1198 then
1199 Verbose_Msg (Full_Lib_File, "has no corresponding object");
1200 ALI := No_ALI_Id;
1201 return;
1202 end if;
1203
1204 -- When compiling with -gnatc, don't take ALI file into account if
1205 -- it has not been generated for the current source, for example if
1206 -- it has been generated for the spec, but we are compiling the body.
1207
1208 if Operating_Mode = Check_Semantics then
1209 declare
1210 File_Name : String := Get_Name_String (Source_File);
1211 OK : Boolean := False;
1212
1213 begin
1214 -- In the ALI file, the source file names are in canonical case
1215
1216 Canonical_Case_File_Name (File_Name);
1217
1218 for U in ALIs.Table (ALI).First_Unit ..
1219 ALIs.Table (ALI).Last_Unit
1220 loop
1221 OK := Get_Name_String (Units.Table (U).Sfile) = File_Name;
1222 exit when OK;
1223 end loop;
1224
1225 if not OK then
1226 Verbose_Msg
1227 (Full_Lib_File, "not generated for the same source");
1228 ALI := No_ALI_Id;
1229 return;
1230 end if;
1231 end;
1232 end if;
1233
1234 -- Check for matching compiler switches if needed
1235
1236 if Check_Switches then
1237
1238 -- First, collect all the switches
1239
1240 Collect_Arguments (The_Args);
1241 Prev_Switch := Dummy_Switch;
1242 Get_Name_String (ALIs.Table (ALI).Sfile);
1243 Switches_To_Check.Set_Last (0);
1244
1245 for J in 1 .. Last_Argument loop
1246
1247 -- Skip -c, -I and -o switches
1248
1249 if Arguments (J) (1) = '-'
1250 and then Arguments (J) (2) /= 'c'
1251 and then Arguments (J) (2) /= 'o'
1252 and then Arguments (J) (2) /= 'I'
1253 then
1254 Normalize_Compiler_Switches
1255 (Arguments (J).all,
1256 Normalized_Switches,
1257 Last_Norm_Switch);
1258
1259 for K in 1 .. Last_Norm_Switch loop
1260 Switches_To_Check.Increment_Last;
1261 Switches_To_Check.Table (Switches_To_Check.Last) :=
1262 Normalized_Switches (K);
1263 end loop;
1264 end if;
1265 end loop;
1266
1267 First_Arg := Units.Table (ALIs.Table (ALI).First_Unit).First_Arg;
1268 Last_Arg := Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg;
1269
1270 for J in 1 .. Switches_To_Check.Last loop
1271
1272 -- Comparing switches is delicate because gcc reorders a number
1273 -- of switches, according to lang-specs.h, but gnatmake doesn't
1274 -- have sufficient knowledge to perform the same reordering.
1275 -- Instead, we ignore orders between different "first letter"
1276 -- switches, but keep orders between same switches, e.g -O -O2
1277 -- is different than -O2 -O, but -g -O is equivalent to -O -g.
1278
1279 if Switches_To_Check.Table (J) (2) /= Prev_Switch (2) or else
1280 (Prev_Switch'Length >= 6 and then
1281 Prev_Switch (2 .. 5) = "gnat" and then
1282 Switches_To_Check.Table (J)'Length >= 6 and then
1283 Switches_To_Check.Table (J) (2 .. 5) = "gnat" and then
1284 Prev_Switch (6) /= Switches_To_Check.Table (J) (6))
1285 then
1286 Prev_Switch := Switches_To_Check.Table (J);
1287 Arg := First_Arg;
1288 end if;
1289
1290 Switch_Found := False;
1291
1292 for K in Arg .. Last_Arg loop
1293 if
1294 Switches_To_Check.Table (J).all = Args.Table (K).all
1295 then
1296 Arg := K + 1;
1297 Switch_Found := True;
1298 exit;
1299 end if;
1300 end loop;
1301
1302 if not Switch_Found then
1303 if Verbose_Mode then
1304 Verbose_Msg (ALIs.Table (ALI).Sfile,
1305 "switch mismatch """ &
1306 Switches_To_Check.Table (J).all & '"');
1307 end if;
1308
1309 ALI := No_ALI_Id;
1310 return;
1311 end if;
1312 end loop;
1313
1314 Number_Of_Switches := Natural (Last_Arg - First_Arg + 1);
1315
1316 -- Do not count the multilib switches reinstated by the compiler
1317 -- according to the lang-specs.h.settings.
1318
1319 for K in First_Arg .. Last_Arg loop
1320 if Args.Table (K).all = "-mrtp" then
1321 Number_Of_Switches := Number_Of_Switches - 1;
1322 end if;
1323 end loop;
1324
1325 if Switches_To_Check.Last /= Number_Of_Switches then
1326 if Verbose_Mode then
1327 Verbose_Msg (ALIs.Table (ALI).Sfile,
1328 "different number of switches");
1329
1330 for K in First_Arg .. Last_Arg loop
1331 Write_Str (Args.Table (K).all);
1332 Write_Char (' ');
1333 end loop;
1334
1335 Write_Eol;
1336
1337 for J in 1 .. Switches_To_Check.Last loop
1338 Write_Str (Switches_To_Check.Table (J).all);
1339 Write_Char (' ');
1340 end loop;
1341
1342 Write_Eol;
1343 end if;
1344
1345 ALI := No_ALI_Id;
1346 return;
1347 end if;
1348 end if;
1349
1350 -- Get the source files and their message digests. Note that some
1351 -- sources may be missing if ALI is out-of-date.
1352
1353 Set_Source_Table (ALI);
1354
1355 Modified_Source := Time_Stamp_Mismatch (ALI, Read_Only);
1356
1357 -- To avoid using too much memory when switch -m is used, free the
1358 -- memory allocated for the source file when computing the checksum.
1359
1360 if Minimal_Recompilation then
1361 Sinput.Clear_Source_File_Table;
1362 end if;
1363
1364 if Modified_Source /= No_File then
1365 ALI := No_ALI_Id;
1366
1367 if Verbose_Mode then
1368 Source_Name := Full_Source_Name (Modified_Source);
1369
1370 if Source_Name /= No_File then
1371 Verbose_Msg (Source_Name, "time stamp mismatch");
1372 else
1373 Verbose_Msg (Modified_Source, "missing");
1374 end if;
1375 end if;
1376
1377 else
1378 New_Spec := First_New_Spec (ALI);
1379
1380 if New_Spec /= No_File then
1381 ALI := No_ALI_Id;
1382
1383 if Verbose_Mode then
1384 Source_Name := Full_Source_Name (New_Spec);
1385
1386 if Source_Name /= No_File then
1387 Verbose_Msg (Source_Name, "new spec");
1388 else
1389 Verbose_Msg (New_Spec, "old spec missing");
1390 end if;
1391 end if;
1392
1393 end if;
1394 end if;
1395 end if;
1396 end Check;
1397
1398 ------------------------
1399 -- Check_For_S_Switch --
1400 ------------------------
1401
1402 procedure Check_For_S_Switch is
1403 begin
1404 -- By default, we generate an object file
1405
1406 Output_Is_Object := True;
1407
1408 for Arg in 1 .. Last_Argument loop
1409 if Arguments (Arg).all = "-S" then
1410 Output_Is_Object := False;
1411
1412 elsif Arguments (Arg).all = "-c" then
1413 Output_Is_Object := True;
1414 end if;
1415 end loop;
1416 end Check_For_S_Switch;
1417
1418 --------------------------
1419 -- Check_Linker_Options --
1420 --------------------------
1421
1422 procedure Check_Linker_Options
1423 (E_Stamp : Time_Stamp_Type;
1424 O_File : out File_Name_Type;
1425 O_Stamp : out Time_Stamp_Type)
1426 is
1427 procedure Check_File (File : File_Name_Type);
1428 -- Update O_File and O_Stamp if the given file is younger than E_Stamp
1429 -- and O_Stamp, or if O_File is No_File and File does not exist.
1430
1431 function Get_Library_File (Name : String) return File_Name_Type;
1432 -- Return the full file name including path of a library based
1433 -- on the name specified with the -l linker option, using the
1434 -- Ada object path. Return No_File if no such file can be found.
1435
1436 type Char_Array is array (Natural) of Character;
1437 type Char_Array_Access is access constant Char_Array;
1438
1439 Template : Char_Array_Access;
1440 pragma Import (C, Template, "__gnat_library_template");
1441
1442 ----------------
1443 -- Check_File --
1444 ----------------
1445
1446 procedure Check_File (File : File_Name_Type) is
1447 Stamp : Time_Stamp_Type;
1448 Name : File_Name_Type := File;
1449
1450 begin
1451 Get_Name_String (Name);
1452
1453 -- Remove any trailing NUL characters
1454
1455 while Name_Len >= Name_Buffer'First
1456 and then Name_Buffer (Name_Len) = NUL
1457 loop
1458 Name_Len := Name_Len - 1;
1459 end loop;
1460
1461 if Name_Len = 0 then
1462 return;
1463
1464 elsif Name_Buffer (1) = '-' then
1465
1466 -- Do not check if File is a switch other than "-l"
1467
1468 if Name_Buffer (2) /= 'l' then
1469 return;
1470 end if;
1471
1472 -- The argument is a library switch, get actual name. It
1473 -- is necessary to make a copy of the relevant part of
1474 -- Name_Buffer as Get_Library_Name uses Name_Buffer as well.
1475
1476 declare
1477 Base_Name : constant String := Name_Buffer (3 .. Name_Len);
1478
1479 begin
1480 Name := Get_Library_File (Base_Name);
1481 end;
1482
1483 if Name = No_File then
1484 return;
1485 end if;
1486 end if;
1487
1488 Stamp := File_Stamp (Name);
1489
1490 -- Find the youngest object file that is younger than the
1491 -- executable. If no such file exist, record the first object
1492 -- file that is not found.
1493
1494 if (O_Stamp < Stamp and then E_Stamp < Stamp)
1495 or else (O_File = No_File and then Stamp (Stamp'First) = ' ')
1496 then
1497 O_Stamp := Stamp;
1498 O_File := Name;
1499
1500 -- Strip the trailing NUL if present
1501
1502 Get_Name_String (O_File);
1503
1504 if Name_Buffer (Name_Len) = NUL then
1505 Name_Len := Name_Len - 1;
1506 O_File := Name_Find;
1507 end if;
1508 end if;
1509 end Check_File;
1510
1511 ----------------------
1512 -- Get_Library_Name --
1513 ----------------------
1514
1515 -- See comments in a-adaint.c about template syntax
1516
1517 function Get_Library_File (Name : String) return File_Name_Type is
1518 File : File_Name_Type := No_File;
1519
1520 begin
1521 Name_Len := 0;
1522
1523 for Ptr in Template'Range loop
1524 case Template (Ptr) is
1525 when '*' =>
1526 Add_Str_To_Name_Buffer (Name);
1527
1528 when ';' =>
1529 File := Full_Lib_File_Name (Name_Find);
1530 exit when File /= No_File;
1531 Name_Len := 0;
1532
1533 when NUL =>
1534 exit;
1535
1536 when others =>
1537 Add_Char_To_Name_Buffer (Template (Ptr));
1538 end case;
1539 end loop;
1540
1541 -- The for loop exited because the end of the template
1542 -- was reached. File contains the last possible file name
1543 -- for the library.
1544
1545 if File = No_File and then Name_Len > 0 then
1546 File := Full_Lib_File_Name (Name_Find);
1547 end if;
1548
1549 return File;
1550 end Get_Library_File;
1551
1552 -- Start of processing for Check_Linker_Options
1553
1554 begin
1555 O_File := No_File;
1556 O_Stamp := (others => ' ');
1557
1558 -- Process linker options from the ALI files
1559
1560 for Opt in 1 .. Linker_Options.Last loop
1561 Check_File (File_Name_Type (Linker_Options.Table (Opt).Name));
1562 end loop;
1563
1564 -- Process options given on the command line
1565
1566 for Opt in Linker_Switches.First .. Linker_Switches.Last loop
1567
1568 -- Check if the previous Opt has one of the two switches
1569 -- that take an extra parameter. (See GCC manual.)
1570
1571 if Opt = Linker_Switches.First
1572 or else (Linker_Switches.Table (Opt - 1).all /= "-u"
1573 and then
1574 Linker_Switches.Table (Opt - 1).all /= "-Xlinker"
1575 and then
1576 Linker_Switches.Table (Opt - 1).all /= "-L")
1577 then
1578 Name_Len := 0;
1579 Add_Str_To_Name_Buffer (Linker_Switches.Table (Opt).all);
1580 Check_File (Name_Find);
1581 end if;
1582 end loop;
1583 end Check_Linker_Options;
1584
1585 -----------------------
1586 -- Collect_Arguments --
1587 -----------------------
1588
1589 procedure Collect_Arguments (Args : Argument_List) is
1590 begin
1591 Last_Argument := 0;
1592 Add_Arguments (Args);
1593
1594 -- Set Output_Is_Object, depending if there is a -S switch.
1595 -- If the bind step is not performed, and there is a -S switch,
1596 -- then we will not check for a valid object file.
1597
1598 Check_For_S_Switch;
1599 end Collect_Arguments;
1600
1601 ---------------------
1602 -- Compile_Sources --
1603 ---------------------
1604
1605 procedure Compile_Sources
1606 (Main_Source : File_Name_Type;
1607 Args : Argument_List;
1608 First_Compiled_File : out File_Name_Type;
1609 Most_Recent_Obj_File : out File_Name_Type;
1610 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
1611 Main_Unit : out Boolean;
1612 Compilation_Failures : out Natural;
1613 Main_Index : Int := 0;
1614 Check_Readonly_Files : Boolean := False;
1615 Do_Not_Execute : Boolean := False;
1616 Force_Compilations : Boolean := False;
1617 Keep_Going : Boolean := False;
1618 In_Place_Mode : Boolean := False;
1619 Initialize_ALI_Data : Boolean := True;
1620 Max_Process : Positive := 1)
1621 is
1622 Mfile : Natural := No_Mapping_File;
1623 Mapping_File_Arg : String_Access;
1624 -- Info on the mapping file
1625
1626 Need_To_Check_Standard_Library : Boolean :=
1627 (Check_Readonly_Files or Must_Compile)
1628 and not Unique_Compile;
1629
1630 procedure Add_Process
1631 (Pid : Process_Id;
1632 Sfile : File_Name_Type;
1633 Afile : File_Name_Type;
1634 Uname : Unit_Name_Type;
1635 Full_Lib_File : File_Name_Type;
1636 Lib_File_Attr : File_Attributes;
1637 Mfile : Natural := No_Mapping_File);
1638 -- Adds process Pid to the current list of outstanding compilation
1639 -- processes and record the full name of the source file Sfile that
1640 -- we are compiling, the name of its library file Afile and the
1641 -- name of its unit Uname. If Mfile is not equal to No_Mapping_File,
1642 -- it is the index of the mapping file used during compilation in the
1643 -- array The_Mapping_File_Names.
1644
1645 procedure Await_Compile
1646 (Data : out Compilation_Data;
1647 OK : out Boolean);
1648 -- Awaits that an outstanding compilation process terminates. When it
1649 -- does set Data to the information registered for the corresponding
1650 -- call to Add_Process. Note that this time stamp can be used to check
1651 -- whether the compilation did generate an object file. OK is set to
1652 -- True if the compilation succeeded. Data could be No_Compilation_Data
1653 -- if there was no compilation to wait for.
1654
1655 function Bad_Compilation_Count return Natural;
1656 -- Returns the number of compilation failures
1657
1658 procedure Check_Standard_Library;
1659 -- Check if s-stalib.adb needs to be compiled
1660
1661 procedure Collect_Arguments_And_Compile
1662 (Full_Source_File : File_Name_Type;
1663 Lib_File : File_Name_Type;
1664 Source_Index : Int;
1665 Pid : out Process_Id;
1666 Process_Created : out Boolean);
1667 -- Collect arguments from project file (if any) and compile. If no
1668 -- compilation was attempted, Processed_Created is set to False, and the
1669 -- value of Pid is unknown.
1670
1671 function Compile
1672 (S : File_Name_Type;
1673 L : File_Name_Type;
1674 Source_Index : Int;
1675 Args : Argument_List) return Process_Id;
1676 -- Compiles S using Args. If S is a GNAT predefined source "-gnatg" is
1677 -- added to Args. Non blocking call. L corresponds to the expected
1678 -- library file name. Process_Id of the process spawned to execute the
1679 -- compilation.
1680
1681 package Good_ALI is new Table.Table (
1682 Table_Component_Type => ALI_Id,
1683 Table_Index_Type => Natural,
1684 Table_Low_Bound => 1,
1685 Table_Initial => 50,
1686 Table_Increment => 100,
1687 Table_Name => "Make.Good_ALI");
1688 -- Contains the set of valid ALI files that have not yet been scanned
1689
1690 function Good_ALI_Present return Boolean;
1691 -- Returns True if any ALI file was recorded in the previous set
1692
1693 procedure Get_Mapping_File;
1694 -- Get a mapping file name. If there is one to be reused, reuse it.
1695 -- Otherwise, create a new mapping file.
1696
1697 function Get_Next_Good_ALI return ALI_Id;
1698 -- Returns the next good ALI_Id record
1699
1700 procedure Record_Failure
1701 (File : File_Name_Type;
1702 Unit : Unit_Name_Type;
1703 Found : Boolean := True);
1704 -- Records in the previous table that the compilation for File failed.
1705 -- If Found is False then the compilation of File failed because we
1706 -- could not find it. Records also Unit when possible.
1707
1708 procedure Record_Good_ALI (A : ALI_Id);
1709 -- Records in the previous set the Id of an ALI file
1710
1711 function Must_Exit_Because_Of_Error return Boolean;
1712 -- Return True if there were errors and the user decided to exit in such
1713 -- a case. This waits for any outstanding compilation.
1714
1715 function Start_Compile_If_Possible (Args : Argument_List) return Boolean;
1716 -- Check if there is more work that we can do (i.e. the Queue is non
1717 -- empty). If there is, do it only if we have not yet used up all the
1718 -- available processes.
1719 -- Returns True if we should exit the main loop
1720
1721 procedure Wait_For_Available_Slot;
1722 -- Check if we should wait for a compilation to finish. This is the case
1723 -- if all the available processes are busy compiling sources or there is
1724 -- nothing else to do (that is the Q is empty and there are no good ALIs
1725 -- to process).
1726
1727 procedure Fill_Queue_From_ALI_Files;
1728 -- Check if we recorded good ALI files. If yes process them now in the
1729 -- order in which they have been recorded. There are two occasions in
1730 -- which we record good ali files. The first is in phase 1 when, after
1731 -- scanning an existing ALI file we realize it is up-to-date, the second
1732 -- instance is after a successful compilation.
1733
1734 -----------------
1735 -- Add_Process --
1736 -----------------
1737
1738 procedure Add_Process
1739 (Pid : Process_Id;
1740 Sfile : File_Name_Type;
1741 Afile : File_Name_Type;
1742 Uname : Unit_Name_Type;
1743 Full_Lib_File : File_Name_Type;
1744 Lib_File_Attr : File_Attributes;
1745 Mfile : Natural := No_Mapping_File)
1746 is
1747 OC1 : constant Positive := Outstanding_Compiles + 1;
1748
1749 begin
1750 pragma Assert (OC1 <= Max_Process);
1751 pragma Assert (Pid /= Invalid_Pid);
1752
1753 Running_Compile (OC1) :=
1754 (Pid => Pid,
1755 Full_Source_File => Sfile,
1756 Lib_File => Afile,
1757 Full_Lib_File => Full_Lib_File,
1758 Lib_File_Attr => Lib_File_Attr,
1759 Source_Unit => Uname,
1760 Mapping_File => Mfile);
1761
1762 Outstanding_Compiles := OC1;
1763
1764 end Add_Process;
1765
1766 --------------------
1767 -- Await_Compile --
1768 -------------------
1769
1770 procedure Await_Compile
1771 (Data : out Compilation_Data;
1772 OK : out Boolean)
1773 is
1774 Pid : Process_Id;
1775
1776 begin
1777 pragma Assert (Outstanding_Compiles > 0);
1778
1779 Data := No_Compilation_Data;
1780 OK := False;
1781
1782 Wait_Process (Pid, OK);
1783
1784 if Pid = Invalid_Pid then
1785 return;
1786 end if;
1787
1788 -- Look into the running compilation processes for this PID
1789
1790 for J in Running_Compile'First .. Outstanding_Compiles loop
1791 if Pid = Running_Compile (J).Pid then
1792 Data := Running_Compile (J);
1793 -- If a mapping file was used by this compilation, get its file
1794 -- name for reuse by a subsequent compilation.
1795
1796 if Running_Compile (J).Mapping_File /= No_Mapping_File then
1797 The_Mapping_Files.Last_Free_Indexes :=
1798 The_Mapping_Files.Last_Free_Indexes + 1;
1799 The_Mapping_Files.Free_Mapping_File_Indexes
1800 (The_Mapping_Files.Last_Free_Indexes) :=
1801 Running_Compile (J).Mapping_File;
1802 end if;
1803
1804 -- To actually remove this Pid and related info from
1805 -- Running_Compile replace its entry with the last valid
1806 -- entry in Running_Compile.
1807
1808 if J = Outstanding_Compiles then
1809 null;
1810 else
1811 Running_Compile (J) :=
1812 Running_Compile (Outstanding_Compiles);
1813 end if;
1814
1815 Outstanding_Compiles := Outstanding_Compiles - 1;
1816 exit;
1817 end if;
1818 end loop;
1819
1820 -- If the PID was not found, return with OK set to False
1821
1822 if Data = No_Compilation_Data then
1823 OK := False;
1824 end if;
1825 end Await_Compile;
1826
1827 ---------------------------
1828 -- Bad_Compilation_Count --
1829 ---------------------------
1830
1831 function Bad_Compilation_Count return Natural is
1832 begin
1833 return Bad_Compilation.Last - Bad_Compilation.First + 1;
1834 end Bad_Compilation_Count;
1835
1836 ----------------------------
1837 -- Check_Standard_Library --
1838 ----------------------------
1839
1840 procedure Check_Standard_Library is
1841 begin
1842 Need_To_Check_Standard_Library := False;
1843 Name_Len := 0;
1844
1845 if not Targparm.Suppress_Standard_Library_On_Target then
1846 Add_Str_To_Name_Buffer (Standard_Library_Package_Body_Name);
1847 else
1848 Add_Str_To_Name_Buffer (System_Package_Spec_Name);
1849 end if;
1850
1851 declare
1852 Add_It : Boolean := True;
1853 Sfile : File_Name_Type;
1854
1855 begin
1856 Sfile := Name_Enter;
1857
1858 -- If we have a special runtime, we add the standard library only
1859 -- if we can find it.
1860
1861 if RTS_Switch then
1862 Add_It := Full_Source_Name (Sfile) /= No_File;
1863 end if;
1864
1865 if Add_It then
1866 if not Queue.Insert
1867 ((File => Sfile,
1868 Unit => No_Unit_Name,
1869 Index => 0))
1870 then
1871 if Is_In_Obsoleted (Sfile) then
1872 Executable_Obsolete := True;
1873 end if;
1874 end if;
1875 end if;
1876 end;
1877 end Check_Standard_Library;
1878
1879 -----------------------------------
1880 -- Collect_Arguments_And_Compile --
1881 -----------------------------------
1882
1883 procedure Collect_Arguments_And_Compile
1884 (Full_Source_File : File_Name_Type;
1885 Lib_File : File_Name_Type;
1886 Source_Index : Int;
1887 Pid : out Process_Id;
1888 Process_Created : out Boolean) is
1889 begin
1890 Process_Created := False;
1891
1892 -- If we use mapping file (-P or -C switches), then get one
1893
1894 if Create_Mapping_File then
1895 Get_Mapping_File;
1896 end if;
1897
1898 Pid :=
1899 Compile
1900 (S => Full_Source_File,
1901 L => Lib_File,
1902 Source_Index => Source_Index,
1903 Args => Arguments (1 .. Last_Argument));
1904 Process_Created := True;
1905 end Collect_Arguments_And_Compile;
1906
1907 -------------
1908 -- Compile --
1909 -------------
1910
1911 function Compile
1912 (S : File_Name_Type;
1913 L : File_Name_Type;
1914 Source_Index : Int;
1915 Args : Argument_List) return Process_Id
1916 is
1917 Comp_Args : Argument_List (Args'First .. Args'Last + 10);
1918 Comp_Next : Integer := Args'First;
1919 Comp_Last : Integer;
1920 Arg_Index : Integer;
1921
1922 function Ada_File_Name (Name : File_Name_Type) return Boolean;
1923 -- Returns True if Name is the name of an ada source file
1924 -- (i.e. suffix is .ads or .adb)
1925
1926 -------------------
1927 -- Ada_File_Name --
1928 -------------------
1929
1930 function Ada_File_Name (Name : File_Name_Type) return Boolean is
1931 begin
1932 Get_Name_String (Name);
1933 return
1934 Name_Len > 4
1935 and then Name_Buffer (Name_Len - 3 .. Name_Len - 1) = ".ad"
1936 and then (Name_Buffer (Name_Len) = 'b'
1937 or else
1938 Name_Buffer (Name_Len) = 's');
1939 end Ada_File_Name;
1940
1941 -- Start of processing for Compile
1942
1943 begin
1944 Enter_Into_Obsoleted (S);
1945
1946 -- By default, Syntax_Only is False
1947
1948 Syntax_Only := False;
1949
1950 for J in Args'Range loop
1951 if Args (J).all = "-gnats" then
1952
1953 -- If we compile with -gnats, the bind step and the link step
1954 -- are inhibited. Also, we set Syntax_Only to True, so that
1955 -- we don't fail when we don't find the ALI file, after
1956 -- compilation.
1957
1958 Do_Bind_Step := False;
1959 Do_Link_Step := False;
1960 Syntax_Only := True;
1961
1962 elsif Args (J).all = "-gnatc" then
1963
1964 -- If we compile with -gnatc, the bind step and the link step
1965 -- are inhibited. We set Syntax_Only to False for the case when
1966 -- -gnats was previously specified.
1967
1968 Do_Bind_Step := False;
1969 Do_Link_Step := False;
1970 Syntax_Only := False;
1971 end if;
1972 end loop;
1973
1974 Comp_Args (Comp_Next) := new String'("-gnatea");
1975 Comp_Next := Comp_Next + 1;
1976
1977 Comp_Args (Comp_Next) := Comp_Flag;
1978 Comp_Next := Comp_Next + 1;
1979
1980 -- Optimize the simple case where the gcc command line looks like
1981 -- gcc -c -I. ... -I- file.adb
1982 -- into
1983 -- gcc -c ... file.adb
1984
1985 if Args (Args'First).all = "-I" & Normalized_CWD
1986 and then Args (Args'Last).all = "-I-"
1987 and then S = Strip_Directory (S)
1988 then
1989 Comp_Last := Comp_Next + Args'Length - 3;
1990 Arg_Index := Args'First + 1;
1991
1992 else
1993 Comp_Last := Comp_Next + Args'Length - 1;
1994 Arg_Index := Args'First;
1995 end if;
1996
1997 -- Make a deep copy of the arguments, because Normalize_Arguments
1998 -- may deallocate some arguments. Also strip target specific -mxxx
1999 -- switches in CodePeer mode.
2000
2001 declare
2002 Index : Natural;
2003 Last : constant Natural := Comp_Last;
2004
2005 begin
2006 Index := Comp_Next;
2007 for J in Comp_Next .. Last loop
2008 declare
2009 Str : String renames Args (Arg_Index).all;
2010 begin
2011 if CodePeer_Mode
2012 and then Str'Length > 2
2013 and then Str (Str'First .. Str'First + 1) = "-m"
2014 then
2015 Comp_Last := Comp_Last - 1;
2016 else
2017 Comp_Args (Index) := new String'(Str);
2018 Index := Index + 1;
2019 end if;
2020 end;
2021
2022 Arg_Index := Arg_Index + 1;
2023 end loop;
2024 end;
2025
2026 -- Set -gnatg for predefined files (for this purpose the renamings
2027 -- such as Text_IO do not count as predefined). Note that we strip
2028 -- the directory name from the source file name because the call to
2029 -- Fname.Is_Predefined_File_Name cannot deal with directory prefixes.
2030
2031 declare
2032 Fname : constant File_Name_Type := Strip_Directory (S);
2033
2034 begin
2035 if Is_Predefined_File_Name
2036 (Fname, Renamings_Included => False)
2037 then
2038 if Check_Readonly_Files or else Must_Compile then
2039 Comp_Args (Comp_Args'First + 2 .. Comp_Last + 1) :=
2040 Comp_Args (Comp_Args'First + 1 .. Comp_Last);
2041 Comp_Last := Comp_Last + 1;
2042 Comp_Args (Comp_Args'First + 1) := GNAT_Flag;
2043
2044 else
2045 Make_Failed
2046 ("not allowed to compile """ &
2047 Get_Name_String (Fname) &
2048 """; use -a switch, or use the compiler directly with "
2049 & "the ""-gnatg"" switch");
2050 end if;
2051 end if;
2052 end;
2053
2054 -- Now check if the file name has one of the suffixes familiar to
2055 -- the gcc driver. If this is not the case then add the ada flag
2056 -- "-x ada".
2057 -- Append systematically "-x adascil" in CodePeer mode instead, to
2058 -- force the use of gnat1scil instead of gnat1.
2059
2060 if CodePeer_Mode then
2061 Comp_Last := Comp_Last + 1;
2062 Comp_Args (Comp_Last) := Ada_Flag_1;
2063 Comp_Last := Comp_Last + 1;
2064 Comp_Args (Comp_Last) := AdaSCIL_Flag;
2065
2066 elsif not Ada_File_Name (S) then
2067 Comp_Last := Comp_Last + 1;
2068 Comp_Args (Comp_Last) := Ada_Flag_1;
2069 Comp_Last := Comp_Last + 1;
2070 Comp_Args (Comp_Last) := Ada_Flag_2;
2071 end if;
2072
2073 if Source_Index /= 0 then
2074 declare
2075 Num : constant String := Source_Index'Img;
2076 begin
2077 Comp_Last := Comp_Last + 1;
2078 Comp_Args (Comp_Last) :=
2079 new String'("-gnateI" & Num (Num'First + 1 .. Num'Last));
2080 end;
2081 end if;
2082
2083 if Source_Index /= 0
2084 or else L /= Strip_Directory (L)
2085 or else Object_Directory_Path /= null
2086 then
2087 -- Build -o argument
2088
2089 Get_Name_String (L);
2090
2091 for J in reverse 1 .. Name_Len loop
2092 if Name_Buffer (J) = '.' then
2093 Name_Len := J + Object_Suffix'Length - 1;
2094 Name_Buffer (J .. Name_Len) := Object_Suffix;
2095 exit;
2096 end if;
2097 end loop;
2098
2099 Comp_Last := Comp_Last + 1;
2100 Comp_Args (Comp_Last) := Output_Flag;
2101 Comp_Last := Comp_Last + 1;
2102
2103 -- If an object directory was specified, prepend the object file
2104 -- name with this object directory.
2105
2106 if Object_Directory_Path /= null then
2107 Comp_Args (Comp_Last) :=
2108 new String'(Object_Directory_Path.all &
2109 Name_Buffer (1 .. Name_Len));
2110
2111 else
2112 Comp_Args (Comp_Last) :=
2113 new String'(Name_Buffer (1 .. Name_Len));
2114 end if;
2115 end if;
2116
2117 if Create_Mapping_File and then Mapping_File_Arg /= null then
2118 Comp_Last := Comp_Last + 1;
2119 Comp_Args (Comp_Last) := new String'(Mapping_File_Arg.all);
2120 end if;
2121
2122 Get_Name_String (S);
2123
2124 Comp_Last := Comp_Last + 1;
2125 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
2126
2127 -- Change to object directory of the project file, if necessary
2128
2129 GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
2130
2131 Comp_Last := Comp_Last + 1;
2132 Comp_Args (Comp_Last) := new String'("-gnatez");
2133
2134 Display (Gcc.all, Comp_Args (Args'First .. Comp_Last));
2135
2136 if Gcc_Path = null then
2137 Make_Failed ("error, unable to locate " & Gcc.all);
2138 end if;
2139
2140 return
2141 GNAT.OS_Lib.Non_Blocking_Spawn
2142 (Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
2143 end Compile;
2144
2145 -------------------------------
2146 -- Fill_Queue_From_ALI_Files --
2147 -------------------------------
2148
2149 procedure Fill_Queue_From_ALI_Files is
2150 ALI : ALI_Id;
2151 Source_Index : Int;
2152 Sfile : File_Name_Type;
2153
2154 begin
2155 while Good_ALI_Present loop
2156 ALI := Get_Next_Good_ALI;
2157 Source_Index := Unit_Index_Of (ALIs.Table (ALI).Afile);
2158
2159 -- If we are processing the library file corresponding to the
2160 -- main source file check if this source can be a main unit.
2161
2162 if ALIs.Table (ALI).Sfile = Main_Source
2163 and then Source_Index = Main_Index
2164 then
2165 Main_Unit := ALIs.Table (ALI).Main_Program /= None;
2166 end if;
2167
2168 -- The following adds the standard library (s-stalib) to the list
2169 -- of files to be handled by gnatmake: this file and any files it
2170 -- depends on are always included in every bind, even if they are
2171 -- not in the explicit dependency list. Of course, it is not added
2172 -- if Suppress_Standard_Library is True.
2173
2174 -- However, to avoid annoying output about s-stalib.ali being read
2175 -- only, when "-v" is used, we add the standard library only when
2176 -- "-a" is used.
2177
2178 if Need_To_Check_Standard_Library then
2179 Check_Standard_Library;
2180 end if;
2181
2182 -- Now insert in the Q the unmarked source files (i.e. those which
2183 -- have never been inserted in the Q and hence never considered).
2184 -- Only do that if Unique_Compile is False.
2185
2186 if not Unique_Compile then
2187 for J in
2188 ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
2189 loop
2190 for K in
2191 Units.Table (J).First_With .. Units.Table (J).Last_With
2192 loop
2193 Sfile := Withs.Table (K).Sfile;
2194
2195 Dependencies.Append ((ALIs.Table (ALI).Sfile, Sfile));
2196
2197 if Is_In_Obsoleted (Sfile) then
2198 Executable_Obsolete := True;
2199 end if;
2200
2201 if Sfile = No_File then
2202 Debug_Msg ("Skipping generic:", Withs.Table (K).Uname);
2203
2204 else
2205 Source_Index := Unit_Index_Of (Withs.Table (K).Afile);
2206
2207 if not (Check_Readonly_Files or Must_Compile)
2208 and then Is_Internal_File_Name (Sfile, False)
2209 then
2210 Debug_Msg ("Skipping internal file:", Sfile);
2211
2212 else
2213 Queue.Insert
2214 ((File => Sfile,
2215 Unit => Withs.Table (K).Uname,
2216 Index => Source_Index));
2217 end if;
2218 end if;
2219 end loop;
2220 end loop;
2221 end if;
2222 end loop;
2223 end Fill_Queue_From_ALI_Files;
2224
2225 ----------------------
2226 -- Get_Mapping_File --
2227 ----------------------
2228
2229 procedure Get_Mapping_File is
2230 begin
2231 -- If there is a mapping file ready to be reused, reuse it
2232
2233 if The_Mapping_Files.Last_Free_Indexes > 0 then
2234 Mfile :=
2235 The_Mapping_Files.Free_Mapping_File_Indexes
2236 (The_Mapping_Files.Last_Free_Indexes);
2237 The_Mapping_Files.Last_Free_Indexes :=
2238 The_Mapping_Files.Last_Free_Indexes - 1;
2239
2240 -- Otherwise, create and initialize a new one
2241
2242 else
2243 Init_Mapping_File (File_Index => Mfile);
2244 end if;
2245
2246 -- Put the name in the mapping file argument for the invocation
2247 -- of the compiler.
2248
2249 Free (Mapping_File_Arg);
2250 Mapping_File_Arg :=
2251 new String'
2252 ("-gnatem=" &
2253 Get_Name_String
2254 (The_Mapping_Files.Mapping_File_Names (Mfile)));
2255 end Get_Mapping_File;
2256
2257 -----------------------
2258 -- Get_Next_Good_ALI --
2259 -----------------------
2260
2261 function Get_Next_Good_ALI return ALI_Id is
2262 ALIP : ALI_Id;
2263
2264 begin
2265 pragma Assert (Good_ALI_Present);
2266 ALIP := Good_ALI.Table (Good_ALI.Last);
2267 Good_ALI.Decrement_Last;
2268 return ALIP;
2269 end Get_Next_Good_ALI;
2270
2271 ----------------------
2272 -- Good_ALI_Present --
2273 ----------------------
2274
2275 function Good_ALI_Present return Boolean is
2276 begin
2277 return Good_ALI.First <= Good_ALI.Last;
2278 end Good_ALI_Present;
2279
2280 --------------------------------
2281 -- Must_Exit_Because_Of_Error --
2282 --------------------------------
2283
2284 function Must_Exit_Because_Of_Error return Boolean is
2285 Data : Compilation_Data;
2286 Success : Boolean;
2287
2288 begin
2289 if Bad_Compilation_Count > 0 and then not Keep_Going then
2290 while Outstanding_Compiles > 0 loop
2291 Await_Compile (Data, Success);
2292
2293 if not Success then
2294 Record_Failure (Data.Full_Source_File, Data.Source_Unit);
2295 end if;
2296 end loop;
2297
2298 return True;
2299 end if;
2300
2301 return False;
2302 end Must_Exit_Because_Of_Error;
2303
2304 --------------------
2305 -- Record_Failure --
2306 --------------------
2307
2308 procedure Record_Failure
2309 (File : File_Name_Type;
2310 Unit : Unit_Name_Type;
2311 Found : Boolean := True)
2312 is
2313 begin
2314 Bad_Compilation.Increment_Last;
2315 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
2316 end Record_Failure;
2317
2318 ---------------------
2319 -- Record_Good_ALI --
2320 ---------------------
2321
2322 procedure Record_Good_ALI (A : ALI_Id) is
2323 begin
2324 Good_ALI.Increment_Last;
2325 Good_ALI.Table (Good_ALI.Last) := A;
2326 end Record_Good_ALI;
2327
2328 -------------------------------
2329 -- Start_Compile_If_Possible --
2330 -------------------------------
2331
2332 function Start_Compile_If_Possible
2333 (Args : Argument_List) return Boolean
2334 is
2335 In_Lib_Dir : Boolean;
2336 Need_To_Compile : Boolean;
2337 Pid : Process_Id := Invalid_Pid;
2338 Process_Created : Boolean;
2339
2340 Source : Queue.Source_Info;
2341 Full_Source_File : File_Name_Type := No_File;
2342 Source_File_Attr : aliased File_Attributes;
2343 -- The full name of the source file and its attributes (size, ...)
2344
2345 Lib_File : File_Name_Type;
2346 Full_Lib_File : File_Name_Type := No_File;
2347 Lib_File_Attr : aliased File_Attributes;
2348 Read_Only : Boolean := False;
2349 ALI : ALI_Id := No_ALI_Id;
2350 -- The ALI file and its attributes (size, stamp, ...)
2351
2352 Obj_File : File_Name_Type := No_File;
2353 Obj_Stamp : Time_Stamp_Type;
2354 -- The object file
2355
2356 Found : Boolean;
2357
2358 begin
2359 if not Queue.Is_Empty and then
2360 Outstanding_Compiles < Max_Process
2361 then
2362 Queue.Extract (Found, Source);
2363
2364 Osint.Full_Source_Name
2365 (Source.File,
2366 Full_File => Full_Source_File,
2367 Attr => Source_File_Attr'Access);
2368
2369 Lib_File := Osint.Lib_File_Name (Source.File, Source.Index);
2370
2371 Osint.Full_Lib_File_Name
2372 (Lib_File,
2373 Lib_File => Full_Lib_File,
2374 Attr => Lib_File_Attr);
2375
2376 -- If source has already been compiled, executable is obsolete
2377
2378 if Is_In_Obsoleted (Source.File) then
2379 Executable_Obsolete := True;
2380 end if;
2381
2382 In_Lib_Dir := Full_Lib_File /= No_File
2383 and then In_Ada_Lib_Dir (Full_Lib_File);
2384
2385 -- Since the following requires a system call, we precompute it
2386 -- when needed.
2387
2388 if not In_Lib_Dir then
2389 if Full_Lib_File /= No_File
2390 and then not (Check_Readonly_Files or else Must_Compile)
2391 then
2392 Get_Name_String (Full_Lib_File);
2393 Name_Buffer (Name_Len + 1) := ASCII.NUL;
2394 Read_Only := not Is_Writable_File
2395 (Name_Buffer'Address, Lib_File_Attr'Access);
2396 else
2397 Read_Only := False;
2398 end if;
2399 end if;
2400
2401 -- If the library file is an Ada library skip it
2402
2403 if In_Lib_Dir then
2404 Verbose_Msg
2405 (Lib_File,
2406 "is in an Ada library",
2407 Prefix => " ",
2408 Minimum_Verbosity => Opt.High);
2409
2410 -- If the library file is a read-only library skip it, but only
2411 -- if, when using project files, this library file is in the
2412 -- right object directory (a read-only ALI file in the object
2413 -- directory of a project being extended must not be skipped).
2414
2415 elsif Read_Only then
2416 Verbose_Msg
2417 (Lib_File,
2418 "is a read-only library",
2419 Prefix => " ",
2420 Minimum_Verbosity => Opt.High);
2421
2422 -- The source file that we are checking cannot be located
2423
2424 elsif Full_Source_File = No_File then
2425 Record_Failure (Source.File, Source.Unit, False);
2426
2427 -- Source and library files can be located but are internal
2428 -- files.
2429
2430 elsif not (Check_Readonly_Files or else Must_Compile)
2431 and then Full_Lib_File /= No_File
2432 and then Is_Internal_File_Name (Source.File, False)
2433 then
2434 if Force_Compilations then
2435 Fail
2436 ("not allowed to compile """ &
2437 Get_Name_String (Source.File) &
2438 """; use -a switch, or use the compiler directly with "
2439 & "the ""-gnatg"" switch");
2440 end if;
2441
2442 Verbose_Msg
2443 (Lib_File,
2444 "is an internal library",
2445 Prefix => " ",
2446 Minimum_Verbosity => Opt.High);
2447
2448 -- The source file that we are checking can be located
2449
2450 else
2451 Collect_Arguments (Args);
2452
2453 -- Don't waste any time if we have to recompile anyway
2454
2455 Obj_Stamp := Empty_Time_Stamp;
2456 Need_To_Compile := Force_Compilations;
2457
2458 if not Force_Compilations then
2459 Check (Source_File => Source.File,
2460 The_Args => Args,
2461 Lib_File => Lib_File,
2462 Full_Lib_File => Full_Lib_File,
2463 Lib_File_Attr => Lib_File_Attr'Access,
2464 Read_Only => Read_Only,
2465 ALI => ALI,
2466 O_File => Obj_File,
2467 O_Stamp => Obj_Stamp);
2468 Need_To_Compile := (ALI = No_ALI_Id);
2469 end if;
2470
2471 if not Need_To_Compile then
2472
2473 -- The ALI file is up-to-date; record its Id
2474
2475 Record_Good_ALI (ALI);
2476
2477 -- Record the time stamp of the most recent object
2478 -- file as long as no (re)compilations are needed.
2479
2480 if First_Compiled_File = No_File
2481 and then (Most_Recent_Obj_File = No_File
2482 or else Obj_Stamp > Most_Recent_Obj_Stamp)
2483 then
2484 Most_Recent_Obj_File := Obj_File;
2485 Most_Recent_Obj_Stamp := Obj_Stamp;
2486 end if;
2487
2488 else
2489 -- Is this the first file we have to compile?
2490
2491 if First_Compiled_File = No_File then
2492 First_Compiled_File := Full_Source_File;
2493 Most_Recent_Obj_File := No_File;
2494
2495 if Do_Not_Execute then
2496
2497 -- Exit the main loop
2498
2499 return True;
2500 end if;
2501 end if;
2502
2503 -- Compute where the ALI file must be generated in
2504 -- In_Place_Mode (this does not require to know the
2505 -- location of the object directory).
2506
2507 if In_Place_Mode then
2508 if Full_Lib_File = No_File then
2509
2510 -- If the library file was not found, then save
2511 -- the library file near the source file.
2512
2513 Lib_File :=
2514 Osint.Lib_File_Name
2515 (Full_Source_File, Source.Index);
2516 Full_Lib_File := Lib_File;
2517
2518 else
2519 -- If the library file was found, then save the
2520 -- library file in the same place.
2521
2522 Lib_File := Full_Lib_File;
2523 end if;
2524 end if;
2525
2526 -- Start the compilation and record it. We can do this
2527 -- because there is at least one free process. This might
2528 -- change the current directory.
2529
2530 Collect_Arguments_And_Compile
2531 (Full_Source_File => Full_Source_File,
2532 Lib_File => Lib_File,
2533 Source_Index => Source.Index,
2534 Pid => Pid,
2535 Process_Created => Process_Created);
2536
2537 -- Compute where the ALI file will be generated (for
2538 -- cases that might require to know the current
2539 -- directory). The current directory might be changed
2540 -- when compiling other files so we cannot rely on it
2541 -- being the same to find the resulting ALI file.
2542
2543 if not In_Place_Mode then
2544
2545 -- Compute the expected location of the ALI file. This
2546 -- can be from several places:
2547 -- -i => in place mode. In such a case,
2548 -- Full_Lib_File has already been set above
2549 -- -D => if specified
2550 -- or defaults in current dir
2551 -- We could simply use a call similar to
2552 -- Osint.Full_Lib_File_Name (Lib_File)
2553 -- but that involves system calls and is thus slower
2554
2555 if Object_Directory_Path /= null then
2556 Name_Len := 0;
2557 Add_Str_To_Name_Buffer (Object_Directory_Path.all);
2558 Add_Str_To_Name_Buffer (Get_Name_String (Lib_File));
2559 Full_Lib_File := Name_Find;
2560
2561 else
2562 Full_Lib_File := Lib_File;
2563 end if;
2564
2565 end if;
2566
2567 Lib_File_Attr := Unknown_Attributes;
2568
2569 -- Make sure we could successfully start the compilation
2570
2571 if Process_Created then
2572 if Pid = Invalid_Pid then
2573 Record_Failure (Full_Source_File, Source.Unit);
2574 else
2575 Add_Process
2576 (Pid => Pid,
2577 Sfile => Full_Source_File,
2578 Afile => Lib_File,
2579 Uname => Source.Unit,
2580 Mfile => Mfile,
2581 Full_Lib_File => Full_Lib_File,
2582 Lib_File_Attr => Lib_File_Attr);
2583 end if;
2584 end if;
2585 end if;
2586 end if;
2587 end if;
2588 return False;
2589 end Start_Compile_If_Possible;
2590
2591 -----------------------------
2592 -- Wait_For_Available_Slot --
2593 -----------------------------
2594
2595 procedure Wait_For_Available_Slot is
2596 Compilation_OK : Boolean;
2597 Text : Text_Buffer_Ptr;
2598 ALI : ALI_Id;
2599 Data : Compilation_Data;
2600
2601 begin
2602 if Outstanding_Compiles = Max_Process
2603 or else (Queue.Is_Empty
2604 and then not Good_ALI_Present
2605 and then Outstanding_Compiles > 0)
2606 then
2607 Await_Compile (Data, Compilation_OK);
2608
2609 if not Compilation_OK then
2610 Record_Failure (Data.Full_Source_File, Data.Source_Unit);
2611 end if;
2612
2613 if Compilation_OK or else Keep_Going then
2614
2615 -- Re-read the updated library file
2616
2617 declare
2618 Saved_Object_Consistency : constant Boolean :=
2619 Check_Object_Consistency;
2620
2621 begin
2622 -- If compilation was not OK, or if output is not an object
2623 -- file and we don't do the bind step, don't check for
2624 -- object consistency.
2625
2626 Check_Object_Consistency :=
2627 Check_Object_Consistency
2628 and Compilation_OK
2629 and (Output_Is_Object or Do_Bind_Step);
2630
2631 Text :=
2632 Read_Library_Info_From_Full
2633 (Data.Full_Lib_File, Data.Lib_File_Attr'Access);
2634
2635 -- Restore Check_Object_Consistency to its initial value
2636
2637 Check_Object_Consistency := Saved_Object_Consistency;
2638 end;
2639
2640 -- If an ALI file was generated by this compilation, scan the
2641 -- ALI file and record it.
2642
2643 -- If the scan fails, a previous ali file is inconsistent with
2644 -- the unit just compiled.
2645
2646 if Text /= null then
2647 ALI :=
2648 Scan_ALI
2649 (Data.Lib_File, Text, Ignore_ED => False, Err => True);
2650
2651 if ALI = No_ALI_Id then
2652
2653 -- Record a failure only if not already done
2654
2655 if Compilation_OK then
2656 Inform
2657 (Data.Lib_File,
2658 "incompatible ALI file, please recompile");
2659 Record_Failure
2660 (Data.Full_Source_File, Data.Source_Unit);
2661 end if;
2662
2663 else
2664 Record_Good_ALI (ALI);
2665 end if;
2666
2667 Free (Text);
2668
2669 -- If we could not read the ALI file that was just generated
2670 -- then there could be a problem reading either the ALI or the
2671 -- corresponding object file (if Check_Object_Consistency is
2672 -- set Read_Library_Info checks that the time stamp of the
2673 -- object file is more recent than that of the ALI). However,
2674 -- we record a failure only if not already done.
2675
2676 else
2677 if Compilation_OK and not Syntax_Only then
2678 Inform
2679 (Data.Lib_File,
2680 "WARNING: ALI or object file not found after compile");
2681
2682 if not Is_Regular_File
2683 (Get_Name_String (Name_Id (Data.Full_Lib_File)))
2684 then
2685 Inform (Data.Full_Lib_File, "not found");
2686 end if;
2687
2688 Record_Failure (Data.Full_Source_File, Data.Source_Unit);
2689 end if;
2690 end if;
2691 end if;
2692 end if;
2693 end Wait_For_Available_Slot;
2694
2695 -- Start of processing for Compile_Sources
2696
2697 begin
2698 pragma Assert (Args'First = 1);
2699
2700 Outstanding_Compiles := 0;
2701 Running_Compile := new Comp_Data_Arr (1 .. Max_Process);
2702
2703 -- Package and Queue initializations
2704
2705 Good_ALI.Init;
2706
2707 if Initialize_ALI_Data then
2708 Initialize_ALI;
2709 Initialize_ALI_Source;
2710 end if;
2711
2712 -- The following two flags affect the behavior of ALI.Set_Source_Table.
2713 -- We set Check_Source_Files to True to ensure that source file time
2714 -- stamps are checked, and we set All_Sources to False to avoid checking
2715 -- the presence of the source files listed in the source dependency
2716 -- section of an ali file (which would be a mistake since the ali file
2717 -- may be obsolete).
2718
2719 Check_Source_Files := True;
2720 All_Sources := False;
2721
2722 Queue.Insert
2723 ((File => Main_Source,
2724 Unit => No_Unit_Name,
2725 Index => Main_Index));
2726
2727 First_Compiled_File := No_File;
2728 Most_Recent_Obj_File := No_File;
2729 Most_Recent_Obj_Stamp := Empty_Time_Stamp;
2730 Main_Unit := False;
2731
2732 -- Keep looping until there is no more work to do (the Q is empty)
2733 -- and all the outstanding compilations have terminated.
2734
2735 Make_Loop :
2736 while not Queue.Is_Empty or else Outstanding_Compiles > 0 loop
2737 exit Make_Loop when Must_Exit_Because_Of_Error;
2738 exit Make_Loop when Start_Compile_If_Possible (Args);
2739
2740 Wait_For_Available_Slot;
2741
2742 -- ??? Should be done as soon as we add a Good_ALI, wouldn't it avoid
2743 -- the need for a list of good ALI?
2744
2745 Fill_Queue_From_ALI_Files;
2746
2747 if Display_Compilation_Progress then
2748 Write_Str ("completed ");
2749 Write_Int (Int (Queue.Processed));
2750 Write_Str (" out of ");
2751 Write_Int (Int (Queue.Size));
2752 Write_Str (" (");
2753 Write_Int (Int ((Queue.Processed * 100) / Queue.Size));
2754 Write_Str ("%)...");
2755 Write_Eol;
2756 end if;
2757 end loop Make_Loop;
2758
2759 Compilation_Failures := Bad_Compilation_Count;
2760
2761 -- Compilation is finished
2762
2763 end Compile_Sources;
2764
2765 ---------------
2766 -- Debug_Msg --
2767 ---------------
2768
2769 procedure Debug_Msg (S : String; N : Name_Id) is
2770 begin
2771 if Debug.Debug_Flag_W then
2772 Write_Str (" ... ");
2773 Write_Str (S);
2774 Write_Str (" ");
2775 Write_Name (N);
2776 Write_Eol;
2777 end if;
2778 end Debug_Msg;
2779
2780 procedure Debug_Msg (S : String; N : File_Name_Type) is
2781 begin
2782 Debug_Msg (S, Name_Id (N));
2783 end Debug_Msg;
2784
2785 procedure Debug_Msg (S : String; N : Unit_Name_Type) is
2786 begin
2787 Debug_Msg (S, Name_Id (N));
2788 end Debug_Msg;
2789
2790 -------------
2791 -- Display --
2792 -------------
2793
2794 procedure Display (Program : String; Args : Argument_List) is
2795 begin
2796 pragma Assert (Args'First = 1);
2797
2798 if not Quiet_Output then
2799 Write_Str (Program);
2800
2801 for J in Args'Range loop
2802
2803 -- Never display -gnatea nor -gnatez
2804
2805 if Args (J).all /= "-gnatea"
2806 and then
2807 Args (J).all /= "-gnatez"
2808 then
2809 -- Do not display the -F=mapping_file switch for gnatbind if
2810 -- -dn is not specified.
2811
2812 if Opt.Keep_Temporary_Files
2813 or else Args (J)'Length < 4
2814 or else
2815 Args (J) (Args (J)'First .. Args (J)'First + 2) /= "-F="
2816 then
2817 Write_Str (" ");
2818
2819 -- If -df is used, only display file names, not path
2820 -- names.
2821
2822 if Debug.Debug_Flag_F then
2823 declare
2824 Equal_Pos : Natural;
2825
2826 begin
2827 Equal_Pos := Args (J)'First - 1;
2828 for K in Args (J)'Range loop
2829 if Args (J) (K) = '=' then
2830 Equal_Pos := K;
2831 exit;
2832 end if;
2833 end loop;
2834
2835 if Is_Absolute_Path
2836 (Args (J) (Equal_Pos + 1 .. Args (J)'Last))
2837 then
2838 Write_Str
2839 (Args (J) (Args (J)'First .. Equal_Pos));
2840 Write_Str
2841 (File_Name
2842 (Args (J)
2843 (Equal_Pos + 1 .. Args (J)'Last)));
2844
2845 else
2846 Write_Str (Args (J).all);
2847 end if;
2848 end;
2849
2850 else
2851 Write_Str (Args (J).all);
2852 end if;
2853 end if;
2854 end if;
2855 end loop;
2856
2857 Write_Eol;
2858 end if;
2859 end Display;
2860
2861 --------------------------
2862 -- Enter_Into_Obsoleted --
2863 --------------------------
2864
2865 procedure Enter_Into_Obsoleted (F : File_Name_Type) is
2866 Name : constant String := Get_Name_String (F);
2867 First : Natural;
2868 F2 : File_Name_Type;
2869
2870 begin
2871 First := Name'Last;
2872 while First > Name'First
2873 and then not Is_Directory_Separator (Name (First - 1))
2874 loop
2875 First := First - 1;
2876 end loop;
2877
2878 if First /= Name'First then
2879 Name_Len := 0;
2880 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
2881 F2 := Name_Find;
2882
2883 else
2884 F2 := F;
2885 end if;
2886
2887 Debug_Msg ("New entry in Obsoleted table:", F2);
2888 Obsoleted.Set (F2, True);
2889 end Enter_Into_Obsoleted;
2890
2891 -------------------
2892 -- Linking_Phase --
2893 -------------------
2894
2895 procedure Linking_Phase
2896 (Non_Std_Executable : Boolean := False;
2897 Executable : File_Name_Type := No_File;
2898 Main_ALI_File : File_Name_Type)
2899 is
2900 Linker_Switches_Last : constant Integer := Linker_Switches.Last;
2901
2902 begin
2903 if not Run_Path_Option then
2904 Linker_Switches.Increment_Last;
2905 Linker_Switches.Table (Linker_Switches.Last) :=
2906 new String'("-R");
2907 end if;
2908
2909 if CodePeer_Mode then
2910 Linker_Switches.Increment_Last;
2911 Linker_Switches.Table (Linker_Switches.Last) :=
2912 new String'(CodePeer_Mode_String);
2913 end if;
2914
2915 -- Add switch -M to gnatlink if builder switch --create-map-file
2916 -- has been specified.
2917
2918 if Map_File /= null then
2919 Linker_Switches.Increment_Last;
2920 Linker_Switches.Table (Linker_Switches.Last) :=
2921 new String'("-M" & Map_File.all);
2922 end if;
2923
2924 declare
2925 Args : Argument_List
2926 (Linker_Switches.First .. Linker_Switches.Last + 2);
2927
2928 Last_Arg : Integer := Linker_Switches.First - 1;
2929 Skip : Boolean := False;
2930
2931 begin
2932 -- Get all the linker switches
2933
2934 for J in Linker_Switches.First .. Linker_Switches.Last loop
2935 if Skip then
2936 Skip := False;
2937
2938 elsif Non_Std_Executable
2939 and then Linker_Switches.Table (J).all = "-o"
2940 then
2941 Skip := True;
2942
2943 -- Here we capture and duplicate the linker argument. We
2944 -- need to do the duplication since the arguments will get
2945 -- normalized. Not doing so will result in calling normalized
2946 -- two times for the same set of arguments if gnatmake is
2947 -- passed multiple mains. This can result in the wrong
2948 -- argument being passed to the linker.
2949
2950 else
2951 Last_Arg := Last_Arg + 1;
2952 Args (Last_Arg) := new String'(Linker_Switches.Table (J).all);
2953 end if;
2954 end loop;
2955
2956 -- If need be, add the -o switch
2957
2958 if Non_Std_Executable then
2959 Last_Arg := Last_Arg + 1;
2960 Args (Last_Arg) := new String'("-o");
2961 Last_Arg := Last_Arg + 1;
2962 Args (Last_Arg) := new String'(Get_Name_String (Executable));
2963 end if;
2964
2965 -- And invoke the linker
2966
2967 declare
2968 Success : Boolean := False;
2969
2970 begin
2971 -- If gnatmake was invoked with --subdirs, put the executable in
2972 -- the subdirectory specified.
2973
2974 if Subdirs /= null then
2975 Change_Dir (Object_Directory_Path.all);
2976 end if;
2977
2978 Link (Main_ALI_File,
2979 Link_With_Shared_Libgcc.all &
2980 Args (Args'First .. Last_Arg),
2981 Success);
2982
2983 if Success then
2984 Successful_Links.Increment_Last;
2985 Successful_Links.Table (Successful_Links.Last) := Main_ALI_File;
2986
2987 elsif Osint.Number_Of_Files = 1 or else not Keep_Going then
2988 Make_Failed ("*** link failed.");
2989
2990 else
2991 Set_Standard_Error;
2992 Write_Line ("*** link failed");
2993
2994 if Commands_To_Stdout then
2995 Set_Standard_Output;
2996 end if;
2997
2998 Failed_Links.Increment_Last;
2999 Failed_Links.Table (Failed_Links.Last) := Main_ALI_File;
3000 end if;
3001 end;
3002 end;
3003
3004 Linker_Switches.Set_Last (Linker_Switches_Last);
3005 end Linking_Phase;
3006
3007 -------------------
3008 -- Binding_Phase --
3009 -------------------
3010
3011 procedure Binding_Phase (Main_ALI_File : File_Name_Type) is
3012 Args : Argument_List (Binder_Switches.First .. Binder_Switches.Last + 2);
3013 -- The arguments for the invocation of gnatbind
3014
3015 Last_Arg : Natural := Binder_Switches.Last;
3016 -- Index of the last argument in Args
3017
3018 Shared_Libs : Boolean := False;
3019 -- Set to True when there are shared library project files or
3020 -- when gnatbind is invoked with -shared.
3021
3022 begin
3023
3024 -- Check now for switch -shared
3025
3026 for J in Binder_Switches.First .. Last_Arg loop
3027 if Binder_Switches.Table (J).all = "-shared" then
3028 Shared_Libs := True;
3029 exit;
3030 end if;
3031 end loop;
3032
3033 -- If shared libraries present, invoke gnatlink with
3034 -- -shared-libgcc.
3035
3036 if Shared_Libs then
3037 Link_With_Shared_Libgcc := Shared_Libgcc_Switch'Access;
3038 end if;
3039
3040 -- Get all the binder switches
3041
3042 for J in Binder_Switches.First .. Last_Arg loop
3043 Args (J) := Binder_Switches.Table (J);
3044 end loop;
3045
3046 if CodePeer_Mode then
3047 Last_Arg := Last_Arg + 1;
3048 Args (Last_Arg) := CodePeer_Mode_String'Access;
3049 end if;
3050
3051 -- If gnatmake was invoked with --subdirs, put the
3052 -- binder generated files in the subdirectory specified.
3053
3054 if Subdirs /= null then
3055 Change_Dir (Object_Directory_Path.all);
3056 end if;
3057
3058 Bind (Main_ALI_File, Bind_Shared.all & Args (Args'First .. Last_Arg));
3059
3060 end Binding_Phase;
3061
3062 -----------------------
3063 -- Compilation_Phase --
3064 -----------------------
3065
3066 procedure Compilation_Phase
3067 (Main_Source_File : File_Name_Type;
3068 Current_Main_Index : Int := 0;
3069 Total_Compilation_Failures : in out Natural;
3070 Executable : File_Name_Type := No_File;
3071 Stop_Compile : out Boolean)
3072 is
3073 Args : Argument_List (1 .. Gcc_Switches.Last);
3074 First_Compiled_File : File_Name_Type;
3075 Youngest_Obj_File : File_Name_Type;
3076 Youngest_Obj_Stamp : Time_Stamp_Type;
3077
3078 Is_Main_Unit : Boolean;
3079 -- Set True by Compile_Sources if Main_Source_File can be a main unit
3080
3081 Compilation_Failures : Natural;
3082
3083 Executable_Stamp : Time_Stamp_Type;
3084
3085 begin
3086 Stop_Compile := False;
3087
3088 for J in 1 .. Gcc_Switches.Last loop
3089 Args (J) := Gcc_Switches.Table (J);
3090 end loop;
3091
3092 -- Now we invoke Compile_Sources for the current main
3093
3094 Compile_Sources
3095 (Main_Source => Main_Source_File,
3096 Args => Args,
3097 First_Compiled_File => First_Compiled_File,
3098 Most_Recent_Obj_File => Youngest_Obj_File,
3099 Most_Recent_Obj_Stamp => Youngest_Obj_Stamp,
3100 Main_Unit => Is_Main_Unit,
3101 Main_Index => Current_Main_Index,
3102 Compilation_Failures => Compilation_Failures,
3103 Check_Readonly_Files => Check_Readonly_Files,
3104 Do_Not_Execute => Do_Not_Execute,
3105 Force_Compilations => Force_Compilations,
3106 In_Place_Mode => In_Place_Mode,
3107 Keep_Going => Keep_Going,
3108 Initialize_ALI_Data => True,
3109 Max_Process => Maximum_Processes);
3110
3111 if Verbose_Mode then
3112 Write_Str ("End of compilation");
3113 Write_Eol;
3114 end if;
3115
3116 Total_Compilation_Failures :=
3117 Total_Compilation_Failures + Compilation_Failures;
3118
3119 if Total_Compilation_Failures /= 0 then
3120 Stop_Compile := True;
3121 return;
3122 end if;
3123
3124 if List_Dependencies then
3125 if First_Compiled_File /= No_File then
3126 Inform
3127 (First_Compiled_File,
3128 "must be recompiled. Can't generate dependence list.");
3129 else
3130 List_Depend;
3131 end if;
3132
3133 elsif First_Compiled_File = No_File
3134 and then not Do_Bind_Step
3135 and then not Quiet_Output
3136 and then Osint.Number_Of_Files = 1
3137 then
3138 Inform (Msg => "objects up to date.");
3139 Stop_Compile := True;
3140 return;
3141
3142 elsif Do_Not_Execute and then First_Compiled_File /= No_File then
3143 Write_Name (First_Compiled_File);
3144 Write_Eol;
3145 end if;
3146
3147 -- Stop after compile step if any of:
3148
3149 -- 1) -n (Do_Not_Execute) specified
3150
3151 -- 2) -M (List_Dependencies) specified (also sets
3152 -- Do_Not_Execute above, so this is probably superfluous).
3153
3154 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
3155
3156 -- 4) Made unit cannot be a main unit
3157
3158 if ((Do_Not_Execute
3159 or List_Dependencies
3160 or not Do_Bind_Step
3161 or not Is_Main_Unit)
3162 and not No_Main_Subprogram
3163 and not Build_Bind_And_Link_Full_Project)
3164 or Unique_Compile
3165 then
3166 Stop_Compile := True;
3167 return;
3168 end if;
3169
3170 -- If the objects were up-to-date check if the executable file is also
3171 -- up-to-date. For now always bind and link in CodePeer mode where there
3172 -- is no executable.
3173
3174 if not CodePeer_Mode
3175 and then Do_Link_Step
3176 and then First_Compiled_File = No_File
3177 then
3178 Executable_Stamp := File_Stamp (Executable);
3179
3180 if not Executable_Obsolete then
3181 Executable_Obsolete := Youngest_Obj_Stamp > Executable_Stamp;
3182 end if;
3183
3184 if not Executable_Obsolete then
3185 for Index in reverse 1 .. Dependencies.Last loop
3186 if Is_In_Obsoleted (Dependencies.Table (Index).Depends_On) then
3187 Enter_Into_Obsoleted (Dependencies.Table (Index).This);
3188 end if;
3189 end loop;
3190
3191 Executable_Obsolete := Is_In_Obsoleted (Main_Source_File);
3192 Dependencies.Init;
3193 end if;
3194
3195 if not Executable_Obsolete then
3196
3197 -- If no Ada object files obsolete the executable, check
3198 -- for younger or missing linker files.
3199
3200 Check_Linker_Options
3201 (Executable_Stamp,
3202 Youngest_Obj_File,
3203 Youngest_Obj_Stamp);
3204
3205 Executable_Obsolete := Youngest_Obj_File /= No_File;
3206 end if;
3207
3208 -- Return if the executable is up to date and otherwise
3209 -- motivate the relink/rebind.
3210
3211 if not Executable_Obsolete then
3212 if not Quiet_Output then
3213 Inform (Executable, "up to date.");
3214 end if;
3215
3216 Stop_Compile := True;
3217 return;
3218 end if;
3219
3220 if Executable_Stamp (1) = ' ' then
3221 if not No_Main_Subprogram then
3222 Verbose_Msg (Executable, "missing.", Prefix => " ");
3223 end if;
3224
3225 elsif Youngest_Obj_Stamp (1) = ' ' then
3226 Verbose_Msg
3227 (Youngest_Obj_File, "missing.", Prefix => " ");
3228
3229 elsif Youngest_Obj_Stamp > Executable_Stamp then
3230 Verbose_Msg
3231 (Youngest_Obj_File,
3232 "(" & String (Youngest_Obj_Stamp) & ") newer than",
3233 Executable,
3234 "(" & String (Executable_Stamp) & ")");
3235
3236 else
3237 Verbose_Msg
3238 (Executable, "needs to be rebuilt", Prefix => " ");
3239
3240 end if;
3241 end if;
3242 end Compilation_Phase;
3243
3244 ------------------------
3245 -- Compute_Executable --
3246 ------------------------
3247
3248 procedure Compute_Executable
3249 (Main_Source_File : File_Name_Type;
3250 Executable : out File_Name_Type;
3251 Non_Std_Executable : out Boolean)
3252 is
3253 begin
3254 Executable := No_File;
3255 Non_Std_Executable :=
3256 Targparm.Executable_Extension_On_Target /= No_Name;
3257
3258 -- Look inside the linker switches to see if the name of the final
3259 -- executable program was specified.
3260
3261 for J in reverse Linker_Switches.First .. Linker_Switches.Last loop
3262 if Linker_Switches.Table (J).all = Output_Flag.all then
3263 pragma Assert (J < Linker_Switches.Last);
3264
3265 -- We cannot specify a single executable for several main
3266 -- subprograms
3267
3268 if Osint.Number_Of_Files > 1 then
3269 Fail ("cannot specify a single executable for several mains");
3270 end if;
3271
3272 Name_Len := 0;
3273 Add_Str_To_Name_Buffer (Linker_Switches.Table (J + 1).all);
3274 Executable := Name_Enter;
3275
3276 Verbose_Msg (Executable, "final executable");
3277 end if;
3278 end loop;
3279
3280 -- If the name of the final executable program was not specified then
3281 -- construct it from the main input file.
3282
3283 if Executable = No_File then
3284 Executable := Executable_Name (Strip_Suffix (Main_Source_File));
3285 end if;
3286
3287 end Compute_Executable;
3288
3289 --------------
3290 -- Gnatmake --
3291 --------------
3292
3293 procedure Gnatmake is
3294 Main_Source_File : File_Name_Type;
3295 -- The source file containing the main compilation unit
3296
3297 Total_Compilation_Failures : Natural := 0;
3298
3299 Main_ALI_File : File_Name_Type;
3300 -- The ali file corresponding to Main_Source_File
3301
3302 Executable : File_Name_Type := No_File;
3303 -- The file name of an executable
3304
3305 Non_Std_Executable : Boolean := False;
3306 -- Non_Std_Executable is set to True when there is a possibility that
3307 -- the linker will not choose the correct executable file name.
3308
3309 Current_Main_Index : Int := 0;
3310 -- If not zero, the index of the current main unit in its source file
3311
3312 Is_First_Main : Boolean;
3313 -- Whether we are processing the first main
3314
3315 Stop_Compile : Boolean;
3316
3317 Discard : Boolean;
3318 pragma Warnings (Off, Discard);
3319
3320 begin
3321 GNAT.Ctrl_C.Install_Handler (Sigint_Intercepted'Access);
3322
3323 Do_Compile_Step := True;
3324 Do_Bind_Step := True;
3325 Do_Link_Step := True;
3326
3327 Obsoleted.Reset;
3328
3329 Make.Initialize;
3330
3331 Bind_Shared := No_Shared_Switch'Access;
3332 Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access;
3333
3334 Failed_Links.Set_Last (0);
3335 Successful_Links.Set_Last (0);
3336
3337 -- Special case when switch -B was specified
3338
3339 if Main_Index /= 0 and then Osint.Number_Of_Files > 1 then
3340 Make_Failed ("cannot specify several mains with a multi-unit index");
3341 end if;
3342
3343 if Verbose_Mode then
3344 Write_Eol;
3345 Display_Version ("GNATMAKE", "1992");
3346 end if;
3347
3348 if Osint.Number_Of_Files = 0 then
3349 -- Call Get_Target_Parameters to ensure that flags are properly
3350 -- set before calling Usage.
3351
3352 Targparm.Get_Target_Parameters;
3353
3354 -- Output usage information if no argument on the command line
3355
3356 if Argument_Count = 0 then
3357 Usage;
3358 else
3359 Try_Help;
3360 end if;
3361
3362 Finish_Program (E_Success);
3363 end if;
3364
3365 -- Get the first executable.
3366 -- ??? This needs to be done early, because Osint.Next_Main_File also
3367 -- initializes the primary search directory, used below to initialize
3368 -- the "-I" parameter
3369
3370 Main_Source_File := Next_Main_Source; -- No directory information
3371
3372 -- If -M was specified, behave as if -n was specified
3373
3374 if List_Dependencies then
3375 Do_Not_Execute := True;
3376 end if;
3377
3378 Add_Switch ("-I-", Compiler);
3379
3380 if Look_In_Primary_Dir then
3381 Add_Switch
3382 ("-I" &
3383 Normalize_Directory_Name
3384 (Get_Primary_Src_Search_Directory.all).all,
3385 Compiler,
3386 Append_Switch => False);
3387
3388 end if;
3389
3390 -- If the user wants a program without a main subprogram, add the
3391 -- appropriate switch to the binder.
3392
3393 if No_Main_Subprogram then
3394 Add_Switch ("-z", Binder);
3395 end if;
3396
3397 -- The combination of -f -u and one or several mains on the command line
3398 -- implies -a.
3399
3400 if Force_Compilations
3401 and then Unique_Compile
3402 and then Main_On_Command_Line
3403 then
3404 Must_Compile := True;
3405 end if;
3406
3407 Bad_Compilation.Init;
3408
3409 -- Here is where the make process is started
3410
3411 Queue.Initialize;
3412
3413 Is_First_Main := True;
3414
3415 Multiple_Main_Loop : for N_File in 1 .. Osint.Number_Of_Files loop
3416 if Current_File_Index /= No_Index then
3417 Main_Index := Current_File_Index;
3418 end if;
3419
3420 Current_Main_Index := Main_Index;
3421
3422 if Is_First_Main then
3423
3424 -- Put the default source dirs in the source path only now, so
3425 -- that we take the correct ones in the case where --RTS= is
3426 -- specified in the Builder switches.
3427
3428 Osint.Add_Default_Search_Dirs;
3429
3430 -- Get the target parameters, which are only needed for a couple
3431 -- of cases in gnatmake. Protect against an exception, such as the
3432 -- case of system.ads missing from the library, and fail
3433 -- gracefully.
3434
3435 begin
3436 Targparm.Get_Target_Parameters;
3437 exception
3438 when Unrecoverable_Error =>
3439 Make_Failed ("*** make failed.");
3440 end;
3441
3442 Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
3443 Gnatbind_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
3444 Gnatlink_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
3445
3446 -- If we have specified -j switch both from the project file
3447 -- and on the command line, the one from the command line takes
3448 -- precedence.
3449
3450 if Debug.Debug_Flag_M then
3451 Write_Line ("Maximum number of simultaneous compilations =" &
3452 Maximum_Processes'Img);
3453 end if;
3454
3455 -- Allocate as many temporary mapping file names as the maximum
3456 -- number of compilations processed.
3457
3458 The_Mapping_Files :=
3459 (Mapping_File_Names =>
3460 new Temp_Path_Names (1 .. Maximum_Processes),
3461 Last_Mapping_File_Names => 0,
3462 Free_Mapping_File_Indexes =>
3463 new Free_File_Indexes (1 .. Maximum_Processes),
3464 Last_Free_Indexes => 0);
3465
3466 Is_First_Main := False;
3467 end if;
3468
3469 Executable_Obsolete := False;
3470
3471 Compute_Executable
3472 (Main_Source_File => Main_Source_File,
3473 Executable => Executable,
3474 Non_Std_Executable => Non_Std_Executable);
3475
3476 if Do_Compile_Step then
3477 Compilation_Phase
3478 (Main_Source_File => Main_Source_File,
3479 Current_Main_Index => Current_Main_Index,
3480 Total_Compilation_Failures => Total_Compilation_Failures,
3481 Executable => Executable,
3482 Stop_Compile => Stop_Compile);
3483
3484 if Stop_Compile then
3485 if Total_Compilation_Failures /= 0 then
3486 if Keep_Going then
3487 goto Next_Main;
3488
3489 else
3490 List_Bad_Compilations;
3491 Report_Compilation_Failed;
3492 end if;
3493
3494 elsif Osint.Number_Of_Files = 1 then
3495 exit Multiple_Main_Loop;
3496 else
3497 goto Next_Main;
3498 end if;
3499 end if;
3500 end if;
3501
3502 -- If we are here, it means that we need to rebuilt the current main,
3503 -- so we set Executable_Obsolete to True to make sure that subsequent
3504 -- mains will be rebuilt.
3505
3506 Main_ALI_In_Place_Mode_Step : declare
3507 ALI_File : File_Name_Type;
3508 Src_File : File_Name_Type;
3509
3510 begin
3511 Src_File := Strip_Directory (Main_Source_File);
3512 ALI_File := Lib_File_Name (Src_File, Current_Main_Index);
3513 Main_ALI_File := Full_Lib_File_Name (ALI_File);
3514
3515 -- When In_Place_Mode, the library file can be located in the
3516 -- Main_Source_File directory which may not be present in the
3517 -- library path. If it is not present then use the corresponding
3518 -- library file name.
3519
3520 if Main_ALI_File = No_File and then In_Place_Mode then
3521 Get_Name_String (Get_Directory (Full_Source_Name (Src_File)));
3522 Get_Name_String_And_Append (ALI_File);
3523 Main_ALI_File := Name_Find;
3524 Main_ALI_File := Full_Lib_File_Name (Main_ALI_File);
3525 end if;
3526
3527 if Main_ALI_File = No_File then
3528 Make_Failed ("could not find the main ALI file");
3529 end if;
3530 end Main_ALI_In_Place_Mode_Step;
3531
3532 if Do_Bind_Step then
3533 Binding_Phase (Main_ALI_File);
3534 end if;
3535
3536 if Do_Link_Step then
3537 Linking_Phase
3538 (Non_Std_Executable => Non_Std_Executable,
3539 Executable => Executable,
3540 Main_ALI_File => Main_ALI_File);
3541 end if;
3542
3543 -- We go to here when we skip the bind and link steps
3544
3545 <<Next_Main>>
3546
3547 Queue.Remove_Marks;
3548
3549 if N_File < Osint.Number_Of_Files then
3550 Main_Source_File := Next_Main_Source; -- No directory information
3551 end if;
3552 end loop Multiple_Main_Loop;
3553
3554 if Failed_Links.Last > 0 then
3555 for Index in 1 .. Successful_Links.Last loop
3556 Write_Str ("Linking of """);
3557 Write_Str (Get_Name_String (Successful_Links.Table (Index)));
3558 Write_Line (""" succeeded.");
3559 end loop;
3560
3561 Set_Standard_Error;
3562
3563 for Index in 1 .. Failed_Links.Last loop
3564 Write_Str ("Linking of """);
3565 Write_Str (Get_Name_String (Failed_Links.Table (Index)));
3566 Write_Line (""" failed.");
3567 end loop;
3568
3569 if Commands_To_Stdout then
3570 Set_Standard_Output;
3571 end if;
3572
3573 if Total_Compilation_Failures = 0 then
3574 Report_Compilation_Failed;
3575 end if;
3576 end if;
3577
3578 if Total_Compilation_Failures /= 0 then
3579 List_Bad_Compilations;
3580 Report_Compilation_Failed;
3581 end if;
3582
3583 Finish_Program (E_Success);
3584
3585 exception
3586 when X : others =>
3587 Set_Standard_Error;
3588 Write_Line (Exception_Information (X));
3589 Make_Failed ("INTERNAL ERROR. Please report.");
3590 end Gnatmake;
3591
3592 ----------
3593 -- Hash --
3594 ----------
3595
3596 function Hash (F : File_Name_Type) return Header_Num is
3597 begin
3598 return Header_Num (1 + F mod Max_Header);
3599 end Hash;
3600
3601 --------------------
3602 -- In_Ada_Lib_Dir --
3603 --------------------
3604
3605 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
3606 D : constant File_Name_Type := Get_Directory (File);
3607 B : constant Byte := Get_Name_Table_Byte (D);
3608 begin
3609 return (B and Ada_Lib_Dir) /= 0;
3610 end In_Ada_Lib_Dir;
3611
3612 -----------------------
3613 -- Init_Mapping_File --
3614 -----------------------
3615
3616 procedure Init_Mapping_File (File_Index : out Natural) is
3617 FD : File_Descriptor;
3618 Status : Boolean;
3619 -- For call to Close
3620
3621 begin
3622 -- Increase the index of the last mapping file for this project
3623
3624 The_Mapping_Files.Last_Mapping_File_Names :=
3625 The_Mapping_Files.Last_Mapping_File_Names + 1;
3626
3627 -- Just create an empty file
3628
3629 Tempdir.Create_Temp_File
3630 (FD,
3631 The_Mapping_Files.Mapping_File_Names
3632 (The_Mapping_Files.Last_Mapping_File_Names));
3633
3634 if FD = Invalid_FD then
3635 Make_Failed ("disk full");
3636 else
3637 Record_Temp_File
3638 (The_Mapping_Files.Mapping_File_Names
3639 (The_Mapping_Files.Last_Mapping_File_Names));
3640 end if;
3641
3642 Close (FD, Status);
3643
3644 if not Status then
3645 Make_Failed ("disk full");
3646 end if;
3647
3648 -- And return the index of the newly created file
3649
3650 File_Index := The_Mapping_Files.Last_Mapping_File_Names;
3651 end Init_Mapping_File;
3652
3653 ----------------
3654 -- Initialize --
3655 ----------------
3656
3657 procedure Initialize is
3658 procedure Check_Version_And_Help is
3659 new Check_Version_And_Help_G (Makeusg);
3660
3661 begin
3662 -- Override default initialization of Check_Object_Consistency since
3663 -- this is normally False for GNATBIND, but is True for GNATMAKE since
3664 -- we do not need to check source consistency again once GNATMAKE has
3665 -- looked at the sources to check.
3666
3667 Check_Object_Consistency := True;
3668
3669 -- Package initializations (the order of calls is important here)
3670
3671 Output.Set_Standard_Error;
3672
3673 Gcc_Switches.Init;
3674 Binder_Switches.Init;
3675 Linker_Switches.Init;
3676
3677 Csets.Initialize;
3678 Snames.Initialize;
3679 Stringt.Initialize;
3680
3681 Dependencies.Init;
3682
3683 RTS_Specified := null;
3684 N_M_Switch := 0;
3685
3686 Mains.Delete;
3687
3688 -- Add the directory where gnatmake is invoked in front of the path,
3689 -- if gnatmake is invoked from a bin directory or with directory
3690 -- information.
3691
3692 declare
3693 Prefix : constant String := Executable_Prefix_Path;
3694 Command : constant String := Command_Name;
3695
3696 begin
3697 if Prefix'Length > 0 then
3698 declare
3699 PATH : constant String :=
3700 Prefix & Directory_Separator & "bin" & Path_Separator
3701 & Getenv ("PATH").all;
3702 begin
3703 Setenv ("PATH", PATH);
3704 end;
3705
3706 else
3707 for Index in reverse Command'Range loop
3708 if Command (Index) = Directory_Separator then
3709 declare
3710 Absolute_Dir : constant String :=
3711 Normalize_Pathname
3712 (Command (Command'First .. Index));
3713 PATH : constant String :=
3714 Absolute_Dir &
3715 Path_Separator &
3716 Getenv ("PATH").all;
3717 begin
3718 Setenv ("PATH", PATH);
3719 end;
3720
3721 exit;
3722 end if;
3723 end loop;
3724 end if;
3725 end;
3726
3727 -- Scan the switches and arguments
3728
3729 -- First, scan to detect --version and/or --help
3730
3731 Check_Version_And_Help ("GNATMAKE", "1995");
3732
3733 -- Scan again the switch and arguments, now that we are sure that they
3734 -- do not include --version or --help.
3735
3736 -- First, check for switch -P and, if found and gprbuild is available,
3737 -- silently invoke gprbuild, with switch --target if not on a native
3738 -- platform.
3739
3740 declare
3741 Arg_Len : Natural := Argument_Count;
3742 Call_Gprbuild : Boolean := False;
3743 Gprbuild : String_Access := null;
3744 Pos : Natural := 0;
3745 Success : Boolean;
3746 Target : String_Access := null;
3747
3748 In_Gnatmake_Switches : Boolean := True;
3749 -- Set to False after -cargs, -bargs, or -largs, to avoid detecting
3750 -- -P switches that are not for gnatmake.
3751
3752 begin
3753 Find_Program_Name;
3754
3755 if Name_Len >= 8
3756 and then Name_Buffer (Name_Len - 7 .. Name_Len) = "gnatmake"
3757 then
3758 if Name_Len > 9 then
3759 Target := new String'(Name_Buffer (1 .. Name_Len - 9));
3760 Arg_Len := Arg_Len + 1;
3761 end if;
3762
3763 for J in 1 .. Argument_Count loop
3764 declare
3765 Arg : constant String := Argument (J);
3766 begin
3767 if Arg = "-cargs" or Arg = "-bargs" or Arg = "-largs" then
3768 In_Gnatmake_Switches := False;
3769
3770 elsif Arg = "-margs" then
3771 In_Gnatmake_Switches := True;
3772
3773 elsif In_Gnatmake_Switches
3774 and then Arg'Length >= 2
3775 and then Arg (Arg'First .. Arg'First + 1) = "-P"
3776 then
3777 Call_Gprbuild := True;
3778 exit;
3779 end if;
3780 end;
3781 end loop;
3782
3783 if Call_Gprbuild then
3784 Gprbuild := Locate_Exec_On_Path (Exec_Name => "gprbuild");
3785
3786 if Gprbuild = null then
3787 Fail_Program
3788 ("project files are no longer supported by gnatmake;" &
3789 " use gprbuild instead");
3790 end if;
3791
3792 declare
3793 Args : Argument_List (1 .. Arg_Len);
3794 begin
3795 if Target /= null then
3796 Args (1) := new String'("--target=" & Target.all);
3797 Pos := 1;
3798 end if;
3799
3800 for J in 1 .. Argument_Count loop
3801 Pos := Pos + 1;
3802 Args (Pos) := new String'(Argument (J));
3803 end loop;
3804
3805 Spawn (Gprbuild.all, Args, Success);
3806
3807 Free (Gprbuild);
3808
3809 if Success then
3810 Exit_Program (E_Success);
3811 else
3812 Exit_Program (E_Errors);
3813 end if;
3814 end;
3815 end if;
3816 end if;
3817 end;
3818
3819 Scan_Args : for Next_Arg in 1 .. Argument_Count loop
3820 Scan_Make_Arg (Argument (Next_Arg));
3821 end loop Scan_Args;
3822
3823 if Make_Steps then
3824 Do_Compile_Step := Compile_Only;
3825 Do_Bind_Step := Bind_Only;
3826 Do_Link_Step := Link_Only;
3827
3828 if Do_Compile_Step and then Do_Link_Step then
3829 Do_Bind_Step := True;
3830 end if;
3831 end if;
3832
3833 if N_M_Switch > 0 and RTS_Specified = null then
3834 Process_Multilib;
3835 end if;
3836
3837 if Commands_To_Stdout then
3838 Set_Standard_Output;
3839 end if;
3840
3841 if Usage_Requested then
3842 Usage;
3843 end if;
3844
3845 -- Test for trailing -P switch
3846
3847 if Project_File_Name_Present and then Project_File_Name = null then
3848 Make_Failed ("project file name missing after -P");
3849
3850 -- Test for trailing -o switch
3851
3852 elsif Output_File_Name_Present and then not Output_File_Name_Seen then
3853 Make_Failed ("output file name missing after -o");
3854
3855 -- Test for trailing -D switch
3856
3857 elsif Object_Directory_Present and then not Object_Directory_Seen then
3858 Make_Failed ("object directory missing after -D");
3859 end if;
3860
3861 -- Test for simultaneity of -i and -D
3862
3863 if Object_Directory_Path /= null and then In_Place_Mode then
3864 Make_Failed ("-i and -D cannot be used simultaneously");
3865 end if;
3866
3867 -- If --subdirs= is specified, but not -P, this is equivalent to -D,
3868 -- except that the directory is created if it does not exist.
3869
3870 if Subdirs /= null then
3871 if Object_Directory_Path /= null then
3872 Make_Failed ("--subdirs and -D cannot be used simultaneously");
3873
3874 elsif In_Place_Mode then
3875 Make_Failed ("--subdirs and -i cannot be used simultaneously");
3876
3877 else
3878 if not Is_Directory (Subdirs.all) then
3879 begin
3880 Ada.Directories.Create_Path (Subdirs.all);
3881 exception
3882 when others =>
3883 Make_Failed ("unable to create object directory " &
3884 Subdirs.all);
3885 end;
3886 end if;
3887
3888 Object_Directory_Present := True;
3889
3890 declare
3891 Argv : constant String (1 .. Subdirs'Length) :=
3892 Subdirs.all;
3893 begin
3894 Scan_Make_Arg (Argv);
3895 end;
3896 end if;
3897 end if;
3898
3899 -- Deal with -C= switch
3900
3901 if Gnatmake_Mapping_File /= null then
3902
3903 -- First, check compatibility with other switches
3904
3905 if Maximum_Processes > 1 then
3906 Make_Failed ("-C= switch is not compatible with -jnnn switch");
3907 end if;
3908
3909 Fmap.Initialize (Gnatmake_Mapping_File.all);
3910 Add_Switch
3911 ("-gnatem=" & Gnatmake_Mapping_File.all,
3912 Compiler);
3913 end if;
3914
3915 Osint.Add_Default_Search_Dirs;
3916
3917 -- Source file lookups should be cached for efficiency. Source files
3918 -- are not supposed to change. However, we do that now only if no
3919 -- project file is used; if a project file is used, we do it just
3920 -- after changing the directory to the object directory.
3921
3922 Osint.Source_File_Data (Cache => True);
3923
3924 -- Read gnat.adc file to initialize Fname.UF
3925
3926 Fname.UF.Initialize;
3927
3928 if Config_File then
3929 begin
3930 Fname.SF.Read_Source_File_Name_Pragmas;
3931
3932 exception
3933 when Err : SFN_Scan.Syntax_Error_In_GNAT_ADC =>
3934 Make_Failed (Exception_Message (Err));
3935 end;
3936 end if;
3937
3938 if Debug.Debug_Flag_N then
3939 Opt.Keep_Temporary_Files := True;
3940 end if;
3941 end Initialize;
3942
3943 ---------------------
3944 -- Is_In_Obsoleted --
3945 ---------------------
3946
3947 function Is_In_Obsoleted (F : File_Name_Type) return Boolean is
3948 begin
3949 if F = No_File then
3950 return False;
3951
3952 else
3953 declare
3954 Name : constant String := Get_Name_String (F);
3955 First : Natural;
3956 F2 : File_Name_Type;
3957
3958 begin
3959 First := Name'Last;
3960 while First > Name'First
3961 and then not Is_Directory_Separator (Name (First - 1))
3962 loop
3963 First := First - 1;
3964 end loop;
3965
3966 if First /= Name'First then
3967 Name_Len := 0;
3968 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
3969 F2 := Name_Find;
3970
3971 else
3972 F2 := F;
3973 end if;
3974
3975 return Obsoleted.Get (F2);
3976 end;
3977 end if;
3978 end Is_In_Obsoleted;
3979
3980 ----------
3981 -- Link --
3982 ----------
3983
3984 procedure Link
3985 (ALI_File : File_Name_Type;
3986 Args : Argument_List;
3987 Success : out Boolean)
3988 is
3989 Link_Args : Argument_List (1 .. Args'Length + 1);
3990
3991 begin
3992 Get_Name_String (ALI_File);
3993 Link_Args (1) := new String'(Name_Buffer (1 .. Name_Len));
3994
3995 Link_Args (2 .. Args'Length + 1) := Args;
3996
3997 GNAT.OS_Lib.Normalize_Arguments (Link_Args);
3998
3999 Display (Gnatlink.all, Link_Args);
4000
4001 if Gnatlink_Path = null then
4002 Make_Failed ("error, unable to locate " & Gnatlink.all);
4003 end if;
4004
4005 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
4006 end Link;
4007
4008 ---------------------------
4009 -- List_Bad_Compilations --
4010 ---------------------------
4011
4012 procedure List_Bad_Compilations is
4013 begin
4014 if not No_Exit_Message then
4015 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
4016 if Bad_Compilation.Table (J).File = No_File then
4017 null;
4018 elsif not Bad_Compilation.Table (J).Found then
4019 Inform (Bad_Compilation.Table (J).File, "not found");
4020 else
4021 Inform (Bad_Compilation.Table (J).File, "compilation error");
4022 end if;
4023 end loop;
4024 end if;
4025 end List_Bad_Compilations;
4026
4027 -----------------
4028 -- List_Depend --
4029 -----------------
4030
4031 procedure List_Depend is
4032 Lib_Name : File_Name_Type;
4033 Obj_Name : File_Name_Type;
4034 Src_Name : File_Name_Type;
4035
4036 Len : Natural;
4037 Line_Pos : Natural;
4038 Line_Size : constant := 77;
4039
4040 begin
4041 Set_Standard_Output;
4042
4043 for A in ALIs.First .. ALIs.Last loop
4044 Lib_Name := ALIs.Table (A).Afile;
4045
4046 -- We have to provide the full library file name in In_Place_Mode
4047
4048 if In_Place_Mode then
4049 Lib_Name := Full_Lib_File_Name (Lib_Name);
4050 end if;
4051
4052 Obj_Name := Object_File_Name (Lib_Name);
4053 Write_Name (Obj_Name);
4054 Write_Str (" :");
4055
4056 Get_Name_String (Obj_Name);
4057 Len := Name_Len;
4058 Line_Pos := Len + 2;
4059
4060 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
4061 Src_Name := Sdep.Table (D).Sfile;
4062
4063 if Is_Internal_File_Name (Src_Name)
4064 and then not Check_Readonly_Files
4065 then
4066 null;
4067 else
4068 if not Quiet_Output then
4069 Src_Name := Full_Source_Name (Src_Name);
4070 end if;
4071
4072 Get_Name_String (Src_Name);
4073 Len := Name_Len;
4074
4075 if Line_Pos + Len + 1 > Line_Size then
4076 Write_Str (" \");
4077 Write_Eol;
4078 Line_Pos := 0;
4079 end if;
4080
4081 Line_Pos := Line_Pos + Len + 1;
4082
4083 Write_Str (" ");
4084 Write_Name (Src_Name);
4085 end if;
4086 end loop;
4087
4088 Write_Eol;
4089 end loop;
4090
4091 if not Commands_To_Stdout then
4092 Set_Standard_Error;
4093 end if;
4094 end List_Depend;
4095
4096 -----------------
4097 -- Make_Failed --
4098 -----------------
4099
4100 procedure Make_Failed (S : String) is
4101 begin
4102 Fail_Program (S);
4103 end Make_Failed;
4104
4105 --------------------
4106 -- Mark_Directory --
4107 --------------------
4108
4109 procedure Mark_Directory (Dir : String; Mark : Lib_Mark_Type) is
4110 N : Name_Id;
4111 B : Byte;
4112
4113 Real_Path : constant String := Normalize_Pathname (Dir, "");
4114
4115 begin
4116 Name_Len := 0;
4117
4118 if Real_Path'Length = 0 then
4119 Add_Str_To_Name_Buffer (Dir);
4120
4121 else
4122 Add_Str_To_Name_Buffer (Real_Path);
4123 end if;
4124
4125 -- Last character is supposed to be a directory separator
4126
4127 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
4128 Add_Char_To_Name_Buffer (Directory_Separator);
4129 end if;
4130
4131 -- Add flags to the already existing flags
4132
4133 N := Name_Find;
4134 B := Get_Name_Table_Byte (N);
4135 Set_Name_Table_Byte (N, B or Mark);
4136 end Mark_Directory;
4137
4138 ----------------------
4139 -- Process_Multilib --
4140 ----------------------
4141
4142 procedure Process_Multilib is
4143 Output_FD : File_Descriptor;
4144 Output_Name : String_Access;
4145 Arg_Index : Natural := 0;
4146 Success : Boolean := False;
4147 Return_Code : Integer := 0;
4148 Multilib_Gcc_Path : String_Access;
4149 Multilib_Gcc : String_Access;
4150 N_Read : Integer := 0;
4151 Line : String (1 .. 1000);
4152 Args : Argument_List (1 .. N_M_Switch + 1);
4153
4154 begin
4155 pragma Assert (N_M_Switch > 0 and RTS_Specified = null);
4156
4157 -- In case we detected a multilib switch and the user has not
4158 -- manually specified a specific RTS we emulate the following command:
4159 -- gnatmake $FLAGS --RTS=$(gcc -print-multi-directory $FLAGS)
4160
4161 -- First select the flags which might have an impact on multilib
4162 -- processing. Note that this is an heuristic selection and it
4163 -- will need to be maintained over time. The condition has to
4164 -- be kept synchronized with N_M_Switch counting in Scan_Make_Arg.
4165
4166 for Next_Arg in 1 .. Argument_Count loop
4167 declare
4168 Argv : constant String := Argument (Next_Arg);
4169
4170 begin
4171 if Argv'Length > 2
4172 and then Argv (1) = '-'
4173 and then Argv (2) = 'm'
4174 and then Argv /= "-margs"
4175
4176 -- Ignore -mieee to avoid spawning an extra gcc in this case
4177
4178 and then Argv /= "-mieee"
4179 then
4180 Arg_Index := Arg_Index + 1;
4181 Args (Arg_Index) := new String'(Argv);
4182 end if;
4183 end;
4184 end loop;
4185
4186 pragma Assert (Arg_Index = N_M_Switch);
4187
4188 Args (Args'Last) := new String'("-print-multi-directory");
4189
4190 -- Call the GCC driver with the collected flags and save its
4191 -- output. Alternate design would be to link in gnatmake the
4192 -- relevant part of the GCC driver.
4193
4194 Multilib_Gcc := Gcc;
4195
4196 Multilib_Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Multilib_Gcc.all);
4197
4198 Create_Temp_Output_File (Output_FD, Output_Name);
4199
4200 if Output_FD = Invalid_FD then
4201 return;
4202 end if;
4203
4204 GNAT.OS_Lib.Spawn
4205 (Multilib_Gcc_Path.all, Args, Output_FD, Return_Code, False);
4206 Close (Output_FD);
4207
4208 if Return_Code /= 0 then
4209 return;
4210 end if;
4211
4212 -- Parse the GCC driver output which is a single line, removing CR/LF
4213
4214 Output_FD := Open_Read (Output_Name.all, Binary);
4215
4216 if Output_FD = Invalid_FD then
4217 return;
4218 end if;
4219
4220 N_Read := Read (Output_FD, Line (1)'Address, Line'Length);
4221 Close (Output_FD);
4222 Delete_File (Output_Name.all, Success);
4223
4224 for J in reverse 1 .. N_Read loop
4225 if Line (J) = ASCII.CR or else Line (J) = ASCII.LF then
4226 N_Read := N_Read - 1;
4227 else
4228 exit;
4229 end if;
4230 end loop;
4231
4232 -- In case the standard RTS is selected do nothing
4233
4234 if N_Read = 0 or else Line (1 .. N_Read) = "." then
4235 return;
4236 end if;
4237
4238 -- Otherwise add -margs --RTS=output
4239
4240 Scan_Make_Arg ("-margs");
4241 Scan_Make_Arg ("--RTS=" & Line (1 .. N_Read));
4242 end Process_Multilib;
4243
4244 -------------------------------
4245 -- Report_Compilation_Failed --
4246 -------------------------------
4247
4248 procedure Report_Compilation_Failed is
4249 begin
4250 Fail_Program ("");
4251 end Report_Compilation_Failed;
4252
4253 ------------------------
4254 -- Sigint_Intercepted --
4255 ------------------------
4256
4257 procedure Sigint_Intercepted is
4258 begin
4259 Set_Standard_Error;
4260 Write_Line ("*** Interrupted ***");
4261
4262 -- Send SIGINT to all outstanding compilation processes spawned
4263
4264 for J in 1 .. Outstanding_Compiles loop
4265 Kill (Running_Compile (J).Pid, Hard_Kill => False);
4266 end loop;
4267
4268 Finish_Program (E_No_Compile);
4269 end Sigint_Intercepted;
4270
4271 -------------------
4272 -- Scan_Make_Arg --
4273 -------------------
4274
4275 procedure Scan_Make_Arg (Argv : String) is
4276 Success : Boolean;
4277
4278 begin
4279 Gnatmake_Switch_Found := True;
4280
4281 pragma Assert (Argv'First = 1);
4282
4283 if Argv'Length = 0 then
4284 return;
4285 end if;
4286
4287 -- If the previous switch has set the Output_File_Name_Present flag
4288 -- (that is we have seen a -o), then the next argument is the name of
4289 -- the output executable.
4290
4291 if Output_File_Name_Present and then not Output_File_Name_Seen then
4292 Output_File_Name_Seen := True;
4293
4294 if Argv (1) = '-' then
4295 Make_Failed ("output file name missing after -o");
4296
4297 else
4298 Add_Switch ("-o", Linker);
4299 Add_Switch (Executable_Name (Argv), Linker);
4300 end if;
4301
4302 -- If the previous switch has set the Object_Directory_Present flag
4303 -- (that is we have seen a -D), then the next argument is the path name
4304 -- of the object directory.
4305
4306 elsif Object_Directory_Present
4307 and then not Object_Directory_Seen
4308 then
4309 Object_Directory_Seen := True;
4310
4311 if Argv (1) = '-' then
4312 Make_Failed ("object directory path name missing after -D");
4313
4314 elsif not Is_Directory (Argv) then
4315 Make_Failed ("cannot find object directory """ & Argv & """");
4316
4317 else
4318 -- Record the object directory. Make sure it ends with a directory
4319 -- separator.
4320
4321 declare
4322 Norm : constant String := Normalize_Pathname (Argv);
4323
4324 begin
4325 if Norm (Norm'Last) = Directory_Separator then
4326 Object_Directory_Path := new String'(Norm);
4327 else
4328 Object_Directory_Path :=
4329 new String'(Norm & Directory_Separator);
4330 end if;
4331
4332 Add_Lib_Search_Dir (Norm);
4333
4334 -- Specify the object directory to the binder
4335
4336 Add_Switch ("-aO" & Norm, Binder);
4337 end;
4338
4339 end if;
4340
4341 -- Then check if we are dealing with -cargs/-bargs/-largs/-margs. These
4342 -- options are taken as is when found in package Compiler, Binder or
4343 -- Linker of the main project file.
4344
4345 elsif Argv = "-bargs" or else
4346 Argv = "-cargs" or else
4347 Argv = "-largs" or else
4348 Argv = "-margs"
4349 then
4350 case Argv (2) is
4351 when 'c' => Program_Args := Compiler;
4352 when 'b' => Program_Args := Binder;
4353 when 'l' => Program_Args := Linker;
4354 when 'm' => Program_Args := None;
4355
4356 when others =>
4357 raise Program_Error;
4358 end case;
4359
4360 -- A special test is needed for the -o switch within a -largs since that
4361 -- is another way to specify the name of the final executable.
4362
4363 elsif Program_Args = Linker and then Argv = "-o" then
4364 Make_Failed
4365 ("switch -o not allowed within a -largs. Use -o directly.");
4366
4367 -- Check to see if we are reading switches after a -cargs, -bargs or
4368 -- -largs switch. If so, save it.
4369
4370 elsif Program_Args /= None then
4371
4372 -- Check to see if we are reading -I switches in order to take into
4373 -- account in the src & lib search directories.
4374
4375 if Argv'Length > 2 and then Argv (1 .. 2) = "-I" then
4376 if Argv (3 .. Argv'Last) = "-" then
4377 Look_In_Primary_Dir := False;
4378
4379 elsif Program_Args = Compiler then
4380 Add_Source_Search_Dir (Argv (3 .. Argv'Last));
4381
4382 elsif Program_Args = Binder then
4383 Add_Library_Search_Dir (Argv (3 .. Argv'Last));
4384 end if;
4385 end if;
4386
4387 Add_Switch (Argv, Program_Args);
4388
4389 -- Make sure that all significant switches -m on the command line
4390 -- are counted.
4391
4392 if Argv'Length > 2
4393 and then Argv (1 .. 2) = "-m"
4394 and then Argv /= "-mieee"
4395 then
4396 N_M_Switch := N_M_Switch + 1;
4397 end if;
4398
4399 -- Handle non-default compiler, binder, linker, and handle --RTS switch
4400
4401 elsif Argv'Length > 2 and then Argv (1 .. 2) = "--" then
4402 if Argv'Length > 6
4403 and then Argv (1 .. 6) = "--GCC="
4404 then
4405 declare
4406 Program_Args : constant Argument_List_Access :=
4407 Argument_String_To_List
4408 (Argv (7 .. Argv'Last));
4409
4410 begin
4411 Gcc := new String'(Program_Args.all (1).all);
4412
4413 for J in 2 .. Program_Args.all'Last loop
4414 Add_Switch
4415 (Program_Args.all (J).all, Compiler);
4416 end loop;
4417 end;
4418
4419 elsif Argv'Length > 11
4420 and then Argv (1 .. 11) = "--GNATBIND="
4421 then
4422 declare
4423 Program_Args : constant Argument_List_Access :=
4424 Argument_String_To_List
4425 (Argv (12 .. Argv'Last));
4426
4427 begin
4428 Gnatbind := new String'(Program_Args.all (1).all);
4429
4430 for J in 2 .. Program_Args.all'Last loop
4431 Add_Switch
4432 (Program_Args.all (J).all, Binder);
4433 end loop;
4434 end;
4435
4436 elsif Argv'Length > 11
4437 and then Argv (1 .. 11) = "--GNATLINK="
4438 then
4439 declare
4440 Program_Args : constant Argument_List_Access :=
4441 Argument_String_To_List
4442 (Argv (12 .. Argv'Last));
4443 begin
4444 Gnatlink := new String'(Program_Args.all (1).all);
4445
4446 for J in 2 .. Program_Args.all'Last loop
4447 Add_Switch (Program_Args.all (J).all, Linker);
4448 end loop;
4449 end;
4450
4451 elsif Argv'Length >= 5 and then
4452 Argv (1 .. 5) = "--RTS"
4453 then
4454 Add_Switch (Argv, Compiler);
4455 Add_Switch (Argv, Binder);
4456
4457 if Argv'Length <= 6 or else Argv (6) /= '=' then
4458 Make_Failed ("missing path for --RTS");
4459
4460 else
4461 -- Check that this is the first time we see this switch or
4462 -- if it is not the first time, the same path is specified.
4463
4464 if RTS_Specified = null then
4465 RTS_Specified := new String'(Argv (7 .. Argv'Last));
4466
4467 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
4468 Make_Failed ("--RTS cannot be specified multiple times");
4469 end if;
4470
4471 -- Valid --RTS switch
4472
4473 No_Stdinc := True;
4474 No_Stdlib := True;
4475 RTS_Switch := True;
4476
4477 declare
4478 Src_Path_Name : constant String_Ptr :=
4479 Get_RTS_Search_Dir
4480 (Argv (7 .. Argv'Last), Include);
4481
4482 Lib_Path_Name : constant String_Ptr :=
4483 Get_RTS_Search_Dir
4484 (Argv (7 .. Argv'Last), Objects);
4485
4486 begin
4487 if Src_Path_Name /= null
4488 and then Lib_Path_Name /= null
4489 then
4490 -- Set RTS_*_Path_Name variables, so that correct direct-
4491 -- ories will be set when Osint.Add_Default_Search_Dirs
4492 -- is called later.
4493
4494 RTS_Src_Path_Name := Src_Path_Name;
4495 RTS_Lib_Path_Name := Lib_Path_Name;
4496
4497 elsif Src_Path_Name = null
4498 and then Lib_Path_Name = null
4499 then
4500 Make_Failed
4501 ("RTS path not valid: missing adainclude and adalib "
4502 & "directories");
4503
4504 elsif Src_Path_Name = null then
4505 Make_Failed
4506 ("RTS path not valid: missing adainclude directory");
4507
4508 elsif Lib_Path_Name = null then
4509 Make_Failed
4510 ("RTS path not valid: missing adalib directory");
4511 end if;
4512 end;
4513 end if;
4514
4515 elsif (Argv'Length >= 8 and then Argv (1 .. 8) = "--param=")
4516 or else (Argv'Length >= 10 and then Argv (1 .. 10) = "--sysroot=")
4517 then
4518 Add_Switch (Argv, Compiler);
4519 Add_Switch (Argv, Linker);
4520
4521 elsif Argv = Create_Map_File_Switch then
4522 Map_File := new String'("");
4523
4524 elsif Argv'Length > Create_Map_File_Switch'Length + 1
4525 and then
4526 Argv (1 .. Create_Map_File_Switch'Length) = Create_Map_File_Switch
4527 and then
4528 Argv (Create_Map_File_Switch'Length + 1) = '='
4529 then
4530 Map_File :=
4531 new String'
4532 (Argv (Create_Map_File_Switch'Length + 2 .. Argv'Last));
4533
4534 else
4535 Scan_Make_Switches (Argv, Success);
4536 end if;
4537
4538 -- If we have seen a regular switch process it
4539
4540 elsif Argv (1) = '-' then
4541 if Argv'Length = 1 then
4542 Make_Failed ("switch character cannot be followed by a blank");
4543
4544 -- Incorrect switches that should start with "--"
4545
4546 elsif (Argv'Length > 5 and then Argv (1 .. 5) = "-RTS=")
4547 or else (Argv'Length > 5 and then Argv (1 .. 5) = "-GCC=")
4548 or else (Argv'Length > 8 and then Argv (1 .. 7) = "-param=")
4549 or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATLINK=")
4550 or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATBIND=")
4551 then
4552 Make_Failed ("option " & Argv & " should start with '--'");
4553
4554 -- -I-
4555
4556 elsif Argv (2 .. Argv'Last) = "I-" then
4557 Look_In_Primary_Dir := False;
4558
4559 -- Forbid -?- or -??- where ? is any character
4560
4561 elsif (Argv'Length = 3 and then Argv (3) = '-')
4562 or else (Argv'Length = 4 and then Argv (4) = '-')
4563 then
4564 Make_Failed
4565 ("trailing ""-"" at the end of " & Argv & " forbidden.");
4566
4567 -- -Idir
4568
4569 elsif Argv (2) = 'I' then
4570 Add_Source_Search_Dir (Argv (3 .. Argv'Last));
4571 Add_Library_Search_Dir (Argv (3 .. Argv'Last));
4572 Add_Switch (Argv, Compiler);
4573 Add_Switch (Argv, Binder);
4574
4575 -- -aIdir (to gcc this is like a -I switch)
4576
4577 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
4578 Add_Source_Search_Dir (Argv (4 .. Argv'Last));
4579 Add_Switch
4580 ("-I" & Argv (4 .. Argv'Last), Compiler);
4581 Add_Switch (Argv, Binder);
4582
4583 -- -aOdir
4584
4585 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
4586 Add_Library_Search_Dir (Argv (4 .. Argv'Last));
4587 Add_Switch (Argv, Binder);
4588
4589 -- -aLdir (to gnatbind this is like a -aO switch)
4590
4591 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
4592 Mark_Directory (Argv (4 .. Argv'Last), Ada_Lib_Dir);
4593 Add_Library_Search_Dir (Argv (4 .. Argv'Last));
4594 Add_Switch
4595 ("-aO" & Argv (4 .. Argv'Last), Binder);
4596
4597 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
4598
4599 elsif Argv (2) = 'A' then
4600 Mark_Directory (Argv (3 .. Argv'Last), Ada_Lib_Dir);
4601 Add_Source_Search_Dir (Argv (3 .. Argv'Last));
4602 Add_Library_Search_Dir (Argv (3 .. Argv'Last));
4603 Add_Switch ("-I" & Argv (3 .. Argv'Last), Compiler);
4604 Add_Switch ("-aO" & Argv (3 .. Argv'Last), Binder);
4605
4606 -- -Ldir
4607
4608 elsif Argv (2) = 'L' then
4609 Add_Switch (Argv, Linker);
4610
4611 -- For -gxxx, -pg, -mxxx, -fxxx, -Oxxx, pass the switch to both the
4612 -- compiler and the linker (except for -gnatxxx which is only for the
4613 -- compiler). Some of the -mxxx (for example -m64) and -fxxx (for
4614 -- example -ftest-coverage for gcov) need to be used when compiling
4615 -- the binder generated files, and using all these gcc switches for
4616 -- them should not be a problem. Pass -Oxxx to the linker for LTO.
4617
4618 elsif
4619 (Argv (2) = 'g' and then (Argv'Last < 5
4620 or else Argv (2 .. 5) /= "gnat"))
4621 or else Argv (2 .. Argv'Last) = "pg"
4622 or else (Argv (2) = 'm' and then Argv'Last > 2)
4623 or else (Argv (2) = 'f' and then Argv'Last > 2)
4624 or else Argv (2) = 'O'
4625 then
4626 Add_Switch (Argv, Compiler);
4627 Add_Switch (Argv, Linker);
4628
4629 -- The following condition has to be kept synchronized with
4630 -- the Process_Multilib one.
4631
4632 if Argv (2) = 'm'
4633 and then Argv /= "-mieee"
4634 then
4635 N_M_Switch := N_M_Switch + 1;
4636 end if;
4637
4638 -- -C=<mapping file>
4639
4640 elsif Argv'Last > 2 and then Argv (2) = 'C' then
4641 if Argv (3) /= '=' or else Argv'Last <= 3 then
4642 Make_Failed ("illegal switch " & Argv);
4643 end if;
4644
4645 Gnatmake_Mapping_File := new String'(Argv (4 .. Argv'Last));
4646
4647 -- -D
4648
4649 elsif Argv'Last = 2 and then Argv (2) = 'D' then
4650 if Project_File_Name /= null then
4651 Make_Failed
4652 ("-D cannot be used in conjunction with a project file");
4653
4654 else
4655 Scan_Make_Switches (Argv, Success);
4656 end if;
4657
4658 -- -d
4659
4660 elsif Argv (2) = 'd' and then Argv'Last = 2 then
4661 Display_Compilation_Progress := True;
4662
4663 -- -i
4664
4665 elsif Argv'Last = 2 and then Argv (2) = 'i' then
4666 if Project_File_Name /= null then
4667 Make_Failed
4668 ("-i cannot be used in conjunction with a project file");
4669 else
4670 Scan_Make_Switches (Argv, Success);
4671 end if;
4672
4673 -- -j (need to save the result)
4674
4675 elsif Argv (2) = 'j' then
4676 Scan_Make_Switches (Argv, Success);
4677
4678 -- -m
4679
4680 elsif Argv (2) = 'm' then
4681 pragma Assert (Argv'Last = 2);
4682 Minimal_Recompilation := True;
4683
4684 -- -u and -U (they are differentiated elsewhere)
4685
4686 elsif Argv (2) in 'u' | 'U' and then Argv'Last = 2 then
4687 Unique_Compile := True;
4688 Compile_Only := True;
4689 Do_Bind_Step := False;
4690 Do_Link_Step := False;
4691
4692 -- -Pprj or -P prj (only once, and only on the command line)
4693
4694 elsif Argv (2) = 'P' then
4695 if Project_File_Name /= null then
4696 Make_Failed ("cannot have several project files specified");
4697
4698 elsif Object_Directory_Path /= null then
4699 Make_Failed
4700 ("-D cannot be used in conjunction with a project file");
4701
4702 elsif In_Place_Mode then
4703 Make_Failed
4704 ("-i cannot be used in conjunction with a project file");
4705
4706 elsif Argv'Last = 2 then
4707
4708 -- -P is used alone: the project file name is the next option
4709
4710 Project_File_Name_Present := True;
4711
4712 else
4713 Project_File_Name := new String'(Argv (3 .. Argv'Last));
4714 end if;
4715
4716 -- -vPx (verbosity of the parsing of the project files)
4717
4718 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "vP" then
4719 if Argv'Last /= 4 or else Argv (4) not in '0' .. '2' then
4720 Make_Failed
4721 ("invalid verbosity level " & Argv (4 .. Argv'Last));
4722 end if;
4723
4724 -- -Xext=val (External assignment)
4725
4726 elsif Argv (2) = 'X' then
4727 null;
4728
4729 -- If -gnath is present, then generate the usage information right
4730 -- now and do not pass this option on to the compiler calls.
4731
4732 elsif Argv = "-gnath" then
4733 Usage;
4734
4735 -- If -gnatc is specified, make sure the bind and link steps are not
4736 -- executed.
4737
4738 elsif Argv'Length >= 6 and then Argv (2 .. 6) = "gnatc" then
4739
4740 -- If -gnatc is specified, make sure the bind and link steps are
4741 -- not executed.
4742
4743 Add_Switch (Argv, Compiler);
4744 Operating_Mode := Check_Semantics;
4745 Check_Object_Consistency := False;
4746
4747 -- Except in CodePeer mode (set by -gnatcC), where we do want to
4748 -- call bind/link in CodePeer mode (-P switch).
4749
4750 if Argv'Last >= 7 and then Argv (7) = 'C' then
4751 CodePeer_Mode := True;
4752 else
4753 Compile_Only := True;
4754 Do_Bind_Step := False;
4755 Do_Link_Step := False;
4756 end if;
4757
4758 -- If -gnatA is specified, make sure that gnat.adc is never read
4759
4760 elsif Argv'Length >= 6 and then Argv (2 .. 6) = "gnatA" then
4761 Add_Switch (Argv, Compiler);
4762 Opt.Config_File := False;
4763
4764 elsif Argv (2 .. Argv'Last) = "nostdlib" then
4765
4766 -- Pass -nstdlib to gnatbind and gnatlink
4767
4768 No_Stdlib := True;
4769 Add_Switch (Argv, Binder);
4770 Add_Switch (Argv, Linker);
4771
4772 elsif Argv (2 .. Argv'Last) = "nostdinc" then
4773
4774 -- Pass -nostdinc to the Compiler and to gnatbind
4775
4776 No_Stdinc := True;
4777 Add_Switch (Argv, Compiler);
4778 Add_Switch (Argv, Binder);
4779
4780 -- All other switches are processed by Scan_Make_Switches. If the
4781 -- call returns with Gnatmake_Switch_Found = False, then the switch
4782 -- is passed to the compiler.
4783
4784 else
4785 Scan_Make_Switches (Argv, Gnatmake_Switch_Found);
4786
4787 if not Gnatmake_Switch_Found then
4788 Add_Switch (Argv, Compiler);
4789 end if;
4790 end if;
4791
4792 -- If not a switch it must be a file name
4793
4794 else
4795 Main_On_Command_Line := True;
4796
4797 Add_File (Argv);
4798 Mains.Add_Main (Argv);
4799 end if;
4800 end Scan_Make_Arg;
4801
4802 -----------
4803 -- Usage --
4804 -----------
4805
4806 procedure Usage is
4807 begin
4808 if Usage_Needed then
4809 Usage_Needed := False;
4810 Makeusg;
4811 end if;
4812 end Usage;
4813
4814 end Make;
This page took 0.237073 seconds and 5 git commands to generate.