OSDN Git Service

* parser.c (cp_parser_class_specifier): Set class location to that
[pf3gnuchains/gcc-fork.git] / gcc / ada / prj-conf.adb
index 8ae9f79..dfebd9a 100644 (file)
 --                                                                          --
 -- 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- --
--- ware  Foundation;  either version 2,  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- --
 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
 -- 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 --
--- Public License  distributed with GNAT;  see file COPYING.  If not, write --
--- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
--- Boston, MA 02110-1301, USA.                                              --
+-- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
+-- http://www.gnu.org/licenses for a complete copy of the license.          --
 --                                                                          --
 -- GNAT was originally developed  by the GNAT team at  New York University. --
 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
 with Ada.Directories;  use Ada.Directories;
 with GNAT.HTable;      use GNAT.HTable;
 with Makeutl;          use Makeutl;
+with MLib.Tgt;
 with Opt;              use Opt;
-with Osint;            use Osint;
 with Output;           use Output;
-with Prj.Err;          use Prj.Err;
+with Prj.Env;
+with Prj.Err;
 with Prj.Part;
+with Prj.PP;
 with Prj.Proc;         use Prj.Proc;
 with Prj.Tree;         use Prj.Tree;
 with Prj.Util;         use Prj.Util;
 with Prj;              use Prj;
-with Sinput.P;
 with Snames;           use Snames;
 with System.Case_Util; use System.Case_Util;
 with System;
@@ -79,15 +79,14 @@ package body Prj.Conf is
    --  found, or null otherwise
 
    function Check_Target
-     (Config_File  : Prj.Project_Id;
+     (Config_File        : Prj.Project_Id;
       Autoconf_Specified : Boolean;
-      Project_Tree : Prj.Project_Tree_Ref;
-      Target       : String := "") return Boolean;
+      Project_Tree       : Prj.Project_Tree_Ref;
+      Target             : String := "") return Boolean;
    --  Check that the config file's target matches Target.
    --  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 function will
-   --  call Osint.Fail to report a fatal error message and stop the program.
+   --  a target. If the target in the configuration file is invalid, this
+   --  function will raise Invalid_Config with an appropriate message.
    --  Autoconf_Specified should be set to True if the user has used --autoconf
 
    --------------------
@@ -118,7 +117,6 @@ package body Prj.Conf is
    begin
       Conf_Attr_Id := Conf_Decl.Attributes;
       User_Attr_Id := User_Decl.Attributes;
-
       while Conf_Attr_Id /= No_Variable loop
          Conf_Attr :=
            Project_Tree.Variable_Elements.Table (Conf_Attr_Id);
@@ -135,25 +133,22 @@ package body Prj.Conf is
                Project_Tree.Variable_Elements.Table (User_Attr_Id) :=
                  User_Attr;
 
-            elsif User_Attr.Value.Kind = List and then
-            Conf_Attr.Value.Values /= Nil_String
+            elsif User_Attr.Value.Kind = List
+              and then Conf_Attr.Value.Values /= Nil_String
             then
-
                --  List attribute declared in both the user project and the
                --  configuration project: prepend the user list with the
                --  configuration list.
 
                declare
-                  Conf_List : String_List_Id :=
-                    Conf_Attr.Value.Values;
+                  Conf_List : String_List_Id := Conf_Attr.Value.Values;
                   Conf_Elem : String_Element;
                   User_List : constant String_List_Id :=
-                    User_Attr.Value.Values;
+                                User_Attr.Value.Values;
                   New_List : String_List_Id;
                   New_Elem : String_Element;
 
                begin
-
                   --  Create new list
 
                   String_Element_Table.Increment_Last
@@ -187,7 +182,6 @@ package body Prj.Conf is
                         exit;
 
                      else
-
                         --  If it is not the last element in the list, add to
                         --  new list.
 
@@ -269,10 +263,11 @@ package body Prj.Conf is
 
                   if Conf_List /= Nil_String then
                      declare
-                        Link : constant String_List_Id :=
-                                 User_Array_Elem.Value.Values;
+                        Link     : constant String_List_Id :=
+                                     User_Array_Elem.Value.Values;
                         Previous : String_List_Id := Nil_String;
                         Next     : String_List_Id;
+
                      begin
                         loop
                            Conf_List_Elem :=
@@ -330,7 +325,6 @@ package body Prj.Conf is
            (Name,
             "." & Path_Separator &
             Prefix_Path & "share" & Directory_Separator & "gpr");
-
       else
          return Locate_Regular_File (Name, ".");
       end if;
@@ -346,20 +340,22 @@ package body Prj.Conf is
       Project_Tree : Prj.Project_Tree_Ref;
       Target       : String := "") return Boolean
    is
-      Variable   : constant Variable_Value :=
-        Value_Of (Name_Target, Config_File.Decl.Attributes, Project_Tree);
+      Variable : constant Variable_Value :=
+                   Value_Of
+                     (Name_Target, Config_File.Decl.Attributes, Project_Tree);
       Tgt_Name : Name_Id := No_Name;
       OK       : Boolean;
+
    begin
       if Variable /= Nil_Variable_Value and then not Variable.Default then
          Tgt_Name := Variable.Value;
       end if;
 
       if Target = "" then
-         OK := not Autoconf_Specified or Tgt_Name = No_Name;
+         OK := not Autoconf_Specified or else Tgt_Name = No_Name;
       else
          OK := Tgt_Name /= No_Name
-           and then Target = Get_Name_String (Tgt_Name);
+                 and then Target = Get_Name_String (Tgt_Name);
       end if;
 
       if not OK then
@@ -372,12 +368,13 @@ package body Prj.Conf is
 
          else
             if Tgt_Name /= No_Name then
-               Osint.Fail ("invalid target name """ &
-                           Get_Name_String (Tgt_Name) &
-                           """ in configuration");
+               raise Invalid_Config
+                 with "invalid target name """
+                   & Get_Name_String (Tgt_Name) & """ in configuration";
 
             else
-               Osint.Fail ("no target specified in configuration file");
+               raise Invalid_Config
+                 with "no target specified in configuration file";
             end if;
          end if;
       end if;
@@ -401,13 +398,17 @@ package body Prj.Conf is
       Packages_To_Check          : String_List_Access := null;
       Config                     : out Prj.Project_Id;
       Config_File_Path           : out String_Access;
-      Automatically_Generated    : out Boolean)
+      Automatically_Generated    : out Boolean;
+      Flags                      : Processing_Flags;
+      On_Load_Config             : Config_File_Hook := null)
    is
       function Default_File_Name return String;
       --  Return the name of the default config file that should be tested
 
       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
+      --  appropriate message
 
       function Get_Config_Switches return Argument_List_Access;
       --  Return the --config switches to use for gprconfig
@@ -423,7 +424,8 @@ package body Prj.Conf is
 
       function Default_File_Name return String is
          Ada_RTS : constant String := Runtime_Name_For (Name_Ada);
-         Tmp : String_Access;
+         Tmp     : String_Access;
+
       begin
          if Target_Name /= "" then
             if Ada_RTS /= "" then
@@ -459,6 +461,7 @@ package body Prj.Conf is
 
       function Might_Have_Sources (Project : Project_Id) return Boolean is
          Variable : Variable_Value;
+
       begin
          Variable :=
            Value_Of
@@ -478,6 +481,7 @@ package body Prj.Conf is
             return Variable = Nil_Variable_Value
               or else Variable.Default
               or else Variable.Values /= Nil_String;
+
          else
             return False;
          end if;
@@ -497,11 +501,11 @@ package body Prj.Conf is
             Equal      => "=");
          --  Hash table to keep the languages used in the project tree
 
-         IDE      : constant Package_Id :=
-           Value_Of
-             (Name_Ide,
-              Project.Decl.Packages,
-              Project_Tree);
+         IDE : constant Package_Id :=
+                 Value_Of
+                   (Name_Ide,
+                    Project.Decl.Packages,
+                    Project_Tree);
 
          Prj_Iter : Project_List;
          List     : String_List_Id;
@@ -512,6 +516,8 @@ package body Prj.Conf is
          Count    : Natural;
          Result   : Argument_List_Access;
 
+         Check_Default : Boolean;
+
       begin
          Prj_Iter := Project_Tree.Projects;
          while Prj_Iter /= null loop
@@ -526,17 +532,31 @@ package body Prj.Conf is
                  or else Variable.Default
                then
                   --  Languages is not declared. If it is not an extending
-                  --  project, check for Default_Language
+                  --  project, or if it extends a project with no Languages,
+                  --  check for Default_Language.
+
+                  Check_Default := Prj_Iter.Project.Extends = No_Project;
+
+                  if not Check_Default then
+                     Variable :=
+                       Value_Of
+                         (Name_Languages,
+                          Prj_Iter.Project.Extends.Decl.Attributes,
+                          Project_Tree);
+                     Check_Default :=
+                       Variable /= Nil_Variable_Value
+                         and then Variable.Values = Nil_String;
+                  end if;
 
-                  if Prj_Iter.Project.Extends = No_Project then
+                  if Check_Default then
                      Variable :=
                        Value_Of
                          (Name_Default_Language,
                           Prj_Iter.Project.Decl.Attributes,
                           Project_Tree);
 
-                     if Variable /= Nil_Variable_Value and then
-                       not Variable.Default
+                     if Variable /= Nil_Variable_Value
+                       and then not Variable.Default
                      then
                         Get_Name_String (Variable.Value);
                         To_Lower (Name_Buffer (1 .. Name_Len));
@@ -544,7 +564,7 @@ package body Prj.Conf is
                         Language_Htable.Set (Lang, Lang);
 
                      else
-                        --  If no language is declared, default to Ada
+                        --  If no default language is declared, default to Ada
 
                         Language_Htable.Set (Name_Ada, Name_Ada);
                      end if;
@@ -574,16 +594,15 @@ package body Prj.Conf is
 
          Name  := Language_Htable.Get_First;
          Count := 0;
-
          while Name /= No_Name loop
             Count := Count + 1;
             Name := Language_Htable.Get_Next;
          end loop;
 
          Result := new String_List (1 .. Count);
-         Count  := 1;
-         Name   := Language_Htable.Get_First;
 
+         Count := 1;
+         Name  := Language_Htable.Get_First;
          while Name /= No_Name loop
             --  Check if IDE'Compiler_Command is declared for the language.
             --  If it is, use its value to invoke gprconfig.
@@ -645,15 +664,20 @@ package body Prj.Conf is
 
       procedure Do_Autoconf is
          Obj_Dir : constant Variable_Value :=
-           Value_Of (Name_Object_Dir, Project.Decl.Attributes, Project_Tree);
+                     Value_Of
+                       (Name_Object_Dir,
+                        Project.Decl.Attributes,
+                        Project_Tree);
 
          Gprconfig_Path  : String_Access;
          Success         : Boolean;
+
       begin
          Gprconfig_Path := Locate_Exec_On_Path (Gprconfig_Name);
 
          if Gprconfig_Path = null then
-            Fail ("could not locate gprconfig for auto-configuration");
+            raise Invalid_Config
+              with "could not locate gprconfig for auto-configuration";
          end if;
 
          --  First, find the object directory of the user's project
@@ -669,7 +693,6 @@ package body Prj.Conf is
                Name_Len := 0;
                Add_Str_To_Name_Buffer
                  (Get_Name_String (Project.Directory.Name));
-               Add_Char_To_Name_Buffer (Directory_Separator);
                Add_Str_To_Name_Buffer (Get_Name_String (Obj_Dir.Value));
             end if;
          end if;
@@ -691,6 +714,8 @@ package body Prj.Conf is
             Args     : Argument_List (1 .. 5);
             Arg_Last : Positive;
 
+            Obj_Dir_Exists : Boolean := True;
+
          begin
             --  Check if the object directory exists. If Setup_Projects is True
             --  (-p) and directory does not exist, attempt to create it.
@@ -698,7 +723,7 @@ package body Prj.Conf is
             --  gprconfig.
 
             if not Is_Directory (Obj_Dir)
-              and then (Setup_Projects or Subdirs /= null)
+              and then (Setup_Projects or else Subdirs /= null)
             then
                begin
                   Create_Path (Obj_Dir);
@@ -711,12 +736,24 @@ package body Prj.Conf is
 
                exception
                   when others =>
-                     Fail ("could not create object directory " & Obj_Dir);
+                     raise Invalid_Config
+                       with "could not create object directory " & Obj_Dir;
                end;
             end if;
 
             if not Is_Directory (Obj_Dir) then
-               Fail ("object directory " & Obj_Dir & " does not exist");
+               case Flags.Require_Obj_Dirs is
+                  when Error =>
+                     raise Invalid_Config
+                       with "object directory " & Obj_Dir & " does not exist";
+                  when Warning =>
+                     Prj.Err.Error_Msg
+                       (Flags,
+                        "?object directory " & Obj_Dir & " does not exist");
+                     Obj_Dir_Exists := False;
+                  when Silent =>
+                     null;
+               end case;
             end if;
 
             --  Invoke gprconfig
@@ -727,19 +764,50 @@ package body Prj.Conf is
             --  If no config file was specified, set the auto.cgpr one
 
             if Config_File_Name = "" then
-               Args (3) := new String'
-                 (Obj_Dir & Directory_Separator & Auto_Cgpr);
+               if Obj_Dir_Exists then
+                  Args (3) :=
+                    new String'(Obj_Dir & Directory_Separator & Auto_Cgpr);
+
+               else
+                  declare
+                     Path_FD   : File_Descriptor;
+                     Path_Name : Path_Name_Type;
+
+                  begin
+                     Prj.Env.Create_Temp_File
+                       (In_Tree   => Project_Tree,
+                        Path_FD   => Path_FD,
+                        Path_Name => Path_Name,
+                        File_Use  => "configuration file");
+
+                     if Path_FD /= Invalid_FD then
+                        Args (3) := new String'(Get_Name_String (Path_Name));
+                        GNAT.OS_Lib.Close (Path_FD);
+
+                     else
+                        --  We'll have an error message later on
+
+                        Args (3) :=
+                          new String'
+                            (Obj_Dir & Directory_Separator & Auto_Cgpr);
+                     end if;
+                  end;
+               end if;
             else
                Args (3) := new String'(Config_File_Name);
             end if;
 
-            if Target_Name = "" then
-               Args (4) := new String'("--target=" & Normalized_Hostname);
+            if Normalized_Hostname = "" then
+               Arg_Last := 3;
             else
-               Args (4) := new String'("--target=" & Target_Name);
-            end if;
+               if Target_Name = "" then
+                  Args (4) := new String'("--target=" & Normalized_Hostname);
+               else
+                  Args (4) := new String'("--target=" & Target_Name);
+               end if;
 
-            Arg_Last := 4;
+               Arg_Last := 4;
+            end if;
 
             if not Verbose_Mode then
                Arg_Last := Arg_Last + 1;
@@ -762,9 +830,16 @@ package body Prj.Conf is
                Write_Eol;
 
             elsif not Quiet_Output then
-               Write_Str ("creating ");
-               Write_Str (Simple_Name (Args (3).all));
-               Write_Eol;
+               --  Display no message if we are creating auto.cgpr, unless in
+               --  verbose mode
+
+               if Config_File_Name /= ""
+                 or else Verbose_Mode
+               then
+                  Write_Str ("creating ");
+                  Write_Str (Simple_Name (Args (3).all));
+                  Write_Eol;
+               end if;
             end if;
 
             Spawn (Gprconfig_Path.all, Args (1 .. Arg_Last) & Switches.all,
@@ -775,7 +850,8 @@ package body Prj.Conf is
             Config_File_Path := Locate_Config_File (Args (3).all);
 
             if Config_File_Path = null then
-               Fail ("could not create " & Args (3).all);
+               raise Invalid_Config
+                 with "could not create " & Args (3).all;
             end if;
 
             for F in Args'Range loop
@@ -789,6 +865,7 @@ package body Prj.Conf is
 
    begin
       Free (Config_File_Path);
+      Config := No_Project;
 
       if Config_File_Name /= "" then
          Config_File_Path := Locate_Config_File (Config_File_Name);
@@ -800,9 +877,9 @@ package body Prj.Conf is
          if (not Allow_Automatic_Generation) and then
             Config_File_Name /= ""
          then
-            Osint.Fail
-              ("could not locate main configuration project " &
-               Config_File_Name);
+            raise Invalid_Config
+              with "could not locate main configuration project "
+                & Config_File_Name;
          end if;
       end if;
 
@@ -812,24 +889,37 @@ package body Prj.Conf is
       <<Process_Config_File>>
 
       if Automatically_Generated then
+         --  This might raise an Invalid_Config exception
          Do_Autoconf;
       end if;
 
       --  Parse the configuration file
 
-      if Verbose_Mode then
+      if Verbose_Mode and then Config_File_Path /= null then
          Write_Str  ("Checking configuration ");
          Write_Line (Config_File_Path.all);
       end if;
 
-      Prj.Part.Parse
-        (In_Tree                => Project_Node_Tree,
-         Project                => Config_Project_Node,
-         Project_File_Name      => Config_File_Path.all,
-         Always_Errout_Finalize => False,
-         Packages_To_Check      => Packages_To_Check,
-         Current_Directory      => Current_Directory,
-         Is_Config_File         => True);
+      if Config_File_Path /= null then
+         Prj.Part.Parse
+           (In_Tree                => Project_Node_Tree,
+            Project                => Config_Project_Node,
+            Project_File_Name      => Config_File_Path.all,
+            Always_Errout_Finalize => False,
+            Packages_To_Check      => Packages_To_Check,
+            Current_Directory      => Current_Directory,
+            Is_Config_File         => True,
+            Flags                  => Flags);
+      else
+         --  Maybe the user will want to create his own configuration file
+         Config_Project_Node := Empty_Node;
+      end if;
+
+      if On_Load_Config /= null then
+         On_Load_Config
+           (Config_File       => Config_Project_Node,
+            Project_Node_Tree => Project_Node_Tree);
+      end if;
 
       if Config_Project_Node /= Empty_Node then
          Prj.Proc.Process_Project_Tree_Phase_1
@@ -838,16 +928,16 @@ package body Prj.Conf is
             Success                => Success,
             From_Project_Node      => Config_Project_Node,
             From_Project_Node_Tree => Project_Node_Tree,
-            Report_Error           => null,
+            Flags                  => Flags,
             Reset_Tree             => False);
       end if;
 
       if Config_Project_Node = Empty_Node
         or else Config = No_Project
       then
-         Osint.Fail
-           ("processing of configuration project """ &
-            Config_File_Path.all & """ failed");
+         raise Invalid_Config
+           with "processing of configuration project """
+             & Config_File_Path.all & """ failed";
       end if;
 
       --  Check that the target of the configuration file is the one the user
@@ -855,24 +945,23 @@ package body Prj.Conf is
       --  auto-conf mode, since the appropriate target was passed to gprconfig.
 
       if not Automatically_Generated
-        and not Check_Target
-          (Config, Autoconf_Specified, Project_Tree, Target_Name)
+        and then not
+          Check_Target (Config, Autoconf_Specified, Project_Tree, Target_Name)
       then
          Automatically_Generated := True;
          goto Process_Config_File;
       end if;
    end Get_Or_Create_Configuration_File;
 
-   ------------------------------------
-   -- Parse_Project_And_Apply_Config --
-   ------------------------------------
+   --------------------------------------
+   -- Process_Project_And_Apply_Config --
+   --------------------------------------
 
-   procedure Parse_Project_And_Apply_Config
+   procedure Process_Project_And_Apply_Config
      (Main_Project               : out Prj.Project_Id;
-      User_Project_Node          : out Prj.Tree.Project_Node_Id;
+      User_Project_Node          : Prj.Tree.Project_Node_Id;
       Config_File_Name           : String := "";
       Autoconf_Specified         : Boolean;
-      Project_File_Name          : String;
       Project_Tree               : Prj.Project_Tree_Ref;
       Project_Node_Tree          : Prj.Tree.Project_Node_Tree_Ref;
       Packages_To_Check          : String_List_Access;
@@ -881,41 +970,25 @@ package body Prj.Conf is
       Config_File_Path           : out String_Access;
       Target_Name                : String := "";
       Normalized_Hostname        : String;
-      On_Load_Config             : Config_File_Hook := null)
+      Flags                      : Processing_Flags;
+      On_Load_Config             : Config_File_Hook := null;
+      Reset_Tree                 : Boolean := True)
    is
       Main_Config_Project : Project_Id;
       Success : Boolean;
 
    begin
-      --  Parse the user project tree
-
-      Prj.Initialize (Project_Tree);
-      Prj.Tree.Initialize (Project_Node_Tree);
-
-      Main_Project      := No_Project;
+      Main_Project := No_Project;
       Automatically_Generated := False;
 
-      Prj.Part.Parse
-        (In_Tree                => Project_Node_Tree,
-         Project                => User_Project_Node,
-         Project_File_Name      => Project_File_Name,
-         Always_Errout_Finalize => False,
-         Packages_To_Check      => Packages_To_Check,
-         Current_Directory      => Current_Directory,
-         Is_Config_File         => False);
-
-      if User_Project_Node = Empty_Node then
-         User_Project_Node := Empty_Node;
-         return;
-      end if;
-
       Process_Project_Tree_Phase_1
         (In_Tree                => Project_Tree,
          Project                => Main_Project,
          Success                => Success,
          From_Project_Node      => User_Project_Node,
          From_Project_Node_Tree => Project_Node_Tree,
-         Report_Error           => null);
+         Flags                  => Flags,
+         Reset_Tree             => Reset_Tree);
 
       if not Success then
          Main_Project := No_Project;
@@ -936,35 +1009,86 @@ package body Prj.Conf is
          Normalized_Hostname        => Normalized_Hostname,
          Packages_To_Check          => Packages_To_Check,
          Config_File_Path           => Config_File_Path,
-         Automatically_Generated    => Automatically_Generated);
-
-      if On_Load_Config /= null then
-         On_Load_Config
-           (Config_File  => Main_Config_Project,
-            Project_Tree => Project_Tree);
-      end if;
+         Automatically_Generated    => Automatically_Generated,
+         Flags                      => Flags,
+         On_Load_Config             => On_Load_Config);
 
       Apply_Config_File (Main_Config_Project, Project_Tree);
 
       --  Finish processing the user's project
 
-      Sinput.P.Reset_First;
-
       Prj.Proc.Process_Project_Tree_Phase_2
-        (In_Tree                => Project_Tree,
-         Project                => Main_Project,
-         Success                => Success,
-         From_Project_Node      => User_Project_Node,
-         From_Project_Node_Tree => Project_Node_Tree,
-         Report_Error           => null,
-         Current_Dir            => Current_Directory,
-         When_No_Sources        => Warning,
-         Is_Config_File         => False);
+        (In_Tree                    => Project_Tree,
+         Project                    => Main_Project,
+         Success                    => Success,
+         From_Project_Node          => User_Project_Node,
+         From_Project_Node_Tree     => Project_Node_Tree,
+         Flags                      => Flags);
 
       if not Success then
-         Prj.Err.Finalize;
-         Osint.Fail ("""" & Project_File_Name & """ processing failed");
+         Main_Project := No_Project;
       end if;
+   end Process_Project_And_Apply_Config;
+
+   ------------------------------------
+   -- Parse_Project_And_Apply_Config --
+   ------------------------------------
+
+   procedure Parse_Project_And_Apply_Config
+     (Main_Project               : out Prj.Project_Id;
+      User_Project_Node          : out Prj.Tree.Project_Node_Id;
+      Config_File_Name           : String := "";
+      Autoconf_Specified         : Boolean;
+      Project_File_Name          : String;
+      Project_Tree               : Prj.Project_Tree_Ref;
+      Project_Node_Tree          : Prj.Tree.Project_Node_Tree_Ref;
+      Packages_To_Check          : String_List_Access;
+      Allow_Automatic_Generation : Boolean := True;
+      Automatically_Generated    : out Boolean;
+      Config_File_Path           : out String_Access;
+      Target_Name                : String := "";
+      Normalized_Hostname        : String;
+      Flags                      : Processing_Flags;
+      On_Load_Config             : Config_File_Hook := null)
+   is
+   begin
+      --  Parse the user project tree
+
+      Prj.Initialize (Project_Tree);
+
+      Main_Project      := No_Project;
+      Automatically_Generated := False;
+
+      Prj.Part.Parse
+        (In_Tree                => Project_Node_Tree,
+         Project                => User_Project_Node,
+         Project_File_Name      => Project_File_Name,
+         Always_Errout_Finalize => False,
+         Packages_To_Check      => Packages_To_Check,
+         Current_Directory      => Current_Directory,
+         Is_Config_File         => False,
+         Flags                  => Flags);
+
+      if User_Project_Node = Empty_Node then
+         User_Project_Node := Empty_Node;
+         return;
+      end if;
+
+      Process_Project_And_Apply_Config
+        (Main_Project               => Main_Project,
+         User_Project_Node          => User_Project_Node,
+         Config_File_Name           => Config_File_Name,
+         Autoconf_Specified         => Autoconf_Specified,
+         Project_Tree               => Project_Tree,
+         Project_Node_Tree          => Project_Node_Tree,
+         Packages_To_Check          => Packages_To_Check,
+         Allow_Automatic_Generation => Allow_Automatic_Generation,
+         Automatically_Generated    => Automatically_Generated,
+         Config_File_Path           => Config_File_Path,
+         Target_Name                => Target_Name,
+         Normalized_Hostname        => Normalized_Hostname,
+         Flags                      => Flags,
+         On_Load_Config             => On_Load_Config);
    end Parse_Project_And_Apply_Config;
 
    -----------------------
@@ -986,7 +1110,6 @@ package body Prj.Conf is
 
    begin
       Proj := Project_Tree.Projects;
-
       while Proj /= null loop
          if Proj.Project /= Config_File then
             User_Decl := Proj.Project.Decl;
@@ -1057,4 +1180,128 @@ package body Prj.Conf is
       end if;
    end Runtime_Name_For;
 
+   ------------------------------------
+   -- Add_Default_GNAT_Naming_Scheme --
+   ------------------------------------
+
+   procedure Add_Default_GNAT_Naming_Scheme
+     (Config_File  : in out Project_Node_Id;
+      Project_Tree : Project_Node_Tree_Ref)
+   is
+      procedure Create_Attribute
+        (Name  : Name_Id;
+         Value : String;
+         Index : String := "";
+         Pkg   : Project_Node_Id := Empty_Node);
+
+      ----------------------
+      -- Create_Attribute --
+      ----------------------
+
+      procedure Create_Attribute
+        (Name  : Name_Id;
+         Value : String;
+         Index : String := "";
+         Pkg   : Project_Node_Id := Empty_Node)
+      is
+         Attr       : Project_Node_Id;
+         pragma Unreferenced (Attr);
+
+         Expr   : Name_Id         := No_Name;
+         Val    : Name_Id         := No_Name;
+         Parent : Project_Node_Id := Config_File;
+      begin
+         if Index /= "" then
+            Name_Len := Index'Length;
+            Name_Buffer (1 .. Name_Len) := Index;
+            Val := Name_Find;
+         end if;
+
+         if Pkg /= Empty_Node then
+            Parent := Pkg;
+         end if;
+
+         Name_Len := Value'Length;
+         Name_Buffer (1 .. Name_Len) := Value;
+         Expr := Name_Find;
+
+         Attr := Create_Attribute
+           (Tree       => Project_Tree,
+            Prj_Or_Pkg => Parent,
+            Name       => Name,
+            Index_Name => Val,
+            Kind       => Prj.Single,
+            Value      => Create_Literal_String (Expr, Project_Tree));
+      end Create_Attribute;
+
+      --  Local variables
+
+      Name   : Name_Id;
+      Naming : Project_Node_Id;
+
+   --  Start of processing for Add_Default_GNAT_Naming_Scheme
+
+   begin
+      if Config_File = Empty_Node then
+
+         --  Create a dummy config file is none was found
+
+         Name_Len := Auto_Cgpr'Length;
+         Name_Buffer (1 .. Name_Len) := Auto_Cgpr;
+         Name := Name_Find;
+
+         --  An invalid project name to avoid conflicts with user-created ones
+
+         Name_Len := 5;
+         Name_Buffer (1 .. Name_Len) := "_auto";
+
+         Config_File :=
+           Create_Project
+             (In_Tree        => Project_Tree,
+              Name           => Name_Find,
+              Full_Path      => Path_Name_Type (Name),
+              Is_Config_File => True);
+
+         --  Setup library support
+
+         case MLib.Tgt.Support_For_Libraries is
+            when None =>
+               null;
+
+            when Static_Only =>
+               Create_Attribute (Name_Library_Support, "static_only");
+
+            when Full =>
+               Create_Attribute (Name_Library_Support, "full");
+         end case;
+
+         if MLib.Tgt.Standalone_Library_Auto_Init_Is_Supported then
+            Create_Attribute (Name_Library_Auto_Init_Supported, "true");
+         else
+            Create_Attribute (Name_Library_Auto_Init_Supported, "false");
+         end if;
+
+         --  Setup Ada support (Ada is the default language here, since this
+         --  is only called when no config file existed initially, ie for
+         --  gnatmake).
+
+         Create_Attribute (Name_Default_Language, "ada");
+
+         Naming := Create_Package (Project_Tree, Config_File, "naming");
+         Create_Attribute (Name_Spec_Suffix, ".ads", "ada",     Pkg => Naming);
+         Create_Attribute (Name_Separate_Suffix, ".adb", "ada", Pkg => Naming);
+         Create_Attribute (Name_Body_Suffix, ".adb", "ada",     Pkg => Naming);
+         Create_Attribute (Name_Dot_Replacement, "-",           Pkg => Naming);
+         Create_Attribute (Name_Casing,          "lowercase",   Pkg => Naming);
+
+         if Current_Verbosity = High then
+            Write_Line ("Automatically generated (in-memory) config file");
+            Prj.PP.Pretty_Print
+              (Project                => Config_File,
+               In_Tree                => Project_Tree,
+               Backward_Compatibility => False);
+         end if;
+      end if;
+   end Add_Default_GNAT_Naming_Scheme;
+
 end Prj.Conf;