From 30074ddfeac5e165eea32b33829bc2bf4185aace Mon Sep 17 00:00:00 2001
From: Tuomas Tynkkynen <tuomas@tuxera.com>
Date: Sat, 24 Dec 2016 22:27:52 +0200
Subject: [PATCH] coreutils: Fix cross build

`make install` was failing presumably due to an upstream cross-compilation bug:

Makefile:3440: *** Recursive variable 'INSTALL' references itself (eventually).  Stop.

While at it, remove the old ugly cross buildPhase. It was seemingly
trying to work around the fact that the man pages are generated by
piping each command's --help output to help2man. That obviously doesn't
work while cross-compiling.

Instead, set PERL=missing in the environment to make the build system
think there's no perl available to run help2man. (This approach was
stolen from buildroot.)
---
 pkgs/tools/misc/coreutils/default.nix | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/pkgs/tools/misc/coreutils/default.nix b/pkgs/tools/misc/coreutils/default.nix
index ec6be06ede3..8b39e3711e1 100644
--- a/pkgs/tools/misc/coreutils/default.nix
+++ b/pkgs/tools/misc/coreutils/default.nix
@@ -54,13 +54,13 @@ let
         ++ optional (stdenv.ccCross.libc ? libiconv)
           stdenv.ccCross.libc.libiconv.crossDrv;
 
-      buildPhase = ''
-        make || (
-          pushd man
-          for a in *.x; do
-            touch `basename $a .x`.1
-          done
-          popd; make )
+      # Prevents attempts of running 'help2man' on cross-built binaries.
+      PERL = "missing";
+
+      # Works around a bug with 8.26:
+      # Makefile:3440: *** Recursive variable 'INSTALL' references itself (eventually).  Stop.
+      preInstall = ''
+        sed -i Makefile -e 's|^INSTALL =.*|INSTALL = ${self}/bin/install -c|'
       '';
 
       postInstall = ''