Description: put PIC options late on the command line for libraries.
 This option is mandatory, and should override incompatible options
 like PIE.  A use case is described at
 https://lists.debian.org/debian-devel/2016/05/msg00302.html.
Author: Nicolas Boulenguez <nicolas@debian.org>

--- a/src/gprbuild-compile.adb
+++ b/src/gprbuild-compile.adb
@@ -2189,23 +2189,6 @@
             end loop;
          end if;
 
-         --  4) The PIC option if it exists, for shared and "static-pic"
-         --     libraries.
-
-         if Id.Project.Library
-           and then Id.Project.Library_Kind /= Static
-         then
-            List := Config.Compilation_PIC_Option;
-            while List /= No_Name_List loop
-               Nam_Nod := Project_Tree.Shared.Name_Lists.Table (List);
-               Add_Option_Internal_Codepeer
-                 (Value   => Get_Name_String (Nam_Nod.Name),
-                  To      => Compilation_Options,
-                  Display => True);
-               List := Nam_Nod.Next;
-            end loop;
-         end if;
-
          --  5) Compiler'Switches(<source file name>), if it is
          --  defined, otherwise Compiler'Switches (<language name>),
          --  if defined.
@@ -2234,6 +2217,23 @@
                   Display => True);
             end loop;
          end if;
+
+         --  4) The PIC option if it exists, for shared and "static-pic"
+         --     libraries.
+
+         if Id.Project.Library
+           and then Id.Project.Library_Kind /= Static
+         then
+            List := Config.Compilation_PIC_Option;
+            while List /= No_Name_List loop
+               Nam_Nod := Project_Tree.Shared.Name_Lists.Table (List);
+               Add_Option_Internal_Codepeer
+                 (Value   => Get_Name_String (Nam_Nod.Name),
+                  To      => Compilation_Options,
+                  Display => True);
+               List := Nam_Nod.Next;
+            end loop;
+         end if;
       end Set_Options_For_File;
 
       -------------------------
--- a/src/gprlib-build_shared_lib.adb
+++ b/src/gprlib-build_shared_lib.adb
@@ -111,12 +111,12 @@
       Arguments := String_Vectors.Empty_Vector;
       --  Argument_Length := Driver'Length;
 
-      --  The minimum arguments
-      Arguments.Append (Shared_Lib_Minimum_Options);
-
       --  The leading library options, if any
       Arguments.Append (Leading_Library_Options_Table);
 
+      --  The minimum arguments
+      Arguments.Append (Shared_Lib_Minimum_Options);
+
       --  -o <library file name>
 
       Arguments.Append (Out_Opt.all);
