From c6b526495bc37e63b43c3fc17705cefac81fa904 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Llu=C3=ADs=20Batlle=20i=20Rossell?=
 <viric@vicerveza.homeunix.net>
Date: Mon, 23 Nov 2009 17:06:57 +0000
Subject: [PATCH] Improving the crossStripping. A cross-glibc gets broken if
 stripped by the native strip. So we now distinguish dontStrip and
 dontCrossStrip. I updated the expressions for glibc-2.9 and glibc-2.11
 accordingly. I could get rid of the cross-glibc depending on the
 cross-gcc-stage-static.

Enabling nls in the final cross-gcc.

I still have problems on wint_t/wchar_t not working on cross build. Gettext
does not build.


svn path=/nixpkgs/branches/stdenv-updates/; revision=18562
---
 pkgs/build-support/gcc-cross-wrapper/setup-hook.sh | 5 ++++-
 pkgs/development/compilers/gcc-4.3/default.nix     | 3 ++-
 pkgs/development/libraries/glibc-2.11/default.nix  | 2 ++
 pkgs/development/libraries/glibc-2.9/builder.sh    | 3 +++
 pkgs/development/libraries/glibc-2.9/default.nix   | 8 ++++----
 5 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/pkgs/build-support/gcc-cross-wrapper/setup-hook.sh b/pkgs/build-support/gcc-cross-wrapper/setup-hook.sh
index e0b520edb4a2..0c98062a2db1 100644
--- a/pkgs/build-support/gcc-cross-wrapper/setup-hook.sh
+++ b/pkgs/build-support/gcc-cross-wrapper/setup-hook.sh
@@ -27,14 +27,17 @@ crossStripDirs() {
 
     if test -n "${dirs}"; then
         header "stripping (with flags $stripFlags) in $dirs"
+        # libc_nonshared.a should never be stripped, or builds will break.
         find $dirs -type f -print0 | xargs -0 ${xargsFlags:--r} $crossConfig-strip $stripFlags || true
         stopNest
     fi
 }
 
 crossStrip () {
+    # In cross_renaming we may rename dontCrossStrip to dontStrip, and
+    # dontStrip to dontNativeStrip.
     # TODO: strip _only_ ELF executables, and return || fail here...
-    if test -z "$dontStrip"; then
+    if test -z "$dontCrossStrip"; then
         stripDebugList=${stripDebugList:-lib lib64 libexec bin sbin}
         if test -n "$stripDebugList"; then
             crossStripDirs "$stripDebugList" "${stripDebugFlags:--S}"
diff --git a/pkgs/development/compilers/gcc-4.3/default.nix b/pkgs/development/compilers/gcc-4.3/default.nix
index efd058756b33..2fd4198d9554 100644
--- a/pkgs/development/compilers/gcc-4.3/default.nix
+++ b/pkgs/development/compilers/gcc-4.3/default.nix
@@ -39,7 +39,8 @@ let
       " --with-headers=${glibcCross}/include" +
       " --enable-__cxa_atexit" +
       " --enable-long-long" +
-      " --enable-threads=posix"
+      " --enable-threads=posix" +
+      " --enable-nls"
       );
   stageNameAddon = if (crossStageStatic) then "-stage-static" else
     "-stage-final";
diff --git a/pkgs/development/libraries/glibc-2.11/default.nix b/pkgs/development/libraries/glibc-2.11/default.nix
index befcd86b8ba7..48f1a12c058a 100644
--- a/pkgs/development/libraries/glibc-2.11/default.nix
+++ b/pkgs/development/libraries/glibc-2.11/default.nix
@@ -44,6 +44,8 @@ EOF
         export CC="$crossConfig-gcc"
         export AR="$crossConfig-ar"
         export RANLIB="$crossConfig-ranlib"
+
+        dontStrip = 1
       '';
    }
    else {}))
diff --git a/pkgs/development/libraries/glibc-2.9/builder.sh b/pkgs/development/libraries/glibc-2.9/builder.sh
index 0d67d96edecc..c81a3ac2a9e9 100644
--- a/pkgs/development/libraries/glibc-2.9/builder.sh
+++ b/pkgs/development/libraries/glibc-2.9/builder.sh
@@ -48,6 +48,9 @@ EOF
         export AR="${crossConfig}-ar"
         export RANLIB="${crossConfig}-ranlib"
         configureFlags="${configureFlags} --cache-file=config.cache"
+
+        # Disable the native stripping, because it breaks libc_nonshared.a
+        dontStrip=1
     fi
 }
 
diff --git a/pkgs/development/libraries/glibc-2.9/default.nix b/pkgs/development/libraries/glibc-2.9/default.nix
index 50dc51bdcb71..0cfad2990383 100644
--- a/pkgs/development/libraries/glibc-2.9/default.nix
+++ b/pkgs/development/libraries/glibc-2.9/default.nix
@@ -80,14 +80,14 @@ stdenv.mkDerivation rec {
 
   buildNativeInputs = stdenv.lib.optionals (cross != null) [ gccCross ];
 
-  preInstall = ''
+  preInstall = if (cross != null) then ''
     ensureDir $out/lib
     ln -s ${stdenv.gcc.gcc}/lib/libgcc_s.so.1 $out/lib/libgcc_s.so.1
-  '';
+  '' else "";
 
-  postInstall = ''
+  postInstall = if (cross != null) then ''
     rm $out/lib/libgcc_s.so.1
-  '';
+  '' else "";
 
   # Workaround for this bug:
   #   http://sourceware.org/bugzilla/show_bug.cgi?id=411