------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
-- --
|
-- --
|
-- GNAT COMPILER COMPONENTS --
|
-- GNAT COMPILER COMPONENTS --
|
-- --
|
-- --
|
-- P R J . C O N F --
|
-- P R J . C O N F --
|
-- --
|
-- --
|
-- B o d y --
|
-- B o d y --
|
-- --
|
-- --
|
-- Copyright (C) 2006-2009, Free Software Foundation, Inc. --
|
-- Copyright (C) 2006-2009, Free Software Foundation, Inc. --
|
-- --
|
-- --
|
-- GNAT is free software; you can redistribute it and/or modify it under --
|
-- GNAT is free software; you can redistribute it and/or modify it under --
|
-- terms of the GNU General Public License as published by the Free Soft- --
|
-- terms of the GNU General Public License as published by the Free Soft- --
|
-- ware Foundation; either version 3, or (at your option) any later ver- --
|
-- ware Foundation; either version 3, or (at your option) any later ver- --
|
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
|
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
|
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
|
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
|
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
|
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
|
-- for more details. You should have received a copy of the GNU General --
|
-- for more details. You should have received a copy of the GNU General --
|
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
|
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
|
-- http://www.gnu.org/licenses for a complete copy of the license. --
|
-- http://www.gnu.org/licenses for a complete copy of the license. --
|
-- --
|
-- --
|
-- GNAT was originally developed by the GNAT team at New York University. --
|
-- GNAT was originally developed by the GNAT team at New York University. --
|
-- Extensive contributions were provided by Ada Core Technologies Inc. --
|
-- Extensive contributions were provided by Ada Core Technologies Inc. --
|
-- --
|
-- --
|
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
|
|
with Ada.Directories; use Ada.Directories;
|
with Ada.Directories; use Ada.Directories;
|
with GNAT.HTable; use GNAT.HTable;
|
with GNAT.HTable; use GNAT.HTable;
|
with Makeutl; use Makeutl;
|
with Makeutl; use Makeutl;
|
with MLib.Tgt;
|
with MLib.Tgt;
|
with Opt; use Opt;
|
with Opt; use Opt;
|
with Output; use Output;
|
with Output; use Output;
|
with Prj.Env;
|
with Prj.Env;
|
with Prj.Err;
|
with Prj.Err;
|
with Prj.Part;
|
with Prj.Part;
|
with Prj.PP;
|
with Prj.PP;
|
with Prj.Proc; use Prj.Proc;
|
with Prj.Proc; use Prj.Proc;
|
with Prj.Tree; use Prj.Tree;
|
with Prj.Tree; use Prj.Tree;
|
with Prj.Util; use Prj.Util;
|
with Prj.Util; use Prj.Util;
|
with Prj; use Prj;
|
with Prj; use Prj;
|
with Snames; use Snames;
|
with Snames; use Snames;
|
with System.Case_Util; use System.Case_Util;
|
with System.Case_Util; use System.Case_Util;
|
with System;
|
with System;
|
|
|
package body Prj.Conf is
|
package body Prj.Conf is
|
|
|
Auto_Cgpr : constant String := "auto.cgpr";
|
Auto_Cgpr : constant String := "auto.cgpr";
|
|
|
Default_Name : constant String := "default.cgpr";
|
Default_Name : constant String := "default.cgpr";
|
-- Default configuration file that will be used if found
|
-- Default configuration file that will be used if found
|
|
|
Config_Project_Env_Var : constant String := "GPR_CONFIG";
|
Config_Project_Env_Var : constant String := "GPR_CONFIG";
|
-- Name of the environment variable that provides the name of the
|
-- Name of the environment variable that provides the name of the
|
-- configuration file to use.
|
-- configuration file to use.
|
|
|
Gprconfig_Name : constant String := "gprconfig";
|
Gprconfig_Name : constant String := "gprconfig";
|
|
|
package RTS_Languages is new GNAT.HTable.Simple_HTable
|
package RTS_Languages is new GNAT.HTable.Simple_HTable
|
(Header_Num => Prj.Header_Num,
|
(Header_Num => Prj.Header_Num,
|
Element => Name_Id,
|
Element => Name_Id,
|
No_Element => No_Name,
|
No_Element => No_Name,
|
Key => Name_Id,
|
Key => Name_Id,
|
Hash => Prj.Hash,
|
Hash => Prj.Hash,
|
Equal => "=");
|
Equal => "=");
|
-- Stores the runtime names for the various languages. This is in general
|
-- Stores the runtime names for the various languages. This is in general
|
-- set from a --RTS command line option.
|
-- set from a --RTS command line option.
|
|
|
procedure Add_Attributes
|
procedure Add_Attributes
|
(Project_Tree : Project_Tree_Ref;
|
(Project_Tree : Project_Tree_Ref;
|
Conf_Decl : Declarations;
|
Conf_Decl : Declarations;
|
User_Decl : in out Declarations);
|
User_Decl : in out Declarations);
|
-- Process the attributes in the config declarations.
|
-- Process the attributes in the config declarations.
|
-- For single string values, if the attribute is not declared in the user
|
-- For single string values, if the attribute is not declared in the user
|
-- declarations, declare it with the value in the config declarations.
|
-- declarations, declare it with the value in the config declarations.
|
-- For string list values, prepend the value in the user declarations with
|
-- For string list values, prepend the value in the user declarations with
|
-- the value in the config declarations.
|
-- the value in the config declarations.
|
|
|
function Locate_Config_File (Name : String) return String_Access;
|
function Locate_Config_File (Name : String) return String_Access;
|
-- Search for Name in the config files directory. Return full path if
|
-- Search for Name in the config files directory. Return full path if
|
-- found, or null otherwise
|
-- found, or null otherwise
|
|
|
function Check_Target
|
function Check_Target
|
(Config_File : Prj.Project_Id;
|
(Config_File : Prj.Project_Id;
|
Autoconf_Specified : Boolean;
|
Autoconf_Specified : Boolean;
|
Project_Tree : Prj.Project_Tree_Ref;
|
Project_Tree : Prj.Project_Tree_Ref;
|
Target : String := "") return Boolean;
|
Target : String := "") return Boolean;
|
-- Check that the config file's target matches Target.
|
-- Check that the config file's target matches Target.
|
-- Target should be set to the empty string when the user did not specify
|
-- Target should be set to the empty string when the user did not specify
|
-- a target. If the target in the configuration file is invalid, this
|
-- a target. If the target in the configuration file is invalid, this
|
-- function will raise Invalid_Config with an appropriate message.
|
-- function will raise Invalid_Config with an appropriate message.
|
-- Autoconf_Specified should be set to True if the user has used --autoconf
|
-- Autoconf_Specified should be set to True if the user has used --autoconf
|
|
|
--------------------
|
--------------------
|
-- Add_Attributes --
|
-- Add_Attributes --
|
--------------------
|
--------------------
|
|
|
procedure Add_Attributes
|
procedure Add_Attributes
|
(Project_Tree : Project_Tree_Ref;
|
(Project_Tree : Project_Tree_Ref;
|
Conf_Decl : Declarations;
|
Conf_Decl : Declarations;
|
User_Decl : in out Declarations)
|
User_Decl : in out Declarations)
|
is
|
is
|
Conf_Attr_Id : Variable_Id;
|
Conf_Attr_Id : Variable_Id;
|
Conf_Attr : Variable;
|
Conf_Attr : Variable;
|
Conf_Array_Id : Array_Id;
|
Conf_Array_Id : Array_Id;
|
Conf_Array : Array_Data;
|
Conf_Array : Array_Data;
|
Conf_Array_Elem_Id : Array_Element_Id;
|
Conf_Array_Elem_Id : Array_Element_Id;
|
Conf_Array_Elem : Array_Element;
|
Conf_Array_Elem : Array_Element;
|
Conf_List : String_List_Id;
|
Conf_List : String_List_Id;
|
Conf_List_Elem : String_Element;
|
Conf_List_Elem : String_Element;
|
|
|
User_Attr_Id : Variable_Id;
|
User_Attr_Id : Variable_Id;
|
User_Attr : Variable;
|
User_Attr : Variable;
|
User_Array_Id : Array_Id;
|
User_Array_Id : Array_Id;
|
User_Array : Array_Data;
|
User_Array : Array_Data;
|
User_Array_Elem_Id : Array_Element_Id;
|
User_Array_Elem_Id : Array_Element_Id;
|
User_Array_Elem : Array_Element;
|
User_Array_Elem : Array_Element;
|
|
|
begin
|
begin
|
Conf_Attr_Id := Conf_Decl.Attributes;
|
Conf_Attr_Id := Conf_Decl.Attributes;
|
User_Attr_Id := User_Decl.Attributes;
|
User_Attr_Id := User_Decl.Attributes;
|
while Conf_Attr_Id /= No_Variable loop
|
while Conf_Attr_Id /= No_Variable loop
|
Conf_Attr :=
|
Conf_Attr :=
|
Project_Tree.Variable_Elements.Table (Conf_Attr_Id);
|
Project_Tree.Variable_Elements.Table (Conf_Attr_Id);
|
User_Attr :=
|
User_Attr :=
|
Project_Tree.Variable_Elements.Table (User_Attr_Id);
|
Project_Tree.Variable_Elements.Table (User_Attr_Id);
|
|
|
if not Conf_Attr.Value.Default then
|
if not Conf_Attr.Value.Default then
|
if User_Attr.Value.Default then
|
if User_Attr.Value.Default then
|
|
|
-- No attribute declared in user project file: just copy the
|
-- No attribute declared in user project file: just copy the
|
-- value of the configuration attribute.
|
-- value of the configuration attribute.
|
|
|
User_Attr.Value := Conf_Attr.Value;
|
User_Attr.Value := Conf_Attr.Value;
|
Project_Tree.Variable_Elements.Table (User_Attr_Id) :=
|
Project_Tree.Variable_Elements.Table (User_Attr_Id) :=
|
User_Attr;
|
User_Attr;
|
|
|
elsif User_Attr.Value.Kind = List
|
elsif User_Attr.Value.Kind = List
|
and then Conf_Attr.Value.Values /= Nil_String
|
and then Conf_Attr.Value.Values /= Nil_String
|
then
|
then
|
-- List attribute declared in both the user project and the
|
-- List attribute declared in both the user project and the
|
-- configuration project: prepend the user list with the
|
-- configuration project: prepend the user list with the
|
-- configuration list.
|
-- configuration list.
|
|
|
declare
|
declare
|
Conf_List : String_List_Id := Conf_Attr.Value.Values;
|
Conf_List : String_List_Id := Conf_Attr.Value.Values;
|
Conf_Elem : String_Element;
|
Conf_Elem : String_Element;
|
User_List : constant String_List_Id :=
|
User_List : constant String_List_Id :=
|
User_Attr.Value.Values;
|
User_Attr.Value.Values;
|
New_List : String_List_Id;
|
New_List : String_List_Id;
|
New_Elem : String_Element;
|
New_Elem : String_Element;
|
|
|
begin
|
begin
|
-- Create new list
|
-- Create new list
|
|
|
String_Element_Table.Increment_Last
|
String_Element_Table.Increment_Last
|
(Project_Tree.String_Elements);
|
(Project_Tree.String_Elements);
|
New_List := String_Element_Table.Last
|
New_List := String_Element_Table.Last
|
(Project_Tree.String_Elements);
|
(Project_Tree.String_Elements);
|
|
|
-- Value of attribute is new list
|
-- Value of attribute is new list
|
|
|
User_Attr.Value.Values := New_List;
|
User_Attr.Value.Values := New_List;
|
Project_Tree.Variable_Elements.Table (User_Attr_Id) :=
|
Project_Tree.Variable_Elements.Table (User_Attr_Id) :=
|
User_Attr;
|
User_Attr;
|
|
|
loop
|
loop
|
|
|
-- Get each element of configuration list
|
-- Get each element of configuration list
|
|
|
Conf_Elem :=
|
Conf_Elem :=
|
Project_Tree.String_Elements.Table (Conf_List);
|
Project_Tree.String_Elements.Table (Conf_List);
|
New_Elem := Conf_Elem;
|
New_Elem := Conf_Elem;
|
Conf_List := Conf_Elem.Next;
|
Conf_List := Conf_Elem.Next;
|
|
|
if Conf_List = Nil_String then
|
if Conf_List = Nil_String then
|
|
|
-- If it is the last element in the list, connect to
|
-- If it is the last element in the list, connect to
|
-- first element of user list, and we are done.
|
-- first element of user list, and we are done.
|
|
|
New_Elem.Next := User_List;
|
New_Elem.Next := User_List;
|
Project_Tree.String_Elements.Table
|
Project_Tree.String_Elements.Table
|
(New_List) := New_Elem;
|
(New_List) := New_Elem;
|
exit;
|
exit;
|
|
|
else
|
else
|
-- If it is not the last element in the list, add to
|
-- If it is not the last element in the list, add to
|
-- new list.
|
-- new list.
|
|
|
String_Element_Table.Increment_Last
|
String_Element_Table.Increment_Last
|
(Project_Tree.String_Elements);
|
(Project_Tree.String_Elements);
|
New_Elem.Next :=
|
New_Elem.Next :=
|
String_Element_Table.Last
|
String_Element_Table.Last
|
(Project_Tree.String_Elements);
|
(Project_Tree.String_Elements);
|
Project_Tree.String_Elements.Table
|
Project_Tree.String_Elements.Table
|
(New_List) := New_Elem;
|
(New_List) := New_Elem;
|
New_List := New_Elem.Next;
|
New_List := New_Elem.Next;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
end;
|
end;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
Conf_Attr_Id := Conf_Attr.Next;
|
Conf_Attr_Id := Conf_Attr.Next;
|
User_Attr_Id := User_Attr.Next;
|
User_Attr_Id := User_Attr.Next;
|
end loop;
|
end loop;
|
|
|
Conf_Array_Id := Conf_Decl.Arrays;
|
Conf_Array_Id := Conf_Decl.Arrays;
|
while Conf_Array_Id /= No_Array loop
|
while Conf_Array_Id /= No_Array loop
|
Conf_Array := Project_Tree.Arrays.Table (Conf_Array_Id);
|
Conf_Array := Project_Tree.Arrays.Table (Conf_Array_Id);
|
|
|
User_Array_Id := User_Decl.Arrays;
|
User_Array_Id := User_Decl.Arrays;
|
while User_Array_Id /= No_Array loop
|
while User_Array_Id /= No_Array loop
|
User_Array := Project_Tree.Arrays.Table (User_Array_Id);
|
User_Array := Project_Tree.Arrays.Table (User_Array_Id);
|
exit when User_Array.Name = Conf_Array.Name;
|
exit when User_Array.Name = Conf_Array.Name;
|
User_Array_Id := User_Array.Next;
|
User_Array_Id := User_Array.Next;
|
end loop;
|
end loop;
|
|
|
-- If this associative array does not exist in the user project file,
|
-- If this associative array does not exist in the user project file,
|
-- do a shallow copy of the full associative array.
|
-- do a shallow copy of the full associative array.
|
|
|
if User_Array_Id = No_Array then
|
if User_Array_Id = No_Array then
|
Array_Table.Increment_Last (Project_Tree.Arrays);
|
Array_Table.Increment_Last (Project_Tree.Arrays);
|
User_Array := Conf_Array;
|
User_Array := Conf_Array;
|
User_Array.Next := User_Decl.Arrays;
|
User_Array.Next := User_Decl.Arrays;
|
User_Decl.Arrays := Array_Table.Last (Project_Tree.Arrays);
|
User_Decl.Arrays := Array_Table.Last (Project_Tree.Arrays);
|
Project_Tree.Arrays.Table (User_Decl.Arrays) := User_Array;
|
Project_Tree.Arrays.Table (User_Decl.Arrays) := User_Array;
|
|
|
else
|
else
|
-- Otherwise, check each array element
|
-- Otherwise, check each array element
|
|
|
Conf_Array_Elem_Id := Conf_Array.Value;
|
Conf_Array_Elem_Id := Conf_Array.Value;
|
while Conf_Array_Elem_Id /= No_Array_Element loop
|
while Conf_Array_Elem_Id /= No_Array_Element loop
|
Conf_Array_Elem :=
|
Conf_Array_Elem :=
|
Project_Tree.Array_Elements.Table (Conf_Array_Elem_Id);
|
Project_Tree.Array_Elements.Table (Conf_Array_Elem_Id);
|
|
|
User_Array_Elem_Id := User_Array.Value;
|
User_Array_Elem_Id := User_Array.Value;
|
while User_Array_Elem_Id /= No_Array_Element loop
|
while User_Array_Elem_Id /= No_Array_Element loop
|
User_Array_Elem :=
|
User_Array_Elem :=
|
Project_Tree.Array_Elements.Table (User_Array_Elem_Id);
|
Project_Tree.Array_Elements.Table (User_Array_Elem_Id);
|
exit when User_Array_Elem.Index = Conf_Array_Elem.Index;
|
exit when User_Array_Elem.Index = Conf_Array_Elem.Index;
|
User_Array_Elem_Id := User_Array_Elem.Next;
|
User_Array_Elem_Id := User_Array_Elem.Next;
|
end loop;
|
end loop;
|
|
|
-- If the array element does not exist in the user array,
|
-- If the array element does not exist in the user array,
|
-- insert a shallow copy of the conf array element in the
|
-- insert a shallow copy of the conf array element in the
|
-- user array.
|
-- user array.
|
|
|
if User_Array_Elem_Id = No_Array_Element then
|
if User_Array_Elem_Id = No_Array_Element then
|
Array_Element_Table.Increment_Last
|
Array_Element_Table.Increment_Last
|
(Project_Tree.Array_Elements);
|
(Project_Tree.Array_Elements);
|
User_Array_Elem := Conf_Array_Elem;
|
User_Array_Elem := Conf_Array_Elem;
|
User_Array_Elem.Next := User_Array.Value;
|
User_Array_Elem.Next := User_Array.Value;
|
User_Array.Value :=
|
User_Array.Value :=
|
Array_Element_Table.Last (Project_Tree.Array_Elements);
|
Array_Element_Table.Last (Project_Tree.Array_Elements);
|
Project_Tree.Array_Elements.Table (User_Array.Value) :=
|
Project_Tree.Array_Elements.Table (User_Array.Value) :=
|
User_Array_Elem;
|
User_Array_Elem;
|
Project_Tree.Arrays.Table (User_Array_Id) := User_Array;
|
Project_Tree.Arrays.Table (User_Array_Id) := User_Array;
|
|
|
-- Otherwise, if the value is a string list, prepend the
|
-- Otherwise, if the value is a string list, prepend the
|
-- user array element with the conf array element value.
|
-- user array element with the conf array element value.
|
|
|
elsif Conf_Array_Elem.Value.Kind = List then
|
elsif Conf_Array_Elem.Value.Kind = List then
|
Conf_List := Conf_Array_Elem.Value.Values;
|
Conf_List := Conf_Array_Elem.Value.Values;
|
|
|
if Conf_List /= Nil_String then
|
if Conf_List /= Nil_String then
|
declare
|
declare
|
Link : constant String_List_Id :=
|
Link : constant String_List_Id :=
|
User_Array_Elem.Value.Values;
|
User_Array_Elem.Value.Values;
|
Previous : String_List_Id := Nil_String;
|
Previous : String_List_Id := Nil_String;
|
Next : String_List_Id;
|
Next : String_List_Id;
|
|
|
begin
|
begin
|
loop
|
loop
|
Conf_List_Elem :=
|
Conf_List_Elem :=
|
Project_Tree.String_Elements.Table
|
Project_Tree.String_Elements.Table
|
(Conf_List);
|
(Conf_List);
|
String_Element_Table.Increment_Last
|
String_Element_Table.Increment_Last
|
(Project_Tree.String_Elements);
|
(Project_Tree.String_Elements);
|
Next :=
|
Next :=
|
String_Element_Table.Last
|
String_Element_Table.Last
|
(Project_Tree.String_Elements);
|
(Project_Tree.String_Elements);
|
Project_Tree.String_Elements.Table (Next) :=
|
Project_Tree.String_Elements.Table (Next) :=
|
Conf_List_Elem;
|
Conf_List_Elem;
|
|
|
if Previous = Nil_String then
|
if Previous = Nil_String then
|
User_Array_Elem.Value.Values := Next;
|
User_Array_Elem.Value.Values := Next;
|
Project_Tree.Array_Elements.Table
|
Project_Tree.Array_Elements.Table
|
(User_Array_Elem_Id) := User_Array_Elem;
|
(User_Array_Elem_Id) := User_Array_Elem;
|
|
|
else
|
else
|
Project_Tree.String_Elements.Table
|
Project_Tree.String_Elements.Table
|
(Previous).Next := Next;
|
(Previous).Next := Next;
|
end if;
|
end if;
|
|
|
Previous := Next;
|
Previous := Next;
|
|
|
Conf_List := Conf_List_Elem.Next;
|
Conf_List := Conf_List_Elem.Next;
|
|
|
if Conf_List = Nil_String then
|
if Conf_List = Nil_String then
|
Project_Tree.String_Elements.Table
|
Project_Tree.String_Elements.Table
|
(Previous).Next := Link;
|
(Previous).Next := Link;
|
exit;
|
exit;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
end;
|
end;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
Conf_Array_Elem_Id := Conf_Array_Elem.Next;
|
Conf_Array_Elem_Id := Conf_Array_Elem.Next;
|
end loop;
|
end loop;
|
end if;
|
end if;
|
|
|
Conf_Array_Id := Conf_Array.Next;
|
Conf_Array_Id := Conf_Array.Next;
|
end loop;
|
end loop;
|
end Add_Attributes;
|
end Add_Attributes;
|
|
|
------------------------
|
------------------------
|
-- Locate_Config_File --
|
-- Locate_Config_File --
|
------------------------
|
------------------------
|
|
|
function Locate_Config_File (Name : String) return String_Access is
|
function Locate_Config_File (Name : String) return String_Access is
|
Prefix_Path : constant String := Executable_Prefix_Path;
|
Prefix_Path : constant String := Executable_Prefix_Path;
|
begin
|
begin
|
if Prefix_Path'Length /= 0 then
|
if Prefix_Path'Length /= 0 then
|
return Locate_Regular_File
|
return Locate_Regular_File
|
(Name,
|
(Name,
|
"." & Path_Separator &
|
"." & Path_Separator &
|
Prefix_Path & "share" & Directory_Separator & "gpr");
|
Prefix_Path & "share" & Directory_Separator & "gpr");
|
else
|
else
|
return Locate_Regular_File (Name, ".");
|
return Locate_Regular_File (Name, ".");
|
end if;
|
end if;
|
end Locate_Config_File;
|
end Locate_Config_File;
|
|
|
------------------
|
------------------
|
-- Check_Target --
|
-- Check_Target --
|
------------------
|
------------------
|
|
|
function Check_Target
|
function Check_Target
|
(Config_File : Project_Id;
|
(Config_File : Project_Id;
|
Autoconf_Specified : Boolean;
|
Autoconf_Specified : Boolean;
|
Project_Tree : Prj.Project_Tree_Ref;
|
Project_Tree : Prj.Project_Tree_Ref;
|
Target : String := "") return Boolean
|
Target : String := "") return Boolean
|
is
|
is
|
Variable : constant Variable_Value :=
|
Variable : constant Variable_Value :=
|
Value_Of
|
Value_Of
|
(Name_Target, Config_File.Decl.Attributes, Project_Tree);
|
(Name_Target, Config_File.Decl.Attributes, Project_Tree);
|
Tgt_Name : Name_Id := No_Name;
|
Tgt_Name : Name_Id := No_Name;
|
OK : Boolean;
|
OK : Boolean;
|
|
|
begin
|
begin
|
if Variable /= Nil_Variable_Value and then not Variable.Default then
|
if Variable /= Nil_Variable_Value and then not Variable.Default then
|
Tgt_Name := Variable.Value;
|
Tgt_Name := Variable.Value;
|
end if;
|
end if;
|
|
|
if Target = "" then
|
if Target = "" then
|
OK := not Autoconf_Specified or else Tgt_Name = No_Name;
|
OK := not Autoconf_Specified or else Tgt_Name = No_Name;
|
else
|
else
|
OK := Tgt_Name /= No_Name
|
OK := Tgt_Name /= No_Name
|
and then Target = Get_Name_String (Tgt_Name);
|
and then Target = Get_Name_String (Tgt_Name);
|
end if;
|
end if;
|
|
|
if not OK then
|
if not OK then
|
if Autoconf_Specified then
|
if Autoconf_Specified then
|
if Verbose_Mode then
|
if Verbose_Mode then
|
Write_Line ("inconsistent targets, performing autoconf");
|
Write_Line ("inconsistent targets, performing autoconf");
|
end if;
|
end if;
|
|
|
return False;
|
return False;
|
|
|
else
|
else
|
if Tgt_Name /= No_Name then
|
if Tgt_Name /= No_Name then
|
raise Invalid_Config
|
raise Invalid_Config
|
with "invalid target name """
|
with "invalid target name """
|
& Get_Name_String (Tgt_Name) & """ in configuration";
|
& Get_Name_String (Tgt_Name) & """ in configuration";
|
|
|
else
|
else
|
raise Invalid_Config
|
raise Invalid_Config
|
with "no target specified in configuration file";
|
with "no target specified in configuration file";
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
return True;
|
return True;
|
end Check_Target;
|
end Check_Target;
|
|
|
--------------------------------------
|
--------------------------------------
|
-- Get_Or_Create_Configuration_File --
|
-- Get_Or_Create_Configuration_File --
|
--------------------------------------
|
--------------------------------------
|
|
|
procedure Get_Or_Create_Configuration_File
|
procedure Get_Or_Create_Configuration_File
|
(Project : Project_Id;
|
(Project : Project_Id;
|
Project_Tree : Project_Tree_Ref;
|
Project_Tree : Project_Tree_Ref;
|
Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
|
Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
|
Allow_Automatic_Generation : Boolean;
|
Allow_Automatic_Generation : Boolean;
|
Config_File_Name : String := "";
|
Config_File_Name : String := "";
|
Autoconf_Specified : Boolean;
|
Autoconf_Specified : Boolean;
|
Target_Name : String := "";
|
Target_Name : String := "";
|
Normalized_Hostname : String;
|
Normalized_Hostname : String;
|
Packages_To_Check : String_List_Access := null;
|
Packages_To_Check : String_List_Access := null;
|
Config : out Prj.Project_Id;
|
Config : out Prj.Project_Id;
|
Config_File_Path : out String_Access;
|
Config_File_Path : out String_Access;
|
Automatically_Generated : out Boolean;
|
Automatically_Generated : out Boolean;
|
Flags : Processing_Flags;
|
Flags : Processing_Flags;
|
On_Load_Config : Config_File_Hook := null)
|
On_Load_Config : Config_File_Hook := null)
|
is
|
is
|
function Default_File_Name return String;
|
function Default_File_Name return String;
|
-- Return the name of the default config file that should be tested
|
-- Return the name of the default config file that should be tested
|
|
|
procedure Do_Autoconf;
|
procedure Do_Autoconf;
|
-- Generate a new config file through gprconfig.
|
-- Generate a new config file through gprconfig.
|
-- In case of error, this raises the Invalid_Config exception with an
|
-- In case of error, this raises the Invalid_Config exception with an
|
-- appropriate message
|
-- appropriate message
|
|
|
function Get_Config_Switches return Argument_List_Access;
|
function Get_Config_Switches return Argument_List_Access;
|
-- Return the --config switches to use for gprconfig
|
-- Return the --config switches to use for gprconfig
|
|
|
function Might_Have_Sources (Project : Project_Id) return Boolean;
|
function Might_Have_Sources (Project : Project_Id) return Boolean;
|
-- True if the specified project might have sources (ie the user has not
|
-- True if the specified project might have sources (ie the user has not
|
-- explicitly specified it. We haven't checked the file system, nor do
|
-- explicitly specified it. We haven't checked the file system, nor do
|
-- we need to at this stage.
|
-- we need to at this stage.
|
|
|
-----------------------
|
-----------------------
|
-- Default_File_Name --
|
-- Default_File_Name --
|
-----------------------
|
-----------------------
|
|
|
function Default_File_Name return String is
|
function Default_File_Name return String is
|
Ada_RTS : constant String := Runtime_Name_For (Name_Ada);
|
Ada_RTS : constant String := Runtime_Name_For (Name_Ada);
|
Tmp : String_Access;
|
Tmp : String_Access;
|
|
|
begin
|
begin
|
if Target_Name /= "" then
|
if Target_Name /= "" then
|
if Ada_RTS /= "" then
|
if Ada_RTS /= "" then
|
return Target_Name & '-' & Ada_RTS
|
return Target_Name & '-' & Ada_RTS
|
& Config_Project_File_Extension;
|
& Config_Project_File_Extension;
|
else
|
else
|
return Target_Name & Config_Project_File_Extension;
|
return Target_Name & Config_Project_File_Extension;
|
end if;
|
end if;
|
|
|
elsif Ada_RTS /= "" then
|
elsif Ada_RTS /= "" then
|
return Ada_RTS & Config_Project_File_Extension;
|
return Ada_RTS & Config_Project_File_Extension;
|
|
|
else
|
else
|
Tmp := Getenv (Config_Project_Env_Var);
|
Tmp := Getenv (Config_Project_Env_Var);
|
|
|
declare
|
declare
|
T : constant String := Tmp.all;
|
T : constant String := Tmp.all;
|
begin
|
begin
|
Free (Tmp);
|
Free (Tmp);
|
|
|
if T'Length = 0 then
|
if T'Length = 0 then
|
return Default_Name;
|
return Default_Name;
|
else
|
else
|
return T;
|
return T;
|
end if;
|
end if;
|
end;
|
end;
|
end if;
|
end if;
|
end Default_File_Name;
|
end Default_File_Name;
|
|
|
------------------------
|
------------------------
|
-- Might_Have_Sources --
|
-- Might_Have_Sources --
|
------------------------
|
------------------------
|
|
|
function Might_Have_Sources (Project : Project_Id) return Boolean is
|
function Might_Have_Sources (Project : Project_Id) return Boolean is
|
Variable : Variable_Value;
|
Variable : Variable_Value;
|
|
|
begin
|
begin
|
Variable :=
|
Variable :=
|
Value_Of
|
Value_Of
|
(Name_Source_Dirs,
|
(Name_Source_Dirs,
|
Project.Decl.Attributes,
|
Project.Decl.Attributes,
|
Project_Tree);
|
Project_Tree);
|
|
|
if Variable = Nil_Variable_Value
|
if Variable = Nil_Variable_Value
|
or else Variable.Default
|
or else Variable.Default
|
or else Variable.Values /= Nil_String
|
or else Variable.Values /= Nil_String
|
then
|
then
|
Variable :=
|
Variable :=
|
Value_Of
|
Value_Of
|
(Name_Source_Files,
|
(Name_Source_Files,
|
Project.Decl.Attributes,
|
Project.Decl.Attributes,
|
Project_Tree);
|
Project_Tree);
|
return Variable = Nil_Variable_Value
|
return Variable = Nil_Variable_Value
|
or else Variable.Default
|
or else Variable.Default
|
or else Variable.Values /= Nil_String;
|
or else Variable.Values /= Nil_String;
|
|
|
else
|
else
|
return False;
|
return False;
|
end if;
|
end if;
|
end Might_Have_Sources;
|
end Might_Have_Sources;
|
|
|
-------------------------
|
-------------------------
|
-- Get_Config_Switches --
|
-- Get_Config_Switches --
|
-------------------------
|
-------------------------
|
|
|
function Get_Config_Switches return Argument_List_Access is
|
function Get_Config_Switches return Argument_List_Access is
|
package Language_Htable is new GNAT.HTable.Simple_HTable
|
package Language_Htable is new GNAT.HTable.Simple_HTable
|
(Header_Num => Prj.Header_Num,
|
(Header_Num => Prj.Header_Num,
|
Element => Name_Id,
|
Element => Name_Id,
|
No_Element => No_Name,
|
No_Element => No_Name,
|
Key => Name_Id,
|
Key => Name_Id,
|
Hash => Prj.Hash,
|
Hash => Prj.Hash,
|
Equal => "=");
|
Equal => "=");
|
-- Hash table to keep the languages used in the project tree
|
-- Hash table to keep the languages used in the project tree
|
|
|
IDE : constant Package_Id :=
|
IDE : constant Package_Id :=
|
Value_Of
|
Value_Of
|
(Name_Ide,
|
(Name_Ide,
|
Project.Decl.Packages,
|
Project.Decl.Packages,
|
Project_Tree);
|
Project_Tree);
|
|
|
Prj_Iter : Project_List;
|
Prj_Iter : Project_List;
|
List : String_List_Id;
|
List : String_List_Id;
|
Elem : String_Element;
|
Elem : String_Element;
|
Lang : Name_Id;
|
Lang : Name_Id;
|
Variable : Variable_Value;
|
Variable : Variable_Value;
|
Name : Name_Id;
|
Name : Name_Id;
|
Count : Natural;
|
Count : Natural;
|
Result : Argument_List_Access;
|
Result : Argument_List_Access;
|
|
|
Check_Default : Boolean;
|
Check_Default : Boolean;
|
|
|
begin
|
begin
|
Prj_Iter := Project_Tree.Projects;
|
Prj_Iter := Project_Tree.Projects;
|
while Prj_Iter /= null loop
|
while Prj_Iter /= null loop
|
if Might_Have_Sources (Prj_Iter.Project) then
|
if Might_Have_Sources (Prj_Iter.Project) then
|
Variable :=
|
Variable :=
|
Value_Of
|
Value_Of
|
(Name_Languages,
|
(Name_Languages,
|
Prj_Iter.Project.Decl.Attributes,
|
Prj_Iter.Project.Decl.Attributes,
|
Project_Tree);
|
Project_Tree);
|
|
|
if Variable = Nil_Variable_Value
|
if Variable = Nil_Variable_Value
|
or else Variable.Default
|
or else Variable.Default
|
then
|
then
|
-- Languages is not declared. If it is not an extending
|
-- Languages is not declared. If it is not an extending
|
-- project, or if it extends a project with no Languages,
|
-- project, or if it extends a project with no Languages,
|
-- check for Default_Language.
|
-- check for Default_Language.
|
|
|
Check_Default := Prj_Iter.Project.Extends = No_Project;
|
Check_Default := Prj_Iter.Project.Extends = No_Project;
|
|
|
if not Check_Default then
|
if not Check_Default then
|
Variable :=
|
Variable :=
|
Value_Of
|
Value_Of
|
(Name_Languages,
|
(Name_Languages,
|
Prj_Iter.Project.Extends.Decl.Attributes,
|
Prj_Iter.Project.Extends.Decl.Attributes,
|
Project_Tree);
|
Project_Tree);
|
Check_Default :=
|
Check_Default :=
|
Variable /= Nil_Variable_Value
|
Variable /= Nil_Variable_Value
|
and then Variable.Values = Nil_String;
|
and then Variable.Values = Nil_String;
|
end if;
|
end if;
|
|
|
if Check_Default then
|
if Check_Default then
|
Variable :=
|
Variable :=
|
Value_Of
|
Value_Of
|
(Name_Default_Language,
|
(Name_Default_Language,
|
Prj_Iter.Project.Decl.Attributes,
|
Prj_Iter.Project.Decl.Attributes,
|
Project_Tree);
|
Project_Tree);
|
|
|
if Variable /= Nil_Variable_Value
|
if Variable /= Nil_Variable_Value
|
and then not Variable.Default
|
and then not Variable.Default
|
then
|
then
|
Get_Name_String (Variable.Value);
|
Get_Name_String (Variable.Value);
|
To_Lower (Name_Buffer (1 .. Name_Len));
|
To_Lower (Name_Buffer (1 .. Name_Len));
|
Lang := Name_Find;
|
Lang := Name_Find;
|
Language_Htable.Set (Lang, Lang);
|
Language_Htable.Set (Lang, Lang);
|
|
|
else
|
else
|
-- If no default language is declared, default to Ada
|
-- If no default language is declared, default to Ada
|
|
|
Language_Htable.Set (Name_Ada, Name_Ada);
|
Language_Htable.Set (Name_Ada, Name_Ada);
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
elsif Variable.Values /= Nil_String then
|
elsif Variable.Values /= Nil_String then
|
|
|
-- Attribute Languages is declared with a non empty
|
-- Attribute Languages is declared with a non empty
|
-- list: put all the languages in Language_HTable.
|
-- list: put all the languages in Language_HTable.
|
|
|
List := Variable.Values;
|
List := Variable.Values;
|
while List /= Nil_String loop
|
while List /= Nil_String loop
|
Elem := Project_Tree.String_Elements.Table (List);
|
Elem := Project_Tree.String_Elements.Table (List);
|
|
|
Get_Name_String (Elem.Value);
|
Get_Name_String (Elem.Value);
|
To_Lower (Name_Buffer (1 .. Name_Len));
|
To_Lower (Name_Buffer (1 .. Name_Len));
|
Lang := Name_Find;
|
Lang := Name_Find;
|
Language_Htable.Set (Lang, Lang);
|
Language_Htable.Set (Lang, Lang);
|
|
|
List := Elem.Next;
|
List := Elem.Next;
|
end loop;
|
end loop;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
Prj_Iter := Prj_Iter.Next;
|
Prj_Iter := Prj_Iter.Next;
|
end loop;
|
end loop;
|
|
|
Name := Language_Htable.Get_First;
|
Name := Language_Htable.Get_First;
|
Count := 0;
|
Count := 0;
|
while Name /= No_Name loop
|
while Name /= No_Name loop
|
Count := Count + 1;
|
Count := Count + 1;
|
Name := Language_Htable.Get_Next;
|
Name := Language_Htable.Get_Next;
|
end loop;
|
end loop;
|
|
|
Result := new String_List (1 .. Count);
|
Result := new String_List (1 .. Count);
|
|
|
Count := 1;
|
Count := 1;
|
Name := Language_Htable.Get_First;
|
Name := Language_Htable.Get_First;
|
while Name /= No_Name loop
|
while Name /= No_Name loop
|
-- Check if IDE'Compiler_Command is declared for the language.
|
-- Check if IDE'Compiler_Command is declared for the language.
|
-- If it is, use its value to invoke gprconfig.
|
-- If it is, use its value to invoke gprconfig.
|
|
|
Variable :=
|
Variable :=
|
Value_Of
|
Value_Of
|
(Name,
|
(Name,
|
Attribute_Or_Array_Name => Name_Compiler_Command,
|
Attribute_Or_Array_Name => Name_Compiler_Command,
|
In_Package => IDE,
|
In_Package => IDE,
|
In_Tree => Project_Tree,
|
In_Tree => Project_Tree,
|
Force_Lower_Case_Index => True);
|
Force_Lower_Case_Index => True);
|
|
|
declare
|
declare
|
Config_Command : constant String :=
|
Config_Command : constant String :=
|
"--config=" & Get_Name_String (Name);
|
"--config=" & Get_Name_String (Name);
|
|
|
Runtime_Name : constant String :=
|
Runtime_Name : constant String :=
|
Runtime_Name_For (Name);
|
Runtime_Name_For (Name);
|
|
|
begin
|
begin
|
if Variable = Nil_Variable_Value
|
if Variable = Nil_Variable_Value
|
or else Length_Of_Name (Variable.Value) = 0
|
or else Length_Of_Name (Variable.Value) = 0
|
then
|
then
|
Result (Count) :=
|
Result (Count) :=
|
new String'(Config_Command & ",," & Runtime_Name);
|
new String'(Config_Command & ",," & Runtime_Name);
|
|
|
else
|
else
|
declare
|
declare
|
Compiler_Command : constant String :=
|
Compiler_Command : constant String :=
|
Get_Name_String (Variable.Value);
|
Get_Name_String (Variable.Value);
|
|
|
begin
|
begin
|
if Is_Absolute_Path (Compiler_Command) then
|
if Is_Absolute_Path (Compiler_Command) then
|
Result (Count) :=
|
Result (Count) :=
|
new String'
|
new String'
|
(Config_Command & ",," & Runtime_Name & "," &
|
(Config_Command & ",," & Runtime_Name & "," &
|
Containing_Directory (Compiler_Command) & "," &
|
Containing_Directory (Compiler_Command) & "," &
|
Simple_Name (Compiler_Command));
|
Simple_Name (Compiler_Command));
|
else
|
else
|
Result (Count) :=
|
Result (Count) :=
|
new String'
|
new String'
|
(Config_Command & ",," & Runtime_Name & ",," &
|
(Config_Command & ",," & Runtime_Name & ",," &
|
Compiler_Command);
|
Compiler_Command);
|
end if;
|
end if;
|
end;
|
end;
|
end if;
|
end if;
|
end;
|
end;
|
|
|
Count := Count + 1;
|
Count := Count + 1;
|
Name := Language_Htable.Get_Next;
|
Name := Language_Htable.Get_Next;
|
end loop;
|
end loop;
|
|
|
return Result;
|
return Result;
|
end Get_Config_Switches;
|
end Get_Config_Switches;
|
|
|
-----------------
|
-----------------
|
-- Do_Autoconf --
|
-- Do_Autoconf --
|
-----------------
|
-----------------
|
|
|
procedure Do_Autoconf is
|
procedure Do_Autoconf is
|
Obj_Dir : constant Variable_Value :=
|
Obj_Dir : constant Variable_Value :=
|
Value_Of
|
Value_Of
|
(Name_Object_Dir,
|
(Name_Object_Dir,
|
Project.Decl.Attributes,
|
Project.Decl.Attributes,
|
Project_Tree);
|
Project_Tree);
|
|
|
Gprconfig_Path : String_Access;
|
Gprconfig_Path : String_Access;
|
Success : Boolean;
|
Success : Boolean;
|
|
|
begin
|
begin
|
Gprconfig_Path := Locate_Exec_On_Path (Gprconfig_Name);
|
Gprconfig_Path := Locate_Exec_On_Path (Gprconfig_Name);
|
|
|
if Gprconfig_Path = null then
|
if Gprconfig_Path = null then
|
raise Invalid_Config
|
raise Invalid_Config
|
with "could not locate gprconfig for auto-configuration";
|
with "could not locate gprconfig for auto-configuration";
|
end if;
|
end if;
|
|
|
-- First, find the object directory of the user's project
|
-- First, find the object directory of the user's project
|
|
|
if Obj_Dir = Nil_Variable_Value or else Obj_Dir.Default then
|
if Obj_Dir = Nil_Variable_Value or else Obj_Dir.Default then
|
Get_Name_String (Project.Directory.Name);
|
Get_Name_String (Project.Directory.Name);
|
|
|
else
|
else
|
if Is_Absolute_Path (Get_Name_String (Obj_Dir.Value)) then
|
if Is_Absolute_Path (Get_Name_String (Obj_Dir.Value)) then
|
Get_Name_String (Obj_Dir.Value);
|
Get_Name_String (Obj_Dir.Value);
|
|
|
else
|
else
|
Name_Len := 0;
|
Name_Len := 0;
|
Add_Str_To_Name_Buffer
|
Add_Str_To_Name_Buffer
|
(Get_Name_String (Project.Directory.Name));
|
(Get_Name_String (Project.Directory.Name));
|
Add_Str_To_Name_Buffer (Get_Name_String (Obj_Dir.Value));
|
Add_Str_To_Name_Buffer (Get_Name_String (Obj_Dir.Value));
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
if Subdirs /= null then
|
if Subdirs /= null then
|
Add_Char_To_Name_Buffer (Directory_Separator);
|
Add_Char_To_Name_Buffer (Directory_Separator);
|
Add_Str_To_Name_Buffer (Subdirs.all);
|
Add_Str_To_Name_Buffer (Subdirs.all);
|
end if;
|
end if;
|
|
|
for J in 1 .. Name_Len loop
|
for J in 1 .. Name_Len loop
|
if Name_Buffer (J) = '/' then
|
if Name_Buffer (J) = '/' then
|
Name_Buffer (J) := Directory_Separator;
|
Name_Buffer (J) := Directory_Separator;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
|
|
declare
|
declare
|
Obj_Dir : constant String := Name_Buffer (1 .. Name_Len);
|
Obj_Dir : constant String := Name_Buffer (1 .. Name_Len);
|
Switches : Argument_List_Access := Get_Config_Switches;
|
Switches : Argument_List_Access := Get_Config_Switches;
|
Args : Argument_List (1 .. 5);
|
Args : Argument_List (1 .. 5);
|
Arg_Last : Positive;
|
Arg_Last : Positive;
|
|
|
Obj_Dir_Exists : Boolean := True;
|
Obj_Dir_Exists : Boolean := True;
|
|
|
begin
|
begin
|
-- Check if the object directory exists. If Setup_Projects is True
|
-- Check if the object directory exists. If Setup_Projects is True
|
-- (-p) and directory does not exist, attempt to create it.
|
-- (-p) and directory does not exist, attempt to create it.
|
-- Otherwise, if directory does not exist, fail without calling
|
-- Otherwise, if directory does not exist, fail without calling
|
-- gprconfig.
|
-- gprconfig.
|
|
|
if not Is_Directory (Obj_Dir)
|
if not Is_Directory (Obj_Dir)
|
and then (Setup_Projects or else Subdirs /= null)
|
and then (Setup_Projects or else Subdirs /= null)
|
then
|
then
|
begin
|
begin
|
Create_Path (Obj_Dir);
|
Create_Path (Obj_Dir);
|
|
|
if not Quiet_Output then
|
if not Quiet_Output then
|
Write_Str ("object directory """);
|
Write_Str ("object directory """);
|
Write_Str (Obj_Dir);
|
Write_Str (Obj_Dir);
|
Write_Line (""" created");
|
Write_Line (""" created");
|
end if;
|
end if;
|
|
|
exception
|
exception
|
when others =>
|
when others =>
|
raise Invalid_Config
|
raise Invalid_Config
|
with "could not create object directory " & Obj_Dir;
|
with "could not create object directory " & Obj_Dir;
|
end;
|
end;
|
end if;
|
end if;
|
|
|
if not Is_Directory (Obj_Dir) then
|
if not Is_Directory (Obj_Dir) then
|
case Flags.Require_Obj_Dirs is
|
case Flags.Require_Obj_Dirs is
|
when Error =>
|
when Error =>
|
raise Invalid_Config
|
raise Invalid_Config
|
with "object directory " & Obj_Dir & " does not exist";
|
with "object directory " & Obj_Dir & " does not exist";
|
when Warning =>
|
when Warning =>
|
Prj.Err.Error_Msg
|
Prj.Err.Error_Msg
|
(Flags,
|
(Flags,
|
"?object directory " & Obj_Dir & " does not exist");
|
"?object directory " & Obj_Dir & " does not exist");
|
Obj_Dir_Exists := False;
|
Obj_Dir_Exists := False;
|
when Silent =>
|
when Silent =>
|
null;
|
null;
|
end case;
|
end case;
|
end if;
|
end if;
|
|
|
-- Invoke gprconfig
|
-- Invoke gprconfig
|
|
|
Args (1) := new String'("--batch");
|
Args (1) := new String'("--batch");
|
Args (2) := new String'("-o");
|
Args (2) := new String'("-o");
|
|
|
-- If no config file was specified, set the auto.cgpr one
|
-- If no config file was specified, set the auto.cgpr one
|
|
|
if Config_File_Name = "" then
|
if Config_File_Name = "" then
|
if Obj_Dir_Exists then
|
if Obj_Dir_Exists then
|
Args (3) :=
|
Args (3) :=
|
new String'(Obj_Dir & Directory_Separator & Auto_Cgpr);
|
new String'(Obj_Dir & Directory_Separator & Auto_Cgpr);
|
|
|
else
|
else
|
declare
|
declare
|
Path_FD : File_Descriptor;
|
Path_FD : File_Descriptor;
|
Path_Name : Path_Name_Type;
|
Path_Name : Path_Name_Type;
|
|
|
begin
|
begin
|
Prj.Env.Create_Temp_File
|
Prj.Env.Create_Temp_File
|
(In_Tree => Project_Tree,
|
(In_Tree => Project_Tree,
|
Path_FD => Path_FD,
|
Path_FD => Path_FD,
|
Path_Name => Path_Name,
|
Path_Name => Path_Name,
|
File_Use => "configuration file");
|
File_Use => "configuration file");
|
|
|
if Path_FD /= Invalid_FD then
|
if Path_FD /= Invalid_FD then
|
Args (3) := new String'(Get_Name_String (Path_Name));
|
Args (3) := new String'(Get_Name_String (Path_Name));
|
GNAT.OS_Lib.Close (Path_FD);
|
GNAT.OS_Lib.Close (Path_FD);
|
|
|
else
|
else
|
-- We'll have an error message later on
|
-- We'll have an error message later on
|
|
|
Args (3) :=
|
Args (3) :=
|
new String'
|
new String'
|
(Obj_Dir & Directory_Separator & Auto_Cgpr);
|
(Obj_Dir & Directory_Separator & Auto_Cgpr);
|
end if;
|
end if;
|
end;
|
end;
|
end if;
|
end if;
|
else
|
else
|
Args (3) := new String'(Config_File_Name);
|
Args (3) := new String'(Config_File_Name);
|
end if;
|
end if;
|
|
|
if Normalized_Hostname = "" then
|
if Normalized_Hostname = "" then
|
Arg_Last := 3;
|
Arg_Last := 3;
|
else
|
else
|
if Target_Name = "" then
|
if Target_Name = "" then
|
Args (4) := new String'("--target=" & Normalized_Hostname);
|
Args (4) := new String'("--target=" & Normalized_Hostname);
|
else
|
else
|
Args (4) := new String'("--target=" & Target_Name);
|
Args (4) := new String'("--target=" & Target_Name);
|
end if;
|
end if;
|
|
|
Arg_Last := 4;
|
Arg_Last := 4;
|
end if;
|
end if;
|
|
|
if not Verbose_Mode then
|
if not Verbose_Mode then
|
Arg_Last := Arg_Last + 1;
|
Arg_Last := Arg_Last + 1;
|
Args (Arg_Last) := new String'("-q");
|
Args (Arg_Last) := new String'("-q");
|
end if;
|
end if;
|
|
|
if Verbose_Mode then
|
if Verbose_Mode then
|
Write_Str (Gprconfig_Name);
|
Write_Str (Gprconfig_Name);
|
|
|
for J in 1 .. Arg_Last loop
|
for J in 1 .. Arg_Last loop
|
Write_Char (' ');
|
Write_Char (' ');
|
Write_Str (Args (J).all);
|
Write_Str (Args (J).all);
|
end loop;
|
end loop;
|
|
|
for J in Switches'Range loop
|
for J in Switches'Range loop
|
Write_Char (' ');
|
Write_Char (' ');
|
Write_Str (Switches (J).all);
|
Write_Str (Switches (J).all);
|
end loop;
|
end loop;
|
|
|
Write_Eol;
|
Write_Eol;
|
|
|
elsif not Quiet_Output then
|
elsif not Quiet_Output then
|
-- Display no message if we are creating auto.cgpr, unless in
|
-- Display no message if we are creating auto.cgpr, unless in
|
-- verbose mode
|
-- verbose mode
|
|
|
if Config_File_Name /= ""
|
if Config_File_Name /= ""
|
or else Verbose_Mode
|
or else Verbose_Mode
|
then
|
then
|
Write_Str ("creating ");
|
Write_Str ("creating ");
|
Write_Str (Simple_Name (Args (3).all));
|
Write_Str (Simple_Name (Args (3).all));
|
Write_Eol;
|
Write_Eol;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
Spawn (Gprconfig_Path.all, Args (1 .. Arg_Last) & Switches.all,
|
Spawn (Gprconfig_Path.all, Args (1 .. Arg_Last) & Switches.all,
|
Success);
|
Success);
|
|
|
Free (Switches);
|
Free (Switches);
|
|
|
Config_File_Path := Locate_Config_File (Args (3).all);
|
Config_File_Path := Locate_Config_File (Args (3).all);
|
|
|
if Config_File_Path = null then
|
if Config_File_Path = null then
|
raise Invalid_Config
|
raise Invalid_Config
|
with "could not create " & Args (3).all;
|
with "could not create " & Args (3).all;
|
end if;
|
end if;
|
|
|
for F in Args'Range loop
|
for F in Args'Range loop
|
Free (Args (F));
|
Free (Args (F));
|
end loop;
|
end loop;
|
end;
|
end;
|
end Do_Autoconf;
|
end Do_Autoconf;
|
|
|
Success : Boolean;
|
Success : Boolean;
|
Config_Project_Node : Project_Node_Id := Empty_Node;
|
Config_Project_Node : Project_Node_Id := Empty_Node;
|
|
|
begin
|
begin
|
Free (Config_File_Path);
|
Free (Config_File_Path);
|
Config := No_Project;
|
Config := No_Project;
|
|
|
if Config_File_Name /= "" then
|
if Config_File_Name /= "" then
|
Config_File_Path := Locate_Config_File (Config_File_Name);
|
Config_File_Path := Locate_Config_File (Config_File_Name);
|
else
|
else
|
Config_File_Path := Locate_Config_File (Default_File_Name);
|
Config_File_Path := Locate_Config_File (Default_File_Name);
|
end if;
|
end if;
|
|
|
if Config_File_Path = null then
|
if Config_File_Path = null then
|
if (not Allow_Automatic_Generation) and then
|
if (not Allow_Automatic_Generation) and then
|
Config_File_Name /= ""
|
Config_File_Name /= ""
|
then
|
then
|
raise Invalid_Config
|
raise Invalid_Config
|
with "could not locate main configuration project "
|
with "could not locate main configuration project "
|
& Config_File_Name;
|
& Config_File_Name;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
Automatically_Generated :=
|
Automatically_Generated :=
|
Allow_Automatic_Generation and then Config_File_Path = null;
|
Allow_Automatic_Generation and then Config_File_Path = null;
|
|
|
<<Process_Config_File>>
|
<<Process_Config_File>>
|
|
|
if Automatically_Generated then
|
if Automatically_Generated then
|
-- This might raise an Invalid_Config exception
|
-- This might raise an Invalid_Config exception
|
Do_Autoconf;
|
Do_Autoconf;
|
end if;
|
end if;
|
|
|
-- Parse the configuration file
|
-- Parse the configuration file
|
|
|
if Verbose_Mode and then Config_File_Path /= null then
|
if Verbose_Mode and then Config_File_Path /= null then
|
Write_Str ("Checking configuration ");
|
Write_Str ("Checking configuration ");
|
Write_Line (Config_File_Path.all);
|
Write_Line (Config_File_Path.all);
|
end if;
|
end if;
|
|
|
if Config_File_Path /= null then
|
if Config_File_Path /= null then
|
Prj.Part.Parse
|
Prj.Part.Parse
|
(In_Tree => Project_Node_Tree,
|
(In_Tree => Project_Node_Tree,
|
Project => Config_Project_Node,
|
Project => Config_Project_Node,
|
Project_File_Name => Config_File_Path.all,
|
Project_File_Name => Config_File_Path.all,
|
Always_Errout_Finalize => False,
|
Always_Errout_Finalize => False,
|
Packages_To_Check => Packages_To_Check,
|
Packages_To_Check => Packages_To_Check,
|
Current_Directory => Current_Directory,
|
Current_Directory => Current_Directory,
|
Is_Config_File => True,
|
Is_Config_File => True,
|
Flags => Flags);
|
Flags => Flags);
|
else
|
else
|
-- Maybe the user will want to create his own configuration file
|
-- Maybe the user will want to create his own configuration file
|
Config_Project_Node := Empty_Node;
|
Config_Project_Node := Empty_Node;
|
end if;
|
end if;
|
|
|
if On_Load_Config /= null then
|
if On_Load_Config /= null then
|
On_Load_Config
|
On_Load_Config
|
(Config_File => Config_Project_Node,
|
(Config_File => Config_Project_Node,
|
Project_Node_Tree => Project_Node_Tree);
|
Project_Node_Tree => Project_Node_Tree);
|
end if;
|
end if;
|
|
|
if Config_Project_Node /= Empty_Node then
|
if Config_Project_Node /= Empty_Node then
|
Prj.Proc.Process_Project_Tree_Phase_1
|
Prj.Proc.Process_Project_Tree_Phase_1
|
(In_Tree => Project_Tree,
|
(In_Tree => Project_Tree,
|
Project => Config,
|
Project => Config,
|
Success => Success,
|
Success => Success,
|
From_Project_Node => Config_Project_Node,
|
From_Project_Node => Config_Project_Node,
|
From_Project_Node_Tree => Project_Node_Tree,
|
From_Project_Node_Tree => Project_Node_Tree,
|
Flags => Flags,
|
Flags => Flags,
|
Reset_Tree => False);
|
Reset_Tree => False);
|
end if;
|
end if;
|
|
|
if Config_Project_Node = Empty_Node
|
if Config_Project_Node = Empty_Node
|
or else Config = No_Project
|
or else Config = No_Project
|
then
|
then
|
raise Invalid_Config
|
raise Invalid_Config
|
with "processing of configuration project """
|
with "processing of configuration project """
|
& Config_File_Path.all & """ failed";
|
& Config_File_Path.all & """ failed";
|
end if;
|
end if;
|
|
|
-- Check that the target of the configuration file is the one the user
|
-- Check that the target of the configuration file is the one the user
|
-- specified on the command line. We do not need to check that when in
|
-- specified on the command line. We do not need to check that when in
|
-- auto-conf mode, since the appropriate target was passed to gprconfig.
|
-- auto-conf mode, since the appropriate target was passed to gprconfig.
|
|
|
if not Automatically_Generated
|
if not Automatically_Generated
|
and then not
|
and then not
|
Check_Target (Config, Autoconf_Specified, Project_Tree, Target_Name)
|
Check_Target (Config, Autoconf_Specified, Project_Tree, Target_Name)
|
then
|
then
|
Automatically_Generated := True;
|
Automatically_Generated := True;
|
goto Process_Config_File;
|
goto Process_Config_File;
|
end if;
|
end if;
|
end Get_Or_Create_Configuration_File;
|
end Get_Or_Create_Configuration_File;
|
|
|
--------------------------------------
|
--------------------------------------
|
-- Process_Project_And_Apply_Config --
|
-- Process_Project_And_Apply_Config --
|
--------------------------------------
|
--------------------------------------
|
|
|
procedure Process_Project_And_Apply_Config
|
procedure Process_Project_And_Apply_Config
|
(Main_Project : out Prj.Project_Id;
|
(Main_Project : out Prj.Project_Id;
|
User_Project_Node : Prj.Tree.Project_Node_Id;
|
User_Project_Node : Prj.Tree.Project_Node_Id;
|
Config_File_Name : String := "";
|
Config_File_Name : String := "";
|
Autoconf_Specified : Boolean;
|
Autoconf_Specified : Boolean;
|
Project_Tree : Prj.Project_Tree_Ref;
|
Project_Tree : Prj.Project_Tree_Ref;
|
Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
|
Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
|
Packages_To_Check : String_List_Access;
|
Packages_To_Check : String_List_Access;
|
Allow_Automatic_Generation : Boolean := True;
|
Allow_Automatic_Generation : Boolean := True;
|
Automatically_Generated : out Boolean;
|
Automatically_Generated : out Boolean;
|
Config_File_Path : out String_Access;
|
Config_File_Path : out String_Access;
|
Target_Name : String := "";
|
Target_Name : String := "";
|
Normalized_Hostname : String;
|
Normalized_Hostname : String;
|
Flags : Processing_Flags;
|
Flags : Processing_Flags;
|
On_Load_Config : Config_File_Hook := null;
|
On_Load_Config : Config_File_Hook := null;
|
Reset_Tree : Boolean := True)
|
Reset_Tree : Boolean := True)
|
is
|
is
|
Main_Config_Project : Project_Id;
|
Main_Config_Project : Project_Id;
|
Success : Boolean;
|
Success : Boolean;
|
|
|
begin
|
begin
|
Main_Project := No_Project;
|
Main_Project := No_Project;
|
Automatically_Generated := False;
|
Automatically_Generated := False;
|
|
|
Process_Project_Tree_Phase_1
|
Process_Project_Tree_Phase_1
|
(In_Tree => Project_Tree,
|
(In_Tree => Project_Tree,
|
Project => Main_Project,
|
Project => Main_Project,
|
Success => Success,
|
Success => Success,
|
From_Project_Node => User_Project_Node,
|
From_Project_Node => User_Project_Node,
|
From_Project_Node_Tree => Project_Node_Tree,
|
From_Project_Node_Tree => Project_Node_Tree,
|
Flags => Flags,
|
Flags => Flags,
|
Reset_Tree => Reset_Tree);
|
Reset_Tree => Reset_Tree);
|
|
|
if not Success then
|
if not Success then
|
Main_Project := No_Project;
|
Main_Project := No_Project;
|
return;
|
return;
|
end if;
|
end if;
|
|
|
-- Find configuration file
|
-- Find configuration file
|
|
|
Get_Or_Create_Configuration_File
|
Get_Or_Create_Configuration_File
|
(Config => Main_Config_Project,
|
(Config => Main_Config_Project,
|
Project => Main_Project,
|
Project => Main_Project,
|
Project_Tree => Project_Tree,
|
Project_Tree => Project_Tree,
|
Project_Node_Tree => Project_Node_Tree,
|
Project_Node_Tree => Project_Node_Tree,
|
Allow_Automatic_Generation => Allow_Automatic_Generation,
|
Allow_Automatic_Generation => Allow_Automatic_Generation,
|
Config_File_Name => Config_File_Name,
|
Config_File_Name => Config_File_Name,
|
Autoconf_Specified => Autoconf_Specified,
|
Autoconf_Specified => Autoconf_Specified,
|
Target_Name => Target_Name,
|
Target_Name => Target_Name,
|
Normalized_Hostname => Normalized_Hostname,
|
Normalized_Hostname => Normalized_Hostname,
|
Packages_To_Check => Packages_To_Check,
|
Packages_To_Check => Packages_To_Check,
|
Config_File_Path => Config_File_Path,
|
Config_File_Path => Config_File_Path,
|
Automatically_Generated => Automatically_Generated,
|
Automatically_Generated => Automatically_Generated,
|
Flags => Flags,
|
Flags => Flags,
|
On_Load_Config => On_Load_Config);
|
On_Load_Config => On_Load_Config);
|
|
|
Apply_Config_File (Main_Config_Project, Project_Tree);
|
Apply_Config_File (Main_Config_Project, Project_Tree);
|
|
|
-- Finish processing the user's project
|
-- Finish processing the user's project
|
|
|
Prj.Proc.Process_Project_Tree_Phase_2
|
Prj.Proc.Process_Project_Tree_Phase_2
|
(In_Tree => Project_Tree,
|
(In_Tree => Project_Tree,
|
Project => Main_Project,
|
Project => Main_Project,
|
Success => Success,
|
Success => Success,
|
From_Project_Node => User_Project_Node,
|
From_Project_Node => User_Project_Node,
|
From_Project_Node_Tree => Project_Node_Tree,
|
From_Project_Node_Tree => Project_Node_Tree,
|
Flags => Flags);
|
Flags => Flags);
|
|
|
if not Success then
|
if not Success then
|
Main_Project := No_Project;
|
Main_Project := No_Project;
|
end if;
|
end if;
|
end Process_Project_And_Apply_Config;
|
end Process_Project_And_Apply_Config;
|
|
|
------------------------------------
|
------------------------------------
|
-- Parse_Project_And_Apply_Config --
|
-- Parse_Project_And_Apply_Config --
|
------------------------------------
|
------------------------------------
|
|
|
procedure Parse_Project_And_Apply_Config
|
procedure Parse_Project_And_Apply_Config
|
(Main_Project : out Prj.Project_Id;
|
(Main_Project : out Prj.Project_Id;
|
User_Project_Node : out Prj.Tree.Project_Node_Id;
|
User_Project_Node : out Prj.Tree.Project_Node_Id;
|
Config_File_Name : String := "";
|
Config_File_Name : String := "";
|
Autoconf_Specified : Boolean;
|
Autoconf_Specified : Boolean;
|
Project_File_Name : String;
|
Project_File_Name : String;
|
Project_Tree : Prj.Project_Tree_Ref;
|
Project_Tree : Prj.Project_Tree_Ref;
|
Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
|
Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
|
Packages_To_Check : String_List_Access;
|
Packages_To_Check : String_List_Access;
|
Allow_Automatic_Generation : Boolean := True;
|
Allow_Automatic_Generation : Boolean := True;
|
Automatically_Generated : out Boolean;
|
Automatically_Generated : out Boolean;
|
Config_File_Path : out String_Access;
|
Config_File_Path : out String_Access;
|
Target_Name : String := "";
|
Target_Name : String := "";
|
Normalized_Hostname : String;
|
Normalized_Hostname : String;
|
Flags : Processing_Flags;
|
Flags : Processing_Flags;
|
On_Load_Config : Config_File_Hook := null)
|
On_Load_Config : Config_File_Hook := null)
|
is
|
is
|
begin
|
begin
|
-- Parse the user project tree
|
-- Parse the user project tree
|
|
|
Prj.Initialize (Project_Tree);
|
Prj.Initialize (Project_Tree);
|
|
|
Main_Project := No_Project;
|
Main_Project := No_Project;
|
Automatically_Generated := False;
|
Automatically_Generated := False;
|
|
|
Prj.Part.Parse
|
Prj.Part.Parse
|
(In_Tree => Project_Node_Tree,
|
(In_Tree => Project_Node_Tree,
|
Project => User_Project_Node,
|
Project => User_Project_Node,
|
Project_File_Name => Project_File_Name,
|
Project_File_Name => Project_File_Name,
|
Always_Errout_Finalize => False,
|
Always_Errout_Finalize => False,
|
Packages_To_Check => Packages_To_Check,
|
Packages_To_Check => Packages_To_Check,
|
Current_Directory => Current_Directory,
|
Current_Directory => Current_Directory,
|
Is_Config_File => False,
|
Is_Config_File => False,
|
Flags => Flags);
|
Flags => Flags);
|
|
|
if User_Project_Node = Empty_Node then
|
if User_Project_Node = Empty_Node then
|
User_Project_Node := Empty_Node;
|
User_Project_Node := Empty_Node;
|
return;
|
return;
|
end if;
|
end if;
|
|
|
Process_Project_And_Apply_Config
|
Process_Project_And_Apply_Config
|
(Main_Project => Main_Project,
|
(Main_Project => Main_Project,
|
User_Project_Node => User_Project_Node,
|
User_Project_Node => User_Project_Node,
|
Config_File_Name => Config_File_Name,
|
Config_File_Name => Config_File_Name,
|
Autoconf_Specified => Autoconf_Specified,
|
Autoconf_Specified => Autoconf_Specified,
|
Project_Tree => Project_Tree,
|
Project_Tree => Project_Tree,
|
Project_Node_Tree => Project_Node_Tree,
|
Project_Node_Tree => Project_Node_Tree,
|
Packages_To_Check => Packages_To_Check,
|
Packages_To_Check => Packages_To_Check,
|
Allow_Automatic_Generation => Allow_Automatic_Generation,
|
Allow_Automatic_Generation => Allow_Automatic_Generation,
|
Automatically_Generated => Automatically_Generated,
|
Automatically_Generated => Automatically_Generated,
|
Config_File_Path => Config_File_Path,
|
Config_File_Path => Config_File_Path,
|
Target_Name => Target_Name,
|
Target_Name => Target_Name,
|
Normalized_Hostname => Normalized_Hostname,
|
Normalized_Hostname => Normalized_Hostname,
|
Flags => Flags,
|
Flags => Flags,
|
On_Load_Config => On_Load_Config);
|
On_Load_Config => On_Load_Config);
|
end Parse_Project_And_Apply_Config;
|
end Parse_Project_And_Apply_Config;
|
|
|
-----------------------
|
-----------------------
|
-- Apply_Config_File --
|
-- Apply_Config_File --
|
-----------------------
|
-----------------------
|
|
|
procedure Apply_Config_File
|
procedure Apply_Config_File
|
(Config_File : Prj.Project_Id;
|
(Config_File : Prj.Project_Id;
|
Project_Tree : Prj.Project_Tree_Ref)
|
Project_Tree : Prj.Project_Tree_Ref)
|
is
|
is
|
Conf_Decl : constant Declarations := Config_File.Decl;
|
Conf_Decl : constant Declarations := Config_File.Decl;
|
Conf_Pack_Id : Package_Id;
|
Conf_Pack_Id : Package_Id;
|
Conf_Pack : Package_Element;
|
Conf_Pack : Package_Element;
|
|
|
User_Decl : Declarations;
|
User_Decl : Declarations;
|
User_Pack_Id : Package_Id;
|
User_Pack_Id : Package_Id;
|
User_Pack : Package_Element;
|
User_Pack : Package_Element;
|
Proj : Project_List;
|
Proj : Project_List;
|
|
|
begin
|
begin
|
Proj := Project_Tree.Projects;
|
Proj := Project_Tree.Projects;
|
while Proj /= null loop
|
while Proj /= null loop
|
if Proj.Project /= Config_File then
|
if Proj.Project /= Config_File then
|
User_Decl := Proj.Project.Decl;
|
User_Decl := Proj.Project.Decl;
|
Add_Attributes
|
Add_Attributes
|
(Project_Tree => Project_Tree,
|
(Project_Tree => Project_Tree,
|
Conf_Decl => Conf_Decl,
|
Conf_Decl => Conf_Decl,
|
User_Decl => User_Decl);
|
User_Decl => User_Decl);
|
|
|
Conf_Pack_Id := Conf_Decl.Packages;
|
Conf_Pack_Id := Conf_Decl.Packages;
|
while Conf_Pack_Id /= No_Package loop
|
while Conf_Pack_Id /= No_Package loop
|
Conf_Pack := Project_Tree.Packages.Table (Conf_Pack_Id);
|
Conf_Pack := Project_Tree.Packages.Table (Conf_Pack_Id);
|
|
|
User_Pack_Id := User_Decl.Packages;
|
User_Pack_Id := User_Decl.Packages;
|
while User_Pack_Id /= No_Package loop
|
while User_Pack_Id /= No_Package loop
|
User_Pack := Project_Tree.Packages.Table (User_Pack_Id);
|
User_Pack := Project_Tree.Packages.Table (User_Pack_Id);
|
exit when User_Pack.Name = Conf_Pack.Name;
|
exit when User_Pack.Name = Conf_Pack.Name;
|
User_Pack_Id := User_Pack.Next;
|
User_Pack_Id := User_Pack.Next;
|
end loop;
|
end loop;
|
|
|
if User_Pack_Id = No_Package then
|
if User_Pack_Id = No_Package then
|
Package_Table.Increment_Last (Project_Tree.Packages);
|
Package_Table.Increment_Last (Project_Tree.Packages);
|
User_Pack := Conf_Pack;
|
User_Pack := Conf_Pack;
|
User_Pack.Next := User_Decl.Packages;
|
User_Pack.Next := User_Decl.Packages;
|
User_Decl.Packages :=
|
User_Decl.Packages :=
|
Package_Table.Last (Project_Tree.Packages);
|
Package_Table.Last (Project_Tree.Packages);
|
Project_Tree.Packages.Table (User_Decl.Packages) :=
|
Project_Tree.Packages.Table (User_Decl.Packages) :=
|
User_Pack;
|
User_Pack;
|
|
|
else
|
else
|
Add_Attributes
|
Add_Attributes
|
(Project_Tree => Project_Tree,
|
(Project_Tree => Project_Tree,
|
Conf_Decl => Conf_Pack.Decl,
|
Conf_Decl => Conf_Pack.Decl,
|
User_Decl => Project_Tree.Packages.Table
|
User_Decl => Project_Tree.Packages.Table
|
(User_Pack_Id).Decl);
|
(User_Pack_Id).Decl);
|
end if;
|
end if;
|
|
|
Conf_Pack_Id := Conf_Pack.Next;
|
Conf_Pack_Id := Conf_Pack.Next;
|
end loop;
|
end loop;
|
|
|
Proj.Project.Decl := User_Decl;
|
Proj.Project.Decl := User_Decl;
|
end if;
|
end if;
|
|
|
Proj := Proj.Next;
|
Proj := Proj.Next;
|
end loop;
|
end loop;
|
end Apply_Config_File;
|
end Apply_Config_File;
|
|
|
---------------------
|
---------------------
|
-- Set_Runtime_For --
|
-- Set_Runtime_For --
|
---------------------
|
---------------------
|
|
|
procedure Set_Runtime_For (Language : Name_Id; RTS_Name : String) is
|
procedure Set_Runtime_For (Language : Name_Id; RTS_Name : String) is
|
begin
|
begin
|
Name_Len := RTS_Name'Length;
|
Name_Len := RTS_Name'Length;
|
Name_Buffer (1 .. Name_Len) := RTS_Name;
|
Name_Buffer (1 .. Name_Len) := RTS_Name;
|
RTS_Languages.Set (Language, Name_Find);
|
RTS_Languages.Set (Language, Name_Find);
|
end Set_Runtime_For;
|
end Set_Runtime_For;
|
|
|
----------------------
|
----------------------
|
-- Runtime_Name_For --
|
-- Runtime_Name_For --
|
----------------------
|
----------------------
|
|
|
function Runtime_Name_For (Language : Name_Id) return String is
|
function Runtime_Name_For (Language : Name_Id) return String is
|
begin
|
begin
|
if RTS_Languages.Get (Language) /= No_Name then
|
if RTS_Languages.Get (Language) /= No_Name then
|
return Get_Name_String (RTS_Languages.Get (Language));
|
return Get_Name_String (RTS_Languages.Get (Language));
|
else
|
else
|
return "";
|
return "";
|
end if;
|
end if;
|
end Runtime_Name_For;
|
end Runtime_Name_For;
|
|
|
------------------------------------
|
------------------------------------
|
-- Add_Default_GNAT_Naming_Scheme --
|
-- Add_Default_GNAT_Naming_Scheme --
|
------------------------------------
|
------------------------------------
|
|
|
procedure Add_Default_GNAT_Naming_Scheme
|
procedure Add_Default_GNAT_Naming_Scheme
|
(Config_File : in out Project_Node_Id;
|
(Config_File : in out Project_Node_Id;
|
Project_Tree : Project_Node_Tree_Ref)
|
Project_Tree : Project_Node_Tree_Ref)
|
is
|
is
|
procedure Create_Attribute
|
procedure Create_Attribute
|
(Name : Name_Id;
|
(Name : Name_Id;
|
Value : String;
|
Value : String;
|
Index : String := "";
|
Index : String := "";
|
Pkg : Project_Node_Id := Empty_Node);
|
Pkg : Project_Node_Id := Empty_Node);
|
|
|
----------------------
|
----------------------
|
-- Create_Attribute --
|
-- Create_Attribute --
|
----------------------
|
----------------------
|
|
|
procedure Create_Attribute
|
procedure Create_Attribute
|
(Name : Name_Id;
|
(Name : Name_Id;
|
Value : String;
|
Value : String;
|
Index : String := "";
|
Index : String := "";
|
Pkg : Project_Node_Id := Empty_Node)
|
Pkg : Project_Node_Id := Empty_Node)
|
is
|
is
|
Attr : Project_Node_Id;
|
Attr : Project_Node_Id;
|
pragma Unreferenced (Attr);
|
pragma Unreferenced (Attr);
|
|
|
Expr : Name_Id := No_Name;
|
Expr : Name_Id := No_Name;
|
Val : Name_Id := No_Name;
|
Val : Name_Id := No_Name;
|
Parent : Project_Node_Id := Config_File;
|
Parent : Project_Node_Id := Config_File;
|
begin
|
begin
|
if Index /= "" then
|
if Index /= "" then
|
Name_Len := Index'Length;
|
Name_Len := Index'Length;
|
Name_Buffer (1 .. Name_Len) := Index;
|
Name_Buffer (1 .. Name_Len) := Index;
|
Val := Name_Find;
|
Val := Name_Find;
|
end if;
|
end if;
|
|
|
if Pkg /= Empty_Node then
|
if Pkg /= Empty_Node then
|
Parent := Pkg;
|
Parent := Pkg;
|
end if;
|
end if;
|
|
|
Name_Len := Value'Length;
|
Name_Len := Value'Length;
|
Name_Buffer (1 .. Name_Len) := Value;
|
Name_Buffer (1 .. Name_Len) := Value;
|
Expr := Name_Find;
|
Expr := Name_Find;
|
|
|
Attr := Create_Attribute
|
Attr := Create_Attribute
|
(Tree => Project_Tree,
|
(Tree => Project_Tree,
|
Prj_Or_Pkg => Parent,
|
Prj_Or_Pkg => Parent,
|
Name => Name,
|
Name => Name,
|
Index_Name => Val,
|
Index_Name => Val,
|
Kind => Prj.Single,
|
Kind => Prj.Single,
|
Value => Create_Literal_String (Expr, Project_Tree));
|
Value => Create_Literal_String (Expr, Project_Tree));
|
end Create_Attribute;
|
end Create_Attribute;
|
|
|
-- Local variables
|
-- Local variables
|
|
|
Name : Name_Id;
|
Name : Name_Id;
|
Naming : Project_Node_Id;
|
Naming : Project_Node_Id;
|
|
|
-- Start of processing for Add_Default_GNAT_Naming_Scheme
|
-- Start of processing for Add_Default_GNAT_Naming_Scheme
|
|
|
begin
|
begin
|
if Config_File = Empty_Node then
|
if Config_File = Empty_Node then
|
|
|
-- Create a dummy config file is none was found
|
-- Create a dummy config file is none was found
|
|
|
Name_Len := Auto_Cgpr'Length;
|
Name_Len := Auto_Cgpr'Length;
|
Name_Buffer (1 .. Name_Len) := Auto_Cgpr;
|
Name_Buffer (1 .. Name_Len) := Auto_Cgpr;
|
Name := Name_Find;
|
Name := Name_Find;
|
|
|
-- An invalid project name to avoid conflicts with user-created ones
|
-- An invalid project name to avoid conflicts with user-created ones
|
|
|
Name_Len := 5;
|
Name_Len := 5;
|
Name_Buffer (1 .. Name_Len) := "_auto";
|
Name_Buffer (1 .. Name_Len) := "_auto";
|
|
|
Config_File :=
|
Config_File :=
|
Create_Project
|
Create_Project
|
(In_Tree => Project_Tree,
|
(In_Tree => Project_Tree,
|
Name => Name_Find,
|
Name => Name_Find,
|
Full_Path => Path_Name_Type (Name),
|
Full_Path => Path_Name_Type (Name),
|
Is_Config_File => True);
|
Is_Config_File => True);
|
|
|
-- Setup library support
|
-- Setup library support
|
|
|
case MLib.Tgt.Support_For_Libraries is
|
case MLib.Tgt.Support_For_Libraries is
|
when None =>
|
when None =>
|
null;
|
null;
|
|
|
when Static_Only =>
|
when Static_Only =>
|
Create_Attribute (Name_Library_Support, "static_only");
|
Create_Attribute (Name_Library_Support, "static_only");
|
|
|
when Full =>
|
when Full =>
|
Create_Attribute (Name_Library_Support, "full");
|
Create_Attribute (Name_Library_Support, "full");
|
end case;
|
end case;
|
|
|
if MLib.Tgt.Standalone_Library_Auto_Init_Is_Supported then
|
if MLib.Tgt.Standalone_Library_Auto_Init_Is_Supported then
|
Create_Attribute (Name_Library_Auto_Init_Supported, "true");
|
Create_Attribute (Name_Library_Auto_Init_Supported, "true");
|
else
|
else
|
Create_Attribute (Name_Library_Auto_Init_Supported, "false");
|
Create_Attribute (Name_Library_Auto_Init_Supported, "false");
|
end if;
|
end if;
|
|
|
-- Setup Ada support (Ada is the default language here, since this
|
-- Setup Ada support (Ada is the default language here, since this
|
-- is only called when no config file existed initially, ie for
|
-- is only called when no config file existed initially, ie for
|
-- gnatmake).
|
-- gnatmake).
|
|
|
Create_Attribute (Name_Default_Language, "ada");
|
Create_Attribute (Name_Default_Language, "ada");
|
|
|
Naming := Create_Package (Project_Tree, Config_File, "naming");
|
Naming := Create_Package (Project_Tree, Config_File, "naming");
|
Create_Attribute (Name_Spec_Suffix, ".ads", "ada", Pkg => Naming);
|
Create_Attribute (Name_Spec_Suffix, ".ads", "ada", Pkg => Naming);
|
Create_Attribute (Name_Separate_Suffix, ".adb", "ada", Pkg => Naming);
|
Create_Attribute (Name_Separate_Suffix, ".adb", "ada", Pkg => Naming);
|
Create_Attribute (Name_Body_Suffix, ".adb", "ada", Pkg => Naming);
|
Create_Attribute (Name_Body_Suffix, ".adb", "ada", Pkg => Naming);
|
Create_Attribute (Name_Dot_Replacement, "-", Pkg => Naming);
|
Create_Attribute (Name_Dot_Replacement, "-", Pkg => Naming);
|
Create_Attribute (Name_Casing, "lowercase", Pkg => Naming);
|
Create_Attribute (Name_Casing, "lowercase", Pkg => Naming);
|
|
|
if Current_Verbosity = High then
|
if Current_Verbosity = High then
|
Write_Line ("Automatically generated (in-memory) config file");
|
Write_Line ("Automatically generated (in-memory) config file");
|
Prj.PP.Pretty_Print
|
Prj.PP.Pretty_Print
|
(Project => Config_File,
|
(Project => Config_File,
|
In_Tree => Project_Tree,
|
In_Tree => Project_Tree,
|
Backward_Compatibility => False);
|
Backward_Compatibility => False);
|
end if;
|
end if;
|
end if;
|
end if;
|
end Add_Default_GNAT_Naming_Scheme;
|
end Add_Default_GNAT_Naming_Scheme;
|
|
|
end Prj.Conf;
|
end Prj.Conf;
|
|
|