[Ada] gnatmake with --subdirs= but no -P

Message ID 20110803105035.GA15879@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Aug. 3, 2011, 10:50 a.m.
When gnatmake is invoked with --subdirs= but not with -P, the specified
subdirectory will now be created, if it does exist, and it will be used
as the object directory as if -D had been used.
The test for this is to invoke gnatmake as such:
   gnatmake --subdirs=toto main.adb
The subdirectory toto should be created and should contain ALI and object

Tested on x86_64-pc-linux-gnu, committed on trunk

2011-08-03  Vincent Celier  <celier@adacore.com>

	* make.adb (Initialize): If --subdirs= is used, but no project file is
	specified, attempt to create the specify subdir if it does not already
	exist and use it as the object directory as if -D had been specified.


Index: make.adb
--- make.adb	(revision 177264)
+++ make.adb	(working copy)
@@ -61,17 +61,18 @@ 
 with Switch;   use Switch;
 with Switch.M; use Switch.M;
+with Table;
 with Targparm; use Targparm;
-with Table;
 with Tempdir;
 with Types;    use Types;
+with Ada.Command_Line;          use Ada.Command_Line;
+with Ada.Directories;
 with Ada.Exceptions;            use Ada.Exceptions;
-with Ada.Command_Line;          use Ada.Command_Line;
+with GNAT.Case_Util;            use GNAT.Case_Util;
 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
 with GNAT.Dynamic_HTables;      use GNAT.Dynamic_HTables;
-with GNAT.Case_Util;            use GNAT.Case_Util;
 with GNAT.OS_Lib;               use GNAT.OS_Lib;
 package body Make is
@@ -5898,6 +5899,10 @@ 
                     (Main_Project, Project_Tree, Use_Include_Path_File);
+                  --  (Project => Main_Project,
+                  --   In_Tree => Project_Tree,
+                  --   Including_Libraries => True,
+                  --   Include_Path => Use_Include_Path_File);
                   --  If switch -C was specified, create a binder mapping file
@@ -6729,6 +6734,38 @@ 
          Make_Failed ("-i and -D cannot be used simultaneously");
       end if;
+      --  If --subdirs= is specified, but not -P, this is equivalent to -D,
+      --  except that the directory is created if it does not exist.
+      if Prj.Subdirs /= null and then Project_File_Name = null then
+         if Object_Directory_Path /= null then
+            Make_Failed ("--subdirs and -D cannot be used simultaneously");
+         elsif In_Place_Mode then
+            Make_Failed ("--subdirs and -i cannot be used simultaneously");
+         else
+            if not Is_Directory (Prj.Subdirs.all) then
+               begin
+                  Ada.Directories.Create_Path (Prj.Subdirs.all);
+               exception
+                  when others =>
+                     Make_Failed ("unable to create object directory " &
+                                  Prj.Subdirs.all);
+               end;
+            end if;
+            Object_Directory_Present := True;
+            declare
+               Argv : constant String (1 .. Prj.Subdirs'Length) :=
+                        Prj.Subdirs.all;
+            begin
+               Scan_Make_Arg (Env, Argv, And_Save => False);
+            end;
+         end if;
+      end if;
       --  Deal with -C= switch
       if Gnatmake_Mapping_File /= null then