about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohn Ericson <Ericson2314@Yahoo.com>2017-04-24 16:00:11 -0400
committerJohn Ericson <Ericson2314@Yahoo.com>2017-05-17 15:33:05 -0400
commit88ea6463a342c2084266395b210d57b1218bad62 (patch)
treec67e3794ebf3475c5de05aed7de65a45bf2a685c
parentbfa8f3049989739223687324aec986d4da3b5dae (diff)
binutils on darwin: Clean up the rats nest
 - No more *Cross duplication for binutils on darwin either.
   `cctools_cross` is merged into plain `cctools`, so `buildPackages`
   chains alone are used to disambiguate.

 - Always use a mashup of cctools and actual GNU Binutils as `binutils`.
   Previously, this was only done in the native case as nobody had
   bothered to implement the masher in the cross case. Implemented it
   basically consisted of extending the wrapper to deal with prefixed
   binaries.
-rw-r--r--pkgs/development/tools/misc/binutils/default.nix3
-rw-r--r--pkgs/os-specific/darwin/binutils/default.nix22
-rw-r--r--pkgs/os-specific/darwin/cctools/port.nix68
-rw-r--r--pkgs/top-level/all-packages.nix15
4 files changed, 68 insertions, 40 deletions
diff --git a/pkgs/development/tools/misc/binutils/default.nix b/pkgs/development/tools/misc/binutils/default.nix
index b0819f6133b62..37c312c6c6b29 100644
--- a/pkgs/development/tools/misc/binutils/default.nix
+++ b/pkgs/development/tools/misc/binutils/default.nix
@@ -40,6 +40,7 @@ stdenv.mkDerivation rec {
     ./no-plugins.patch
   ];
 
+  # TODO: all outputs on all platform
   outputs = [ "out" ]
     ++ optional (cross == null && !stdenv.isDarwin) "lib" # problems in Darwin stdenv
     ++ [ "info" ]
@@ -75,7 +76,7 @@ stdenv.mkDerivation rec {
   configureFlags =
     [ "--enable-shared" "--enable-deterministic-archives" "--disable-werror" ]
     ++ optional (stdenv.system == "mips64el-linux") "--enable-fix-loongson2f-nop"
-    ++ optional (cross != null) "--target=${cross.config}"
+    ++ optional (cross != null) "--target=${cross.config}" # TODO: make this unconditional
     ++ optionals gold [ "--enable-gold" "--enable-plugins" ]
     ++ optional (stdenv.system == "i686-linux") "--enable-targets=x86_64-linux-gnu";
 
diff --git a/pkgs/os-specific/darwin/binutils/default.nix b/pkgs/os-specific/darwin/binutils/default.nix
index c4ccdb94b8123..bde42e45e9c23 100644
--- a/pkgs/os-specific/darwin/binutils/default.nix
+++ b/pkgs/os-specific/darwin/binutils/default.nix
@@ -1,11 +1,25 @@
-{ stdenv, binutils-raw, cctools }:
+{ stdenv, binutils-raw, cctools
+, hostPlatform, targetPlatform
+}:
 
+let
+  prefix = stdenv.lib.optionalString
+    (targetPlatform != hostPlatform)
+    "${targetPlatform.config}-";
+
+  cmds = [
+    "ar" "ranlib" "as" "dsymutil" "install_name_tool"
+    "ld" "strip" "otool" "lipo" "nm" "strings" "size"
+  ];
+in
+
+# TODO loop over prefixed binaries too
 stdenv.mkDerivation {
   name = "cctools-binutils-darwin";
   buildCommand = ''
     mkdir -p $out/bin $out/include
 
-    ln -s ${binutils-raw.out}/bin/c++filt $out/bin/c++filt
+    ln -s ${binutils-raw.out}/bin/${prefix}c++filt $out/bin/${prefix}c++filt
 
     # We specifically need:
     # - ld: binutils doesn't provide it on darwin
@@ -18,11 +32,11 @@ stdenv.mkDerivation {
     # - strip: the binutils one seems to break mach-o files
     # - lipo: gcc build assumes it exists
     # - nm: the gnu one doesn't understand many new load commands
-    for i in ar ranlib as dsymutil install_name_tool ld strip otool lipo nm strings size; do
+    for i in ${stdenv.lib.concatStringsSep " " (builtins.map (e: prefix + e) cmds)}; do
       ln -sf "${cctools}/bin/$i" "$out/bin/$i"
     done
 
-    for i in ${binutils-raw.dev}/include/*.h; do
+    for i in ${binutils-raw.dev or binutils-raw.out}/include/*.h; do
       ln -s "$i" "$out/include/$(basename $i)"
     done
 
diff --git a/pkgs/os-specific/darwin/cctools/port.nix b/pkgs/os-specific/darwin/cctools/port.nix
index 0154d395216ff..204a4789bcc33 100644
--- a/pkgs/os-specific/darwin/cctools/port.nix
+++ b/pkgs/os-specific/darwin/cctools/port.nix
@@ -1,9 +1,23 @@
-{ stdenv, fetchFromGitHub, autoconf, automake, libtool_2
+{ stdenv, fetchFromGitHub, makeWrapper, autoconf, automake, libtool_2
 , llvm, libcxx, libcxxabi, clang, libuuid
-, libobjc ? null
+, libobjc ? null, maloader ? null, xctoolchain ? null
+, buildPlatform, hostPlatform, targetPlatform
 }:
 
 let
+  inherit (stdenv.lib.systems.parse) isDarwin;
+
+  prefix = stdenv.lib.optionalString
+    (targetPlatform != hostPlatform)
+    "${targetPlatform.config}-";
+in
+
+assert isDarwin targetPlatform.parsed;
+
+# Non-Darwin alternatives
+assert (!isDarwin hostPlatform.parsed) -> (maloader != null && xctoolchain != null);
+
+let
   baseParams = rec {
     name = "cctools-port-${version}";
     version = "895";
@@ -26,7 +40,14 @@ let
 
     enableParallelBuilding = true;
 
-    configureFlags = stdenv.lib.optionals (!stdenv.isDarwin) [ "CXXFLAGS=-I${libcxx}/include/c++/v1" ];
+    configureFlags = stdenv.lib.optionals (!stdenv.isDarwin) [
+      "CXXFLAGS=-I${libcxx}/include/c++/v1"
+    ] ++ stdenv.lib.optionals (targetPlatform != buildPlatform) [
+      # TODO make unconditional next hash break
+      "--build=${buildPlatform.config}"
+      "--host=${hostPlatform.config}"
+      "--target=${targetPlatform.config}"
+    ];
 
     postPatch = ''
       sed -i -e 's/addStandardLibraryDirectories = true/addStandardLibraryDirectories = false/' cctools/ld64/src/ld/Options.cpp
@@ -69,33 +90,26 @@ let
       popd
     '';
 
+    postInstall =
+      if isDarwin hostPlatform.parsed
+      then ''
+        cat >$out/bin/dsymutil << EOF
+        #!${stdenv.shell}
+        EOF
+        chmod +x $out/bin/dsymutil
+      ''
+      else ''
+        for tool in dyldinfo dwarfdump dsymutil; do
+          ${makeWrapper}/bin/makeWrapper "${maloader}/bin/ld-mac" "$out/bin/${targetPlatform.config}-$tool" \
+            --add-flags "${xctoolchain}/bin/$tool"
+          ln -s "$out/bin/${targetPlatform.config}-$tool" "$out/bin/$tool"
+        done
+      '';
+
     meta = {
       homepage = "http://www.opensource.apple.com/source/cctools/";
       description = "Mac OS X Compiler Tools (cross-platform port)";
       license = stdenv.lib.licenses.apsl20;
     };
   };
-in {
-  native = stdenv.mkDerivation (baseParams // {
-    # A hack for now...
-    postInstall = ''
-      cat >$out/bin/dsymutil << EOF
-      #!${stdenv.shell}
-      EOF
-      chmod +x $out/bin/dsymutil
-    '';
-  });
-
-  cross =
-    { cross, maloader, makeWrapper, xctoolchain}: stdenv.mkDerivation (baseParams // {
-      configureFlags = baseParams.configureFlags ++ [ "--target=${cross.config}" ];
-
-      postInstall = ''
-        for tool in dyldinfo dwarfdump dsymutil; do
-          ${makeWrapper}/bin/makeWrapper "${maloader}/bin/ld-mac" "$out/bin/${cross.config}-$tool" \
-            --add-flags "${xctoolchain}/bin/$tool"
-          ln -s "$out/bin/${cross.config}-$tool" "$out/bin/$tool"
-        done
-      '';
-    });
-}
+in stdenv.mkDerivation baseParams
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 1abdf7d2d0c9d..d2a171a732df2 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -6396,7 +6396,10 @@ with pkgs;
 
   bin_replace_string = callPackage ../development/tools/misc/bin_replace_string { };
 
-  binutils = if stdenv.isDarwin then darwin.binutils else binutils-raw;
+  binutils =
+    if lib.systems.parse.isDarwin targetPlatform.parsed
+    then darwin.binutils
+    else binutils-raw;
 
   binutils-raw = callPackage ../development/tools/misc/binutils {
     # FHS sys dirs presumably only have stuff for the build platform
@@ -11444,17 +11447,13 @@ with pkgs;
   darwin = let
     apple-source-releases = callPackage ../os-specific/darwin/apple-source-releases { };
   in apple-source-releases // rec {
-    cctools_cross = callPackage (forcedNativePackages.callPackage ../os-specific/darwin/cctools/port.nix {}).cross {
-      cross = assert targetPlatform != buildPlatform; targetPlatform;
+    cctools = callPackage ../os-specific/darwin/cctools/port.nix {
+      inherit libobjc;
+      stdenv = if stdenv.isDarwin then stdenv else libcxxStdenv;
       inherit maloader;
       xctoolchain = xcode.toolchain;
     };
 
-    cctools = (callPackage ../os-specific/darwin/cctools/port.nix {
-      inherit libobjc;
-      stdenv = if stdenv.isDarwin then stdenv else libcxxStdenv;
-    }).native;
-
     cf-private = callPackage ../os-specific/darwin/cf-private {
       inherit (apple-source-releases) CF;
       inherit osx_private_sdk;