150276Speter------------------------------------------------------------------------------
276726Speter--                                                                          --
376726Speter--                         GNAT COMPILER COMPONENTS                         --
462449Speter--                                                                          --
562449Speter--                              M A K E U T L                               --
676726Speter--                                                                          --
762449Speter--                                 S p e c                                  --
850276Speter--                                                                          --
950276Speter--          Copyright (C) 2004-2014, Free Software Foundation, Inc.         --
1050276Speter--                                                                          --
1150276Speter-- GNAT is free software;  you can  redistribute it  and/or modify it under --
1250276Speter-- terms of the  GNU General Public License as published  by the Free Soft- --
1350276Speter-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
1450276Speter-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
1550276Speter-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
1650276Speter-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
1750276Speter-- for  more details.  You should have  received  a copy of the GNU General --
1850276Speter-- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
1950276Speter-- http://www.gnu.org/licenses for a complete copy of the license.          --
2050276Speter--                                                                          --
2150276Speter-- GNAT was originally developed  by the GNAT team at  New York University. --
2250276Speter-- Extensive contributions were provided by Ada Core Technologies Inc.      --
2350276Speter--                                                                          --
2450276Speter------------------------------------------------------------------------------
2550276Speter
2650276Speter--  This package contains various subprograms used by the builders, in
2750276Speter--  particular those subprograms related to project management and build
2850276Speter--  queue management.
2950276Speter
3050276Speterwith ALI;
3150276Speterwith Namet;    use Namet;
3262449Speterwith Opt;
3362449Speterwith Osint;
3450276Speterwith Prj;      use Prj;
3550276Speterwith Prj.Tree;
3650276Speterwith Snames;   use Snames;
3750276Speterwith Table;
3850276Speterwith Types;    use Types;
3950276Speter
4050276Speterwith GNAT.OS_Lib; use GNAT.OS_Lib;
4150276Speter
4250276Speterpackage Makeutl is
4350276Speter
4450276Speter   type Fail_Proc is access procedure (S : String);
4550276Speter   --  Pointer to procedure which outputs a failure message
4650276Speter
4750276Speter   Root_Environment : Prj.Tree.Environment;
4850276Speter   --  The environment coming from environment variables and command line
4950276Speter   --  switches. When we do not have an aggregate project, this is used for
5050276Speter   --  parsing the project tree. When we have an aggregate project, this is
5150276Speter   --  used to parse the aggregate project; the latter then generates another
5250276Speter   --  environment (with additional external values and project path) to parse
5350276Speter   --  the aggregated projects.
5462449Speter
5550276Speter   Default_Config_Name : constant String := "default.cgpr";
5662449Speter   --  Name of the configuration file used by gprbuild and generated by
5762449Speter   --  gprconfig by default.
5862449Speter
5962449Speter   On_Windows : constant Boolean := Directory_Separator = '\';
6062449Speter   --  True when on Windows
6162449Speter
6262449Speter   Source_Info_Option : constant String := "--source-info=";
6376726Speter   --  Switch to indicate the source info file
6476726Speter
6576726Speter   Subdirs_Option : constant String := "--subdirs=";
6662449Speter   --  Switch used to indicate that the real directories (object, exec,
6776726Speter   --  library, ...) are subdirectories of those in the project file.
6876726Speter
6976726Speter   Unchecked_Shared_Lib_Imports : constant String :=
7076726Speter                                    "--unchecked-shared-lib-imports";
7176726Speter   --  Command line switch to allow shared library projects to import projects
7276726Speter   --  that are not shared library projects.
7376726Speter
7476726Speter   Single_Compile_Per_Obj_Dir_Switch : constant String :=
7576726Speter                                         "--single-compile-per-obj-dir";
7676726Speter   --  Switch to forbid simultaneous compilations for the same object directory
7776726Speter   --  when project files are used.
7862449Speter
7962449Speter   Create_Map_File_Switch : constant String := "--create-map-file";
8062449Speter   --  Switch to create a map file when an executable is linked
8162449Speter
8262449Speter   No_Exit_Message_Option : constant String := "--no-exit-message";
8376726Speter   --  Switch to suppress exit error message when there are compilation
8476726Speter   --  failures. This is useful when a tool, such as gnatprove, silently calls
8576726Speter   --  the builder and does not want to pollute its output with error messages
8676726Speter   --  coming from the builder. This is an internal switch.
8762449Speter
8862449Speter   Keep_Temp_Files_Option : constant String := "--keep-temp-files";
8962449Speter   --  Switch to suppress deletion of temp files created by the builder.
9062449Speter   --  Note that debug switch -gnatdn also has this effect.
9162449Speter
9262449Speter   Load_Standard_Base : Boolean := True;
9362449Speter   --  False when gprbuild is called with --db-
9462449Speter
9576726Speter   package Db_Switch_Args is new Table.Table
9662449Speter     (Table_Component_Type => Name_Id,
9762449Speter      Table_Index_Type     => Integer,
9862449Speter      Table_Low_Bound      => 1,
9962449Speter      Table_Initial        => 200,
10062449Speter      Table_Increment      => 100,
10162449Speter      Table_Name           => "Makegpr.Db_Switch_Args");
10262449Speter   --  Table of all the arguments of --db switches of gprbuild
10362449Speter
10462449Speter   package Directories is new Table.Table
10562449Speter     (Table_Component_Type => Path_Name_Type,
10662449Speter      Table_Index_Type     => Integer,
10762449Speter      Table_Low_Bound      => 1,
10862449Speter      Table_Initial        => 200,
10962449Speter      Table_Increment      => 100,
11062449Speter      Table_Name           => "Makegpr.Directories");
11162449Speter   --  Table of all the source or object directories, filled up by
11262449Speter   --  Get_Directories.
11362449Speter
11450276Speter   procedure Add
11550276Speter     (Option : String_Access;
11650276Speter      To     : in out String_List_Access;
11750276Speter      Last   : in out Natural);
11850276Speter   procedure Add
11950276Speter     (Option : String;
12076726Speter      To     : in out String_List_Access;
12150276Speter      Last   : in out Natural);
12250276Speter   --  Add a string to a list of strings
12350276Speter
12450276Speter   function Absolute_Path
12550276Speter     (Path    : Path_Name_Type;
12650276Speter      Project : Project_Id) return String;
12750276Speter   --  Returns an absolute path for a configuration pragmas file
12850276Speter
12950276Speter   function Create_Binder_Mapping_File
13050276Speter     (Project_Tree : Project_Tree_Ref) return Path_Name_Type;
13150276Speter   --  Create a binder mapping file and returns its path name
13250276Speter
13350276Speter   function Create_Name (Name : String) return File_Name_Type;
13450276Speter   function Create_Name (Name : String) return Name_Id;
13550276Speter   function Create_Name (Name : String) return Path_Name_Type;
13650276Speter   --  Get an id for a name
13750276Speter
13850276Speter   function Base_Name_Index_For
13950276Speter     (Main            : String;
14050276Speter      Main_Index      : Int;
14150276Speter      Index_Separator : Character) return File_Name_Type;
14250276Speter   --  Returns the base name of Main, without the extension, followed by the
14350276Speter   --  Index_Separator followed by the Main_Index if it is non-zero.
14450276Speter
14550276Speter   function Executable_Prefix_Path return String;
14662449Speter   --  Return the absolute path parent directory of the directory where the
14750276Speter   --  current executable resides, if its directory is named "bin", otherwise
14850276Speter   --  return an empty string. When a directory is returned, it is guaranteed
14950276Speter   --  to end with a directory separator.
15062449Speter
15162449Speter   procedure Inform (N : Name_Id := No_Name; Msg : String);
15262449Speter   procedure Inform (N : File_Name_Type; Msg : String);
15362449Speter   --  Prints out the program name followed by a colon, N and S
15462449Speter
15562449Speter   function File_Not_A_Source_Of
15662449Speter     (Project_Tree : Project_Tree_Ref;
15762449Speter      Uname        : Name_Id;
15862449Speter      Sfile        : File_Name_Type) return Boolean;
15962449Speter   --  Check that file name Sfile is one of the source of unit Uname. Returns
16050276Speter   --  True if the unit is in one of the project file, but the file name is not
16150276Speter   --  one of its source. Returns False otherwise.
16250276Speter
16350276Speter   function Check_Source_Info_In_ALI
16462449Speter     (The_ALI      : ALI.ALI_Id;
16550276Speter      Tree         : Project_Tree_Ref) return Name_Id;
16650276Speter   --  Check whether all file references in ALI are still valid (i.e. the
16750276Speter   --  source files are still associated with the same units). Return the name
16850276Speter   --  of the unit if everything is still valid. Return No_Name otherwise.
16950276Speter
17050276Speter   procedure Ensure_Absolute_Path
17150276Speter     (Switch               : in out String_Access;
17250276Speter      Parent               : String;
17350276Speter      Do_Fail              : Fail_Proc;
17450276Speter      For_Gnatbind         : Boolean := False;
17550276Speter      Including_Non_Switch : Boolean := True;
17650276Speter      Including_RTS        : Boolean := False);
17750276Speter   --  Do nothing if Switch is an absolute path switch. If relative, fail if
17850276Speter   --  Parent is the empty string, otherwise prepend the path with Parent. This
17950276Speter   --  subprogram is only used when using project files. If For_Gnatbind is
18050276Speter   --  True, consider gnatbind specific syntax for -L (not a path, left
18150276Speter   --  unchanged) and -A (path is optional, preceded with "=" if present).
18250276Speter   --  If Including_RTS is True, process also switches --RTS=. Do_Fail is
18362449Speter   --  called in case of error. Using Osint.Fail might be appropriate.
18462449Speter
18562449Speter   function Is_Subunit (Source : Source_Id) return Boolean;
18650276Speter   --  Return True if source is a subunit
18750276Speter
18850276Speter   procedure Initialize_Source_Record (Source : Source_Id);
18950276Speter   --  Get information either about the source file, or the object and
19050276Speter   --  dependency file, as well as their timestamps.
19150276Speter
19250276Speter   function Is_External_Assignment
19350276Speter     (Env  : Prj.Tree.Environment;
19450276Speter      Argv : String) return Boolean;
19550276Speter   --  Verify that an external assignment switch is syntactically correct
19650276Speter   --
19750276Speter   --  Correct forms are:
19850276Speter   --
19950276Speter   --      -Xname=value
20050276Speter   --      -X"name=other value"
20150276Speter   --
20250276Speter   --  Assumptions: 'First = 1, Argv (1 .. 2) = "-X"
20350276Speter   --
20450276Speter   --  When this function returns True, the external assignment has been
20550276Speter   --  entered by a call to Prj.Ext.Add, so that in a project file, External
20650276Speter   --  ("name") will return "value".
20750276Speter
20862449Speter   type Name_Ids is array (Positive range <>) of Name_Id;
20962449Speter   No_Names : constant Name_Ids := (1 .. 0 => No_Name);
21062449Speter   --  Name_Ids is used for list of language names in procedure Get_Directories
21162449Speter   --  below.
21250276Speter
21350276Speter   Ada_Only : constant Name_Ids := (1 => Name_Ada);
21450276Speter   --  Used to invoke Get_Directories in gnatmake
21550276Speter
21650276Speter   type Activity_Type is (Compilation, Executable_Binding, SAL_Binding);
21750276Speter
21876726Speter   procedure Get_Directories
21976726Speter     (Project_Tree : Project_Tree_Ref;
22076726Speter      For_Project  : Project_Id;
22150276Speter      Activity     : Activity_Type;
22276726Speter      Languages    : Name_Ids);
22362449Speter   --  Put in table Directories the source (when Sources is True) or
22462449Speter   --  object/library (when Sources is False) directories of project
22562449Speter   --  For_Project and of all the project it imports directly or indirectly.
22662449Speter   --  The source directories of imported projects are only included if one
22762449Speter   --  of the declared languages is in the list Languages.
22862449Speter
22976726Speter   function Aggregate_Libraries_In (Tree : Project_Tree_Ref) return Boolean;
23076726Speter   --  Return True iff there is one or more aggregate library projects in
23162449Speter   --  the project tree Tree.
23262449Speter
23376726Speter   procedure Write_Path_File (FD : File_Descriptor);
23462449Speter   --  Write in the specified open path file the directories in table
23576726Speter   --  Directories, then closed the path file.
23650276Speter
23750276Speter   procedure Get_Switches
23866963Speter     (Source       : Source_Id;
23966963Speter      Pkg_Name     : Name_Id;
24066963Speter      Project_Tree : Project_Tree_Ref;
24166963Speter      Value        : out Variable_Value;
24266963Speter      Is_Default   : out Boolean);
24362449Speter   procedure Get_Switches
24462449Speter     (Source_File         : File_Name_Type;
24562449Speter      Source_Lang         : Name_Id;
24650276Speter      Source_Prj          : Project_Id;
24750276Speter      Pkg_Name            : Name_Id;
24850276Speter      Project_Tree        : Project_Tree_Ref;
24976726Speter      Value               : out Variable_Value;
25050276Speter      Is_Default          : out Boolean;
25150276Speter      Test_Without_Suffix : Boolean := False;
25250276Speter      Check_ALI_Suffix    : Boolean := False);
25350276Speter   --  Compute the switches (Compilation switches for instance) for the given
25450276Speter   --  file. This checks various attributes to see if there are file specific
25550276Speter   --  switches, or else defaults on the switches for the corresponding
25650276Speter   --  language. Is_Default is set to False if there were file-specific
25750276Speter   --  switches. Source_File can be set to No_File to force retrieval of the
25862449Speter   --  default switches. If Test_Without_Suffix is True, and there is no "for
25962449Speter   --  Switches(Source_File) use", then this procedure also tests without the
26076726Speter   --  extension of the filename. If Test_Without_Suffix is True and
26176726Speter   --  Check_ALI_Suffix is True, then we also replace the file extension with
26250276Speter   --  ".ali" when testing.
26362449Speter
26450276Speter   function Linker_Options_Switches
26576726Speter     (Project  : Project_Id;
26650276Speter      Do_Fail  : Fail_Proc;
26762449Speter      In_Tree  : Project_Tree_Ref) return String_List;
26862449Speter   --  Collect the options specified in the Linker'Linker_Options attributes
26962449Speter   --  of project Project, in project tree In_Tree, and in the projects that
27062449Speter   --  it imports directly or indirectly, and returns the result.
27162449Speter
27276726Speter   function Path_Or_File_Name (Path : Path_Name_Type) return String;
27362449Speter   --  Returns a file name if -df is used, otherwise return a path name
27462449Speter
27562449Speter   function Unit_Index_Of (ALI_File : File_Name_Type) return Int;
27662449Speter   --  Find the index of a unit in a source file. Return zero if the file is
27776726Speter   --  not a multi-unit source file.
27876726Speter
27962449Speter   procedure Verbose_Msg
28062449Speter     (N1                : Name_Id;
28176726Speter      S1                : String;
28250276Speter      N2                : Name_Id := No_Name;
28350276Speter      S2                : String  := "";
28450276Speter      Prefix            : String  := "  -> ";
28562449Speter      Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low);
28662449Speter   procedure Verbose_Msg
28762449Speter     (N1                : File_Name_Type;
28862449Speter      S1                : String;
28950276Speter      N2                : File_Name_Type := No_File;
29050276Speter      S2                : String  := "";
29150276Speter      Prefix            : String  := "  -> ";
29250276Speter      Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low);
29350276Speter   --  If the verbose flag (Verbose_Mode) is set and the verbosity level is at
29450276Speter   --  least equal to Minimum_Verbosity, then print Prefix to standard output
29562449Speter   --  followed by N1 and S1. If N2 /= No_Name then N2 is printed after S1. S2
29662449Speter   --  is printed last. Both N1 and N2 are printed in quotation marks. The two
29762449Speter   --  forms differ only in taking Name_Id or File_name_Type arguments.
29862449Speter
29962449Speter   -------------------------
30062449Speter   -- Program termination --
30162449Speter   -------------------------
30262449Speter
30350276Speter   procedure Fail_Program
30450276Speter     (Project_Tree   : Project_Tree_Ref;
30550276Speter      S              : String;
30650276Speter      Flush_Messages : Boolean := True);
30750276Speter   --  Terminate program with a message and a fatal status code
30850276Speter
30950276Speter   procedure Finish_Program
31050276Speter     (Project_Tree : Project_Tree_Ref;
31150276Speter      Exit_Code    : Osint.Exit_Code_Type := Osint.E_Success;
31250276Speter      S            : String := "");
31350276Speter   --  Terminate program, with or without a message, setting the status code
31450276Speter   --  according to Fatal. This properly removes all temporary files.
31550276Speter
31650276Speter   --------------
31750276Speter   -- Switches --
31876726Speter   --------------
31950276Speter
32050276Speter   generic
32176726Speter      with function Add_Switch
32250276Speter        (Switch      : String;
32350276Speter         For_Lang    : Name_Id;
32450276Speter         For_Builder : Boolean;
32576726Speter         Has_Global_Compilation_Switches : Boolean) return Boolean;
32650276Speter      --  For_Builder is true if we have a builder switch. This function
32750276Speter      --  should return True in case of success (the switch is valid),
32850276Speter      --  False otherwise. The error message will be displayed by
32950276Speter      --  Compute_Builder_Switches itself.
33050276Speter      --
33150276Speter      --  Has_Global_Compilation_Switches is True if the attribute
33262449Speter      --  Global_Compilation_Switches is defined in the project.
33362449Speter
33462449Speter   procedure Compute_Builder_Switches
33562449Speter     (Project_Tree     : Project_Tree_Ref;
33650276Speter      Env              : in out Prj.Tree.Environment;
33750276Speter      Main_Project     : Project_Id;
33850276Speter      Only_For_Lang    : Name_Id := No_Name);
33950276Speter   --  Compute the builder switches and global compilation switches. Every time
34050276Speter   --  a switch is found in the project, it is passed to Add_Switch. You can
34150276Speter   --  provide a value for Only_For_Lang so that we only look for this language
34250276Speter   --  when parsing the global compilation switches.
34350276Speter
34450276Speter   -----------------------
34550276Speter   -- Project_Tree data --
34650276Speter   -----------------------
34750276Speter
34850276Speter   --  The following types are specific to builders, and associated with each
34950276Speter   --  of the loaded project trees.
35050276Speter
35150276Speter   type Binding_Data_Record;
35250276Speter   type Binding_Data is access Binding_Data_Record;
35350276Speter   type Binding_Data_Record is record
35450276Speter      Language           : Language_Ptr;
35550276Speter      Language_Name      : Name_Id;
35650276Speter      Binder_Driver_Name : File_Name_Type;
35750276Speter      Binder_Driver_Path : String_Access;
35850276Speter      Binder_Prefix      : Name_Id;
35950276Speter      Next               : Binding_Data;
36050276Speter   end record;
36150276Speter   --  Data for a language that have a binder driver
36250276Speter
36350276Speter   type Builder_Project_Tree_Data is new Project_Tree_Appdata with record
36450276Speter      Binding : Binding_Data;
36550276Speter
36650276Speter      There_Are_Binder_Drivers : Boolean := False;
36750276Speter      --  True when there is a binder driver. Set by Get_Configuration when
36850276Speter      --  an attribute Language_Processing'Binder_Driver is declared.
36950276Speter      --  Reset to False if there are no sources of the languages with binder
37050276Speter      --  drivers.
37150276Speter
37276726Speter      Number_Of_Mains : Natural := 0;
37376726Speter      --  Number of main units in this project tree
37450276Speter
37550276Speter      Closure_Needed : Boolean := False;
37650276Speter      --  If True, we need to add the closure of the file we just compiled to
37750276Speter      --  the queue. If False, it is assumed that all files are already on the
37850276Speter      --  queue so we do not waste time computing the closure.
37962449Speter
38062449Speter      Need_Compilation : Boolean := True;
38162449Speter      Need_Binding     : Boolean := True;
38250276Speter      Need_Linking     : Boolean := True;
38350276Speter      --  Which of the compilation phases are needed for this project tree
38450276Speter   end record;
38550276Speter   type Builder_Data_Access is access all Builder_Project_Tree_Data;
38650276Speter
38750276Speter   procedure Free (Data : in out Builder_Project_Tree_Data);
38850276Speter   --  Free all memory allocated for Data
38950276Speter
39050276Speter   function Builder_Data (Tree : Project_Tree_Ref) return Builder_Data_Access;
39150276Speter   --  Return (allocate if needed) tree-specific data
39250276Speter
39350276Speter   procedure Compute_Compilation_Phases
39450276Speter     (Tree                  : Project_Tree_Ref;
39550276Speter      Root_Project          : Project_Id;
39650276Speter      Option_Unique_Compile : Boolean := False;   --  Was "-u" specified ?
39750276Speter      Option_Compile_Only   : Boolean := False;   --  Was "-c" specified ?
39850276Speter      Option_Bind_Only      : Boolean := False;
39950276Speter      Option_Link_Only      : Boolean := False);
40050276Speter   --  Compute which compilation phases will be needed for Tree. This also does
40150276Speter   --  the computation for aggregated trees. This also check whether we'll need
40250276Speter   --  to check the closure of the files we have just compiled to add them to
40350276Speter   --  the queue.
40450276Speter
40550276Speter   -----------
40650276Speter   -- Mains --
40750276Speter   -----------
40850276Speter
40950276Speter   --  Package Mains is used to store the mains specified on the command line
41050276Speter   --  and to retrieve them when a project file is used, to verify that the
41150276Speter   --  files exist and that they belong to a project file.
41250276Speter
41350276Speter   --  Mains are stored in a table. An index is used to retrieve the mains
41450276Speter   --  from the table.
41562449Speter
41662449Speter   type Main_Info is record
41762449Speter      File      : File_Name_Type;  --  Always canonical casing
41862449Speter      Index     : Int := 0;
41950276Speter      Location  : Source_Ptr := No_Location;
42050276Speter
42150276Speter      Source    : Prj.Source_Id := No_Source;
42250276Speter      Project   : Project_Id;
42350276Speter      Tree      : Project_Tree_Ref;
42450276Speter   end record;
42550276Speter
42650276Speter   No_Main_Info : constant Main_Info :=
42750276Speter                    (No_File, 0, No_Location, No_Source, No_Project, null);
42850276Speter
42976726Speter   package Mains is
43076726Speter      procedure Add_Main
43176726Speter        (Name     : String;
43276726Speter         Index    : Int := 0;
43350276Speter         Location : Source_Ptr := No_Location;
43450276Speter         Project  : Project_Id := No_Project;
43550276Speter         Tree     : Project_Tree_Ref := null);
43650276Speter      --  Add one main to the table. This is in general used to add the main
43750276Speter      --  files specified on the command line. Index is used for multi-unit
43850276Speter      --  source files, and indicates which unit in the source is concerned.
43950276Speter      --  Location is the location within the project file (if a project file
44050276Speter      --  is used). Project and Tree indicate to which project the main should
44162449Speter      --  belong. In particular, for aggregate projects, this isn't necessarily
44262449Speter      --  the main project tree. These can be set to No_Project and null when
44362449Speter      --  not using projects.
44462449Speter
44562449Speter      procedure Delete;
44662449Speter      --  Empty the table
44762449Speter
44862449Speter      procedure Reset;
44950276Speter      --  Reset the cursor to the beginning of the table
45050276Speter
45150276Speter      procedure Set_Multi_Unit_Index
45250276Speter        (Project_Tree : Project_Tree_Ref := null;
45350276Speter         Index        : Int := 0);
45450276Speter      --  If a single main file was defined, this subprogram indicates which
45550276Speter      --  unit inside it is the main (case of a multi-unit source files).
45650276Speter      --  Errors are raised if zero or more than one main file was defined,
45750276Speter      --  and Index is non-zaero. This subprogram is used for the handling
45850276Speter      --  of the command line switch.
45950276Speter
46050276Speter      function Next_Main return String;
46150276Speter      function Next_Main return Main_Info;
46250276Speter      --  Moves the cursor forward and returns the new current entry. Returns
46350276Speter      --  No_Main_Info there are no more mains in the table.
46462449Speter
46562449Speter      function Number_Of_Mains (Tree : Project_Tree_Ref) return Natural;
46662449Speter      --  Returns the number of mains in this project tree (if Tree is null, it
46750276Speter      --  returns the total number of project trees)
46850276Speter
46950276Speter      procedure Fill_From_Project
47050276Speter        (Root_Project : Project_Id;
47150276Speter         Project_Tree : Project_Tree_Ref);
47250276Speter      --  If no main was already added (presumably from the command line), add
47362449Speter      --  the main units from root_project (or in the case of an aggregate
47462449Speter      --  project from all the aggregated projects).
47562449Speter
47662449Speter      procedure Complete_Mains
47750276Speter        (Flags        : Processing_Flags;
47850276Speter         Root_Project : Project_Id;
47962449Speter         Project_Tree : Project_Tree_Ref);
48062449Speter      --  If some main units were already added from the command line, check
48162449Speter      --  that they all belong to the root project, and that they are full
48262449Speter      --  paths rather than (partial) base names (e.g. no body suffix was
48362449Speter      --  specified).
48462449Speter
48562449Speter   end Mains;
48662449Speter
48762449Speter   -----------
48862449Speter   -- Queue --
48962449Speter   -----------
49050276Speter
49150276Speter   type Source_Info_Format is (Format_Gprbuild, Format_Gnatmake);
49250276Speter
49350276Speter   package Queue is
49450276Speter
49550276Speter      --  The queue of sources to be checked for compilation. There can be a
49662449Speter      --  single such queue per application.
49762449Speter
49862449Speter      type Source_Info (Format : Source_Info_Format := Format_Gprbuild) is
49962449Speter         record
50062449Speter            case Format is
50162449Speter               when Format_Gprbuild =>
50262449Speter                  Tree    : Project_Tree_Ref := No_Project_Tree;
50362449Speter                  Id      : Source_Id        := No_Source;
50450276Speter                  Closure : Boolean          := False;
50550276Speter
50650276Speter               when Format_Gnatmake =>
50750276Speter                  File    : File_Name_Type := No_File;
50850276Speter                  Unit    : Unit_Name_Type := No_Unit_Name;
50950276Speter                  Index   : Int            := 0;
51050276Speter                  Project : Project_Id     := No_Project;
51150276Speter                  Sid     : Source_Id      := No_Source;
51250276Speter            end case;
51350276Speter         end record;
51450276Speter      --  Information about files stored in the queue. The exact information
51550276Speter      --  depends on the builder, and in particular whether it only supports
51650276Speter      --  project-based files (in which case we have a full Source_Id record).
51750276Speter
51850276Speter      No_Source_Info : constant Source_Info :=
51950276Speter                         (Format_Gprbuild, null, null, False);
52050276Speter
52150276Speter      procedure Initialize
52250276Speter        (Queue_Per_Obj_Dir : Boolean;
52350276Speter         Force             : Boolean := False);
52462449Speter      --  Initialize the queue
52562449Speter      --
52662449Speter      --  Queue_Per_Obj_Dir matches the --single-compile-per-obj-dir switch:
52762449Speter      --  when True, there cannot be simultaneous compilations with the object
52862449Speter      --  files in the same object directory when project files are used.
52962449Speter      --
53062449Speter      --  Nothing is done if Force is False and the queue was already
53162449Speter      --  initialized.
53250276Speter
53350276Speter      procedure Remove_Marks;
53450276Speter      --  Remove all marks set for the files. This means that the files will be
53550276Speter      --  handed to the compiler if they are added to the queue, and is mostly
53650276Speter      --  useful when recompiling several executables in non-project mode, as
53750276Speter      --  the switches may be different and -s may be in use.
53850276Speter
53950276Speter      function Is_Empty return Boolean;
54050276Speter      --  Returns True if the queue is empty
54150276Speter
54250276Speter      function Is_Virtually_Empty return Boolean;
54350276Speter      --  Returns True if queue is empty or if all object directories are busy
54450276Speter
54550276Speter      procedure Insert (Source  : Source_Info; With_Roots : Boolean := False);
54650276Speter      function Insert
54750276Speter        (Source  : Source_Info; With_Roots : Boolean := False) return Boolean;
54850276Speter      --  Insert source in the queue. The second version returns False if the
54950276Speter      --  Source was already marked in the queue. If With_Roots is True and the
55050276Speter      --  source is in Format_Gprbuild mode (ie with a project), this procedure
55150276Speter      --  also includes the "Roots" for this main, ie all the other files that
55250276Speter      --  must be included in the library or binary (in particular to combine
55350276Speter      --  Ada and C files connected through pragma Export/Import). When the
55450276Speter      --  roots are computed, they are also stored in the corresponding
55550276Speter      --  Source_Id for later reuse by the binder.
55650276Speter
55776726Speter      procedure Insert_Project_Sources
55876726Speter        (Project        : Project_Id;
55976726Speter         Project_Tree   : Project_Tree_Ref;
56076726Speter         All_Projects   : Boolean;
56150276Speter         Unique_Compile : Boolean);
56250276Speter      --  Insert all the compilable sources of the project in the queue. If
56350276Speter      --  All_Project is true, then all sources from imported projects are also
56462449Speter      --  inserted. Unique_Compile should be true if "-u" was specified on the
56562449Speter      --  command line: if True and some files were given on the command line),
56662449Speter      --  only those files will be compiled (so Insert_Project_Sources will do
56762449Speter      --  nothing). If True and no file was specified on the command line, all
56850276Speter      --  files of the project(s) will be compiled. This procedure also
56950276Speter      --  processed aggregated projects.
57050276Speter
57150276Speter      procedure Insert_Withed_Sources_For
57250276Speter        (The_ALI               : ALI.ALI_Id;
57350276Speter         Project_Tree          : Project_Tree_Ref;
57450276Speter         Excluding_Shared_SALs : Boolean := False);
57550276Speter      --  Insert in the queue those sources withed by The_ALI, if there are not
57650276Speter      --  already in the queue and Only_Interfaces is False or they are part of
57750276Speter      --  the interfaces of their project.
57850276Speter
57950276Speter      procedure Extract
58050276Speter        (Found  : out Boolean;
58150276Speter         Source : out Source_Info);
58262449Speter      --  Get the first source that can be compiled from the queue. If no
58362449Speter      --  source may be compiled, sets Found to False. In this case, the value
58462449Speter      --  for Source is undefined.
58562449Speter
58662449Speter      function Size return Natural;
58762449Speter      --  Return the total size of the queue, including the sources already
58862449Speter      --  extracted.
58962449Speter
59062449Speter      function Processed return Natural;
59176726Speter      --  Return the number of source in the queue that have aready been
59262449Speter      --  processed.
59362449Speter
59462449Speter      procedure Set_Obj_Dir_Busy (Obj_Dir : Path_Name_Type);
59562449Speter      procedure Set_Obj_Dir_Free (Obj_Dir : Path_Name_Type);
59662449Speter      --  Mark Obj_Dir as busy or free (see the parameter to Initialize)
59762449Speter
59850276Speter      function Element (Rank : Positive) return File_Name_Type;
59950276Speter      --  Get the file name for element of index Rank in the queue
60050276Speter
60150276Speter   end Queue;
60262449Speter
60362449Speterend Makeutl;
60462449Speter