1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2006-2009, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Ada.Directories; use Ada.Directories;
28 with GNAT.HTable; use GNAT.HTable;
29 with Makeutl; use Makeutl;
32 with Output; use Output;
35 with Prj.Proc; use Prj.Proc;
36 with Prj.Tree; use Prj.Tree;
37 with Prj.Util; use Prj.Util;
39 with Snames; use Snames;
40 with System.Case_Util; use System.Case_Util;
43 package body Prj.Conf is
45 Auto_Cgpr : constant String := "auto.cgpr";
47 Default_Name : constant String := "default.cgpr";
48 -- Default configuration file that will be used if found
50 Config_Project_Env_Var : constant String := "GPR_CONFIG";
51 -- Name of the environment variable that provides the name of the
52 -- configuration file to use.
54 Gprconfig_Name : constant String := "gprconfig";
56 package RTS_Languages is new GNAT.HTable.Simple_HTable
57 (Header_Num => Prj.Header_Num,
59 No_Element => No_Name,
63 -- Stores the runtime names for the various languages. This is in general
64 -- set from a --RTS command line option.
66 procedure Add_Attributes
67 (Project_Tree : Project_Tree_Ref;
68 Conf_Decl : Declarations;
69 User_Decl : in out Declarations);
70 -- Process the attributes in the config declarations.
71 -- For single string values, if the attribute is not declared in the user
72 -- declarations, declare it with the value in the config declarations.
73 -- For string list values, prepend the value in the user declarations with
74 -- the value in the config declarations.
76 function Locate_Config_File (Name : String) return String_Access;
77 -- Search for Name in the config files directory. Return full path if
78 -- found, or null otherwise
81 (Config_File : Prj.Project_Id;
82 Autoconf_Specified : Boolean;
83 Project_Tree : Prj.Project_Tree_Ref;
84 Target : String := "") return Boolean;
85 -- Check that the config file's target matches Target.
86 -- Target should be set to the empty string when the user did not specify
87 -- a target. If the target in the configuration file is invalid, this
88 -- function will raise Invalid_Config with an appropriate message.
89 -- Autoconf_Specified should be set to True if the user has used --autoconf
95 procedure Add_Attributes
96 (Project_Tree : Project_Tree_Ref;
97 Conf_Decl : Declarations;
98 User_Decl : in out Declarations)
100 Conf_Attr_Id : Variable_Id;
101 Conf_Attr : Variable;
102 Conf_Array_Id : Array_Id;
103 Conf_Array : Array_Data;
104 Conf_Array_Elem_Id : Array_Element_Id;
105 Conf_Array_Elem : Array_Element;
106 Conf_List : String_List_Id;
107 Conf_List_Elem : String_Element;
109 User_Attr_Id : Variable_Id;
110 User_Attr : Variable;
111 User_Array_Id : Array_Id;
112 User_Array : Array_Data;
113 User_Array_Elem_Id : Array_Element_Id;
114 User_Array_Elem : Array_Element;
117 Conf_Attr_Id := Conf_Decl.Attributes;
118 User_Attr_Id := User_Decl.Attributes;
119 while Conf_Attr_Id /= No_Variable loop
121 Project_Tree.Variable_Elements.Table (Conf_Attr_Id);
123 Project_Tree.Variable_Elements.Table (User_Attr_Id);
125 if not Conf_Attr.Value.Default then
126 if User_Attr.Value.Default then
128 -- No attribute declared in user project file: just copy the
129 -- value of the configuration attribute.
131 User_Attr.Value := Conf_Attr.Value;
132 Project_Tree.Variable_Elements.Table (User_Attr_Id) :=
135 elsif User_Attr.Value.Kind = List
136 and then Conf_Attr.Value.Values /= Nil_String
138 -- List attribute declared in both the user project and the
139 -- configuration project: prepend the user list with the
140 -- configuration list.
143 Conf_List : String_List_Id := Conf_Attr.Value.Values;
144 Conf_Elem : String_Element;
145 User_List : constant String_List_Id :=
146 User_Attr.Value.Values;
147 New_List : String_List_Id;
148 New_Elem : String_Element;
153 String_Element_Table.Increment_Last
154 (Project_Tree.String_Elements);
155 New_List := String_Element_Table.Last
156 (Project_Tree.String_Elements);
158 -- Value of attribute is new list
160 User_Attr.Value.Values := New_List;
161 Project_Tree.Variable_Elements.Table (User_Attr_Id) :=
166 -- Get each element of configuration list
169 Project_Tree.String_Elements.Table (Conf_List);
170 New_Elem := Conf_Elem;
171 Conf_List := Conf_Elem.Next;
173 if Conf_List = Nil_String then
175 -- If it is the last element in the list, connect to
176 -- first element of user list, and we are done.
178 New_Elem.Next := User_List;
179 Project_Tree.String_Elements.Table
180 (New_List) := New_Elem;
184 -- If it is not the last element in the list, add to
187 String_Element_Table.Increment_Last
188 (Project_Tree.String_Elements);
190 String_Element_Table.Last
191 (Project_Tree.String_Elements);
192 Project_Tree.String_Elements.Table
193 (New_List) := New_Elem;
194 New_List := New_Elem.Next;
201 Conf_Attr_Id := Conf_Attr.Next;
202 User_Attr_Id := User_Attr.Next;
205 Conf_Array_Id := Conf_Decl.Arrays;
206 while Conf_Array_Id /= No_Array loop
207 Conf_Array := Project_Tree.Arrays.Table (Conf_Array_Id);
209 User_Array_Id := User_Decl.Arrays;
210 while User_Array_Id /= No_Array loop
211 User_Array := Project_Tree.Arrays.Table (User_Array_Id);
212 exit when User_Array.Name = Conf_Array.Name;
213 User_Array_Id := User_Array.Next;
216 -- If this associative array does not exist in the user project file,
217 -- do a shallow copy of the full associative array.
219 if User_Array_Id = No_Array then
220 Array_Table.Increment_Last (Project_Tree.Arrays);
221 User_Array := Conf_Array;
222 User_Array.Next := User_Decl.Arrays;
223 User_Decl.Arrays := Array_Table.Last (Project_Tree.Arrays);
224 Project_Tree.Arrays.Table (User_Decl.Arrays) := User_Array;
227 -- Otherwise, check each array element
229 Conf_Array_Elem_Id := Conf_Array.Value;
230 while Conf_Array_Elem_Id /= No_Array_Element loop
232 Project_Tree.Array_Elements.Table (Conf_Array_Elem_Id);
234 User_Array_Elem_Id := User_Array.Value;
235 while User_Array_Elem_Id /= No_Array_Element loop
237 Project_Tree.Array_Elements.Table (User_Array_Elem_Id);
238 exit when User_Array_Elem.Index = Conf_Array_Elem.Index;
239 User_Array_Elem_Id := User_Array_Elem.Next;
242 -- If the array element does not exist in the user array,
243 -- insert a shallow copy of the conf array element in the
246 if User_Array_Elem_Id = No_Array_Element then
247 Array_Element_Table.Increment_Last
248 (Project_Tree.Array_Elements);
249 User_Array_Elem := Conf_Array_Elem;
250 User_Array_Elem.Next := User_Array.Value;
252 Array_Element_Table.Last (Project_Tree.Array_Elements);
253 Project_Tree.Array_Elements.Table (User_Array.Value) :=
255 Project_Tree.Arrays.Table (User_Array_Id) := User_Array;
257 -- Otherwise, if the value is a string list, prepend the
258 -- user array element with the conf array element value.
260 elsif Conf_Array_Elem.Value.Kind = List then
261 Conf_List := Conf_Array_Elem.Value.Values;
263 if Conf_List /= Nil_String then
265 Link : constant String_List_Id :=
266 User_Array_Elem.Value.Values;
267 Previous : String_List_Id := Nil_String;
268 Next : String_List_Id;
273 Project_Tree.String_Elements.Table
275 String_Element_Table.Increment_Last
276 (Project_Tree.String_Elements);
278 String_Element_Table.Last
279 (Project_Tree.String_Elements);
280 Project_Tree.String_Elements.Table (Next) :=
283 if Previous = Nil_String then
284 User_Array_Elem.Value.Values := Next;
285 Project_Tree.Array_Elements.Table
286 (User_Array_Elem_Id) := User_Array_Elem;
289 Project_Tree.String_Elements.Table
290 (Previous).Next := Next;
295 Conf_List := Conf_List_Elem.Next;
297 if Conf_List = Nil_String then
298 Project_Tree.String_Elements.Table
299 (Previous).Next := Link;
307 Conf_Array_Elem_Id := Conf_Array_Elem.Next;
311 Conf_Array_Id := Conf_Array.Next;
315 ------------------------
316 -- Locate_Config_File --
317 ------------------------
319 function Locate_Config_File (Name : String) return String_Access is
320 Prefix_Path : constant String := Executable_Prefix_Path;
322 if Prefix_Path'Length /= 0 then
323 return Locate_Regular_File
325 "." & Path_Separator &
326 Prefix_Path & "share" & Directory_Separator & "gpr");
328 return Locate_Regular_File (Name, ".");
330 end Locate_Config_File;
336 function Check_Target
337 (Config_File : Project_Id;
338 Autoconf_Specified : Boolean;
339 Project_Tree : Prj.Project_Tree_Ref;
340 Target : String := "") return Boolean
342 Variable : constant Variable_Value :=
344 (Name_Target, Config_File.Decl.Attributes, Project_Tree);
345 Tgt_Name : Name_Id := No_Name;
349 if Variable /= Nil_Variable_Value and then not Variable.Default then
350 Tgt_Name := Variable.Value;
354 OK := not Autoconf_Specified or Tgt_Name = No_Name;
356 OK := Tgt_Name /= No_Name
357 and then Target = Get_Name_String (Tgt_Name);
361 if Autoconf_Specified then
363 Write_Line ("inconsistent targets, performing autoconf");
369 if Tgt_Name /= No_Name then
371 with "invalid target name """
372 & Get_Name_String (Tgt_Name) & """ in configuration";
376 with "no target specified in configuration file";
384 --------------------------------------
385 -- Get_Or_Create_Configuration_File --
386 --------------------------------------
388 procedure Get_Or_Create_Configuration_File
389 (Project : Project_Id;
390 Project_Tree : Project_Tree_Ref;
391 Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
392 Allow_Automatic_Generation : Boolean;
393 Config_File_Name : String := "";
394 Autoconf_Specified : Boolean;
395 Target_Name : String := "";
396 Normalized_Hostname : String;
397 Packages_To_Check : String_List_Access := null;
398 Config : out Prj.Project_Id;
399 Config_File_Path : out String_Access;
400 Automatically_Generated : out Boolean;
401 Flags : Processing_Flags;
402 On_Load_Config : Config_File_Hook := null)
404 function Default_File_Name return String;
405 -- Return the name of the default config file that should be tested
407 procedure Do_Autoconf;
408 -- Generate a new config file through gprconfig.
409 -- In case of error, this raises the Invalid_Config exception with an
410 -- appropriate message
412 function Get_Config_Switches return Argument_List_Access;
413 -- Return the --config switches to use for gprconfig
415 function Might_Have_Sources (Project : Project_Id) return Boolean;
416 -- True if the specified project might have sources (ie the user has not
417 -- explicitly specified it. We haven't checked the file system, nor do
418 -- we need to at this stage.
420 -----------------------
421 -- Default_File_Name --
422 -----------------------
424 function Default_File_Name return String is
425 Ada_RTS : constant String := Runtime_Name_For (Name_Ada);
429 if Target_Name /= "" then
430 if Ada_RTS /= "" then
431 return Target_Name & '-' & Ada_RTS
432 & Config_Project_File_Extension;
434 return Target_Name & Config_Project_File_Extension;
437 elsif Ada_RTS /= "" then
438 return Ada_RTS & Config_Project_File_Extension;
441 Tmp := Getenv (Config_Project_Env_Var);
444 T : constant String := Tmp.all;
455 end Default_File_Name;
457 ------------------------
458 -- Might_Have_Sources --
459 ------------------------
461 function Might_Have_Sources (Project : Project_Id) return Boolean is
462 Variable : Variable_Value;
468 Project.Decl.Attributes,
471 if Variable = Nil_Variable_Value
472 or else Variable.Default
473 or else Variable.Values /= Nil_String
478 Project.Decl.Attributes,
480 return Variable = Nil_Variable_Value
481 or else Variable.Default
482 or else Variable.Values /= Nil_String;
487 end Might_Have_Sources;
489 -------------------------
490 -- Get_Config_Switches --
491 -------------------------
493 function Get_Config_Switches return Argument_List_Access is
494 package Language_Htable is new GNAT.HTable.Simple_HTable
495 (Header_Num => Prj.Header_Num,
497 No_Element => No_Name,
501 -- Hash table to keep the languages used in the project tree
503 IDE : constant Package_Id :=
506 Project.Decl.Packages,
509 Prj_Iter : Project_List;
510 List : String_List_Id;
511 Elem : String_Element;
513 Variable : Variable_Value;
516 Result : Argument_List_Access;
519 Prj_Iter := Project_Tree.Projects;
520 while Prj_Iter /= null loop
521 if Might_Have_Sources (Prj_Iter.Project) then
525 Prj_Iter.Project.Decl.Attributes,
528 if Variable = Nil_Variable_Value
529 or else Variable.Default
531 -- Languages is not declared. If it is not an extending
532 -- project, check for Default_Language
534 if Prj_Iter.Project.Extends = No_Project then
537 (Name_Default_Language,
538 Prj_Iter.Project.Decl.Attributes,
541 if Variable /= Nil_Variable_Value
542 and then not Variable.Default
544 Get_Name_String (Variable.Value);
545 To_Lower (Name_Buffer (1 .. Name_Len));
547 Language_Htable.Set (Lang, Lang);
550 -- If no language is declared, default to Ada
552 Language_Htable.Set (Name_Ada, Name_Ada);
556 elsif Variable.Values /= Nil_String then
558 -- Attribute Languages is declared with a non empty
559 -- list: put all the languages in Language_HTable.
561 List := Variable.Values;
562 while List /= Nil_String loop
563 Elem := Project_Tree.String_Elements.Table (List);
565 Get_Name_String (Elem.Value);
566 To_Lower (Name_Buffer (1 .. Name_Len));
568 Language_Htable.Set (Lang, Lang);
575 Prj_Iter := Prj_Iter.Next;
578 Name := Language_Htable.Get_First;
580 while Name /= No_Name loop
582 Name := Language_Htable.Get_Next;
585 Result := new String_List (1 .. Count);
588 Name := Language_Htable.Get_First;
589 while Name /= No_Name loop
590 -- Check if IDE'Compiler_Command is declared for the language.
591 -- If it is, use its value to invoke gprconfig.
596 Attribute_Or_Array_Name => Name_Compiler_Command,
598 In_Tree => Project_Tree,
599 Force_Lower_Case_Index => True);
602 Config_Command : constant String :=
603 "--config=" & Get_Name_String (Name);
605 Runtime_Name : constant String :=
606 Runtime_Name_For (Name);
609 if Variable = Nil_Variable_Value
610 or else Length_Of_Name (Variable.Value) = 0
613 new String'(Config_Command & ",," & Runtime_Name);
617 Compiler_Command : constant String :=
618 Get_Name_String (Variable.Value);
621 if Is_Absolute_Path (Compiler_Command) then
624 (Config_Command & ",," & Runtime_Name & "," &
625 Containing_Directory (Compiler_Command) & "," &
626 Simple_Name (Compiler_Command));
630 (Config_Command & ",," & Runtime_Name & ",," &
638 Name := Language_Htable.Get_Next;
642 end Get_Config_Switches;
648 procedure Do_Autoconf is
649 Obj_Dir : constant Variable_Value :=
652 Project.Decl.Attributes,
655 Gprconfig_Path : String_Access;
659 Gprconfig_Path := Locate_Exec_On_Path (Gprconfig_Name);
661 if Gprconfig_Path = null then
663 with "could not locate gprconfig for auto-configuration";
666 -- First, find the object directory of the user's project
668 if Obj_Dir = Nil_Variable_Value or else Obj_Dir.Default then
669 Get_Name_String (Project.Directory.Name);
672 if Is_Absolute_Path (Get_Name_String (Obj_Dir.Value)) then
673 Get_Name_String (Obj_Dir.Value);
677 Add_Str_To_Name_Buffer
678 (Get_Name_String (Project.Directory.Name));
679 Add_Char_To_Name_Buffer (Directory_Separator);
680 Add_Str_To_Name_Buffer (Get_Name_String (Obj_Dir.Value));
684 if Subdirs /= null then
685 Add_Char_To_Name_Buffer (Directory_Separator);
686 Add_Str_To_Name_Buffer (Subdirs.all);
689 for J in 1 .. Name_Len loop
690 if Name_Buffer (J) = '/' then
691 Name_Buffer (J) := Directory_Separator;
696 Obj_Dir : constant String := Name_Buffer (1 .. Name_Len);
697 Switches : Argument_List_Access := Get_Config_Switches;
698 Args : Argument_List (1 .. 5);
702 -- Check if the object directory exists. If Setup_Projects is True
703 -- (-p) and directory does not exist, attempt to create it.
704 -- Otherwise, if directory does not exist, fail without calling
707 if not Is_Directory (Obj_Dir)
708 and then (Setup_Projects or Subdirs /= null)
711 Create_Path (Obj_Dir);
713 if not Quiet_Output then
714 Write_Str ("object directory """);
716 Write_Line (""" created");
722 with "could not create object directory " & Obj_Dir;
726 if not Is_Directory (Obj_Dir) then
728 with "object directory " & Obj_Dir & " does not exist";
733 Args (1) := new String'("--batch");
734 Args (2) := new String'("-o");
736 -- If no config file was specified, set the auto.cgpr one
738 if Config_File_Name = "" then
739 Args (3) := new String'
740 (Obj_Dir & Directory_Separator & Auto_Cgpr);
742 Args (3) := new String'(Config_File_Name);
745 if Normalized_Hostname = "" then
748 if Target_Name = "" then
749 Args (4) := new String'("--target=" & Normalized_Hostname);
751 Args (4) := new String'("--target=" & Target_Name);
757 if not Verbose_Mode then
758 Arg_Last := Arg_Last + 1;
759 Args (Arg_Last) := new String'("-q");
763 Write_Str (Gprconfig_Name);
765 for J in 1 .. Arg_Last loop
767 Write_Str (Args (J).all);
770 for J in Switches'Range loop
772 Write_Str (Switches (J).all);
777 elsif not Quiet_Output then
778 Write_Str ("creating ");
779 Write_Str (Simple_Name (Args (3).all));
783 Spawn (Gprconfig_Path.all, Args (1 .. Arg_Last) & Switches.all,
788 Config_File_Path := Locate_Config_File (Args (3).all);
790 if Config_File_Path = null then
792 with "could not create " & Args (3).all;
795 for F in Args'Range loop
802 Config_Project_Node : Project_Node_Id := Empty_Node;
805 Free (Config_File_Path);
806 Config := No_Project;
808 if Config_File_Name /= "" then
809 Config_File_Path := Locate_Config_File (Config_File_Name);
811 Config_File_Path := Locate_Config_File (Default_File_Name);
814 if Config_File_Path = null then
815 if (not Allow_Automatic_Generation) and then
816 Config_File_Name /= ""
819 with "could not locate main configuration project "
824 Automatically_Generated :=
825 Allow_Automatic_Generation and then Config_File_Path = null;
827 <<Process_Config_File>>
829 if Automatically_Generated then
830 -- This might raise an Invalid_Config exception
834 -- Parse the configuration file
836 if Verbose_Mode and then Config_File_Path /= null then
837 Write_Str ("Checking configuration ");
838 Write_Line (Config_File_Path.all);
841 if Config_File_Path /= null then
843 (In_Tree => Project_Node_Tree,
844 Project => Config_Project_Node,
845 Project_File_Name => Config_File_Path.all,
846 Always_Errout_Finalize => False,
847 Packages_To_Check => Packages_To_Check,
848 Current_Directory => Current_Directory,
849 Is_Config_File => True);
851 -- Maybe the user will want to create his own configuration file
852 Config_Project_Node := Empty_Node;
855 if On_Load_Config /= null then
857 (Config_File => Config_Project_Node,
858 Project_Node_Tree => Project_Node_Tree);
861 if Config_Project_Node /= Empty_Node then
862 Prj.Proc.Process_Project_Tree_Phase_1
863 (In_Tree => Project_Tree,
866 From_Project_Node => Config_Project_Node,
867 From_Project_Node_Tree => Project_Node_Tree,
869 Reset_Tree => False);
872 if Config_Project_Node = Empty_Node
873 or else Config = No_Project
876 with "processing of configuration project """
877 & Config_File_Path.all & """ failed";
880 -- Check that the target of the configuration file is the one the user
881 -- specified on the command line. We do not need to check that when in
882 -- auto-conf mode, since the appropriate target was passed to gprconfig.
884 if not Automatically_Generated
886 (Config, Autoconf_Specified, Project_Tree, Target_Name)
888 Automatically_Generated := True;
889 goto Process_Config_File;
891 end Get_Or_Create_Configuration_File;
893 --------------------------------------
894 -- Process_Project_And_Apply_Config --
895 --------------------------------------
897 procedure Process_Project_And_Apply_Config
898 (Main_Project : out Prj.Project_Id;
899 User_Project_Node : Prj.Tree.Project_Node_Id;
900 Config_File_Name : String := "";
901 Autoconf_Specified : Boolean;
902 Project_Tree : Prj.Project_Tree_Ref;
903 Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
904 Packages_To_Check : String_List_Access;
905 Allow_Automatic_Generation : Boolean := True;
906 Automatically_Generated : out Boolean;
907 Config_File_Path : out String_Access;
908 Target_Name : String := "";
909 Normalized_Hostname : String;
910 Flags : Processing_Flags;
911 On_Load_Config : Config_File_Hook := null;
912 Reset_Tree : Boolean := True)
914 Main_Config_Project : Project_Id;
918 Main_Project := No_Project;
919 Automatically_Generated := False;
921 Process_Project_Tree_Phase_1
922 (In_Tree => Project_Tree,
923 Project => Main_Project,
925 From_Project_Node => User_Project_Node,
926 From_Project_Node_Tree => Project_Node_Tree,
928 Reset_Tree => Reset_Tree);
931 Main_Project := No_Project;
935 -- Find configuration file
937 Get_Or_Create_Configuration_File
938 (Config => Main_Config_Project,
939 Project => Main_Project,
940 Project_Tree => Project_Tree,
941 Project_Node_Tree => Project_Node_Tree,
942 Allow_Automatic_Generation => Allow_Automatic_Generation,
943 Config_File_Name => Config_File_Name,
944 Autoconf_Specified => Autoconf_Specified,
945 Target_Name => Target_Name,
946 Normalized_Hostname => Normalized_Hostname,
947 Packages_To_Check => Packages_To_Check,
948 Config_File_Path => Config_File_Path,
949 Automatically_Generated => Automatically_Generated,
951 On_Load_Config => On_Load_Config);
953 Apply_Config_File (Main_Config_Project, Project_Tree);
955 -- Finish processing the user's project
957 Prj.Proc.Process_Project_Tree_Phase_2
958 (In_Tree => Project_Tree,
959 Project => Main_Project,
961 From_Project_Node => User_Project_Node,
962 From_Project_Node_Tree => Project_Node_Tree,
966 Main_Project := No_Project;
968 end Process_Project_And_Apply_Config;
970 ------------------------------------
971 -- Parse_Project_And_Apply_Config --
972 ------------------------------------
974 procedure Parse_Project_And_Apply_Config
975 (Main_Project : out Prj.Project_Id;
976 User_Project_Node : out Prj.Tree.Project_Node_Id;
977 Config_File_Name : String := "";
978 Autoconf_Specified : Boolean;
979 Project_File_Name : String;
980 Project_Tree : Prj.Project_Tree_Ref;
981 Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
982 Packages_To_Check : String_List_Access;
983 Allow_Automatic_Generation : Boolean := True;
984 Automatically_Generated : out Boolean;
985 Config_File_Path : out String_Access;
986 Target_Name : String := "";
987 Normalized_Hostname : String;
988 Flags : Processing_Flags;
989 On_Load_Config : Config_File_Hook := null)
992 -- Parse the user project tree
994 Prj.Tree.Initialize (Project_Node_Tree);
995 Prj.Initialize (Project_Tree);
997 Main_Project := No_Project;
998 Automatically_Generated := False;
1001 (In_Tree => Project_Node_Tree,
1002 Project => User_Project_Node,
1003 Project_File_Name => Project_File_Name,
1004 Always_Errout_Finalize => False,
1005 Packages_To_Check => Packages_To_Check,
1006 Current_Directory => Current_Directory,
1007 Is_Config_File => False);
1009 if User_Project_Node = Empty_Node then
1010 User_Project_Node := Empty_Node;
1014 Process_Project_And_Apply_Config
1015 (Main_Project => Main_Project,
1016 User_Project_Node => User_Project_Node,
1017 Config_File_Name => Config_File_Name,
1018 Autoconf_Specified => Autoconf_Specified,
1019 Project_Tree => Project_Tree,
1020 Project_Node_Tree => Project_Node_Tree,
1021 Packages_To_Check => Packages_To_Check,
1022 Allow_Automatic_Generation => Allow_Automatic_Generation,
1023 Automatically_Generated => Automatically_Generated,
1024 Config_File_Path => Config_File_Path,
1025 Target_Name => Target_Name,
1026 Normalized_Hostname => Normalized_Hostname,
1028 On_Load_Config => On_Load_Config);
1029 end Parse_Project_And_Apply_Config;
1031 -----------------------
1032 -- Apply_Config_File --
1033 -----------------------
1035 procedure Apply_Config_File
1036 (Config_File : Prj.Project_Id;
1037 Project_Tree : Prj.Project_Tree_Ref)
1039 Conf_Decl : constant Declarations := Config_File.Decl;
1040 Conf_Pack_Id : Package_Id;
1041 Conf_Pack : Package_Element;
1043 User_Decl : Declarations;
1044 User_Pack_Id : Package_Id;
1045 User_Pack : Package_Element;
1046 Proj : Project_List;
1049 Proj := Project_Tree.Projects;
1050 while Proj /= null loop
1051 if Proj.Project /= Config_File then
1052 User_Decl := Proj.Project.Decl;
1054 (Project_Tree => Project_Tree,
1055 Conf_Decl => Conf_Decl,
1056 User_Decl => User_Decl);
1058 Conf_Pack_Id := Conf_Decl.Packages;
1059 while Conf_Pack_Id /= No_Package loop
1060 Conf_Pack := Project_Tree.Packages.Table (Conf_Pack_Id);
1062 User_Pack_Id := User_Decl.Packages;
1063 while User_Pack_Id /= No_Package loop
1064 User_Pack := Project_Tree.Packages.Table (User_Pack_Id);
1065 exit when User_Pack.Name = Conf_Pack.Name;
1066 User_Pack_Id := User_Pack.Next;
1069 if User_Pack_Id = No_Package then
1070 Package_Table.Increment_Last (Project_Tree.Packages);
1071 User_Pack := Conf_Pack;
1072 User_Pack.Next := User_Decl.Packages;
1073 User_Decl.Packages :=
1074 Package_Table.Last (Project_Tree.Packages);
1075 Project_Tree.Packages.Table (User_Decl.Packages) :=
1080 (Project_Tree => Project_Tree,
1081 Conf_Decl => Conf_Pack.Decl,
1082 User_Decl => Project_Tree.Packages.Table
1083 (User_Pack_Id).Decl);
1086 Conf_Pack_Id := Conf_Pack.Next;
1089 Proj.Project.Decl := User_Decl;
1094 end Apply_Config_File;
1096 ---------------------
1097 -- Set_Runtime_For --
1098 ---------------------
1100 procedure Set_Runtime_For (Language : Name_Id; RTS_Name : String) is
1102 Name_Len := RTS_Name'Length;
1103 Name_Buffer (1 .. Name_Len) := RTS_Name;
1104 RTS_Languages.Set (Language, Name_Find);
1105 end Set_Runtime_For;
1107 ----------------------
1108 -- Runtime_Name_For --
1109 ----------------------
1111 function Runtime_Name_For (Language : Name_Id) return String is
1113 if RTS_Languages.Get (Language) /= No_Name then
1114 return Get_Name_String (RTS_Languages.Get (Language));
1118 end Runtime_Name_For;
1120 ------------------------------------
1121 -- Add_Default_GNAT_Naming_Scheme --
1122 ------------------------------------
1124 procedure Add_Default_GNAT_Naming_Scheme
1125 (Config_File : in out Project_Node_Id;
1126 Project_Tree : Project_Node_Tree_Ref)
1128 procedure Create_Attribute
1131 Index : String := "";
1132 Pkg : Project_Node_Id := Empty_Node);
1134 ----------------------
1135 -- Create_Attribute --
1136 ----------------------
1138 procedure Create_Attribute
1141 Index : String := "";
1142 Pkg : Project_Node_Id := Empty_Node)
1144 Attr : Project_Node_Id;
1145 Val : Name_Id := No_Name;
1146 Parent : Project_Node_Id := Config_File;
1149 Name_Len := Index'Length;
1150 Name_Buffer (1 .. Name_Len) := Index;
1154 if Pkg /= Empty_Node then
1158 Attr := Create_Attribute
1159 (Tree => Project_Tree,
1160 Prj_Or_Pkg => Parent,
1163 Kind => Prj.Single);
1165 Name_Len := Value'Length;
1166 Name_Buffer (1 .. Name_Len) := Value;
1170 (Attr, Project_Tree,
1171 Enclose_In_Expression
1172 (Create_Literal_String (Val, Project_Tree),
1174 end Create_Attribute;
1177 Naming : Project_Node_Id;
1180 if Config_File = Empty_Node then
1182 -- Create a dummy config file is none was found
1184 Name_Len := Auto_Cgpr'Length;
1185 Name_Buffer (1 .. Name_Len) := Auto_Cgpr;
1190 (In_Tree => Project_Tree,
1191 Name => Name_Default,
1192 Full_Path => Path_Name_Type (Name),
1193 Is_Config_File => True);
1195 -- Setup library support
1197 case MLib.Tgt.Support_For_Libraries is
1202 Create_Attribute (Name_Library_Support, "static_only");
1205 Create_Attribute (Name_Library_Support, "full");
1208 if MLib.Tgt.Standalone_Library_Auto_Init_Is_Supported then
1209 Create_Attribute (Name_Library_Auto_Init_Supported, "true");
1211 Create_Attribute (Name_Library_Auto_Init_Supported, "false");
1214 -- Setup Ada support (Ada is the default language here, since this is
1215 -- only called when no config file existed initially, ie for
1218 Create_Attribute (Name_Default_Language, "ada");
1220 Naming := Create_Package (Project_Tree, Config_File, "naming");
1221 Create_Attribute (Name_Spec_Suffix, ".ads", "ada", Pkg => Naming);
1222 Create_Attribute (Name_Separate_Suffix, ".adb", "ada", Pkg => Naming);
1223 Create_Attribute (Name_Body_Suffix, ".adb", "ada", Pkg => Naming);
1224 Create_Attribute (Name_Dot_Replacement, "-", Pkg => Naming);
1225 Create_Attribute (Name_Casing, "lowercase", Pkg => Naming);
1227 if Current_Verbosity = High then
1228 Write_Line ("Automatically generated (in-memory) config file");
1230 (Project => Config_File,
1231 In_Tree => Project_Tree,
1232 Backward_Compatibility => False);
1236 end Add_Default_GNAT_Naming_Scheme;