diff --git a/pkgs/development/compilers/gcc/10/default.nix b/pkgs/development/compilers/gcc/10/default.nix index 1502b09cca6..c265fff2215 100644 --- a/pkgs/development/compilers/gcc/10/default.nix +++ b/pkgs/development/compilers/gcc/10/default.nix @@ -186,8 +186,7 @@ stdenv.mkDerivation ({ dontDisableStatic = true; - # TODO(@Ericson2314): Always pass "--target" and always prefix. - configurePlatforms = [ "build" "host" ] ++ lib.optional (targetPlatform != hostPlatform) "target"; + configurePlatforms = [ "build" "host" "target" ]; configureFlags = import ../common/configure-flags.nix { inherit diff --git a/pkgs/development/compilers/gcc/4.8/default.nix b/pkgs/development/compilers/gcc/4.8/default.nix index 6a2121a8298..957c85cfde5 100644 --- a/pkgs/development/compilers/gcc/4.8/default.nix +++ b/pkgs/development/compilers/gcc/4.8/default.nix @@ -196,8 +196,7 @@ stdenv.mkDerivation ({ dontDisableStatic = true; - # TODO(@Ericson2314): Always pass "--target" and always prefix. - configurePlatforms = [ "build" "host" ] ++ lib.optional (targetPlatform != hostPlatform) "target"; + configurePlatforms = [ "build" "host" "target" ]; configureFlags = import ../common/configure-flags.nix { inherit diff --git a/pkgs/development/compilers/gcc/4.9/default.nix b/pkgs/development/compilers/gcc/4.9/default.nix index 709288559d1..5d30f80edb2 100644 --- a/pkgs/development/compilers/gcc/4.9/default.nix +++ b/pkgs/development/compilers/gcc/4.9/default.nix @@ -209,8 +209,7 @@ stdenv.mkDerivation ({ dontDisableStatic = true; - # TODO(@Ericson2314): Always pass "--target" and always prefix. - configurePlatforms = [ "build" "host" ] ++ lib.optional (targetPlatform != hostPlatform) "target"; + configurePlatforms = [ "build" "host" "target" ]; configureFlags = import ../common/configure-flags.nix { inherit diff --git a/pkgs/development/compilers/gcc/6/default.nix b/pkgs/development/compilers/gcc/6/default.nix index 93c9dde61fc..0ac54e093b4 100644 --- a/pkgs/development/compilers/gcc/6/default.nix +++ b/pkgs/development/compilers/gcc/6/default.nix @@ -232,8 +232,7 @@ stdenv.mkDerivation ({ dontDisableStatic = true; - # TODO(@Ericson2314): Always pass "--target" and always prefix. - configurePlatforms = [ "build" "host" ] ++ lib.optional (targetPlatform != hostPlatform) "target"; + configurePlatforms = [ "build" "host" "target" ]; configureFlags = import ../common/configure-flags.nix { inherit diff --git a/pkgs/development/compilers/gcc/7/default.nix b/pkgs/development/compilers/gcc/7/default.nix index d9b4c639b5a..233d022514e 100644 --- a/pkgs/development/compilers/gcc/7/default.nix +++ b/pkgs/development/compilers/gcc/7/default.nix @@ -197,8 +197,7 @@ stdenv.mkDerivation ({ dontDisableStatic = true; - # TODO(@Ericson2314): Always pass "--target" and always prefix. - configurePlatforms = [ "build" "host" ] ++ lib.optional (targetPlatform != hostPlatform) "target"; + configurePlatforms = [ "build" "host" "target" ]; configureFlags = import ../common/configure-flags.nix { inherit diff --git a/pkgs/development/compilers/gcc/8/default.nix b/pkgs/development/compilers/gcc/8/default.nix index 6ecf462d54d..4e57e43437f 100644 --- a/pkgs/development/compilers/gcc/8/default.nix +++ b/pkgs/development/compilers/gcc/8/default.nix @@ -182,8 +182,7 @@ stdenv.mkDerivation ({ dontDisableStatic = true; - # TODO(@Ericson2314): Always pass "--target" and always prefix. - configurePlatforms = [ "build" "host" ] ++ lib.optional (targetPlatform != hostPlatform) "target"; + configurePlatforms = [ "build" "host" "target" ]; configureFlags = import ../common/configure-flags.nix { inherit diff --git a/pkgs/development/compilers/gcc/9/default.nix b/pkgs/development/compilers/gcc/9/default.nix index 7f35f5c7bb9..92810ecffaf 100644 --- a/pkgs/development/compilers/gcc/9/default.nix +++ b/pkgs/development/compilers/gcc/9/default.nix @@ -199,8 +199,7 @@ stdenv.mkDerivation ({ dontDisableStatic = true; - # TODO(@Ericson2314): Always pass "--target" and always prefix. - configurePlatforms = [ "build" "host" ] ++ lib.optional (targetPlatform != hostPlatform) "target"; + configurePlatforms = [ "build" "host" "target" ]; configureFlags = import ../common/configure-flags.nix { inherit diff --git a/pkgs/development/compilers/gcc/common/configure-flags.nix b/pkgs/development/compilers/gcc/common/configure-flags.nix index fc4fbb34c50..4cf06cd4107 100644 --- a/pkgs/development/compilers/gcc/common/configure-flags.nix +++ b/pkgs/development/compilers/gcc/common/configure-flags.nix @@ -44,6 +44,9 @@ let crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; crossDarwin = targetPlatform != hostPlatform && targetPlatform.libc == "libSystem"; + targetPrefix = lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) + "${stdenv.targetPlatform.config}-"; + crossConfigureFlags = # Ensure that -print-prog-name is able to find the correct programs. [ @@ -112,6 +115,18 @@ let # Basic configuration ++ [ + # Force target prefix. The behavior if `--target` and `--host` + # are specified is inconsistent: Sometimes specifying `--target` + # always causes a prefix to be generated, sometimes it's only + # added if the `--host` and `--target` differ. This means that + # sometimes there may be a prefix even though nixpkgs doesn't + # expect one and sometimes there may be none even though nixpkgs + # expects one (since not all information is serialized into the + # config attribute). The easiest way out of these problems is to + # always set the program prefix, so gcc will conform to our + # expectations. + "--program-prefix=${targetPrefix}" + (lib.enableFeature enableLTO "lto") "--disable-libstdcxx-pch" "--without-included-gettext"