summary refs log tree commit diff
path: root/pkgs/development/compilers
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2017-09-22 14:29:04 -0400
committerDomen Kožar <domen@dev.si>2017-12-25 16:36:46 +0000
commit150255e318ce9d945684baafa657fee436e649fd (patch)
tree2a54fd2ec3c27e1f46976f0af6f0d2ebc56492e8 /pkgs/development/compilers
parent26a46295eb4e47dff8997d2d97b50fe409535439 (diff)
downloadnixlib-150255e318ce9d945684baafa657fee436e649fd.tar
nixlib-150255e318ce9d945684baafa657fee436e649fd.tar.gz
nixlib-150255e318ce9d945684baafa657fee436e649fd.tar.bz2
nixlib-150255e318ce9d945684baafa657fee436e649fd.tar.lz
nixlib-150255e318ce9d945684baafa657fee436e649fd.tar.xz
nixlib-150255e318ce9d945684baafa657fee436e649fd.tar.zst
nixlib-150255e318ce9d945684baafa657fee436e649fd.zip
ghc binary: Fix interpreter than patch RPATH
The newer to-be-added binaries have relative RPATHs that we'll break if
we try to `patchelf` before installation. We instead us LD_LOAD_LIBRARY
during the installation, which avoids needing to change the RPATH
temporarily.
Diffstat (limited to 'pkgs/development/compilers')
-rw-r--r--pkgs/development/compilers/ghc/6.10.2-binary.nix17
-rw-r--r--pkgs/development/compilers/ghc/7.0.4-binary.nix65
-rw-r--r--pkgs/development/compilers/ghc/7.4.2-binary.nix67
3 files changed, 95 insertions, 54 deletions
diff --git a/pkgs/development/compilers/ghc/6.10.2-binary.nix b/pkgs/development/compilers/ghc/6.10.2-binary.nix
index 2030e0e5fc29..129bc8e89e85 100644
--- a/pkgs/development/compilers/ghc/6.10.2-binary.nix
+++ b/pkgs/development/compilers/ghc/6.10.2-binary.nix
@@ -24,6 +24,10 @@ stdenv.mkDerivation rec {
 
   nativeBuildInputs = [ perl ];
 
+  # Cannot patchelf beforehand due to relative RPATHs that anticipate
+  # the final install location/
+  LD_LIBRARY_PATH = stdenv.lib.makeLibraryPath [ libedit ncurses5 gmp ];
+
   postUnpack =
     # Strip is harmful, see also below. It's important that this happens
     # first. The GHC Cabal build system makes use of strip by default and
@@ -40,9 +44,9 @@ stdenv.mkDerivation rec {
     # On Linux, use patchelf to modify the executables so that they can
     # find editline/gmp.
     stdenv.lib.optionalString stdenv.hostPlatform.isLinux ''
-      find . -type f -perm -0100 \
-          -exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
-          --set-rpath "${stdenv.lib.makeLibraryPath [ libedit ncurses5 gmp ]}" {} \;
+      find . -type f -perm -0100 -exec patchelf \
+          --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" {} \;
+
       for prog in ld ar gcc strip ranlib; do
         find . -name "setup-config" -exec sed -i "s@/usr/bin/$prog@$(type -p $prog)@g" {} \;
       done
@@ -67,6 +71,13 @@ stdenv.mkDerivation rec {
     sed -i "s@^\(.*pkgName = PackageName \"rts\".*\libraryDirs = \\[\)\(.*\)@\\1\"${gmp.out}/lib\",\2@" $out/lib/ghc-${version}/package.conf
   '';
 
+  # On Linux, use patchelf to modify the executables so that they can
+  # find editline/gmp.
+  preFixup = stdenv.lib.optionalString stdenv.isLinux ''
+    find "$out" -type f -executable \
+        -exec patchelf  --set-rpath "${LD_LIBRARY_PATH}" {} \;
+  '';
+
   doInstallCheck = true;
   installCheckPhase = ''
     # Sanity check, can ghc create executables?
diff --git a/pkgs/development/compilers/ghc/7.0.4-binary.nix b/pkgs/development/compilers/ghc/7.0.4-binary.nix
index 918e649f8fe0..bb592a6cfe33 100644
--- a/pkgs/development/compilers/ghc/7.0.4-binary.nix
+++ b/pkgs/development/compilers/ghc/7.0.4-binary.nix
@@ -3,6 +3,16 @@
 , ncurses5, gmp, libiconv
 }:
 
+let
+  libPath = stdenv.lib.makeLibraryPath ([
+    ncurses5 gmp
+  ] ++ stdenv.lib.optional (stdenv.hostPlatform.isDarwin) libiconv);
+
+  libEnvVar = stdenv.lib.optionalString stdenv.hostPlatform.isDarwin "DY"
+    + "LD_LIBRARY_PATH";
+
+in
+
 stdenv.mkDerivation rec {
   version = "7.0.4";
 
@@ -30,6 +40,10 @@ stdenv.mkDerivation rec {
 
   nativeBuildInputs = [ perl ];
 
+  # Cannot patchelf beforehand due to relative RPATHs that anticipate
+  # the final install location/
+  ${libEnvVar} = libPath;
+
   postUnpack =
     # GHC has dtrace probes, which causes ld to try to open /usr/lib/libdtrace.dylib
     # during linking
@@ -57,34 +71,18 @@ stdenv.mkDerivation rec {
       find . -name base.buildinfo \
           -exec sed -i "s@extra-lib-dirs: @extra-lib-dirs: ${libiconv}/lib@" {} \;
     '' +
-    # On Linux, use patchelf to modify the executables so that they can
-    # find editline/gmp.
+    # Rename needed libraries and binaries, fix interpreter
     stdenv.lib.optionalString stdenv.isLinux ''
-      find . -type f -perm -0100 \
-          -exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
-          --set-rpath "${stdenv.lib.makeLibraryPath [ ncurses5 gmp ]}" {} \;
+      find . -type f -perm -0100 -exec patchelf \
+          --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" {} \;
+
+      paxmark m ./ghc-${version}/ghc/stage2/build/tmp/ghc-stage2
+
       sed -i "s|/usr/bin/perl|perl\x00        |" ghc-${version}/ghc/stage2/build/tmp/ghc-stage2
       sed -i "s|/usr/bin/gcc|gcc\x00        |" ghc-${version}/ghc/stage2/build/tmp/ghc-stage2
       for prog in ld ar gcc strip ranlib; do
         find . -name "setup-config" -exec sed -i "s@/usr/bin/$prog@$(type -p $prog)@g" {} \;
       done
-    '' + stdenv.lib.optionalString stdenv.isDarwin ''
-      # not enough room in the object files for the full path to libiconv :(
-      fix () {
-        install_name_tool -change /usr/lib/libiconv.2.dylib @executable_path/libiconv.dylib $1
-      }
-
-      ln -s ${libiconv}/lib/libiconv.dylib ghc-${version}/utils/ghc-pwd/dist/build/tmp
-      ln -s ${libiconv}/lib/libiconv.dylib ghc-${version}/utils/hpc/dist/build/tmp
-      ln -s ${libiconv}/lib/libiconv.dylib ghc-${version}/ghc/stage2/build/tmp
-
-      for file in ghc-cabal ghc-pwd ghc-stage2 ghc-pkg haddock hsc2hs hpc; do
-        fix $(find . -type f -name $file)
-      done
-
-      for file in $(find . -name setup-config); do
-        substituteInPlace $file --replace /usr/bin/ranlib "$(type -P ranlib)"
-      done
     '';
 
   configurePlatforms = [ ];
@@ -101,6 +99,29 @@ stdenv.mkDerivation rec {
   # calls install-strip ...
   dontBuild = true;
 
+  # On Linux, use patchelf to modify the executables so that they can
+  # find editline/gmp.
+  preFixup = stdenv.lib.optionalString stdenv.isLinux ''
+    find "$out" -type f -executable \
+        -exec patchelf --set-rpath "${libPath}" {} \;
+  '' + stdenv.lib.optionalString stdenv.isDarwin ''
+    # not enough room in the object files for the full path to libiconv :(
+    ln -s ${libiconv}/lib/libiconv.dylib $out/bin
+    ln -s ${libiconv}/lib/libiconv.dylib $out/lib/ghc-${version}/libiconv.dylib
+
+    fix () {
+      install_name_tool -change /usr/lib/libiconv.2.dylib @executable_path/libiconv.dylib $1
+    }
+
+    for file in ghc-cabal ghc-pwd ghc-stage2 ghc-pkg haddock hsc2hs hpc; do
+      fix $(find "$out" -type f -name $file)
+    done
+
+    for file in $(find "$out" -name setup-config); do
+      substituteInPlace $file --replace /usr/bin/ranlib "$(type -P ranlib)"
+    done
+  '';
+
   doInstallCheck = true;
   installCheckPhase = ''
     # Sanity check, can ghc create executables?
diff --git a/pkgs/development/compilers/ghc/7.4.2-binary.nix b/pkgs/development/compilers/ghc/7.4.2-binary.nix
index 4554d56d2742..65a3d2a7f730 100644
--- a/pkgs/development/compilers/ghc/7.4.2-binary.nix
+++ b/pkgs/development/compilers/ghc/7.4.2-binary.nix
@@ -1,8 +1,18 @@
 { stdenv
-, fetchurl, perl, makeWrapper
+, fetchurl, perl
 , ncurses5, gmp, libiconv
 }:
 
+let
+  libPath = stdenv.lib.makeLibraryPath ([
+    ncurses5 gmp
+  ] ++ stdenv.lib.optional (stdenv.hostPlatform.isDarwin) libiconv);
+
+  libEnvVar = stdenv.lib.optionalString stdenv.hostPlatform.isDarwin "DY"
+    + "LD_LIBRARY_PATH";
+
+in
+
 stdenv.mkDerivation rec {
   version = "7.4.2";
 
@@ -30,6 +40,10 @@ stdenv.mkDerivation rec {
 
   nativeBuildInputs = [ perl ];
 
+  # Cannot patchelf beforehand due to relative RPATHs that anticipate
+  # the final install location/
+  ${libEnvVar} = libPath;
+
   postUnpack =
     # GHC has dtrace probes, which causes ld to try to open /usr/lib/libdtrace.dylib
     # during linking
@@ -57,14 +71,11 @@ stdenv.mkDerivation rec {
       find . -name base.buildinfo \
           -exec sed -i "s@extra-lib-dirs: @extra-lib-dirs: ${libiconv}/lib@" {} \;
     '' +
-    # On Linux, use patchelf to modify the executables so that they can
-    # find editline/gmp.
+    # Rename needed libraries and binaries, fix interpreter
     stdenv.lib.optionalString stdenv.isLinux ''
-      mkdir -p "$out/lib"
-      ln -sv "${ncurses5.out}/lib/libncurses.so" "$out/lib/libncurses${stdenv.lib.optionalString stdenv.is64bit "w"}.so.5"
-      find . -type f -perm -0100 \
-          -exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
-          --set-rpath "${stdenv.lib.makeLibraryPath [ "$out" gmp ]}" {} \;
+      find . -type f -perm -0100 -exec patchelf \
+          --replace-needed libncurses${stdenv.lib.optionalString stdenv.is64bit "w"}.so.5 libncurses.so \
+          --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" {} \;
 
       paxmark m ./ghc-${version}/ghc/stage2/build/tmp/ghc-stage2
 
@@ -73,23 +84,6 @@ stdenv.mkDerivation rec {
       for prog in ld ar gcc strip ranlib; do
         find . -name "setup-config" -exec sed -i "s@/usr/bin/$prog@$(type -p $prog)@g" {} \;
       done
-    '' + stdenv.lib.optionalString stdenv.isDarwin ''
-      # not enough room in the object files for the full path to libiconv :(
-      fix () {
-        install_name_tool -change /usr/lib/libiconv.2.dylib @executable_path/libiconv.dylib $1
-      }
-
-      ln -s ${libiconv}/lib/libiconv.dylib ghc-${version}/utils/ghc-pwd/dist-install/build/tmp
-      ln -s ${libiconv}/lib/libiconv.dylib ghc-${version}/utils/hpc/dist-install/build/tmp
-      ln -s ${libiconv}/lib/libiconv.dylib ghc-${version}/ghc/stage2/build/tmp
-
-      for file in ghc-cabal ghc-pwd ghc-stage2 ghc-pkg haddock hsc2hs hpc; do
-        fix $(find . -type f -name $file)
-      done
-
-      for file in $(find . -name setup-config); do
-        substituteInPlace $file --replace /usr/bin/ranlib "$(type -P ranlib)"
-      done
     '';
 
   configurePlatforms = [ ];
@@ -106,12 +100,27 @@ stdenv.mkDerivation rec {
   # calls install-strip ...
   dontBuild = true;
 
-  preInstall = stdenv.lib.optionalString stdenv.isDarwin ''
-    mkdir -p $out/lib/ghc-${version}
-    mkdir -p $out/bin
+  # On Linux, use patchelf to modify the executables so that they can
+  # find editline/gmp.
+  preFixup = stdenv.lib.optionalString stdenv.isLinux ''
+    find "$out" -type f -executable \
+        -exec patchelf --set-rpath "${libPath}" {} \;
+  '' + stdenv.lib.optionalString stdenv.isDarwin ''
+    # not enough room in the object files for the full path to libiconv :(
     ln -s ${libiconv}/lib/libiconv.dylib $out/bin
     ln -s ${libiconv}/lib/libiconv.dylib $out/lib/ghc-${version}/libiconv.dylib
-    ln -s ${libiconv}/lib/libiconv.dylib utils/ghc-cabal/dist-install/build/tmp
+
+    fix () {
+      install_name_tool -change /usr/lib/libiconv.2.dylib @executable_path/libiconv.dylib $1
+    }
+
+    for file in ghc-cabal ghc-pwd ghc-stage2 ghc-pkg haddock hsc2hs hpc; do
+      fix $(find "$out" -type f -name $file)
+    done
+
+    for file in $(find "$out" -name setup-config); do
+      substituteInPlace $file --replace /usr/bin/ranlib "$(type -P ranlib)"
+    done
   '';
 
   doInstallCheck = true;