Blame SOURCES/gcc44-rh801144.patch

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