Blame SOURCES/gcc44-rh801144.patch

dc1507
2009-09-07  Laurent GUERBY  <laurent@guerby.net>
dc1507
        
dc1507
	* make.adb: Add missing documentation for multilib handling.
dc1507
dc1507
2009-08-17  Robert Dewar  <dewar@adacore.com>
dc1507
        
dc1507
	* make.adb: Add ??? comment
dc1507
dc1507
2009-08-17  Arnaud Charlet  <charlet@adacore.com>
dc1507
        
dc1507
	* make.adb (Process_Multilib, Scan_Make_Arg): Refine previous change
dc1507
	and ignore -mieee switch to avoid spawning an extra gcc in this case.
dc1507
dc1507
2009-08-10  Laurent GUERBY  <laurent@guerby.net>
dc1507
dc1507
	* make.adb: Handle multilib
dc1507
dc1507
--- gcc/ada/make.adb	(revision 150622,150828,150830,151472)
dc1507
+++ gcc/ada/make.adb	(revision 150623,150829,150831,151473)
dc1507
@@ -195,6 +195,9 @@ package body Make is
dc1507
    RTS_Specified : String_Access := null;
dc1507
    --  Used to detect multiple --RTS= switches
dc1507
 
dc1507
+   N_M_Switch : Natural := 0;
dc1507
+   --  Used to count -mxxx switches that can affect multilib
dc1507
+
dc1507
    type Q_Record is record
dc1507
       File  : File_Name_Type;
dc1507
       Unit  : Unit_Name_Type;
dc1507
@@ -666,6 +669,9 @@ package body Make is
dc1507
    --  directory of the ultimate extending project. If it is not, we ignore
dc1507
    --  the fact that this ALI file is read-only.
dc1507
 
dc1507
+   procedure Process_Multilib;
dc1507
+   --  Add appropriate --RTS argument to handle multilib.
dc1507
+
dc1507
    ----------------------------------------------------
dc1507
    -- Compiler, Binder & Linker Data and Subprograms --
dc1507
    ----------------------------------------------------
dc1507
@@ -6854,6 +6860,7 @@ package body Make is
dc1507
       Dependencies.Init;
dc1507
 
dc1507
       RTS_Specified := null;
dc1507
+      N_M_Switch := 0;
dc1507
 
dc1507
       Mains.Delete;
dc1507
 
dc1507
@@ -6913,6 +6920,10 @@ package body Make is
dc1507
          Scan_Make_Arg (Argument (Next_Arg), And_Save => True);
dc1507
       end loop Scan_Args;
dc1507
 
dc1507
+      if N_M_Switch > 0 and RTS_Specified = null then
dc1507
+         Process_Multilib;
dc1507
+      end if;
dc1507
+
dc1507
       if Commands_To_Stdout then
dc1507
          Set_Standard_Output;
dc1507
       end if;
dc1507
@@ -7587,6 +7598,117 @@ package body Make is
dc1507
       Set_Name_Table_Byte (N, B or Mark);
dc1507
    end Mark_Directory;
dc1507
 
dc1507
+   ----------------------
dc1507
+   -- Process_Multilib --
dc1507
+   ----------------------
dc1507
+
dc1507
+   procedure Process_Multilib is
dc1507
+
dc1507
+      Output_FD         : File_Descriptor;
dc1507
+      Output_Name       : String_Access;
dc1507
+      Arg_Index         : Natural := 0;
dc1507
+      Success           : Boolean := False;
dc1507
+      Return_Code       : Integer := 0;
dc1507
+      Multilib_Gcc_Path : String_Access;
dc1507
+      Multilib_Gcc      : String_Access;
dc1507
+      N_Read            : Integer := 0;
dc1507
+      Line              : String (1 .. 1000);
dc1507
+      Args              : Argument_List (1 .. N_M_Switch + 1);
dc1507
+
dc1507
+   begin
dc1507
+      pragma Assert (N_M_Switch > 0 and RTS_Specified = null);
dc1507
+
dc1507
+      --  In case we detected a multilib switch and the user has not
dc1507
+      --  manually specified a specific RTS we emulate the following command:
dc1507
+      --  gnatmake $FLAGS --RTS=$(gcc -print-multi-directory $FLAGS)
dc1507
+
dc1507
+      --  First select the flags which might have an impact on multilib
dc1507
+      --  processing. Note that this is an heuristic selection and it
dc1507
+      --  will need to be maintained over time. The condition has to
dc1507
+      --  be kept synchronized with N_M_Switch counting in Scan_Make_Arg.
dc1507
+
dc1507
+      for Next_Arg in 1 .. Argument_Count loop
dc1507
+         declare
dc1507
+            Argv : constant String := Argument (Next_Arg);
dc1507
+         begin
dc1507
+            if Argv'Length > 2
dc1507
+              and then Argv (1) = '-'
dc1507
+              and then Argv (2) = 'm'
dc1507
+              and then Argv /= "-margs"
dc1507
+
dc1507
+              --  Ignore -mieee to avoid spawning an extra gcc in this case
dc1507
+
dc1507
+              and then Argv /= "-mieee"
dc1507
+            then
dc1507
+               Arg_Index := Arg_Index + 1;
dc1507
+               Args (Arg_Index) := new String'(Argv);
dc1507
+            end if;
dc1507
+
dc1507
+         end;
dc1507
+      end loop;
dc1507
+
dc1507
+      pragma Assert (Arg_Index = N_M_Switch);
dc1507
+
dc1507
+      Args (Args'Last) := new String'("-print-multi-directory");
dc1507
+
dc1507
+      --  Call the GCC driver with the collected flags and save its
dc1507
+      --  output. Alternate design would be to link in gnatmake the
dc1507
+      --  relevant part of the GCC driver.
dc1507
+
dc1507
+      if Saved_Gcc /= null then
dc1507
+         Multilib_Gcc := Saved_Gcc;
dc1507
+      else
dc1507
+         Multilib_Gcc := Gcc;
dc1507
+      end if;
dc1507
+
dc1507
+      Multilib_Gcc_Path :=
dc1507
+        GNAT.OS_Lib.Locate_Exec_On_Path (Multilib_Gcc.all);
dc1507
+
dc1507
+      Create_Temp_File (Output_FD, Output_Name);
dc1507
+      if Output_FD = Invalid_FD then
dc1507
+         return;
dc1507
+      end if;
dc1507
+
dc1507
+      GNAT.OS_Lib.Spawn (Multilib_Gcc_Path.all, Args, Output_FD,
dc1507
+                         Return_Code, False);
dc1507
+      Close (Output_FD);
dc1507
+      if Return_Code /= 0 then
dc1507
+         return;
dc1507
+      end if;
dc1507
+
dc1507
+      --  Parse the GCC driver output which is a single line, removing CR/LF
dc1507
+
dc1507
+      Output_FD := Open_Read (Output_Name.all, Binary);
dc1507
+      if Output_FD = Invalid_FD then
dc1507
+         return;
dc1507
+      end if;
dc1507
+
dc1507
+      N_Read := Read (Output_FD, Line (1)'Address, Line'Length);
dc1507
+      Close (Output_FD);
dc1507
+      Delete_File (Output_Name.all, Success);
dc1507
+
dc1507
+      for I in reverse 1 .. N_Read loop
dc1507
+         if Line (I) = ASCII.CR or else Line (I) = ASCII.LF then
dc1507
+            N_Read := N_Read - 1;
dc1507
+         else
dc1507
+            exit;
dc1507
+         end if;
dc1507
+      end loop;
dc1507
+
dc1507
+      --  In case the standard RTS is selected do nothing
dc1507
+
dc1507
+      if N_Read = 0 or else Line (1 .. N_Read) = "." then
dc1507
+         return;
dc1507
+      end if;
dc1507
+
dc1507
+      --  Otherwise add -margs --RTS=output
dc1507
+
dc1507
+      Scan_Make_Arg ("-margs", And_Save => True);
dc1507
+      Scan_Make_Arg ("--RTS=" & Line (1 .. N_Read),
dc1507
+                     And_Save => True);
dc1507
+
dc1507
+   end Process_Multilib;
dc1507
+
dc1507
    -----------------------------
dc1507
    -- Recursive_Compute_Depth --
dc1507
    -----------------------------
dc1507
@@ -8043,6 +8165,15 @@ package body Make is
dc1507
             Add_Switch (Argv, Compiler, And_Save => And_Save);
dc1507
             Add_Switch (Argv, Linker, And_Save => And_Save);
dc1507
 
dc1507
+            --  The following condition has to be kept synchronized with
dc1507
+            --  the Process_Multilib one.
dc1507
+
dc1507
+            if Argv (2) = 'm'
dc1507
+              and then Argv /= "-mieee"
dc1507
+            then
dc1507
+               N_M_Switch := N_M_Switch + 1;
dc1507
+            end if;
dc1507
+
dc1507
          --  -C=<mapping file>
dc1507
 
dc1507
          elsif Argv'Last > 2 and then Argv (2) = 'C' then