summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/applications/editors/ed/default.nix4
-rw-r--r--pkgs/applications/editors/vim/default.nix15
-rw-r--r--pkgs/applications/misc/simgrid/default.nix59
-rw-r--r--pkgs/applications/networking/browsers/elinks/default.nix10
-rw-r--r--pkgs/applications/networking/browsers/lynx/default.nix1
-rw-r--r--pkgs/applications/networking/browsers/rekonq/source.nix28
-rw-r--r--pkgs/applications/science/math/yacas/default.nix21
-rw-r--r--pkgs/applications/version-management/fossil/default.nix4
-rw-r--r--pkgs/applications/video/MPlayer/default.nix31
-rw-r--r--pkgs/build-support/fetchurl/mirrors.nix5
-rw-r--r--pkgs/build-support/gcc-cross-wrapper/builder.sh31
-rw-r--r--pkgs/build-support/gcc-cross-wrapper/default.nix20
-rw-r--r--pkgs/build-support/gcc-cross-wrapper/gcc-wrapper.sh16
-rw-r--r--pkgs/build-support/gcc-cross-wrapper/setup-hook.sh6
-rw-r--r--pkgs/build-support/gcc-wrapper/default.nix1
-rw-r--r--pkgs/build-support/gcc-wrapper/default2.nix72
-rw-r--r--pkgs/build-support/gcc-wrapper/ld-wrapper.sh30
-rw-r--r--pkgs/build-support/gcc-wrapper/ld-wrapper2.sh154
-rw-r--r--pkgs/desktops/kde-4.4/support/phonon/phonon-4.4.1-gst-plugins-include.patch263
-rw-r--r--pkgs/development/compilers/gcc-4.4/builder.sh35
-rw-r--r--pkgs/development/compilers/gcc-4.4/default.nix48
-rw-r--r--pkgs/development/compilers/gcc-4.5/builder.sh72
-rw-r--r--pkgs/development/compilers/gcc-4.5/default.nix71
-rw-r--r--pkgs/development/compilers/gcc-4.5/dragonegg-2.7.patch46
-rw-r--r--pkgs/development/compilers/gcc-4.5/softfp-hurd.patch32
-rw-r--r--pkgs/development/compilers/gcc-4.5/sources.nix14
-rw-r--r--pkgs/development/interpreters/guile/cpp-4.5.patch24
-rw-r--r--pkgs/development/interpreters/guile/default.nix4
-rw-r--r--pkgs/development/libraries/SDL/default.nix25
-rw-r--r--pkgs/development/libraries/acl/default.nix20
-rw-r--r--pkgs/development/libraries/attr/default.nix14
-rw-r--r--pkgs/development/libraries/cloog-ppl/default.nix24
-rw-r--r--pkgs/development/libraries/cyrus-sasl/default.nix3
-rw-r--r--pkgs/development/libraries/gdbm/default.nix7
-rw-r--r--pkgs/development/libraries/gettext/0.18.nix66
-rw-r--r--pkgs/development/libraries/gettext/default.nix14
-rw-r--r--pkgs/development/libraries/glib/2.24.x.nix3
-rw-r--r--pkgs/development/libraries/glibc-2.11/builder.sh20
-rw-r--r--pkgs/development/libraries/glibc-2.11/builder2.sh58
-rw-r--r--pkgs/development/libraries/glibc-2.11/common.nix26
-rw-r--r--pkgs/development/libraries/glibc-2.11/default.nix10
-rw-r--r--pkgs/development/libraries/glibc-2.11/gnu89-inline.patch26
-rw-r--r--pkgs/development/libraries/glibc-2.11/locale-override.patch72
-rw-r--r--pkgs/development/libraries/glibc-2.11/nix-locale-archive.patch122
-rw-r--r--pkgs/development/libraries/glibc-2.11/nss-skip-unavail.patch42
-rw-r--r--pkgs/development/libraries/gmp/4.nix59
-rw-r--r--pkgs/development/libraries/gmp/default.nix46
-rw-r--r--pkgs/development/libraries/libgcrypt/default.nix4
-rw-r--r--pkgs/development/libraries/libxcrypt/default.nix3
-rw-r--r--pkgs/development/libraries/mesa/default.nix2
-rw-r--r--pkgs/development/libraries/mpfr/default.nix2
-rw-r--r--pkgs/development/libraries/mpfr/patch01.patch184
-rw-r--r--pkgs/development/libraries/mpfr/patch02.patch75
-rw-r--r--pkgs/development/libraries/openssl/1.x.nix45
-rw-r--r--pkgs/development/libraries/openssl/darwin-arch-1.patch16
-rw-r--r--pkgs/development/libraries/openssl/darwin-arch.patch44
-rw-r--r--pkgs/development/libraries/openssl/default.nix9
-rw-r--r--pkgs/development/libraries/pcre/default.nix10
-rw-r--r--pkgs/development/libraries/ppl/default.nix16
-rw-r--r--pkgs/development/tools/misc/binutils/as-pr10856.patch83
-rw-r--r--pkgs/development/tools/misc/binutils/default.nix6
-rw-r--r--pkgs/development/tools/misc/binutils/snapshot.nix59
-rw-r--r--pkgs/development/tools/misc/cscope/default.nix8
-rw-r--r--pkgs/development/tools/misc/gnum4/default.nix6
-rw-r--r--pkgs/development/tools/misc/patchelf/0.6.nix4
-rw-r--r--pkgs/games/prboom/default.nix20
-rw-r--r--pkgs/games/scummvm/default.nix12
-rw-r--r--pkgs/lib/platforms.nix3
-rw-r--r--pkgs/misc/busybox/default.nix62
-rw-r--r--pkgs/misc/uboot/nanonote.nix58
-rw-r--r--pkgs/os-specific/linux/alsa-lib/default.nix6
-rw-r--r--pkgs/os-specific/linux/kbd/default.nix15
-rw-r--r--pkgs/os-specific/linux/kernel-headers/2.6.28.nix1
-rw-r--r--pkgs/os-specific/linux/kernel-headers/2.6.32.nix1
-rw-r--r--pkgs/os-specific/linux/kernel/builder.sh143
-rw-r--r--pkgs/os-specific/linux/kernel/generic.nix6
-rw-r--r--pkgs/os-specific/linux/kernel/linux-nanonote-jz-2.6.34.nix241
-rw-r--r--pkgs/os-specific/linux/kernel/linux-nanonote-jz-2.6.35.nix241
-rw-r--r--pkgs/os-specific/linux/klibc/default.nix35
-rw-r--r--pkgs/os-specific/linux/lvm2/default.nix2
-rw-r--r--pkgs/os-specific/linux/pam/default.nix4
-rw-r--r--pkgs/os-specific/linux/uclibc/default.nix13
-rw-r--r--pkgs/os-specific/linux/util-linux-ng/default.nix6
-rw-r--r--pkgs/stdenv/adapters.nix4
-rw-r--r--pkgs/stdenv/default.nix1
-rw-r--r--pkgs/stdenv/generic/default.nix3
-rw-r--r--pkgs/stdenv/generic/setup.sh3
-rwxr-xr-xpkgs/stdenv/linux/bootstrap/loongson2f/bzip2bin0 -> 146364 bytes
-rwxr-xr-xpkgs/stdenv/linux/bootstrap/loongson2f/cpiobin0 -> 88564 bytes
-rwxr-xr-xpkgs/stdenv/linux/bootstrap/loongson2f/curl.bz2bin0 -> 172614 bytes
-rw-r--r--pkgs/stdenv/linux/bootstrap/loongson2f/default.nix13
-rwxr-xr-xpkgs/stdenv/linux/bootstrap/loongson2f/lnbin0 -> 59552 bytes
-rwxr-xr-xpkgs/stdenv/linux/bootstrap/loongson2f/mkdirbin0 -> 59548 bytes
-rwxr-xr-xpkgs/stdenv/linux/bootstrap/loongson2f/shbin0 -> 155016 bytes
-rw-r--r--pkgs/stdenv/linux/default.nix18
-rw-r--r--pkgs/stdenv/linux/make-bootstrap-tools.nix2
-rw-r--r--pkgs/stdenv/linux/scripts/unpack-bootstrap-tools.sh38
-rw-r--r--pkgs/tools/archivers/gnutar/default.nix13
-rw-r--r--pkgs/tools/archivers/gnutar/implausible.patch20
-rw-r--r--pkgs/tools/compression/bzip2/default.nix10
-rw-r--r--pkgs/tools/misc/coreutils/default.nix31
-rw-r--r--pkgs/tools/misc/findutils/default.nix11
-rw-r--r--pkgs/tools/package-management/nix/0001-Added-support-for-passing-an-impure-NIX_BUILD_CORES-.patch126
-rw-r--r--pkgs/tools/text/diffutils/default.nix8
-rw-r--r--pkgs/tools/text/gnugrep/default.nix8
-rw-r--r--pkgs/tools/text/gnugrep/malloc.patch15
-rw-r--r--pkgs/tools/text/gnupatch/default.nix8
-rw-r--r--pkgs/tools/text/gnused/default.nix16
-rw-r--r--pkgs/tools/text/gnused/gettext-fix.patch32
-rw-r--r--pkgs/tools/text/replace/default.nix4
-rw-r--r--pkgs/top-level/all-packages.nix124
-rw-r--r--pkgs/top-level/platforms.nix53
-rw-r--r--pkgs/top-level/release-lib.nix4
113 files changed, 2752 insertions, 1032 deletions
diff --git a/pkgs/applications/editors/ed/default.nix b/pkgs/applications/editors/ed/default.nix
index 9f26c0a2886..905cde880ed 100644
--- a/pkgs/applications/editors/ed/default.nix
+++ b/pkgs/applications/editors/ed/default.nix
@@ -10,6 +10,10 @@ stdenv.mkDerivation rec {
 
   doCheck = true;
 
+  crossAttrs = {
+    compileFlags = [ "CC=${stdenv.cross.config}-gcc" ];
+  };
+
   meta = {
     description = "GNU ed, an implementation of the standard Unix editor";
 
diff --git a/pkgs/applications/editors/vim/default.nix b/pkgs/applications/editors/vim/default.nix
index 6f6a592a02d..65811a3dc8f 100644
--- a/pkgs/applications/editors/vim/default.nix
+++ b/pkgs/applications/editors/vim/default.nix
@@ -11,6 +11,21 @@ stdenv.mkDerivation rec {
   buildInputs = [ ncurses ];
 
   postInstall = "ln -s $out/bin/vim $out/bin/vi";
+
+  crossAttrs = {
+    configureFlags = [
+      "vim_cv_toupper_broken=no"
+      "--with-tlib=ncurses"
+      "vim_cv_terminfo=yes"
+      "vim_cv_tty_group=tty"
+      "vim_cv_tty_mode=0660"
+      "vim_cv_getcwd_broken=no"
+      "vim_cv_stat_ignores_slash=yes"
+      "ac_cv_sizeof_int=4"
+      "vim_cv_memmove_handles_overlap=yes"
+      "STRIP=${stdenv.cross.config}-strip"
+    ];
+  };
   
   meta = {
     description = "The most popular clone of the VI editor";
diff --git a/pkgs/applications/misc/simgrid/default.nix b/pkgs/applications/misc/simgrid/default.nix
new file mode 100644
index 00000000000..45b93dab830
--- /dev/null
+++ b/pkgs/applications/misc/simgrid/default.nix
@@ -0,0 +1,59 @@
+{ fetchurl, stdenv, cmake, ruby }:
+
+stdenv.mkDerivation rec {
+  name = "simgrid-3.4.1";
+
+  src = fetchurl {
+    url = "https://gforge.inria.fr/frs/download.php/26944/${name}.tar.bz2";
+    sha256 = "acd2bb2c1abf59e9b190279b1c38582b7c1edd4b6ef4c6a9b01100740f1a6b28";
+  };
+
+  /* FIXME: Ruby currently disabled because of this:
+
+     Linking C shared library ../src/.libs/libsimgrid.so
+     ld: cannot find -lruby-1.8.7-p72
+
+   */
+  buildInputs = [ cmake /* ruby */ ];
+
+  preConfigure =
+    # Make it so that libsimgrid.so will be found when running programs from
+    # the build dir.
+    '' export LD_LIBRARY_PATH="$PWD/src/.libs"
+       export cmakeFlags="-Dprefix=$out"
+    '';
+
+  makeFlags = "VERBOSE=1";
+
+  patchPhase =
+    '' for i in "src/smpi/"*
+       do
+         sed -i "$i" -e's|/bin/bash|/bin/sh|g'
+       done
+    '';
+
+  installPhase = "make install-simgrid";
+
+  # Fixing the few tests that fail is left as an exercise to the reader.
+  doCheck = false;
+
+  meta = {
+    description = "SimGrid, a simulator for distributed applications in heterogeneous environments";
+
+    longDescription =
+      '' SimGrid is a toolkit that provides core functionalities for the
+         simulation of distributed applications in heterogeneous distributed
+         environments.  The specific goal of the project is to facilitate
+         research in the area of distributed and parallel application
+         scheduling on distributed computing platforms ranging from simple
+         network of workstations to Computational Grids.
+      '';
+
+    homepage = http://simgrid.gforge.inria.fr/;
+
+    license = "LGPLv2+";
+
+    maintainers = [ stdenv.lib.maintainers.ludo ];
+    platforms = stdenv.lib.platforms.gnu;  # arbitrary choice
+  };
+}
diff --git a/pkgs/applications/networking/browsers/elinks/default.nix b/pkgs/applications/networking/browsers/elinks/default.nix
index 9fb59fcdb86..e06bfe538c0 100644
--- a/pkgs/applications/networking/browsers/elinks/default.nix
+++ b/pkgs/applications/networking/browsers/elinks/default.nix
@@ -18,6 +18,16 @@ stdenv.mkDerivation rec {
       --enable-nntp --with-openssl=${openssl}
     '';
 
+  crossAttrs = {
+    propagatedBuildInputs = [ ncurses.hostDrv zlib.hostDrv openssl.hostDrv ];
+    configureFlags = ''
+      --enable-finger --enable-html-highlight
+      --enable-gopher --enable-cgi --enable-bittorrent --enable-nntp
+      --with-openssl=${openssl.hostDrv}
+      --with-bzip2=${bzip2.hostDrv}
+    '';
+  };
+
   meta = {
     description = "Full-featured text-mode web browser";
     homepage = http://elinks.or.cz;
diff --git a/pkgs/applications/networking/browsers/lynx/default.nix b/pkgs/applications/networking/browsers/lynx/default.nix
index c9da94258c8..97d28dd7e2f 100644
--- a/pkgs/applications/networking/browsers/lynx/default.nix
+++ b/pkgs/applications/networking/browsers/lynx/default.nix
@@ -15,6 +15,7 @@ stdenv.mkDerivation {
   configureFlags = if sslSupport then "--with-ssl" else "";
   
   buildInputs = [ ncurses ] ++ stdenv.lib.optional sslSupport openssl;
+  buildNativeInputs = [ ncurses ];
 
   meta = {
     homepage = http://lynx.isc.org/;
diff --git a/pkgs/applications/networking/browsers/rekonq/source.nix b/pkgs/applications/networking/browsers/rekonq/source.nix
new file mode 100644
index 00000000000..5faeddaaf2a
--- /dev/null
+++ b/pkgs/applications/networking/browsers/rekonq/source.nix
@@ -0,0 +1,28 @@
+{ fetchurl, fetchgit }:
+
+builtins.listToAttrs
+[
+  {
+    name = "0.4.90";
+    value = rec {
+      name = "rekonq-0.4.90";
+      src = fetchurl {
+        url = "http://kde-apps.org/CONTENT/content-files/94258-${name}.tar.bz2";
+        name = "${name}.tar.bz2";
+        sha256 = "1dmdx54asv0b4xzc8p5nadn92l8pks9cl1y9j8a46lsslwsjw3ws";
+      };
+    };
+  }
+
+  {
+    name = "scm";
+    value = {
+      name = "rekonq-0.4.0-20100514";
+      src = fetchgit {
+        url = git://gitorious.org/rekonq/mainline.git;
+        rev = "6b4f4d69a3c599bc958ccddc5f7ac1c8648a7042";
+        sha256 = "1qcwf7rsrnsbnq62cl44r48bmavc2nysi2wqhy1jxmj2ndwvsxy1";
+      };
+    };
+  }
+]
diff --git a/pkgs/applications/science/math/yacas/default.nix b/pkgs/applications/science/math/yacas/default.nix
index 148e95acee0..7b97e1a82c0 100644
--- a/pkgs/applications/science/math/yacas/default.nix
+++ b/pkgs/applications/science/math/yacas/default.nix
@@ -9,10 +9,29 @@ stdenv.mkDerivation rec {
   };
 
   # Perl is only for the documentation
-  buildInputs = [ perl ];
+  buildNativeInputs = [ perl ];
 
   patches = [ ./gcc43.patch ];
 
+  crossAttrs = {
+    # Trick to get host-built programs needed for the cross-build.
+    # If yacas had proper makefiles, this would not be needed.
+    preConfigure = ''
+      ./configure
+      pushd src
+      make mkfastprimes 
+      cp mkfastprimes ../..
+      popd
+      pushd manmake
+      make manripper removeduplicates
+      cp manripper removeduplicates ../..
+      popd
+    '';
+    preBuild = ''
+      cp ../mkfastprimes ../manripper ../removeduplicates src
+    '';
+  };
+
   meta = { 
       description = "Easy to use, general purpose Computer Algebra System";
       homepage = http://yacas.sourceforge.net/;
diff --git a/pkgs/applications/version-management/fossil/default.nix b/pkgs/applications/version-management/fossil/default.nix
index b9f6ec941b4..e9334db2ee2 100644
--- a/pkgs/applications/version-management/fossil/default.nix
+++ b/pkgs/applications/version-management/fossil/default.nix
@@ -19,6 +19,10 @@ stdenv.mkDerivation {
     INSTALLDIR=$out/bin make install
   '';
 
+  crossAttrs = {
+    makeFlagsArray = [ "TCC=${stdenv.cross.config}-gcc" ];
+  };
+
   meta = {
     description = "Simple, high-reliability, distributed software configuration management.";
     longDescription = ''
diff --git a/pkgs/applications/video/MPlayer/default.nix b/pkgs/applications/video/MPlayer/default.nix
index e2c25c3360c..e65ba86200b 100644
--- a/pkgs/applications/video/MPlayer/default.nix
+++ b/pkgs/applications/video/MPlayer/default.nix
@@ -1,10 +1,11 @@
 { alsaSupport ? false, xvSupport ? true, theoraSupport ? false, cacaSupport ? false
 , xineramaSupport ? false, randrSupport ? false, dvdnavSupport ? true
 , stdenv, fetchurl, x11, freetype, fontconfig, zlib
-, alsa ? null, libX11, libXv ? null, libtheora ? null, libcaca ? null
+, alsa ? null, libXv ? null, libtheora ? null, libcaca ? null
 , libXinerama ? null, libXrandr ? null, libdvdnav ? null
 , cdparanoia ? null, cddaSupport ? true
 , amrnb ? null, amrwb ? null, amrSupport ? false
+, x11Support ? true, libX11 ? null
 , jackaudioSupport ? false, jackaudio ? null
 , x264Support ? false, x264 ? null
 , xvidSupport ? false, xvidcore ? null
@@ -13,11 +14,12 @@
 }:
 
 assert alsaSupport -> alsa != null;
-assert xvSupport -> libXv != null;
+assert x11Support -> libX11 != null;
+assert xvSupport -> (libXv != null && x11Support);
 assert theoraSupport -> libtheora != null;
 assert cacaSupport -> libcaca != null;
-assert xineramaSupport -> libXinerama != null;
-assert randrSupport -> libXrandr != null;
+assert xineramaSupport -> (libXinerama != null && x11Support);
+assert randrSupport -> (libXrandr != null && x11Support);
 assert dvdnavSupport -> libdvdnav != null;
 assert cddaSupport -> cdparanoia != null;
 assert jackaudioSupport -> jackaudio != null;
@@ -54,7 +56,8 @@ stdenv.mkDerivation {
   };
 
   buildInputs =
-    [ x11 libXv freetype zlib mesa pkgconfig yasm ]
+    [ freetype zlib pkgconfig ]
+    ++ stdenv.lib.optional x11Support [ libX11 mesa ]
     ++ stdenv.lib.optional alsaSupport alsa
     ++ stdenv.lib.optional xvSupport libXv
     ++ stdenv.lib.optional theoraSupport libtheora
@@ -69,18 +72,32 @@ stdenv.mkDerivation {
     ++ stdenv.lib.optional xvidSupport xvidcore
     ++ stdenv.lib.optional lameSupport lame;
 
+  buildNativeInputs = [ yasm ];
+
   configureFlags = ''
     ${if cacaSupport then "--enable-caca" else "--disable-caca"}
     ${if dvdnavSupport then "--enable-dvdnav --enable-dvdread --disable-dvdread-internal" else ""}
     ${if x264Support then "--enable-x264 --extra-libs=-lx264" else ""}
     --codecsdir=${codecs}
     --enable-runtime-cpudetection
-    --enable-x11
+    ${if x11Support then "--enable-x11" else ""}
     --disable-xanim
     --disable-ivtv
   '';
 
-  NIX_LDFLAGS = "-lX11 -lXext";
+  NIX_LDFLAGS = if x11Support then "-lX11 -lXext" else "";
+
+  crossAttrs = {
+    preConfigure = ''
+      configureFlags="`echo $configureFlags |
+        sed -e 's/--build[^ ]\+//' \
+        -e 's/--host[^ ]\+//' \
+        -e 's/--codecsdir[^ ]\+//' \
+        -e 's/--enable-runtime-cpudetection//' `"
+      configureFlags="$configureFlags --target=${stdenv.cross.arch}-linux
+        --cc=$crossConfig-gcc --as=$crossConfig-as"
+    '';
+  };
 
   meta = {
     description = "A movie player that supports many video formats";
diff --git a/pkgs/build-support/fetchurl/mirrors.nix b/pkgs/build-support/fetchurl/mirrors.nix
index cd53f0d0d55..c27b8967e80 100644
--- a/pkgs/build-support/fetchurl/mirrors.nix
+++ b/pkgs/build-support/fetchurl/mirrors.nix
@@ -122,14 +122,9 @@ rec {
     http://ftp.cc.uoc.gr/mirrors/nongnu.org/
     http://ftp.twaren.net/Unix/NonGNU/
     http://mirror.csclub.uwaterloo.ca/nongnu/
-    http://mirror.publicns.net/pub/nongnu/
     http://nongnu.askapache.com/
-    http://nongnu.bigsearcher.com/
     http://savannah.c3sl.ufpr.br/
     http://www.centervenus.com/mirrors/nongnu/
-    http://www.de-mirrors.de/nongnu/
-    http://www.very-clever.com/download/nongnu/
-    http://www.wikifusion.info/nongnu/
   ];
 
   # BitlBee mirrors, see http://www.bitlbee.org/main.php/mirrors.html .
diff --git a/pkgs/build-support/gcc-cross-wrapper/builder.sh b/pkgs/build-support/gcc-cross-wrapper/builder.sh
index 674c2b89b52..fae37342940 100644
--- a/pkgs/build-support/gcc-cross-wrapper/builder.sh
+++ b/pkgs/build-support/gcc-cross-wrapper/builder.sh
@@ -1,34 +1,51 @@
 source $stdenv/setup
 
+mkdir $out
+mkdir $out/bin
+mkdir $out/nix-support
 
 # Force gcc to use ld-wrapper.sh when calling ld.
 cflagsCompile="-B$out/bin/"
 
 if test -z "$nativeLibc"; then
-    cflagsCompile="$cflagsCompile -B$libc/lib/ -isystem $libc/include"
+    cflagsCompile="$cflagsCompile -B$gccLibs/lib -B$libc/lib/ -isystem $libc/include"
     ldflags="$ldflags -L$libc/lib"
     # Get the proper dynamic linker for glibc and uclibc. 
     dlinker=`eval 'echo $libc/lib/ld*.so.?'`
     if [ -n "$dlinker" ]; then
       ldflagsBefore="-dynamic-linker $dlinker"
+
+      # The same as above, but put into files, useful for the gcc builder.
+      echo $dlinker > $out/nix-support/dynamic-linker
+      # This trick is to avoid dependencies on the cross-toolchain gcc
+      # for libgcc, libstdc++, ...
+      # -L is for libtool's .la files, and -rpath for the usual fixupPhase
+      # shrinking rpaths.
+      if [ -n "$gccLibs" ]; then
+        ldflagsBefore="$ldflagsBefore -rpath $gccLibs/lib"
+      fi
     fi
+
+    echo "$cflagsCompile -B$libc/lib/ -idirafter $libc/include -idirafter $gcc/lib/gcc/*/*/include-fixed" > $out/nix-support/libc-cflags
+
+    echo "-L$libc/lib" > $out/nix-support/libc-ldflags
+
+    # The dynamic linker is passed in `ldflagsBefore' to allow
+    # explicit overrides of the dynamic linker by callers to gcc/ld
+    # (the *last* value counts, so ours should come first).
+    echo "$ldflagsBefore" > $out/nix-support/libc-ldflags-before
 fi
 
 if test -n "$nativeTools"; then
     gccPath="$nativePrefix/bin"
     ldPath="$nativePrefix/bin"
 else
-    ldflags="$ldflags -L$gcc/lib"
+    ldflags="$ldflags -L$gcc/lib -L$gcc/lib64"
     gccPath="$gcc/bin"
     ldPath="$binutils/$crossConfig/bin"
 fi
 
 
-mkdir $out
-mkdir $out/bin
-mkdir $out/nix-support
-
-
 doSubstitute() {
     local src=$1
     local dst=$2
diff --git a/pkgs/build-support/gcc-cross-wrapper/default.nix b/pkgs/build-support/gcc-cross-wrapper/default.nix
index 362e378273d..8bf820e3d34 100644
--- a/pkgs/build-support/gcc-cross-wrapper/default.nix
+++ b/pkgs/build-support/gcc-cross-wrapper/default.nix
@@ -13,6 +13,23 @@ assert nativeTools -> nativePrefix != "";
 assert !nativeTools -> gcc != null && binutils != null;
 assert !noLibc -> (!nativeLibc -> libc != null);
 
+let
+  chosenName = if name == "" then gcc.name else name;
+  gccLibs = stdenv.mkDerivation {
+    name = chosenName + "-libs";
+    phases = [ "installPhase" ];
+    installPhase = ''
+      echo $out
+      ensureDir $out
+      cp -Rd ${gcc}/${cross.config}/lib $out/lib
+      chmod -R +w $out/lib
+      for a in $out/lib/*.la; do
+          sed -i -e s,${gcc}/${cross.config}/lib,$out/lib,g $a
+      done
+      rm -f $out/lib/*.py
+    '';
+  };
+in
 stdenv.mkDerivation {
   builder = ./builder.sh;
   setupHook = ./setup-hook.sh;
@@ -22,7 +39,8 @@ stdenv.mkDerivation {
   addFlags = ./add-flags;
   inherit nativeTools nativeLibc nativePrefix gcc libc binutils;
   crossConfig = if (cross != null) then cross.config else null;
-  name = if name == "" then gcc.name else name;
+  gccLibs = if gcc != null then gccLibs else null;
+  name = chosenName;
   langC = if nativeTools then true else gcc.langC;
   langCC = if nativeTools then true else gcc.langCC;
   langF77 = if nativeTools then false else gcc ? langFortran;
diff --git a/pkgs/build-support/gcc-cross-wrapper/gcc-wrapper.sh b/pkgs/build-support/gcc-cross-wrapper/gcc-wrapper.sh
index 491de8f7f98..98baafb4878 100644
--- a/pkgs/build-support/gcc-cross-wrapper/gcc-wrapper.sh
+++ b/pkgs/build-support/gcc-cross-wrapper/gcc-wrapper.sh
@@ -75,14 +75,18 @@ if test "$dontLink" != "1"; then
     # Add the flags that should be passed to the linker (and prevent
     # `ld-wrapper' from adding NIX_CROSS_LDFLAGS again).
     for i in $NIX_CROSS_LDFLAGS_BEFORE; do
-        extraBefore=(${extraBefore[@]} "-Wl,$i")
+        if test "${i:0:3}" = "-L/"; then
+            extraBefore=(${extraBefore[@]} "$i")
+        else
+            extraBefore=(${extraBefore[@]} "-Wl,$i")
+        fi
     done
     for i in $NIX_CROSS_LDFLAGS; do
-	if test "${i:0:3}" = "-L/"; then
-	    extraAfter=(${extraAfter[@]} "$i")
-	else
-	    extraAfter=(${extraAfter[@]} "-Wl,$i")
-	fi
+        if test "${i:0:3}" = "-L/"; then
+            extraAfter=(${extraAfter[@]} "$i")
+        else
+            extraAfter=(${extraAfter[@]} "-Wl,$i")
+        fi
     done
     export NIX_CROSS_LDFLAGS_SET=1
 
diff --git a/pkgs/build-support/gcc-cross-wrapper/setup-hook.sh b/pkgs/build-support/gcc-cross-wrapper/setup-hook.sh
index 0c98062a2db..a7be09283ee 100644
--- a/pkgs/build-support/gcc-cross-wrapper/setup-hook.sh
+++ b/pkgs/build-support/gcc-cross-wrapper/setup-hook.sh
@@ -26,7 +26,7 @@ crossStripDirs() {
     dirs=${dirsNew}
 
     if test -n "${dirs}"; then
-        header "stripping (with flags $stripFlags) in $dirs"
+        header "cross 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
@@ -68,7 +68,9 @@ if test -n "@libc@"; then
     crossAddCVars @libc@
 fi
 
-configureFlags="$configureFlags --build=$system --host=$crossConfig"
+if test "$dontSetConfigureCross" != "1"; then
+    configureFlags="$configureFlags --build=$system --host=$crossConfig"
+fi
 # Disabling the tests when cross compiling, as usually the tests are meant for
 # native compilations.
 doCheck=""
diff --git a/pkgs/build-support/gcc-wrapper/default.nix b/pkgs/build-support/gcc-wrapper/default.nix
index c97fd4eb495..2c7ef16674b 100644
--- a/pkgs/build-support/gcc-wrapper/default.nix
+++ b/pkgs/build-support/gcc-wrapper/default.nix
@@ -67,6 +67,7 @@ stdenv.mkDerivation {
        if stdenv.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else
        if stdenv.system == "armv5tel-linux" then "ld-linux.so.3" else
        if stdenv.system == "powerpc-linux" then "ld.so.1" else
+       if stdenv.system == "ict_loongson-2_v0.3_fpu_v0.1-linux" then "ld.so.1" else
        abort "don't know the name of the dynamic linker for this platform")
     else "";
 }
diff --git a/pkgs/build-support/gcc-wrapper/default2.nix b/pkgs/build-support/gcc-wrapper/default2.nix
deleted file mode 100644
index efade01963b..00000000000
--- a/pkgs/build-support/gcc-wrapper/default2.nix
+++ /dev/null
@@ -1,72 +0,0 @@
-# The Nix `gcc' stdenv.mkDerivation is not directly usable, since it doesn't
-# know where the C library and standard header files are.  Therefore
-# the compiler produced by that package cannot be installed directly
-# in a user environment and used from the command line.  This
-# stdenv.mkDerivation provides a wrapper that sets up the right environment
-# variables so that the compiler and the linker just "work".
-
-{ name ? "", stdenv, nativeTools, nativeLibc, nativePrefix ? ""
-, gcc ? null, libc ? null, binutils ? null, coreutils ? null, shell ? ""
-, zlib ? null
-}:
-
-assert nativeTools -> nativePrefix != "";
-assert !nativeTools -> gcc != null && binutils != null && coreutils != null;
-assert !nativeLibc -> libc != null;
-
-# For ghdl (the vhdl language provider to gcc) we need zlib in the wrapper
-assert (gcc != null && gcc ? langVhdl && gcc.langVhdl) -> zlib != null;
-
-let
-
-  gccVersion = (builtins.parseDrvName gcc.name).version;
-  gccName = (builtins.parseDrvName gcc.name).name;
-  
-in
-
-stdenv.mkDerivation {
-  name =
-    (if name != "" then name else gccName + "-wrapper") +
-    (if gcc != null && gccVersion != "" then "-" + gccVersion else "");
-  
-  builder = ./builder.sh;
-  setupHook = ./setup-hook.sh;
-  gccWrapper = ./gcc-wrapper.sh;
-  gnatWrapper = ./gnat-wrapper.sh;
-  gnatlinkWrapper = ./gnatlink-wrapper.sh;
-  ldWrapper = ./ld-wrapper2.sh;
-  utils = ./utils.sh;
-  addFlags = ./add-flags;
-  
-  inherit nativeTools nativeLibc nativePrefix gcc;
-  libc = if nativeLibc then null else libc;
-  binutils = if nativeTools then null else binutils;
-  # The wrapper scripts use 'cat', so we may need coreutils
-  coreutils = if nativeTools then null else coreutils;
-  
-  langC = if nativeTools then true else gcc.langC;
-  langCC = if nativeTools then true else gcc.langCC;
-  langFortran = if nativeTools then false else gcc ? langFortran;
-  langAda = if nativeTools then false else gcc ? langAda && gcc.langAda;
-  langVhdl = if nativeTools then false else gcc ? langVhdl && gcc.langVhdl;
-  zlib = if (gcc != null && gcc ? langVhdl) then zlib else null;
-  shell = if shell == "" then stdenv.shell else shell;
-  
-  meta =
-    let gcc_ = if gcc != null then gcc else {}; in
-    (if gcc_ ? meta then removeAttrs gcc.meta ["priority"] else {}) //
-    { description =
-        stdenv.lib.attrByPath ["meta" "description"] "System C compiler" gcc_
-        + " (wrapper script)";
-    };
-
-  # The dynamic linker has different names on different Linux platforms.
-  dynamicLinker =
-    if !nativeLibc then
-      (if stdenv.system == "i686-linux" then "ld-linux.so.2" else
-       if stdenv.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else
-       if stdenv.system == "armv5tel-linux" then "ld-linux.so.3" else
-       if stdenv.system == "powerpc-linux" then "ld.so.1" else
-       abort "don't know the name of the dynamic linker for this platform")
-    else "";
-}
diff --git a/pkgs/build-support/gcc-wrapper/ld-wrapper.sh b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh
index 3ca9e815a8f..99ba3968ae3 100644
--- a/pkgs/build-support/gcc-wrapper/ld-wrapper.sh
+++ b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh
@@ -82,6 +82,13 @@ if test "$NIX_DONT_SET_RPATH" != "1"; then
         rpath="$rpath $1 "
     }
 
+    libs=""
+    addToLibs() {
+        libs="$libs $1"
+    }
+
+    rpath=""
+
     # First, find all -L... switches.
     allParams=("${params[@]}" ${extra[@]})
     n=0
@@ -93,6 +100,11 @@ if test "$NIX_DONT_SET_RPATH" != "1"; then
         elif test "$p" = "-L"; then
             addToLibPath ${p2}
             n=$((n + 1))
+        elif test "$p" = "-l"; then
+            addToLibs ${p2}
+            n=$((n + 1))
+        elif test "${p:0:2}" = "-l"; then
+            addToLibs ${p:2}
         elif [[ "$p" =~ ^[^-].*\.so($|\.) ]]; then
             # This is a direct reference to a shared library, so add
             # its directory to the rpath.
@@ -105,24 +117,14 @@ if test "$NIX_DONT_SET_RPATH" != "1"; then
     # Second, for each directory in the library search path (-L...),
     # see if it contains a dynamic library used by a -l... flag.  If
     # so, add the directory to the rpath.
-    rpath=""
     
-    for i in $libPath; do
-        n=0
-        while test $n -lt ${#allParams[*]}; do
-            p=${allParams[n]}
-            p2=${allParams[$((n+1))]}
-            if test "${p:0:2}" = "-l" -a -f "$i/lib${p:2}.so"; then
-                addToRPath $i
-                break
-            elif test "$p" = "-l" -a -f "$i/lib${p2}"; then
-                # I haven't seen `-l foo', but you never know...
-                addToRPath $i
+    for i in $libs; do
+        for j in $libPath; do
+            if test -f "$j/lib$i.so"; then
+                addToRPath $j
                 break
             fi
-            n=$((n + 1))
         done
-            
     done
     
 
diff --git a/pkgs/build-support/gcc-wrapper/ld-wrapper2.sh b/pkgs/build-support/gcc-wrapper/ld-wrapper2.sh
deleted file mode 100644
index 99ba3968ae3..00000000000
--- a/pkgs/build-support/gcc-wrapper/ld-wrapper2.sh
+++ /dev/null
@@ -1,154 +0,0 @@
-#! @shell@ -e
-
-if test -n "$NIX_LD_WRAPPER_START_HOOK"; then
-    source "$NIX_LD_WRAPPER_START_HOOK"
-fi
-
-if test -z "$NIX_GCC_WRAPPER_FLAGS_SET"; then
-    source @out@/nix-support/add-flags.sh
-fi
-
-source @out@/nix-support/utils.sh
-
-
-# Optionally filter out paths not refering to the store.
-params=("$@")
-if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE" \
-        -a \( -z "$NIX_IGNORE_LD_THROUGH_GCC" -o -z "$NIX_LDFLAGS_SET" \); then
-    rest=()
-    n=0
-    while test $n -lt ${#params[*]}; do
-        p=${params[n]}
-        p2=${params[$((n+1))]}
-        if test "${p:0:3}" = "-L/" && badPath "${p:2}"; then
-            skip $p
-        elif test "$p" = "-L" && badPath "$p2"; then
-            n=$((n + 1)); skip $p2
-        elif test "$p" = "-rpath" && badPath "$p2"; then
-            n=$((n + 1)); skip $p2
-        elif test "$p" = "-dynamic-linker" && badPath "$p2"; then
-            n=$((n + 1)); skip $p2
-        elif test "${p:0:1}" = "/" && badPath "$p"; then
-            # We cannot skip this; barf.
-            echo "impure path \`$p' used in link" >&2
-            exit 1
-        else
-            rest=("${rest[@]}" "$p")
-        fi
-        n=$((n + 1))
-    done
-    params=("${rest[@]}")
-fi
-
-
-extra=()
-extraBefore=()
-
-if test -z "$NIX_LDFLAGS_SET"; then
-    extra=(${extra[@]} $NIX_LDFLAGS)
-    extraBefore=(${extraBefore[@]} $NIX_LDFLAGS_BEFORE)
-fi
-
-
-# Add all used dynamic libraries to the rpath.
-if test "$NIX_DONT_SET_RPATH" != "1"; then
-
-    libPath=""
-    addToLibPath() {
-        local path="$1"
-        if test "${path:0:1}" != "/"; then return 0; fi
-        case "$path" in
-            *..*|*./*|*/.*|*//*)
-                local path2
-                if path2=$(readlink -f "$path"); then
-                    path="$path2"
-                fi
-                ;;
-        esac
-        case $libPath in
-            *\ $path\ *) return 0 ;;
-        esac
-        libPath="$libPath $path "
-    }
-    
-    addToRPath() {
-        # If the path is not in the store, don't add it to the rpath.
-        # This typically happens for libraries in /tmp that are later
-        # copied to $out/lib.  If not, we're screwed.
-        if test "${1:0:${#NIX_STORE}}" != "$NIX_STORE"; then return 0; fi
-        case $rpath in
-            *\ $1\ *) return 0 ;;
-        esac
-        rpath="$rpath $1 "
-    }
-
-    libs=""
-    addToLibs() {
-        libs="$libs $1"
-    }
-
-    rpath=""
-
-    # First, find all -L... switches.
-    allParams=("${params[@]}" ${extra[@]})
-    n=0
-    while test $n -lt ${#allParams[*]}; do
-        p=${allParams[n]}
-        p2=${allParams[$((n+1))]}
-        if test "${p:0:3}" = "-L/"; then
-            addToLibPath ${p:2}
-        elif test "$p" = "-L"; then
-            addToLibPath ${p2}
-            n=$((n + 1))
-        elif test "$p" = "-l"; then
-            addToLibs ${p2}
-            n=$((n + 1))
-        elif test "${p:0:2}" = "-l"; then
-            addToLibs ${p:2}
-        elif [[ "$p" =~ ^[^-].*\.so($|\.) ]]; then
-            # This is a direct reference to a shared library, so add
-            # its directory to the rpath.
-            path="$(dirname "$p")";
-            addToRPath "${path}"
-        fi
-        n=$((n + 1))
-    done
-
-    # Second, for each directory in the library search path (-L...),
-    # see if it contains a dynamic library used by a -l... flag.  If
-    # so, add the directory to the rpath.
-    
-    for i in $libs; do
-        for j in $libPath; do
-            if test -f "$j/lib$i.so"; then
-                addToRPath $j
-                break
-            fi
-        done
-    done
-    
-
-    # Finally, add `-rpath' switches.
-    for i in $rpath; do
-        extra=(${extra[@]} -rpath $i)
-    done
-fi
-
-
-# Optionally print debug info.
-if test "$NIX_DEBUG" = "1"; then
-  echo "original flags to @ld@:" >&2
-  for i in "${params[@]}"; do
-      echo "  $i" >&2
-  done
-  echo "extra flags to @ld@:" >&2
-  for i in ${extra[@]}; do
-      echo "  $i" >&2
-  done
-fi
-
-if test -n "$NIX_LD_WRAPPER_EXEC_HOOK"; then
-    source "$NIX_LD_WRAPPER_EXEC_HOOK"
-fi
-
-exec @ld@ ${extraBefore[@]} "${params[@]}" ${extra[@]}
diff --git a/pkgs/desktops/kde-4.4/support/phonon/phonon-4.4.1-gst-plugins-include.patch b/pkgs/desktops/kde-4.4/support/phonon/phonon-4.4.1-gst-plugins-include.patch
new file mode 100644
index 00000000000..46782840570
--- /dev/null
+++ b/pkgs/desktops/kde-4.4/support/phonon/phonon-4.4.1-gst-plugins-include.patch
@@ -0,0 +1,263 @@
+From 1e3a6c25bc258021899c0a31ea9b68ea656d8f6b Mon Sep 17 00:00:00 2001
+From: Yury G. Kudryashov <urkud.urkud@gmail.com>
+Date: Sat, 8 May 2010 18:42:35 +0400
+Subject: [PATCH] Find include directories as well
+
+Makes it possible to compile phonon if gstreamer and gst-plugins-base are
+installed into different prefixes. Theoretically, should work even if each
+plugin is installed into dedicated prefix, but this feature is not tested.
+---
+ cmake/FindGStreamerPlugins.cmake |  160 +++++++++++++++-----------------------
+ gstreamer/CMakeLists.txt         |    4 +-
+ gstreamer/ConfigureChecks.cmake  |   10 +-
+ 3 files changed, 72 insertions(+), 102 deletions(-)
+
+diff --git a/cmake/FindGStreamerPlugins.cmake b/cmake/FindGStreamerPlugins.cmake
+index f6d70d5..9e7a4d0 100644
+--- a/cmake/FindGStreamerPlugins.cmake
++++ b/cmake/FindGStreamerPlugins.cmake
+@@ -2,19 +2,63 @@
+ # Once done this will define
+ #
+ #  GSTREAMERPLUGINSBASE_FOUND - system has GStreamer_Plugins
+-#  GSTREAMERPLUGINSBASE_INCLUDE_DIR - the GStreamer_Plugins include directory
++#  GSTREAMERPLUGINSBASE_INCLUDE_DIRS - the GStreamer_Plugins include directories
+ #  GSTREAMERPLUGINSBASE_LIBRARIES - the libraries needed to use GStreamer_Plugins
+-#  GSTREAMERPLUGINSBASE_DEFINITIONS - Compiler switches required for using GStreamer_Plugins
++#
++# The following variables are set for each plugin PLUGINNAME:
++#
++#  GSTREAMER_PLUGIN_PLUGINNAME_FOUND - plugin is found
++#  GSTREAMER_PLUGIN_PLUGINNAME_INCLUDE_DIR - plugin include directory
++#  GSTREAMER_PLUGIN_PLUGINNAME_LIBRARY - the library needed to use plugin
+ #
+ #  (c)2009 Nokia Corporation
++#  (c)2010 Yury G. Kudryashov <urkud@ya.ru>
+ 
+ FIND_PACKAGE(PkgConfig REQUIRED)
+ 
+ IF (NOT WIN32)
+    # don't make this check required - otherwise you can't use macro_optional_find_package on this one
+-   PKG_CHECK_MODULES( PKG_GSTREAMER gstreamer-plugins-base-0.10 )
++   PKG_CHECK_MODULES( PKG_GSTREAMER_PLUGINSBASE gstreamer-plugins-base-0.10 )
+ ENDIF (NOT WIN32)
+ 
++MACRO(MACRO_FIND_GSTREAMER_PLUGIN _plugin _header)
++   STRING(TOUPPER ${_plugin} _upper)
++   IF (NOT WIN32)
++      # don't make this check required - otherwise you can't use macro_optional_find_package on this one
++      PKG_CHECK_MODULES( PKG_GSTREAMER_${_upper} gstreamer-${_plugin}-0.10 )
++   ENDIF (NOT WIN32)
++
++   FIND_LIBRARY(GSTREAMER_PLUGIN_${_upper}_LIBRARY NAMES gst${_plugin}-0.10
++      PATHS
++      ${PKG_GSTREAMER_PLUGINSBASE_LIBRARY_DIRS}
++      ${PKG_GSTREAMER_${_upper}_LIBRARY_DIRS}
++      )
++
++   FIND_PATH(GSTREAMER_PLUGIN_${_upper}_INCLUDE_DIR
++       NAMES gst/${_plugin}/${_header}
++       PATHS
++       ${PKG_GSTREAMER_PLUGINSBASE_INCLUDE_DIRS}
++       ${PKG_GSTREAMER_${_upper}_INCLUDE_DIRS}
++       )
++
++   IF(GSTREAMER_PLUGIN_${_upper}_LIBRARY AND GSTREAMER_PLUGIN_${_upper}_INCLUDE_DIR)
++      SET(GSTREAMER_PLUGIN_${_upper}_FOUND TRUE)
++      LIST(APPEND GSTREAMERPLUGINSBASE_INCLUDE_DIRS GSTREAMER_${_upper}_INCLUDE_DIR)
++      LIST(APPEND GSTREAMERPLUGINSBASE_LIBRARIES GSTREAMER_${_upper}_LIBRARY)
++   ELSE(GSTREAMER_PLUGIN_${_upper}_LIBRARY AND GSTREAMER_PLUGIN_${_upper}_INCLUDE_DIR)
++      MESSAGE(STATUS "Could not find ${_plugin} plugin")
++      MESSAGE(STATUS "${_upper} library: ${GSTREAMER_${_upper}_LIBRARY}")
++      MESSAGE(STATUS "${_upper} include dir: ${GSTREAMER_${_upper}_INCLUDE_DIR}")
++      SET(GSTREAMER_PLUGIN_${_upper}_FOUND FALSE)
++      SET(GSTREAMER_PLUGIN_${_upper}_LIBRARY GSTREAMER_${_upper}_LIBRARY-NOTFOUND)
++      SET(GSTREAMER_PLUGIN_${_upper}_INCLUDE_DIR GSTREAMER_${_upper}_INCLUDE_DIR-NOTFOUND)
++      SET(GSTREAMERPLUGINSBASE_FOUND FALSE)
++   ENDIF(GSTREAMER_PLUGIN_${_upper}_LIBRARY AND GSTREAMER_PLUGIN_${_upper}_INCLUDE_DIR)
++
++   MARK_AS_ADVANCED(GSTREAMER_PLUGIN_${_upper}_LIBRARY
++      GSTREAMER_PLUGIN_${_upper}_INCLUDE_DIR)
++ENDMACRO(MACRO_FIND_GSTREAMER_PLUGIN)
++
+ #
+ # Base plugins:
+ #  audio
+@@ -31,87 +75,21 @@ ENDIF (NOT WIN32)
+ # The gstinterfaces-0.10 library is found by FindGStreamer.cmake
+ #
+ 
+-FIND_LIBRARY(GSTREAMER_PLUGIN_AUDIO_LIBRARIES NAMES gstaudio-0.10
+-   PATHS
+-   ${PKG_GSTREAMER_LIBRARY_DIRS}
+-   )
+-FIND_LIBRARY(GSTREAMER_PLUGIN_CDDA_LIBRARIES NAMES gstcdda-0.10
+-   PATHS
+-   ${PKG_GSTREAMER_LIBRARY_DIRS}
+-   )
+-FIND_LIBRARY(GSTREAMER_PLUGIN_NETBUFFER_LIBRARIES NAMES gstnetbuffer-0.10
+-   PATHS
+-   ${PKG_GSTREAMER_LIBRARY_DIRS}
+-   )
+-FIND_LIBRARY(GSTREAMER_PLUGIN_PBUTILS_LIBRARIES NAMES gstpbutils-0.10
+-   PATHS
+-   ${PKG_GSTREAMER_LIBRARY_DIRS}
+-   )
+-FIND_LIBRARY(GSTREAMER_PLUGIN_RIFF_LIBRARIES NAMES gstriff-0.10
+-   PATHS
+-   ${PKG_GSTREAMER_LIBRARY_DIRS}
+-   )
+-FIND_LIBRARY(GSTREAMER_PLUGIN_RTP_LIBRARIES NAMES gstrtp-0.10
+-   PATHS
+-   ${PKG_GSTREAMER_LIBRARY_DIRS}
+-   )
+-FIND_LIBRARY(GSTREAMER_PLUGIN_RTSP_LIBRARIES NAMES gstrtsp-0.10
+-   PATHS
+-   ${PKG_GSTREAMER_LIBRARY_DIRS}
+-   )
+-FIND_LIBRARY(GSTREAMER_PLUGIN_SDP_LIBRARIES NAMES gstsdp-0.10
+-   PATHS
+-   ${PKG_GSTREAMER_LIBRARY_DIRS}
+-   )
+-FIND_LIBRARY(GSTREAMER_PLUGIN_TAG_LIBRARIES NAMES gsttag-0.10
+-   PATHS
+-   ${PKG_GSTREAMER_LIBRARY_DIRS}
+-   )
+-FIND_LIBRARY(GSTREAMER_PLUGIN_VIDEO_LIBRARIES NAMES gstvideo-0.10
+-   PATHS
+-   ${PKG_GSTREAMER_LIBRARY_DIRS}
+-   )
+-
+-IF (GSTREAMER_PLUGIN_AUDIO_LIBRARIES AND
+-    GSTREAMER_PLUGIN_CDDA_LIBRARIES AND
+-    GSTREAMER_PLUGIN_NETBUFFER_LIBRARIES AND
+-    GSTREAMER_PLUGIN_PBUTILS_LIBRARIES AND
+-    GSTREAMER_PLUGIN_RIFF_LIBRARIES AND
+-    GSTREAMER_PLUGIN_RTP_LIBRARIES AND
+-    GSTREAMER_PLUGIN_RTSP_LIBRARIES AND
+-    GSTREAMER_PLUGIN_SDP_LIBRARIES AND
+-    GSTREAMER_PLUGIN_TAG_LIBRARIES AND
+-    GSTREAMER_PLUGIN_VIDEO_LIBRARIES)
+-   SET(GSTREAMERPLUGINSBASE_FOUND TRUE)
+-ELSE (GSTREAMER_PLUGIN_AUDIO_LIBRARIES AND
+-    GSTREAMER_PLUGIN_CDDA_LIBRARIES AND
+-    GSTREAMER_PLUGIN_NETBUFFER_LIBRARIES AND
+-    GSTREAMER_PLUGIN_PBUTILS_LIBRARIES AND
+-    GSTREAMER_PLUGIN_RIFF_LIBRARIES AND
+-    GSTREAMER_PLUGIN_RTP_LIBRARIES AND
+-    GSTREAMER_PLUGIN_RTSP_LIBRARIES AND
+-    GSTREAMER_PLUGIN_SDP_LIBRARIES AND
+-    GSTREAMER_PLUGIN_TAG_LIBRARIES AND
+-    GSTREAMER_PLUGIN_VIDEO_LIBRARIES)
+-   SET(GSTREAMERPLUGINSBASE_FOUND FALSE)
+-ENDIF (GSTREAMER_PLUGIN_AUDIO_LIBRARIES AND
+-    GSTREAMER_PLUGIN_CDDA_LIBRARIES AND
+-    GSTREAMER_PLUGIN_NETBUFFER_LIBRARIES AND
+-    GSTREAMER_PLUGIN_PBUTILS_LIBRARIES AND
+-    GSTREAMER_PLUGIN_RIFF_LIBRARIES AND
+-    GSTREAMER_PLUGIN_RTP_LIBRARIES AND
+-    GSTREAMER_PLUGIN_RTSP_LIBRARIES AND
+-    GSTREAMER_PLUGIN_SDP_LIBRARIES AND
+-    GSTREAMER_PLUGIN_TAG_LIBRARIES AND
+-    GSTREAMER_PLUGIN_VIDEO_LIBRARIES)
++SET(GSTREAMER_PLUGINSBASE_FOUND TRUE)
++MACRO_FIND_GSTREAMER_PLUGIN(audio audio.h)
++MACRO_FIND_GSTREAMER_PLUGIN(cdda gstcddabasesrc.h)
++MACRO_FIND_GSTREAMER_PLUGIN(netbuffer gstnetbuffer.h)
++MACRO_FIND_GSTREAMER_PLUGIN(pbutils pbutils.h)
++MACRO_FIND_GSTREAMER_PLUGIN(riff riff-ids.h)
++MACRO_FIND_GSTREAMER_PLUGIN(rtp gstrtpbuffer.h)
++MACRO_FIND_GSTREAMER_PLUGIN(rtsp gstrtspdefs.h)
++MACRO_FIND_GSTREAMER_PLUGIN(sdp gstsdp.h)
++MACRO_FIND_GSTREAMER_PLUGIN(tag tag.h)
++MACRO_FIND_GSTREAMER_PLUGIN(video video.h)
+ 
+ IF (GSTREAMERPLUGINSBASE_FOUND)
+-   SET(GSTREAMERPLUGINS_FOUND TRUE)
+-ELSE (GSTREAMERPLUGINSBASE_FOUND)
+-   SET(GSTREAMERPLUGINS_FOUND FALSE)
+-ENDIF (GSTREAMERPLUGINSBASE_FOUND)
+-
+-IF (GSTREAMERPLUGINS_FOUND)
++   LIST(REMOVE_DUPLICATES GSTREAMERPLUGINSBASE_LIBRARIES)
++   LIST(REMOVE_DUPLICATES GSTREAMERPLUGINSBASE_INCLUDE_DIRS)
+    IF (NOT GStreamer_Plugins_FIND_QUIETLY)
+       MESSAGE(STATUS "Found GStreamer Plugins:
+     ${GSTREAMER_PLUGIN_AUDIO_LIBRARIES}
+@@ -125,20 +103,10 @@ IF (GSTREAMERPLUGINS_FOUND)
+     ${GSTREAMER_PLUGIN_TAG_LIBRARIES}
+     ${GSTREAMER_PLUGIN_VIDEO_LIBRARIES}")
+    ENDIF (NOT GStreamer_Plugins_FIND_QUIETLY)
+-ELSE (GSTREAMERPLUGINS_FOUND)
++ELSE (GSTREAMERPLUGINSBASE_FOUND)
++   SET(GSTREAMERPLUGINSBASE_LIBRARIES GSTREAMERPLUGINSBASE_LIBRARIES-NOTFOUND)
++   SET(GSTREAMERPLUGINSBASE_INCLUDE_DIRS GSTREAMERPLUGINSBASE_INCLUDE_DIRS-NOTFOUND)
+    IF (GStreamer_Plugins_FIND_REQUIRED)
+       MESSAGE(SEND_ERROR "Could NOT find GStreamer Plugins")
+    ENDIF (GStreamer_Plugins_FIND_REQUIRED)
+-ENDIF (GSTREAMERPLUGINS_FOUND)
+-
+-MARK_AS_ADVANCED(GSTREAMERPLUGINS_DEFINITIONS
+-    GSTREAMER_PLUGIN_AUDIO_LIBRARIES
+-    GSTREAMER_PLUGIN_CDDA_LIBRARIES
+-    GSTREAMER_PLUGIN_NETBUFFER_LIBRARIES
+-    GSTREAMER_PLUGIN_PBUTILS_LIBRARIES
+-    GSTREAMER_PLUGIN_RIFF_LIBRARIES
+-    GSTREAMER_PLUGIN_RTP_LIBRARIES
+-    GSTREAMER_PLUGIN_RTSP_LIBRARIES
+-    GSTREAMER_PLUGIN_SDP_LIBRARIES
+-    GSTREAMER_PLUGIN_TAG_LIBRARIES
+-    GSTREAMER_PLUGIN_VIDEO_LIBRARIES)
++ENDIF (GSTREAMERPLUGINSBASE_FOUND)
+diff --git a/gstreamer/CMakeLists.txt b/gstreamer/CMakeLists.txt
+index d529fb6..c42710b 100644
+--- a/gstreamer/CMakeLists.txt
++++ b/gstreamer/CMakeLists.txt
+@@ -20,6 +20,8 @@ if (BUILD_PHONON_GSTREAMER)
+    include_directories(
+ 	  ${CMAKE_CURRENT_BINARY_DIR}
+ 	  ${GSTREAMER_INCLUDE_DIR}
++	  ${GSTREAMER_PLUGIN_VIDEO_INCLUDE_DIR}
++	  ${GSTREAMER_PLUGIN_AUDIO_INCLUDE_DIR}
+ 	  ${GLIB2_INCLUDE_DIR}
+       ${LIBXML2_INCLUDE_DIR}
+ 	  ${X11_X11_INCLUDE_PATH})
+@@ -78,7 +80,7 @@ if (BUILD_PHONON_GSTREAMER)
+       ${QT_QTOPENGL_LIBRARY}
+       ${PHONON_LIBS} ${OPENGL_gl_LIBRARY}
+       ${GSTREAMER_LIBRARIES} ${GSTREAMER_BASE_LIBRARY} ${GSTREAMER_INTERFACE_LIBRARY}
+-      ${GSTREAMER_PLUGIN_VIDEO_LIBRARIES} ${GSTREAMER_PLUGIN_AUDIO_LIBRARIES}
++      ${GSTREAMER_PLUGIN_VIDEO_LIBRARY} ${GSTREAMER_PLUGIN_AUDIO_LIBRARY}
+       ${GLIB2_LIBRARIES} ${GOBJECT_LIBRARIES})
+    if(ALSA_FOUND)
+       target_link_libraries(phonon_gstreamer ${ASOUND_LIBRARY})
+diff --git a/gstreamer/ConfigureChecks.cmake b/gstreamer/ConfigureChecks.cmake
+index 095a0e9..73616fa 100644
+--- a/gstreamer/ConfigureChecks.cmake
++++ b/gstreamer/ConfigureChecks.cmake
+@@ -16,8 +16,8 @@ macro_optional_find_package(GStreamer)
+ macro_log_feature(GSTREAMER_FOUND "GStreamer" "gstreamer 0.10 is required for the multimedia backend" "http://gstreamer.freedesktop.org/modules/" FALSE "0.10")
+ 
+ macro_optional_find_package(GStreamerPlugins)
+-macro_log_feature(GSTREAMER_PLUGIN_VIDEO_LIBRARIES "GStreamer video plugin" "The gstreamer video plugin (part of gstreamer-plugins-base 0.10) is required for the multimedia gstreamer backend" "http://gstreamer.freedesktop.org/modules/" FALSE "0.10")
+-macro_log_feature(GSTREAMER_PLUGIN_AUDIO_LIBRARIES "GStreamer audio plugin" "The gstreamer audio plugin (part of gstreamer-plugins-base 0.10) is required for the multimedia gstreamer backend" "http://gstreamer.freedesktop.org/modules/" FALSE "0.10")
++macro_log_feature(GSTREAMER_PLUGIN_VIDEO_FOUND "GStreamer video plugin" "The gstreamer video plugin (part of gstreamer-plugins-base 0.10) is required for the multimedia gstreamer backend" "http://gstreamer.freedesktop.org/modules/" FALSE "0.10")
++macro_log_feature(GSTREAMER_PLUGIN_AUDIO_FOUND "GStreamer audio plugin" "The gstreamer audio plugin (part of gstreamer-plugins-base 0.10) is required for the multimedia gstreamer backend" "http://gstreamer.freedesktop.org/modules/" FALSE "0.10")
+ 
+ macro_optional_find_package(GLIB2)
+ macro_log_feature(GLIB2_FOUND "GLib2" "GLib 2 is required to compile the gstreamer backend for Phonon" "http://www.gtk.org/download/" FALSE)
+@@ -31,8 +31,8 @@ macro_log_feature(LIBXML2_FOUND "LibXml2" "LibXml2 is required to compile the gs
+ macro_optional_find_package(OpenGL)
+ macro_log_feature(OPENGL_FOUND "OpenGL" "OpenGL support is required to compile the gstreamer backend for Phonon" "" FALSE)
+ 
+-if (GSTREAMER_FOUND AND GSTREAMER_PLUGIN_VIDEO_LIBRARIES AND GSTREAMER_PLUGIN_AUDIO_LIBRARIES AND GLIB2_FOUND AND GOBJECT_FOUND AND LIBXML2_FOUND AND OPENGL_FOUND)
++if (GSTREAMER_FOUND AND GSTREAMER_PLUGIN_VIDEO_FOUND AND GSTREAMER_PLUGIN_AUDIO_FOUND AND GLIB2_FOUND AND GOBJECT_FOUND AND LIBXML2_FOUND AND OPENGL_FOUND)
+    set(BUILD_PHONON_GSTREAMER TRUE)
+-else (GSTREAMER_FOUND AND GSTREAMER_PLUGIN_VIDEO_LIBRARIES AND GSTREAMER_PLUGIN_AUDIO_LIBRARIES AND GLIB2_FOUND AND GOBJECT_FOUND AND LIBXML2_FOUND AND OPENGL_FOUND)
++else (GSTREAMER_FOUND AND GSTREAMER_PLUGIN_VIDEO_FOUND AND GSTREAMER_PLUGIN_AUDIO_FOUND AND GLIB2_FOUND AND GOBJECT_FOUND AND LIBXML2_FOUND AND OPENGL_FOUND)
+    set(BUILD_PHONON_GSTREAMER FALSE)
+-endif (GSTREAMER_FOUND AND GSTREAMER_PLUGIN_VIDEO_LIBRARIES AND GSTREAMER_PLUGIN_AUDIO_LIBRARIES AND GLIB2_FOUND AND GOBJECT_FOUND AND LIBXML2_FOUND AND OPENGL_FOUND)
++endif (GSTREAMER_FOUND AND GSTREAMER_PLUGIN_VIDEO_FOUND AND GSTREAMER_PLUGIN_AUDIO_FOUND AND GLIB2_FOUND AND GOBJECT_FOUND AND LIBXML2_FOUND AND OPENGL_FOUND)
+-- 
+1.7.1
+
diff --git a/pkgs/development/compilers/gcc-4.4/builder.sh b/pkgs/development/compilers/gcc-4.4/builder.sh
index b9724e7ad50..abe14b457ab 100644
--- a/pkgs/development/compilers/gcc-4.4/builder.sh
+++ b/pkgs/development/compilers/gcc-4.4/builder.sh
@@ -61,10 +61,39 @@ if test "$noSysDirs" = "1"; then
             EXTRA_LDFLAGS_TARGET="-Wl,-L${libcCross}/lib"
         fi
     else
-        EXTRA_FLAGS_TARGET="$EXTRA_FLAGS"
-        EXTRA_LDFLAGS_TARGET="$EXTRA_LDFLAGS"
+        if test -z "$NIX_GCC_CROSS"; then
+            EXTRA_FLAGS_TARGET="$EXTRA_FLAGS"
+            EXTRA_LDFLAGS_TARGET="$EXTRA_LDFLAGS"
+        else
+            # This the case of cross-building the gcc.
+            # We need special flags for the target, different than those of the build
+            # Assertion:
+            test -e $NIX_GCC_CROSS/nix-support/orig-libc
+
+            # Figure out what extra flags to pass to the gcc compilers
+            # being generated to make sure that they use our glibc.
+            extraFlags="$(cat $NIX_GCC_CROSS/nix-support/libc-cflags)"
+            extraLDFlags="$(cat $NIX_GCC_CROSS/nix-support/libc-ldflags) $(cat $NIX_GCC_CROSS/nix-support/libc-ldflags-before)"
+
+            # Use *real* header files, otherwise a limits.h is generated
+            # that does not include Glibc's limits.h (notably missing
+            # SSIZE_MAX, which breaks the build).
+            NIX_FIXINC_DUMMY_CROSS=$(cat $NIX_GCC_CROSS/nix-support/orig-libc)/include
+
+            # The path to the Glibc binaries such as `crti.o'.
+            glibc_libdir="$(cat $NIX_GCC_CROSS/nix-support/orig-libc)/lib"
+
+            extraFlags="-g0 -O2 -I$NIX_FIXINC_DUMMY_CROSS $extraFlags"
+            extraLDFlags="--strip-debug -L$glibc_libdir -rpath $glibc_libdir $extraLDFlags"
+
+            EXTRA_FLAGS_TARGET="$extraFlags"
+            for i in $extraLDFlags; do
+                EXTRA_LDFLAGS_TARGET="$EXTRA_LDFLAGS_TARGET -Wl,$i"
+            done
+        fi
     fi
 
+
     # CFLAGS_FOR_TARGET are needed for the libstdc++ configure script to find
     # the startfiles.
     # FLAGS_FOR_TARGET are needed for the target libraries to receive the -Bxxx
@@ -160,7 +189,7 @@ postInstall() {
 }
 
 
-if test -z "$targetConfig"; then
+if test -z "$targetConfig" && test -z "$crossConfig"; then
     if test -z "$profiledCompiler"; then
         buildFlags="bootstrap $buildFlags"
     else    
diff --git a/pkgs/development/compilers/gcc-4.4/default.nix b/pkgs/development/compilers/gcc-4.4/default.nix
index e4206cabd8a..bc9c2c89e1d 100644
--- a/pkgs/development/compilers/gcc-4.4/default.nix
+++ b/pkgs/development/compilers/gcc-4.4/default.nix
@@ -126,7 +126,9 @@ stdenv.mkDerivation ({
   inherit noSysDirs profiledCompiler staticCompiler langJava crossStageStatic
     libcCross;
 
-  buildInputs = [ texinfo gmp mpfr gettext which ]
+  buildNativeInputs = [ texinfo which ];
+
+  buildInputs = [ gmp mpfr gettext ]
     ++ (optional (ppl != null) ppl)
     ++ (optional (cloogppl != null) cloogppl)
     ++ (optionals langTreelang [bison flex])
@@ -176,6 +178,50 @@ stdenv.mkDerivation ({
   LD = "ld";
   CC = "gcc";
 
+  crossAttrs = {
+    AR = "${stdenv.cross.config}-ar";
+    LD = "${stdenv.cross.config}-ld";
+    CC = "${stdenv.cross.config}-gcc";
+    CXX = "${stdenv.cross.config}-gcc";
+    AR_FOR_TARGET = "${stdenv.cross.config}-ar";
+    LD_FOR_TARGET = "${stdenv.cross.config}-ld";
+    CC_FOR_TARGET = "${stdenv.cross.config}-gcc";
+    NM_FOR_TARGET = "${stdenv.cross.config}-nm";
+    CXX_FOR_TARGET = "${stdenv.cross.config}-g++";
+    # If we are making a cross compiler, cross != null
+    NIX_GCC_CROSS = if cross == null then "${stdenv.gccCross}" else "";
+    configureFlags = "
+      ${if enableMultilib then "" else "--disable-multilib"}
+      ${if enableShared then "" else "--disable-shared"}
+      ${if ppl != null then "--with-ppl=${ppl.hostDrv}" else ""}
+      ${if cloogppl != null then "--with-cloog=${cloogppl.hostDrv}" else ""}
+      ${if langJava then "--with-ecj-jar=${javaEcj.hostDrv}" else ""}
+      ${if javaAwtGtk then "--enable-java-awt=gtk" else ""}
+      ${if langJava && javaAntlr != null then "--with-antlr-jar=${javaAntlr.hostDrv}" else ""}
+      --with-gmp=${gmp.hostDrv}
+      --with-mpfr=${mpfr.hostDrv}
+      --disable-libstdcxx-pch
+      --without-included-gettext
+      --with-system-zlib
+      --enable-languages=${
+        concatStrings (intersperse ","
+          (  optional langC        "c"
+          ++ optional langCC       "c++"
+          ++ optional langFortran  "fortran"
+          ++ optional langJava     "java"
+          ++ optional langTreelang "treelang"
+          ++ optional langAda      "ada"
+          ++ optional langVhdl     "vhdl"
+          )
+        )
+      }
+      ${if langAda then " --enable-libada" else ""}
+      ${if (cross == null && stdenv.isi686) then "--with-arch=i686" else ""}
+      ${if cross != null then crossConfigureFlags else ""}
+      --target=${stdenv.cross.config}
+    ";
+  };
+
   # Setting $CPATH and $LIBRARY_PATH to make sure both `gcc' and `xgcc' find
   # the library headers and binaries, regarless of the language being
   # compiled.
diff --git a/pkgs/development/compilers/gcc-4.5/builder.sh b/pkgs/development/compilers/gcc-4.5/builder.sh
index 6c3ced85d75..5d66cc09532 100644
--- a/pkgs/development/compilers/gcc-4.5/builder.sh
+++ b/pkgs/development/compilers/gcc-4.5/builder.sh
@@ -54,11 +54,52 @@ if test "$noSysDirs" = "1"; then
         EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,$i"
     done
 
-    if test -z "$targetConfig"; then
-        EXTRA_TARGET_CFLAGS="$EXTRA_FLAGS"
-        EXTRA_TARGET_LDFLAGS="$EXTRA_LDFLAGS"
+    if test -n "$targetConfig"; then
+        # Cross-compiling, we need gcc not to read ./specs in order to build
+        # the g++ compiler (after the specs for the cross-gcc are created).
+        # Having LIBRARY_PATH= makes gcc read the specs from ., and the build
+        # breaks. Having this variable comes from the default.nix code to bring
+        # gcj in.
+        unset LIBRARY_PATH
+        unset CPATH
+        if test -z "$crossStageStatic"; then
+            EXTRA_TARGET_CFLAGS="-g0 -O2 -B${libcCross}/lib -idirafter ${libcCross}/include"
+            EXTRA_TARGET_LDFLAGS="-Wl,-L${libcCross}/lib"
+        fi
+    else
+        if test -z "$NIX_GCC_CROSS"; then
+            EXTRA_TARGET_CFLAGS="$EXTRA_FLAGS"
+            EXTRA_TARGET_LDFLAGS="$EXTRA_LDFLAGS"
+        else
+            # This the case of cross-building the gcc.
+            # We need special flags for the target, different than those of the build
+            # Assertion:
+            test -e $NIX_GCC_CROSS/nix-support/orig-libc
+
+            # Figure out what extra flags to pass to the gcc compilers
+            # being generated to make sure that they use our glibc.
+            extraFlags="$(cat $NIX_GCC_CROSS/nix-support/libc-cflags)"
+            extraLDFlags="$(cat $NIX_GCC_CROSS/nix-support/libc-ldflags) $(cat $NIX_GCC_CROSS/nix-support/libc-ldflags-before)"
+
+            # Use *real* header files, otherwise a limits.h is generated
+            # that does not include Glibc's limits.h (notably missing
+            # SSIZE_MAX, which breaks the build).
+            NIX_FIXINC_DUMMY_CROSS=$(cat $NIX_GCC_CROSS/nix-support/orig-libc)/include
+
+            # The path to the Glibc binaries such as `crti.o'.
+            glibc_libdir="$(cat $NIX_GCC_CROSS/nix-support/orig-libc)/lib"
+
+            extraFlags="-g0 -O2 -I$NIX_FIXINC_DUMMY_CROSS $extraFlags"
+            extraLDFlags="--strip-debug -L$glibc_libdir -rpath $glibc_libdir $extraLDFlags"
+
+            EXTRA_TARGET_CFLAGS="$extraFlags"
+            for i in $extraLDFlags; do
+                EXTRA_TARGET_LDFLAGS="$EXTRA_TARGET_LDFLAGS -Wl,$i"
+            done
+        fi
     fi
 
+
     # CFLAGS_FOR_TARGET are needed for the libstdc++ configure script to find
     # the startfiles.
     # FLAGS_FOR_TARGET are needed for the target libraries to receive the -Bxxx
@@ -68,17 +109,17 @@ if test "$noSysDirs" = "1"; then
         NATIVE_SYSTEM_HEADER_DIR="$NIX_FIXINC_DUMMY" \
         SYSTEM_HEADER_DIR="$NIX_FIXINC_DUMMY" \
         CFLAGS_FOR_BUILD="$EXTRA_FLAGS $EXTRA_LDFLAGS" \
-        CFLAGS_FOR_TARGET="$EXTRA_TARGET_CFLAGS" \
+        CFLAGS_FOR_TARGET="$EXTRA_TARGET_CFLAGS $EXTRA_TARGET_LDFLAGS" \
         FLAGS_FOR_TARGET="$EXTRA_TARGET_CFLAGS $EXTRA_TARGET_LDFLAGS" \
         LDFLAGS_FOR_BUILD="$EXTRA_FLAGS $EXTRA_LDFLAGS" \
-        LDFLAGS_FOR_TARGET="$EXTRA_TARGET_LDFLAGS" \
+        LDFLAGS_FOR_TARGET="$EXTRA_TARGET_LDFLAGS $EXTRA_TARGET_LDFLAGS" \
         )
 
     if test -z "$targetConfig"; then
         makeFlagsArray=( \
             "${makeFlagsArray[@]}" \
             BOOT_CFLAGS="$EXTRA_FLAGS $EXTRA_LDFLAGS" \
-            BOOT_LDFLAGS="$EXTRA_FLAGS $EXTRA_LDFLAGS" \
+            BOOT_LDFLAGS="$EXTRA_TARGET_CFLAGS $EXTRA_TARGET_LDFLAGS" \
             )
     fi
 
@@ -102,6 +143,7 @@ if test -n "$targetConfig"; then
     dontStrip=1
 fi
 
+
 preConfigure() {
     if test -n "$newlibSrc"; then
         tar xvf "$newlibSrc" -C ..
@@ -131,6 +173,12 @@ preConfigure() {
 }
 
 
+postConfigure() {
+    # Don't store the configure flags in the resulting executables.
+    sed -e '/TOPLEVEL_CONFIGURE_ARGUMENTS=/d' -i Makefile
+}
+
+
 postInstall() {
     # Remove precompiled headers for now.  They are very big and
     # probably not very useful yet.
@@ -140,6 +188,14 @@ postInstall() {
     # previous gcc.
     rm -rf $out/libexec/gcc/*/*/install-tools
     rm -rf $out/lib/gcc/*/*/install-tools
+    
+    # More dependencies with the previous gcc or some libs (gccbug stores the build command line)
+    rm -rf $out/bin/gccbug
+    # Take out the bootstrap-tools from the rpath, as it's not needed at all having $out
+    for i in $out/libexec/gcc/*/*/*; do
+        PREV_RPATH=`patchelf --print-rpath $i`
+        patchelf --set-rpath `echo $PREV_RPATH | sed 's,:[^:]*bootstrap-tools/lib,,'` $i
+    done
 
     # Get rid of some "fixed" header files
     rm -rf $out/lib/gcc/*/*/include/root
@@ -151,7 +207,7 @@ postInstall() {
         fi
     done
 
-    for i in $out/bin/*-c++* $out/bin/*-g++*; do
+    for i in $out/bin/c++ $out/bin/*-c++* $out/bin/*-g++*; do
         if cmp -s $out/bin/g++ $i; then
             ln -sfn g++ $i
         fi
@@ -161,7 +217,7 @@ postInstall() {
 }
 
 
-if test -z "$targetConfig"; then
+if test -z "$targetConfig" && test -z "$crossConfig"; then
     if test -z "$profiledCompiler"; then
         buildFlags="bootstrap $buildFlags"
     else    
diff --git a/pkgs/development/compilers/gcc-4.5/default.nix b/pkgs/development/compilers/gcc-4.5/default.nix
index 38f4338d4ac..c1e3d3a402a 100644
--- a/pkgs/development/compilers/gcc-4.5/default.nix
+++ b/pkgs/development/compilers/gcc-4.5/default.nix
@@ -41,7 +41,7 @@ assert libelf != null -> zlib != null;
 with stdenv.lib;
 with builtins;
 
-let version = "4.5.0";
+let version = "4.5.1";
     javaEcj = fetchurl {
       # The `$(top_srcdir)/ecj.jar' file is automatically picked up at
       # `configure' time.
@@ -136,7 +136,7 @@ stdenv.mkDerivation ({
   };
 
   patches =
-    [ ./softfp-hurd.patch ./dragonegg-2.7.patch ]
+    [ ]
     ++ optional (cross != null) ./libstdc++-target.patch
     ++ optional noSysDirs ./no-sys-dirs.patch
     # The GNAT Makefiles did not pay attention to CFLAGS_FOR_TARGET for its
@@ -181,8 +181,10 @@ stdenv.mkDerivation ({
   inherit noSysDirs profiledCompiler staticCompiler langJava crossStageStatic
     libcCross crossMingw;
 
-  buildInputs = [ texinfo gmp mpfr mpc libelf gettext which ]
-    ++ (optional (perl != null) perl)
+  buildNativeInputs = [ texinfo which ]
+    ++ optional (perl != null) perl;
+    
+  buildInputs = [ gmp mpfr mpc libelf gettext ]
     ++ (optional (ppl != null) ppl)
     ++ (optional (cloogppl != null) cloogppl)
     ++ (optionals langTreelang [bison flex])
@@ -195,6 +197,11 @@ stdenv.mkDerivation ({
     ++ (optionals langVhdl [gnat])
     ;
 
+  configureFlagsArray = stdenv.lib.optionals
+    (ppl != null && ppl.dontDisableStatic == true)
+        [ "--with-host-libstdcxx=-lstdc++ -lgcc_s"
+            "--with-stage1-libs=-lstdc++ -lgcc_s" ];
+
   configureFlags = "
     ${if enableMultilib then "" else "--disable-multilib"}
     ${if enableShared then "" else "--disable-shared"}
@@ -235,6 +242,52 @@ stdenv.mkDerivation ({
 
   targetConfig = if (cross != null) then cross.config else null;
 
+  crossAttrs = {
+    AR = "${stdenv.cross.config}-ar";
+    LD = "${stdenv.cross.config}-ld";
+    CC = "${stdenv.cross.config}-gcc";
+    CXX = "${stdenv.cross.config}-gcc";
+    AR_FOR_TARGET = "${stdenv.cross.config}-ar";
+    LD_FOR_TARGET = "${stdenv.cross.config}-ld";
+    CC_FOR_TARGET = "${stdenv.cross.config}-gcc";
+    NM_FOR_TARGET = "${stdenv.cross.config}-nm";
+    CXX_FOR_TARGET = "${stdenv.cross.config}-g++";
+    # If we are making a cross compiler, cross != null
+    NIX_GCC_CROSS = if cross == null then "${stdenv.gccCross}" else "";
+    dontStrip = true;
+    configureFlags = ''
+      ${if enableMultilib then "" else "--disable-multilib"}
+      ${if enableShared then "" else "--disable-shared"}
+      ${if ppl != null then "--with-ppl=${ppl.hostDrv}" else ""}
+      ${if cloogppl != null then "--with-cloog=${cloogppl.hostDrv}" else ""}
+      ${if langJava then "--with-ecj-jar=${javaEcj.hostDrv}" else ""}
+      ${if javaAwtGtk then "--enable-java-awt=gtk" else ""}
+      ${if langJava && javaAntlr != null then "--with-antlr-jar=${javaAntlr.hostDrv}" else ""}
+      --with-gmp=${gmp.hostDrv}
+      --with-mpfr=${mpfr.hostDrv}
+      --disable-libstdcxx-pch
+      --without-included-gettext
+      --with-system-zlib
+      --enable-languages=${
+        concatStrings (intersperse ","
+          (  optional langC        "c"
+          ++ optional langCC       "c++"
+          ++ optional langFortran  "fortran"
+          ++ optional langJava     "java"
+          ++ optional langTreelang "treelang"
+          ++ optional langAda      "ada"
+          ++ optional langVhdl     "vhdl"
+          )
+        )
+      }
+      ${if langAda then " --enable-libada" else ""}
+      ${if (cross == null && stdenv.isi686) then "--with-arch=i686" else ""}
+      ${if cross != null then crossConfigureFlags else ""}
+      --target=${stdenv.cross.config}
+    '';
+  };
+ 
+
   # Needed for the cross compilation to work
   AR = "ar";
   LD = "ld";
@@ -316,11 +369,13 @@ stdenv.mkDerivation ({
     platforms = stdenv.lib.platforms.linux ++ optionals (langAda == false) [ "i686-darwin" ];
   };
 }
-// (if cross != null && cross.libc == "msvcrt" && crossStageStatic then rec {
+
+// optionalAttrs (cross != null && cross.libc == "msvcrt" && crossStageStatic) {
   makeFlags = [ "all-gcc" "all-target-libgcc" ];
   installTargets = "install-gcc install-target-libgcc";
-} else {})
-// (if langVhdl then rec {
+}
+
+// optionalAttrs langVhdl rec {
   name = "ghdl-0.29";
 
   ghdlSrc = fetchurl {
@@ -353,4 +408,4 @@ stdenv.mkDerivation ({
     platforms = with stdenv.lib.platforms; linux;
   };
 
-} else {}))
+})
diff --git a/pkgs/development/compilers/gcc-4.5/dragonegg-2.7.patch b/pkgs/development/compilers/gcc-4.5/dragonegg-2.7.patch
deleted file mode 100644
index 6b37672ddef..00000000000
--- a/pkgs/development/compilers/gcc-4.5/dragonegg-2.7.patch
+++ /dev/null
@@ -1,46 +0,0 @@
-Index: mainline/gcc/config/i386/i386.c
-===================================================================
---- mainline.orig/gcc/config/i386/i386.c	2010-04-02 09:11:58.733574308 +0200
-+++ mainline/gcc/config/i386/i386.c	2010-04-02 09:29:11.276111437 +0200
-@@ -4992,7 +4992,8 @@
-    case, we return the original mode and warn ABI change if CUM isn't
-    NULL.  */
- 
--static enum machine_mode
-+extern enum machine_mode type_natural_mode (const_tree, CUMULATIVE_ARGS *);
-+enum machine_mode
- type_natural_mode (const_tree type, CUMULATIVE_ARGS *cum)
- {
-   enum machine_mode mode = TYPE_MODE (type);
-@@ -5123,7 +5124,9 @@
-    See the x86-64 PS ABI for details.
- */
- 
--static int
-+extern int classify_argument (enum machine_mode, const_tree,
-+                              enum x86_64_reg_class [MAX_CLASSES], int);
-+int
- classify_argument (enum machine_mode mode, const_tree type,
- 		   enum x86_64_reg_class classes[MAX_CLASSES], int bit_offset)
- {
-@@ -5504,7 +5507,9 @@
- 
- /* Examine the argument and return set number of register required in each
-    class.  Return 0 iff parameter should be passed in memory.  */
--static int
-+extern int examine_argument (enum machine_mode, const_tree, int,
-+                             int *, int *);
-+int
- examine_argument (enum machine_mode mode, const_tree type, int in_return,
- 		  int *int_nregs, int *sse_nregs)
- {
-@@ -6186,7 +6191,8 @@
- 
- /* Return true when TYPE should be 128bit aligned for 32bit argument passing
-    ABI.  */
--static bool
-+extern bool contains_aligned_value_p (tree);
-+bool
- contains_aligned_value_p (tree type)
- {
-   enum machine_mode mode = TYPE_MODE (type);
diff --git a/pkgs/development/compilers/gcc-4.5/softfp-hurd.patch b/pkgs/development/compilers/gcc-4.5/softfp-hurd.patch
deleted file mode 100644
index 7e2a8a9c290..00000000000
--- a/pkgs/development/compilers/gcc-4.5/softfp-hurd.patch
+++ /dev/null
@@ -1,32 +0,0 @@
-This patch fixes undefined references to softp symbols (__multf3, __fixunstfsi,
-__subtf3, etc.) in libgcc_s.so on GNU/Hurd.
-
-Taken from <http://gcc.gnu.org/ml/gcc-patches/2010-04/msg00602.html>, with second
-hunk adjusted so that it applies to GCC 4.5.0.
-
-diff --git a/gcc/config.gcc b/gcc/config.gcc
-index 9e499cb..9aec392 100644
---- a/gcc/config.gcc
-+++ b/gcc/config.gcc
-@@ -3070,7 +3070,9 @@ case ${target} in
- 	i[34567]86-*-darwin* | x86_64-*-darwin*)
- 		tmake_file="${tmake_file} i386/t-fprules-softfp soft-fp/t-softfp"
- 		;;
--	i[34567]86-*-linux* | x86_64-*-linux* | i[34567]86-*-kfreebsd*-gnu | x86_64-*-kfreebsd*-gnu)
-+	i[34567]86-*-linux* | x86_64-*-linux* | \
-+	  i[34567]86-*-kfreebsd*-gnu | x86_64-*-kfreebsd*-gnu | \
-+	  i[34567]86-*-gnu*)
- 		tmake_file="${tmake_file} i386/t-fprules-softfp soft-fp/t-softfp i386/t-linux"
- 		;;
- 	ia64*-*-linux*)
-diff --git a/libgcc/config.host b/libgcc/config.host
---- a/libgcc/config.host
-+++ b/libgcc/config.host
-@@ -600,6 +600,7 @@ case ${host} in
- i[34567]86-*-darwin* | x86_64-*-darwin* | \
-   i[34567]86-*-kfreebsd*-gnu | x86_64-*-kfreebsd*-gnu | \
-   i[34567]86-*-linux* | x86_64-*-linux* | \
-+  i[34567]86-*-gnu* | \
-   i[34567]86-*-solaris2* | \
-   i[34567]86-*-cygwin* | i[34567]86-*-mingw* | x86_64-*-mingw*)
- 	if test "${host_address}" = 32; then
diff --git a/pkgs/development/compilers/gcc-4.5/sources.nix b/pkgs/development/compilers/gcc-4.5/sources.nix
index 4a9201d08eb..6059e03880b 100644
--- a/pkgs/development/compilers/gcc-4.5/sources.nix
+++ b/pkgs/development/compilers/gcc-4.5/sources.nix
@@ -1,26 +1,26 @@
 /* Automatically generated by `update-gcc.sh', do not edit.
-   For GCC 4.5.0.  */
+   For GCC 4.5.1.  */
 { fetchurl, optional, version, langC, langCC, langFortran, langJava, langAda }:
 
-assert version == "4.5.0";
+assert version == "4.5.1";
 optional /* langC */ true (fetchurl {
   url = "mirror://gcc/releases/gcc-${version}/gcc-core-${version}.tar.bz2";
-  sha256 = "19ykzyd938d4pblsihrsalk9ch1s23z57s0r5an8sqs7acv51r0g";
+  sha256 = "0sjjw3qfcpdk0fs5d2rhl0xqcaclg86ifbq45dbk9ca072l3fyxm";
 }) ++
 optional langCC (fetchurl {
   url = "mirror://gcc/releases/gcc-${version}/gcc-g++-${version}.tar.bz2";
-  sha256 = "0hialil4v2hi7klr14x6h5z7b9ryzzy9kchr96s2p9hmsm7famlk";
+  sha256 = "0j6ffb96b3r75hrjshg52llv21ax7r8jdx44hhj0maiisnl9wd55";
 }) ++
 optional langFortran (fetchurl {
   url = "mirror://gcc/releases/gcc-${version}/gcc-fortran-${version}.tar.bz2";
-  sha256 = "0anby974dikygjmxr6h1pd9s24fdps84fki1dijzhqqvq6lr3hbb";
+  sha256 = "0xgwjc3h5fc5c100bnw24c35255il33lj5qbgpxf0zl8di2q13aw";
 }) ++
 optional langJava (fetchurl {
   url = "mirror://gcc/releases/gcc-${version}/gcc-java-${version}.tar.bz2";
-  sha256 = "0mlbxyhj7svjgby5vrpc49l2vk0k0878nlx0ap6jqq7xdyysvlcn";
+  sha256 = "0mh37q4ibg05h1hdh39pkj1hycvdg6i79m4698knw7pppm14ax8q";
 }) ++
 optional langAda (fetchurl {
   url = "mirror://gcc/releases/gcc-${version}/gcc-ada-${version}.tar.bz2";
-  sha256 = "1yar842bixmh2n9siy8s383lg8mz611xjdbbacgcznwab601czzv";
+  sha256 = "11chdbl7h046lnl83k79vj7dvgxz6kq7cnmwx94z644vaiflg153";
 }) ++
 []
diff --git a/pkgs/development/interpreters/guile/cpp-4.5.patch b/pkgs/development/interpreters/guile/cpp-4.5.patch
new file mode 100644
index 00000000000..7e7671f0da0
--- /dev/null
+++ b/pkgs/development/interpreters/guile/cpp-4.5.patch
@@ -0,0 +1,24 @@
+Fix doc snarfing with GCC 4.5.
+From <http://git.savannah.gnu.org/cgit/guile.git/commit/?h=branch_release-1-8&id=aac41d28358cea594bb30f6e547afb82bb6004a6>.
+
+diff --git a/scripts/snarf-check-and-output-texi b/scripts/snarf-check-and-output-texi
+index ea33e17..8cd42e8 100755
+--- a/scripts/snarf-check-and-output-texi
++++ b/scripts/snarf-check-and-output-texi
+@@ -267,6 +267,17 @@ exec ${GUILE-guile} -l $0 -c "(apply $main (cdr (command-line)))" "$@"
+       (set! *file* file)
+       (set! *line* line))
+ 
++     ;; newer gccs like to throw around more location markers into the
++     ;; preprocessed source; these (hash . hash) bits are what they translate to
++     ;; in snarfy terms.
++     (('location ('string . file) ('int . line) ('hash . 'hash))
++      (set! *file* file)
++      (set! *line* line))
++
++     (('location ('hash . 'hash) ('string . file) ('int . line) ('hash . 'hash))
++      (set! *file* file)
++      (set! *line* line))
++
+      (('arglist rest ...)
+       (set! *args* (do-arglist rest)))
diff --git a/pkgs/development/interpreters/guile/default.nix b/pkgs/development/interpreters/guile/default.nix
index 8dd7953a42d..dae6a69bcb6 100644
--- a/pkgs/development/interpreters/guile/default.nix
+++ b/pkgs/development/interpreters/guile/default.nix
@@ -9,6 +9,8 @@ stdenv.mkDerivation rec {
     sha256 = "1czhcrn6l63xhsw3fjmv88djflqxbdpxjhgmwwvscm8rv4wn7vmz";
   };
 
+  patches = [ ./cpp-4.5.patch ];
+
   buildNativeInputs = [ makeWrapper gawk ];
   propagatedBuildInputs = [ readline gmp libtool ];
   selfBuildNativeInput = true;
@@ -31,6 +33,8 @@ stdenv.mkDerivation rec {
 
   # One test fails.
   # ERROR: file: "libtest-asmobs", message: "file not found"
+  # This is fixed here:
+  # <http://git.savannah.gnu.org/cgit/guile.git/commit/?h=branch_release-1-8&id=a0aa1e5b69d6ef0311aeea8e4b9a94eae18a1aaf>.
   doCheck = false;
 
   setupHook = ./setup-hook.sh;
diff --git a/pkgs/development/libraries/SDL/default.nix b/pkgs/development/libraries/SDL/default.nix
index ca1b7086e39..7205e0fa7ea 100644
--- a/pkgs/development/libraries/SDL/default.nix
+++ b/pkgs/development/libraries/SDL/default.nix
@@ -1,6 +1,7 @@
-{ stdenv, fetchurl, x11, libXrandr, pkgconfig
+{ stdenv, fetchurl, pkgconfig
 , openglSupport ? false, mesa ? null
 , alsaSupport ? true, alsaLib ? null
+, x11Support ? true, x11 ? null, libXrandr ? null
 , pulseaudioSupport ? true, pulseaudio ? null
 }:
 
@@ -8,10 +9,18 @@
 # PulseAudio.
 assert alsaSupport || pulseaudioSupport;
 
-assert openglSupport -> mesa != null;
+assert openglSupport -> (mesa != null && x11Support);
+assert x11Support -> (x11 != null && libXrandr != null);
 assert alsaSupport -> alsaLib != null;
 assert pulseaudioSupport -> pulseaudio != null;
 
+let
+  configureFlagsFun = attrs: ''
+        --disable-oss
+        --disable-x11-shared --disable-alsa-shared --enable-rpath --disable-pulseaudio-shared
+        ${if alsaSupport then "--with-alsa-prefix=${attrs.alsaLib}/lib" else ""}
+      '';
+in
 stdenv.mkDerivation rec {
   name = "SDL-1.2.14";
 
@@ -21,7 +30,7 @@ stdenv.mkDerivation rec {
   };
 
   # Since `libpulse*.la' contain `-lgdbm', PulseAudio must be propagated.
-  propagatedBuildInputs = [ x11 libXrandr ] ++
+  propagatedBuildInputs = stdenv.lib.optionals x11Support [ x11 libXrandr ] ++
     stdenv.lib.optional pulseaudioSupport pulseaudio;
 
   buildInputs = [ pkgconfig ] ++
@@ -31,11 +40,11 @@ stdenv.mkDerivation rec {
   # XXX: By default, SDL wants to dlopen() PulseAudio, in which case
   # we must arrange to add it to its RPATH; however, `patchelf' seems
   # to fail at doing this, hence `--disable-pulseaudio-shared'.
-  configureFlags = ''
-    --disable-oss
-    --disable-x11-shared --disable-alsa-shared --enable-rpath --disable-pulseaudio-shared
-    ${if alsaSupport then "--with-alsa-prefix=${alsaLib}/lib" else ""}
-  '';
+  configureFlags = configureFlagsFun { inherit alsaLib; };
+
+  crossAttrs = {
+      configureFlags = configureFlagsFun { alsaLib = alsaLib.hostDrv; };
+  };
 
   passthru = {inherit openglSupport;};
 
diff --git a/pkgs/development/libraries/acl/default.nix b/pkgs/development/libraries/acl/default.nix
index 06dd8cb2fb9..d3a3bbd38c5 100644
--- a/pkgs/development/libraries/acl/default.nix
+++ b/pkgs/development/libraries/acl/default.nix
@@ -1,21 +1,29 @@
 {stdenv, fetchurl, gettext, attr, libtool}:
 
-stdenv.mkDerivation {
-  name = "acl-2.2.47";
+stdenv.mkDerivation rec {
+  name = "acl-2.2.49";
 
   src = fetchurl {
-    url = http://nixos.org/tarballs/acl_2.2.47-1.tar.gz;
-    sha256 = "1j39g62fki0iyji9s62slgwdfskpkqy7rmjlqcnmsvsnxbxhc294";
+    url = "mirror://savannah/acl/${name}.src.tar.gz";
+    sha256 = "1mg5nxr0r9y08lmyxmm2lfss5jz1xzbs0npsc8597x2f5rsz9ixr";
   };
 
-  buildInputs = [gettext attr libtool];
+  buildNativeInputs = [gettext];
+  buildInputs = [attr libtool];
+
+  # Upstream use C++-style comments in C code. Remove them.
+  # This comment breaks compilation if too strict gcc flags are used.
+  patchPhase = ''
+    echo "Removing C++-style comments from include/acl.h"
+    sed -e '/^\/\//d' -i include/acl.h
+  '';
 
   configureFlags = "MAKE=make LIBTOOL=libtool MSGFMT=msgfmt MSGMERGE=msgmerge XGETTEXT=xgettext ZIP=gzip ECHO=echo SED=sed AWK=gawk";
 
   installTargets = "install install-lib install-dev";
 
   meta = {
-    homepage = ftp://oss.sgi.com/projects/xfs/cmd_tars/;
+    homepage = http://savannah.nongnu.org/projects/acl;
     description = "Library and tools for manipulating access control lists";
   };
 }
diff --git a/pkgs/development/libraries/attr/default.nix b/pkgs/development/libraries/attr/default.nix
index 532f97a9fdf..643b4cdaae5 100644
--- a/pkgs/development/libraries/attr/default.nix
+++ b/pkgs/development/libraries/attr/default.nix
@@ -1,22 +1,22 @@
 {stdenv, fetchurl, libtool, gettext}:
 
-stdenv.mkDerivation {
-  name = "attr-2.4.43";
+stdenv.mkDerivation rec {
+  name = "attr-2.4.44";
 
   src = fetchurl {
-    # The SGI site throws away old versions, so don't use it.
-    url = mirror://gentoo/distfiles/attr_2.4.43-1.tar.gz;
-    sha256 = "1gy5zspj8ynxv6q29r24d18cfvq06zirg1pxcdg27bg2ncrv4n6k";
+    url = "mirror://savannah/attr/${name}.src.tar.gz";
+    sha256 = "16244r2vrd57i5fnf7dz3yi2mcckc47jr9y539jvljrzwnw18qlz";
   };
 
-  buildInputs = [libtool gettext];
+  buildNativeInputs = [gettext];
+  buildInputs = [libtool];
 
   configureFlags = "MAKE=make LIBTOOL=libtool MSGFMT=msgfmt MSGMERGE=msgmerge XGETTEXT=xgettext ECHO=echo SED=sed AWK=gawk";
 
   installTargets = "install install-lib install-dev";
 
   meta = {
-    homepage = ftp://oss.sgi.com/projects/xfs/cmd_tars/;
+    homepage = http://savannah.nongnu.org/projects/attr/;
     description = "Library and tools for manipulating extended attributes";
   };
 }
diff --git a/pkgs/development/libraries/cloog-ppl/default.nix b/pkgs/development/libraries/cloog-ppl/default.nix
index b1372d79cb5..ca662d30eb0 100644
--- a/pkgs/development/libraries/cloog-ppl/default.nix
+++ b/pkgs/development/libraries/cloog-ppl/default.nix
@@ -1,16 +1,32 @@
-{ fetchurl, stdenv, ppl }:
+{ fetchurl, stdenv, ppl, static ? false }:
+
+let
+
+  # --with-host-libstdcxx helps when *ppl* is built statically.
+  # But I will suppose that this is statically built only when ppl is also
+  # statically built.
+  staticFlags =
+    assert static -> ppl.dontDisableStatic == true;
+    if static then " --enable-static --disable-shared --with-host-libstdcxx=-lstdc++" else "";
+    
+in
 
 stdenv.mkDerivation rec {
-  name = "cloog-ppl-0.15.7";
+  name = "cloog-ppl-0.15.9";
 
   src = fetchurl {
     url = "mirror://gcc/infrastructure/${name}.tar.gz";
-    sha256 = "0zb96524jk2l78gr5gw0wq3dnvdsmyr2av59v89zv5xcps417q55";
+    sha256 = "19a2n75k3d3n8llng25f2g88lpvd4zn0lm073rkndjw6l6yd8m4c";
   };
 
   propagatedBuildInputs = [ ppl ];
 
-  configureFlags = "--with-ppl=${ppl}";
+  configureFlags = "--with-ppl=${ppl}" + staticFlags;
+  dontDisableStatic = if static then true else false;
+
+  crossAttrs = {
+    configureFlags = "--with-ppl=${ppl.hostDrv}" + staticFlags;
+  };
 
   doCheck = true;
 
diff --git a/pkgs/development/libraries/cyrus-sasl/default.nix b/pkgs/development/libraries/cyrus-sasl/default.nix
index c9d14fe8465..0da4d5da3e7 100644
--- a/pkgs/development/libraries/cyrus-sasl/default.nix
+++ b/pkgs/development/libraries/cyrus-sasl/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, openssl, db4, gettext} :
+{ stdenv, fetchurl, openssl, db4, gettext, automake} :
 
 stdenv.mkDerivation {
   name = "cyrus-sasl-2.1.23";
@@ -9,6 +9,7 @@ stdenv.mkDerivation {
   };
   preConfigure=''
     configureFlags="--with-openssl=${openssl} --with-plugindir=$out/lib/sasl2 --with-configdir=$out/lib/sasl2 --enable-login"
+    cp ${automake}/share/automake*/config.{sub,guess} config
   '';
   buildInputs = [ openssl db4 gettext ];
   patches = [ ./cyrus-sasl-2.1.22-bad-elif.patch ];
diff --git a/pkgs/development/libraries/gdbm/default.nix b/pkgs/development/libraries/gdbm/default.nix
index d6f1d118f82..448fd04edd8 100644
--- a/pkgs/development/libraries/gdbm/default.nix
+++ b/pkgs/development/libraries/gdbm/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl }:
+{ stdenv, fetchurl, automake }:
 
 stdenv.mkDerivation rec {
   name = "gdbm-1.8.3";
@@ -9,6 +9,11 @@ stdenv.mkDerivation rec {
 
   patches = [ ./install.patch ];
 
+  # The fuloong2f is not supported by gdbm 1.8.3 still
+  preConfigure = ''
+    cp ${automake}/share/automake*/config.{sub,guess} .
+  '';
+
   meta = {
     description = "GNU DBM key/value database library";
     homepage = http://www.gnu.org/software/gdbm/;
diff --git a/pkgs/development/libraries/gettext/0.18.nix b/pkgs/development/libraries/gettext/0.18.nix
deleted file mode 100644
index f7f0cb0018c..00000000000
--- a/pkgs/development/libraries/gettext/0.18.nix
+++ /dev/null
@@ -1,66 +0,0 @@
-# XXX: Remove me when `stdenv-updates' is merged.
-
-{ stdenv, fetchurl, libiconv }:
-
-stdenv.mkDerivation (rec {
-  name = "gettext-0.18.1.1";
-  
-  src = fetchurl {
-    url = "mirror://gnu/gettext/${name}.tar.gz";
-    sha256 = "1sa3ch12qxa4h3ya6hkz119yclcccmincl9j20dhrdx5mykp3b4k";
-  };
-
-  configureFlags = "--disable-csharp";
-
-  # On cross building, gettext supposes that the wchar.h from libc
-  # does not fulfill gettext needs, so it tries to work with its
-  # own wchar.h file, which does not cope well with the system's
-  # wchar.h and stddef.h (gcc-4.3 - glibc-2.9)
-  preConfigure = ''
-    if test -n "$crossConfig"; then
-      echo gl_cv_func_wcwidth_works=yes > cachefile
-      configureFlags="$configureFlags --cache-file=`pwd`/cachefile"
-    fi
-  '';
-
-  crossAttrs = {
-    buildInputs = stdenv.lib.optional (stdenv.gccCross.libc ? libiconv)
-      stdenv.gccCross.libc.libiconv.hostDrv;
-  };
-
-  meta = {
-    description = "GNU gettext, a well integrated set of translation tools and documentation";
-
-    longDescription = ''
-      Usually, programs are written and documented in English, and use
-      English at execution time for interacting with users.  Using a common
-      language is quite handy for communication between developers,
-      maintainers and users from all countries.  On the other hand, most
-      people are less comfortable with English than with their own native
-      language, and would rather be using their mother tongue for day to
-      day's work, as far as possible.  Many would simply love seeing their
-      computer screen showing a lot less of English, and far more of their
-      own language.
-
-      GNU `gettext' is an important step for the GNU Translation Project, as
-      it is an asset on which we may build many other steps. This package
-      offers to programmers, translators, and even users, a well integrated
-      set of tools and documentation. Specifically, the GNU `gettext'
-      utilities are a set of tools that provides a framework to help other
-      GNU packages produce multi-lingual messages.
-    '';
-
-    homepage = http://www.gnu.org/software/gettext/;
-
-    maintainers = [ stdenv.lib.maintainers.ludo ];
-    platforms = stdenv.lib.platforms.all;
-  };
-}
-
-//
-
-(if (!stdenv.isLinux) # any non-GNU system
-    then {
-      buildInputs = [ libiconv ];
-    }
-    else {}))
diff --git a/pkgs/development/libraries/gettext/default.nix b/pkgs/development/libraries/gettext/default.nix
index 6b094fdc839..ddcfc327a9e 100644
--- a/pkgs/development/libraries/gettext/default.nix
+++ b/pkgs/development/libraries/gettext/default.nix
@@ -1,11 +1,13 @@
+# XXX: Remove me when `stdenv-updates' is merged.
+
 { stdenv, fetchurl, libiconv }:
 
 stdenv.mkDerivation (rec {
-  name = "gettext-0.17";
+  name = "gettext-0.18.1.1";
   
   src = fetchurl {
     url = "mirror://gnu/gettext/${name}.tar.gz";
-    sha256 = "1fipjpaxxwifdw6cbr7mkxp1yvy643i38nhlh7124bqnisxki5i0";
+    sha256 = "1sa3ch12qxa4h3ya6hkz119yclcccmincl9j20dhrdx5mykp3b4k";
   };
 
   configureFlags = "--disable-csharp";
@@ -21,6 +23,13 @@ stdenv.mkDerivation (rec {
     fi
   '';
 
+  crossAttrs = {
+    buildInputs = stdenv.lib.optional (stdenv.gccCross.libc ? libiconv)
+      stdenv.gccCross.libc.libiconv.hostDrv;
+    # Gettext fails to guess the cross compiler
+    configureFlags = "CXX=${stdenv.cross.config}-g++";
+  };
+
   meta = {
     description = "GNU gettext, a well integrated set of translation tools and documentation";
 
@@ -46,6 +55,7 @@ stdenv.mkDerivation (rec {
     homepage = http://www.gnu.org/software/gettext/;
 
     maintainers = [ stdenv.lib.maintainers.ludo ];
+    platforms = stdenv.lib.platforms.all;
   };
 }
 
diff --git a/pkgs/development/libraries/glib/2.24.x.nix b/pkgs/development/libraries/glib/2.24.x.nix
index 6fdb18e9b4d..0cdff4254b0 100644
--- a/pkgs/development/libraries/glib/2.24.x.nix
+++ b/pkgs/development/libraries/glib/2.24.x.nix
@@ -8,7 +8,8 @@ stdenv.mkDerivation rec {
     sha256 = "014c3da960bf17117371075c16495f05f36501db990851ceea658f15d2ea6d04";
   };
 
-  buildInputs = [ pkgconfig gettext perl libiconv ];
+  buildInputs = [ pkgconfig gettext libiconv ];
+  buildNativeInputs = [ perl ];
 
   propagatedBuildInputs = [ zlib ];
 
diff --git a/pkgs/development/libraries/glibc-2.11/builder.sh b/pkgs/development/libraries/glibc-2.11/builder.sh
index cbdb55b121b..9a1c1490019 100644
--- a/pkgs/development/libraries/glibc-2.11/builder.sh
+++ b/pkgs/development/libraries/glibc-2.11/builder.sh
@@ -22,10 +22,24 @@ postInstall() {
     
     test -f $out/etc/ld.so.cache && rm $out/etc/ld.so.cache
 
-    # Include the Linux kernel headers in Glibc, except the `scsi'
-    # subdirectory, which Glibc provides itself. 
-    (cd $out/include && ln -s $(ls -d $kernelHeaders/include/* | grep -v 'scsi$') .)
+    # FIXME: Use `test -n $linuxHeaders' when `kernelHeaders' has been
+    # renamed.
+    if test -z "$hurdHeaders"; then
+        # Include the Linux kernel headers in Glibc, except the `scsi'
+        # subdirectory, which Glibc provides itself.
+	(cd $out/include && \
+	 ln -sv $(ls -d $kernelHeaders/include/* | grep -v 'scsi$') .)
+    fi
 
+    if test -f "$out/lib/libhurduser.so"; then
+	# libc.so, libhurduser.so, and libmachuser.so depend on each
+	# other, so add them to libc.so (a RUNPATH on libc.so.0.3
+	# would be ignored by the cross-linker.)
+	echo "adding \`libhurduser.so' and \`libmachuser.so' to the \`libc.so' linker script..."
+	sed -i "$out/lib/libc.so" \
+	    -e"s|\(libc\.so\.[^ ]\+\>\)|\1 $out/lib/libhurduser.so $out/lib/libmachuser.so|g"
+    fi
+	
     # Fix for NIXOS-54 (ldd not working on x86_64).  Make a symlink
     # "lib64" to "lib".
     if test -n "$is64bit"; then
diff --git a/pkgs/development/libraries/glibc-2.11/builder2.sh b/pkgs/development/libraries/glibc-2.11/builder2.sh
deleted file mode 100644
index 7d1a05131c2..00000000000
--- a/pkgs/development/libraries/glibc-2.11/builder2.sh
+++ /dev/null
@@ -1,58 +0,0 @@
-### XXX: This file should replace `builder.sh' in the `stdenv-updates'
-### branch!
-
-# Glibc cannot have itself in its RPATH.
-export NIX_NO_SELF_RPATH=1
-
-source $stdenv/setup
-
-postConfigure() {
-    # Hack: get rid of the `-static' flag set by the bootstrap stdenv.
-    # This has to be done *after* `configure' because it builds some
-    # test binaries.
-    export NIX_CFLAGS_LINK=
-    export NIX_LDFLAGS_BEFORE=
-
-    export NIX_DONT_SET_RPATH=1
-    unset CFLAGS
-}
-
-
-postInstall() {
-    if test -n "$installLocales"; then
-        make -j${NIX_BUILD_CORES:-1} -l${NIX_BUILD_CORES:-1} localedata/install-locales
-    fi
-    
-    test -f $out/etc/ld.so.cache && rm $out/etc/ld.so.cache
-
-    # FIXME: Use `test -n $linuxHeaders' when `kernelHeaders' has been
-    # renamed.
-    if test -z "$hurdHeaders"; then
-        # Include the Linux kernel headers in Glibc, except the `scsi'
-        # subdirectory, which Glibc provides itself.
-	(cd $out/include && \
-	 ln -sv $(ls -d $kernelHeaders/include/* | grep -v 'scsi$') .)
-    fi
-
-    if test -f "$out/lib/libhurduser.so"; then
-	# libc.so, libhurduser.so, and libmachuser.so depend on each
-	# other, so add them to libc.so (a RUNPATH on libc.so.0.3
-	# would be ignored by the cross-linker.)
-	echo "adding \`libhurduser.so' and \`libmachuser.so' to the \`libc.so' linker script..."
-	sed -i "$out/lib/libc.so" \
-	    -e"s|\(libc\.so\.[^ ]\+\>\)|\1 $out/lib/libhurduser.so $out/lib/libmachuser.so|g"
-    fi
-	
-    # Fix for NIXOS-54 (ldd not working on x86_64).  Make a symlink
-    # "lib64" to "lib".
-    if test -n "$is64bit"; then
-        ln -s lib $out/lib64
-    fi
-
-    # This file, that should not remain in the glibc derivation,
-    # may have not been created during the preInstall
-    rm -f $out/lib/libgcc_s.so.1
-}
-
-
-genericBuild
diff --git a/pkgs/development/libraries/glibc-2.11/common.nix b/pkgs/development/libraries/glibc-2.11/common.nix
index 00d9b99cc51..b2dd01690df 100644
--- a/pkgs/development/libraries/glibc-2.11/common.nix
+++ b/pkgs/development/libraries/glibc-2.11/common.nix
@@ -11,9 +11,7 @@ cross :
 
 let
   # For GNU/Hurd, see below.
-  date = "20100512";
-  rev = "df4c3faf0ccc848b5a8086c222bdb42679a9798f";
-  version = if hurdHeaders != null then date else "2.11.1";
+  version = if hurdHeaders != null then "20100512" else "2.11.2";
 in
 
 assert (cross != null) -> (gccCross != null);
@@ -56,18 +54,19 @@ stdenv.mkDerivation ({
        does work because "status" will contain UNAVAIL after the
        failure to find mdns4_minimal. */
     ./nss-skip-unavail.patch
-
-    ++ [
-    /* Make it possible to override the locale-archive in NixOS. */
-    ./locale-override.patch
-
+  ++ [
     /* Have rpcgen(1) look for cpp(1) in $PATH.  */
     ./rpcgen-path.patch
 
     /* Make sure `nscd' et al. are linked against `libssp'.  */
     ./stack-protector-link.patch
-  ]
 
+    /* Fix for the check of -fgnu89-inline compiler flag */
+    ./gnu89-inline.patch
+
+    /* Allow nixos and nix handle the locale-archive. */
+    ./nix-locale-archive.patch
+  ]
   ++ stdenv.lib.optional (fetchgit == null)
     /* MOD_NANO definition, for ntp (taken from glibc upstream) */
     ./mod_nano.patch;
@@ -75,6 +74,7 @@ stdenv.mkDerivation ({
   configureFlags = [
     "-C"
     "--enable-add-ons"
+    "--localedir=/var/run/current-system/sw/lib/locale"
     (if kernelHeaders != null
      then "--with-headers=${kernelHeaders}/include"
      else "--without-headers")
@@ -91,7 +91,7 @@ stdenv.mkDerivation ({
     "--build=arm-linux-gnueabi"
     "--without-fp"
   ];
-
+  
   buildInputs = stdenv.lib.optionals (cross != null) [ gccCross ]
     ++ stdenv.lib.optional (mig != null) mig;
 
@@ -124,11 +124,11 @@ stdenv.mkDerivation ({
       # See <http://www.gnu.org/software/hurd/source_repositories/glibc.html>.
       url = "git://git.sv.gnu.org/hurd/glibc.git";
       sha256 = "f3590a54a9d897d121f91113949edbaaf3e30cdeacbb8d0a44de7b6564f6643e";
-      inherit rev;
+      rev = "df4c3faf0ccc848b5a8086c222bdb42679a9798f";
     }
     else fetchurl {
       url = "mirror://gnu/glibc/glibc-${version}.tar.bz2";
-      sha256 = "18azb6518ryqhkfmddr25p0h1s2msrmx7dblij58sjlnzh61vq34";
+      sha256 = "04w74879psq961cas1amidkg8fc1h6r9yj3plfr33v9y6vp7db62";
     };
 
   srcPorts = fetchurl {
@@ -154,7 +154,7 @@ stdenv.mkDerivation ({
     mkdir ../build
     cd ../build
 
-    configureScript="../$sourceRoot/configure"
+    configureScript="`pwd`/../$sourceRoot/configure"
 
     ${preConfigure}
   '';
diff --git a/pkgs/development/libraries/glibc-2.11/default.nix b/pkgs/development/libraries/glibc-2.11/default.nix
index a9d82e677b1..31a8ef13a4f 100644
--- a/pkgs/development/libraries/glibc-2.11/default.nix
+++ b/pkgs/development/libraries/glibc-2.11/default.nix
@@ -50,9 +50,6 @@ in
        # thing.
        inherit propagatedBuildInputs;
      };
-
-     # XXX: Remove this hack in `stdenv-updates'.
-     builder = ./builder2.sh;
    }
    else { })
 
@@ -77,5 +74,10 @@ in
 
         dontStrip=1
       '';
-   }
+
+      # To avoid a dependency on the build system 'bash'.
+      preFixup = ''
+        rm $out/bin/{ldd,tzselect,catchsegv,xtrace}
+      '';
+    }
    else {}))
diff --git a/pkgs/development/libraries/glibc-2.11/gnu89-inline.patch b/pkgs/development/libraries/glibc-2.11/gnu89-inline.patch
new file mode 100644
index 00000000000..16d8f914a19
--- /dev/null
+++ b/pkgs/development/libraries/glibc-2.11/gnu89-inline.patch
@@ -0,0 +1,26 @@
+diff --git a/configure b/configure
+index ce76653..fba6de2 100755
+--- a/configure
++++ b/configure
+@@ -6891,7 +6891,7 @@ fi
+ $as_echo "$libc_cv_gnu89_inline" >&6; }
+ if test $libc_cv_gnu89_inline = yes; then
+   libc_cv_gnu89_inline=-fgnu89-inline
+-else
++elif test $libc_cv_gnu89_inline = no; then
+   libc_cv_gnu89_inline=
+ fi
+ 
+diff --git a/configure.in b/configure.in
+index 182c683..b867371 100644
+--- a/configure.in
++++ b/configure.in
+@@ -1777,7 +1777,7 @@ fi
+ rm -f conftest*])
+ if test $libc_cv_gnu89_inline = yes; then
+   libc_cv_gnu89_inline=-fgnu89-inline
+-else
++elif test $libc_cv_gnu89_inline = no; then
+   libc_cv_gnu89_inline=
+ fi
+ AC_SUBST(libc_cv_gnu89_inline)
diff --git a/pkgs/development/libraries/glibc-2.11/locale-override.patch b/pkgs/development/libraries/glibc-2.11/locale-override.patch
deleted file mode 100644
index 108d0e35dac..00000000000
--- a/pkgs/development/libraries/glibc-2.11/locale-override.patch
+++ /dev/null
@@ -1,72 +0,0 @@
-diff -rc glibc-2.9-20081208-orig/locale/loadarchive.c glibc-2.9-20081208/locale/loadarchive.c
-*** glibc-2.9-20081208-orig/locale/loadarchive.c	2005-09-09 18:56:52.000000000 +0200
---- glibc-2.9-20081208/locale/loadarchive.c	2009-04-19 13:54:26.000000000 +0200
-***************
-*** 124,129 ****
---- 124,142 ----
-  }
-  
-  
-+ static int
-+ open_locale_archive ()
-+ {
-+   int fd = -1;
-+   char *path = getenv ("LOCALE_ARCHIVE");
-+   if (path)
-+     fd = open_not_cancel_2 (path, O_RDONLY|O_LARGEFILE);
-+   if (fd < 0)
-+     fd = open_not_cancel_2 (archfname, O_RDONLY|O_LARGEFILE);
-+   return fd;
-+ }
-+ 
-+ 
-  /* Find the locale *NAMEP in the locale archive, and return the
-     internalized data structure for its CATEGORY data.  If this locale has
-     already been loaded from the archive, just returns the existing data
-***************
-*** 203,209 ****
-        archmapped = &headmap;
-  
-        /* The archive has never been opened.  */
-!       fd = open_not_cancel_2 (archfname, O_RDONLY|O_LARGEFILE);
-        if (fd < 0)
-  	/* Cannot open the archive, for whatever reason.  */
-  	return NULL;
---- 216,222 ----
-        archmapped = &headmap;
-  
-        /* The archive has never been opened.  */
-!       fd = open_locale_archive ();
-        if (fd < 0)
-  	/* Cannot open the archive, for whatever reason.  */
-  	return NULL;
-***************
-*** 394,400 ****
-  	  if (fd == -1)
-  	    {
-  	      struct stat64 st;
-! 	      fd = open_not_cancel_2 (archfname, O_RDONLY|O_LARGEFILE);
-  	      if (fd == -1)
-  		/* Cannot open the archive, for whatever reason.  */
-  		return NULL;
---- 407,413 ----
-  	  if (fd == -1)
-  	    {
-  	      struct stat64 st;
-! 	      fd = open_locale_archive ();
-  	      if (fd == -1)
-  		/* Cannot open the archive, for whatever reason.  */
-  		return NULL;
-diff -rc glibc-2.9-20081208-orig/sysdeps/generic/unsecvars.h glibc-2.9-20081208/sysdeps/generic/unsecvars.h
-*** glibc-2.9-20081208-orig/sysdeps/generic/unsecvars.h	2006-10-11 18:24:05.000000000 +0200
---- glibc-2.9-20081208/sysdeps/generic/unsecvars.h	2009-04-19 13:55:34.000000000 +0200
-***************
-*** 16,21 ****
---- 16,22 ----
-    "LD_SHOW_AUXV\0"							      \
-    "LD_USE_LOAD_BIAS\0"							      \
-    "LOCALDOMAIN\0"							      \
-+   "LOCALE_ARCHIVE\0"							      \
-    "LOCPATH\0"								      \
-    "MALLOC_TRACE\0"							      \
-    "NIS_PATH\0"								      \
diff --git a/pkgs/development/libraries/glibc-2.11/nix-locale-archive.patch b/pkgs/development/libraries/glibc-2.11/nix-locale-archive.patch
new file mode 100644
index 00000000000..30e05498662
--- /dev/null
+++ b/pkgs/development/libraries/glibc-2.11/nix-locale-archive.patch
@@ -0,0 +1,122 @@
+diff --git a/locale/loadarchive.c b/locale/loadarchive.c
+index d545f17..0d8638a 100644
+--- a/locale/loadarchive.c
++++ b/locale/loadarchive.c
+@@ -124,6 +124,25 @@ calculate_head_size (const struct locarhead *h)
+ }
+ 
+ 
++static int
++open_locale_archive ()
++{
++  int fd = -1;
++  char *path = getenv ("LOCALE_ARCHIVE_2_11");
++  char *path2 = getenv ("LOCALE_ARCHIVE");
++  const char *usualpath = "/usr/lib/locale/locale-archive";
++  if (path)
++    fd = open_not_cancel_2 (path, O_RDONLY|O_LARGEFILE);
++  if (path2 && fd < 0)
++    fd = open_not_cancel_2 (path2, O_RDONLY|O_LARGEFILE);
++  if (fd < 0)
++    fd = open_not_cancel_2 (archfname, O_RDONLY|O_LARGEFILE);
++  if (fd < 0)
++    fd = open_not_cancel_2 (usualpath, O_RDONLY|O_LARGEFILE);
++  return fd;
++}
++
++
+ /* Find the locale *NAMEP in the locale archive, and return the
+    internalized data structure for its CATEGORY data.  If this locale has
+    already been loaded from the archive, just returns the existing data
+@@ -203,7 +222,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
+       archmapped = &headmap;
+ 
+       /* The archive has never been opened.  */
+-      fd = open_not_cancel_2 (archfname, O_RDONLY|O_LARGEFILE);
++      fd = open_locale_archive ();
+       if (fd < 0)
+ 	/* Cannot open the archive, for whatever reason.  */
+ 	return NULL;
+@@ -394,7 +413,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
+ 	  if (fd == -1)
+ 	    {
+ 	      struct stat64 st;
+-	      fd = open_not_cancel_2 (archfname, O_RDONLY|O_LARGEFILE);
++	      fd = open_locale_archive ();
+ 	      if (fd == -1)
+ 		/* Cannot open the archive, for whatever reason.  */
+ 		return NULL;
+diff --git a/locale/programs/locale.c b/locale/programs/locale.c
+index 77262b7..fddc00d 100644
+--- a/locale/programs/locale.c
++++ b/locale/programs/locale.c
+@@ -628,6 +628,23 @@ nameentcmp (const void *a, const void *b)
+ 		  ((const struct nameent *) b)->name);
+ }
+ 
++static int
++open_nix_locale_archive (const char * fname, int access)
++{
++  int fd = -1;
++  char *path = getenv ("LOCALE_ARCHIVE_2_11");
++  char *path2 = getenv ("LOCALE_ARCHIVE");
++  const char *usualpath = "/usr/lib/locale/locale-archive";
++  if (path)
++    fd = open64 (path, access);
++  if (path2 && fd < 0)
++    fd = open64 (path2, access);
++  if (fd < 0)
++    fd = open64 (fname, access);
++  if (fd < 0)
++    fd = open64 (usualpath, access);
++  return fd;
++}
+ 
+ static int
+ write_archive_locales (void **all_datap, char *linebuf)
+@@ -641,7 +658,7 @@ write_archive_locales (void **all_datap, char *linebuf)
+   int fd, ret = 0;
+   uint32_t cnt;
+ 
+-  fd = open64 (ARCHIVE_NAME, O_RDONLY);
++  fd = open_nix_locale_archive (ARCHIVE_NAME, O_RDONLY);
+   if (fd < 0)
+     return 0;
+ 
+diff --git a/locale/programs/locarchive.c b/locale/programs/locarchive.c
+index 85ba77d..3ad2af8 100644
+--- a/locale/programs/locarchive.c
++++ b/locale/programs/locarchive.c
+@@ -512,6 +512,23 @@ enlarge_archive (struct locarhandle *ah, const struct locarhead *head)
+   *ah = new_ah;
+ }
+ 
++static int
++open_nix_locale_archive (const char * fname, int access)
++{
++  int fd = -1;
++  char *path = getenv ("LOCALE_ARCHIVE_2_11");
++  char *path2 = getenv ("LOCALE_ARCHIVE");
++  const char *usualpath = "/usr/lib/locale/locale-archive";
++  if (path)
++    fd = open64 (path, access);
++  if (path2 && fd < 0)
++    fd = open64 (path2, access);
++  if (fd < 0)
++    fd = open64 (fname, access);
++  if (fd < 0)
++    fd = open64 (usualpath, access);
++  return fd;
++}
+ 
+ void
+ open_archive (struct locarhandle *ah, bool readonly)
+@@ -531,7 +548,7 @@ open_archive (struct locarhandle *ah, bool readonly)
+   while (1)
+     {
+       /* Open the archive.  We must have exclusive write access.  */
+-      fd = open64 (archivefname, readonly ? O_RDONLY : O_RDWR);
++      fd = open_nix_locale_archive (archivefname, readonly ? O_RDONLY : O_RDWR);
+       if (fd == -1)
+ 	{
+ 	  /* Maybe the file does not yet exist.  */
diff --git a/pkgs/development/libraries/glibc-2.11/nss-skip-unavail.patch b/pkgs/development/libraries/glibc-2.11/nss-skip-unavail.patch
index dc09b509870..e48dc2bc0a6 100644
--- a/pkgs/development/libraries/glibc-2.11/nss-skip-unavail.patch
+++ b/pkgs/development/libraries/glibc-2.11/nss-skip-unavail.patch
@@ -1,25 +1,21 @@
-diff -rc glibc-2.9-20081208-orig/sysdeps/posix/getaddrinfo.c glibc-2.9-20081208/sysdeps/posix/getaddrinfo.c
-*** glibc-2.9-20081208-orig/sysdeps/posix/getaddrinfo.c	2008-07-30 21:14:22.000000000 +0200
---- glibc-2.9-20081208/sysdeps/posix/getaddrinfo.c	2008-12-10 11:39:32.000000000 +0100
-***************
-*** 505,512 ****
-  	  int no_data = 0;
-  	  int no_inet6_data = 0;
-  	  service_user *nip = NULL;
-- 	  enum nss_status inet6_status = NSS_STATUS_UNAVAIL;
-- 	  enum nss_status status = NSS_STATUS_UNAVAIL;
-  	  int no_more;
-  	  int old_res_options;
-  
---- 505,510 ----
-***************
-*** 702,707 ****
---- 700,707 ----
-  
-  	  while (!no_more)
-  	    {
+diff -ru glibc-2.11.2-orig/sysdeps/posix/getaddrinfo.c glibc-2.11.2/sysdeps/posix/getaddrinfo.c
+--- glibc-2.11.2-orig/sysdeps/posix/getaddrinfo.c	2010-05-19 22:38:20.000000000 +0200
++++ glibc-2.11.2/sysdeps/posix/getaddrinfo.c	2010-08-05 18:39:54.259556327 +0200
+@@ -505,8 +505,6 @@
+ 	  int no_data = 0;
+ 	  int no_inet6_data = 0;
+ 	  service_user *nip = NULL;
+-	  enum nss_status inet6_status = NSS_STATUS_UNAVAIL;
+-	  enum nss_status status = NSS_STATUS_UNAVAIL;
+ 	  int no_more;
+ 	  int old_res_options;
+ 
+@@ -702,6 +700,8 @@
+ 
+ 	  while (!no_more)
+ 	    {
 + 	      enum nss_status inet6_status = NSS_STATUS_UNAVAIL;
 + 	      enum nss_status status = NSS_STATUS_UNAVAIL;
-  	      nss_gethostbyname4_r fct4
-  		= __nss_lookup_function (nip, "gethostbyname4_r");
-  	      if (fct4 != NULL)
+ 	      no_data = 0;
+ 	      nss_gethostbyname4_r fct4
+ 		= __nss_lookup_function (nip, "gethostbyname4_r");
diff --git a/pkgs/development/libraries/gmp/4.nix b/pkgs/development/libraries/gmp/4.nix
new file mode 100644
index 00000000000..c5a59045bbe
--- /dev/null
+++ b/pkgs/development/libraries/gmp/4.nix
@@ -0,0 +1,59 @@
+{stdenv, fetchurl, m4, cxx ? true, static ? false}:
+
+let
+  staticFlags = if static then " --enable-static --disable-shared" else "";
+in
+
+stdenv.mkDerivation rec {
+  name = "gmp-4.3.2";
+
+  src = fetchurl {
+    url = "mirror://gnu/gmp/${name}.tar.bz2";
+    sha256 = "0x8prpqi9amfcmi7r4zrza609ai9529pjaq0h4aw51i867064qck";
+  };
+
+  buildNativeInputs = [m4];
+
+  # Prevent the build system from using sub-architecture-specific
+  # instructions (e.g., SSE2 on i686).
+  preConfigure = "ln -sf configfsf.guess config.guess";
+
+  configureFlags = (if cxx then "--enable-cxx" else "--disable-cxx") +
+      staticFlags;
+
+  dontDisableStatic = if static then true else false;
+
+  doCheck = true;
+
+  meta = {
+    description = "GMP, the GNU multiple precision arithmetic library";
+
+    longDescription =
+      '' GMP is a free library for arbitrary precision arithmetic, operating
+         on signed integers, rational numbers, and floating point numbers.
+         There is no practical limit to the precision except the ones implied
+         by the available memory in the machine GMP runs on.  GMP has a rich
+         set of functions, and the functions have a regular interface.
+
+         The main target applications for GMP are cryptography applications
+         and research, Internet security applications, algebra systems,
+         computational algebra research, etc.
+
+         GMP is carefully designed to be as fast as possible, both for small
+         operands and for huge operands.  The speed is achieved by using
+         fullwords as the basic arithmetic type, by using fast algorithms,
+         with highly optimised assembly code for the most common inner loops
+         for a lot of CPUs, and by a general emphasis on speed.
+
+         GMP is faster than any other bignum library.  The advantage for GMP
+         increases with the operand sizes for many operations, since GMP uses
+         asymptotically faster algorithms.
+      '';
+
+    homepage = http://gmplib.org/;
+    license = "LGPLv3+";
+
+    maintainers = [ stdenv.lib.maintainers.ludo ];
+    platforms = stdenv.lib.platforms.all;
+  };
+}
diff --git a/pkgs/development/libraries/gmp/default.nix b/pkgs/development/libraries/gmp/default.nix
index ac20bc68f4d..338debaa81e 100644
--- a/pkgs/development/libraries/gmp/default.nix
+++ b/pkgs/development/libraries/gmp/default.nix
@@ -1,27 +1,61 @@
-{stdenv, fetchurl, m4, cxx ? true}:
+{stdenv, fetchurl, m4, cxx ? true, static ? false}:
+
+let
+  staticFlags = if static then " --enable-static --disable-shared" else "";
+in
 
 stdenv.mkDerivation rec {
-  name = "gmp-4.3.2";
+  name = "gmp-5.0.1";
 
   src = fetchurl {
     url = "mirror://gnu/gmp/${name}.tar.bz2";
-    sha256 = "0x8prpqi9amfcmi7r4zrza609ai9529pjaq0h4aw51i867064qck";
+    sha256 = "1yrr14l6vvhm1g27y8nb3c75j0i4ii4k1gw7ik08safk3zq119m2";
   };
 
   buildNativeInputs = [m4];
 
+  # Prevent the build system from using sub-architecture-specific
+  # instructions (e.g., SSE2 on i686).
   preConfigure = "ln -sf configfsf.guess config.guess";
 
-  configureFlags = if cxx then "--enable-cxx" else "--disable-cxx";
+  configureFlags = if cxx then "--enable-cxx" else "--disable-cxx" +
+      staticFlags;
+
+  dontDisableStatic = if static then true else false;
 
   doCheck = true;
 
   enableParallelBuilding = true;
 
   meta = {
-    description = "A free library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating point numbers";
+    description = "GMP, the GNU multiple precision arithmetic library";
+
+    longDescription =
+      '' GMP is a free library for arbitrary precision arithmetic, operating
+         on signed integers, rational numbers, and floating point numbers.
+         There is no practical limit to the precision except the ones implied
+         by the available memory in the machine GMP runs on.  GMP has a rich
+         set of functions, and the functions have a regular interface.
+
+         The main target applications for GMP are cryptography applications
+         and research, Internet security applications, algebra systems,
+         computational algebra research, etc.
+
+         GMP is carefully designed to be as fast as possible, both for small
+         operands and for huge operands.  The speed is achieved by using
+         fullwords as the basic arithmetic type, by using fast algorithms,
+         with highly optimised assembly code for the most common inner loops
+         for a lot of CPUs, and by a general emphasis on speed.
+
+         GMP is faster than any other bignum library.  The advantage for GMP
+         increases with the operand sizes for many operations, since GMP uses
+         asymptotically faster algorithms.
+      '';
+
     homepage = http://gmplib.org/;
-    license = "LGPL";
+    license = "LGPLv3+";
+
+    maintainers = [ stdenv.lib.maintainers.ludo ];
     platforms = stdenv.lib.platforms.all;
   };
 }
diff --git a/pkgs/development/libraries/libgcrypt/default.nix b/pkgs/development/libraries/libgcrypt/default.nix
index 438cc212b54..038fbef69e5 100644
--- a/pkgs/development/libraries/libgcrypt/default.nix
+++ b/pkgs/development/libraries/libgcrypt/default.nix
@@ -1,11 +1,11 @@
 { fetchurl, stdenv, libgpgerror }:
 
 stdenv.mkDerivation rec {
-  name = "libgcrypt-1.4.5";
+  name = "libgcrypt-1.4.6";
 
   src = fetchurl {
     url = "mirror://gnupg/libgcrypt/${name}.tar.bz2";
-    sha256 = "0h4ypld775rm1g15v134pkq9wc6ixszn6766gqv7bpi4ady90vs9";
+    sha256 = "11bbpjlqwp0nh4q76wmsk6z1812anqrj28nh6d9mcyrmdgd30jry";
   };
 
   propagatedBuildInputs = [ libgpgerror ];
diff --git a/pkgs/development/libraries/libxcrypt/default.nix b/pkgs/development/libraries/libxcrypt/default.nix
index 1ae5d3054f4..bc4272da3c8 100644
--- a/pkgs/development/libraries/libxcrypt/default.nix
+++ b/pkgs/development/libraries/libxcrypt/default.nix
@@ -1,7 +1,8 @@
 {stdenv, fetchurl}:
 
-# I could not build it in armv5tel-linux
+# I could not build it in armv5tel-linux or the fuloon2f
 assert stdenv.system != "armv5tel-linux";
+assert stdenv.system != "ict_loongson-2_v0.3_fpu_v0.1-linux";
    
 stdenv.mkDerivation {
   name = "libxcrypt-3.0.2";
diff --git a/pkgs/development/libraries/mesa/default.nix b/pkgs/development/libraries/mesa/default.nix
index d878135923d..1060ae8f738 100644
--- a/pkgs/development/libraries/mesa/default.nix
+++ b/pkgs/development/libraries/mesa/default.nix
@@ -14,6 +14,8 @@ stdenv.mkDerivation {
 
   configureFlags =
     "--disable-gallium"
+    + (if stdenv.system == "ict_loongson-2_v0.3_fpu_v0.1-linux" then
+      " --with-dri-drivers=swrast --with-driver=dri" else "")
     + (if stdenv.isDarwin then " --disable-egl" else "");
 
   buildInputs =
diff --git a/pkgs/development/libraries/mpfr/default.nix b/pkgs/development/libraries/mpfr/default.nix
index 1bfd1448200..94cf6e3cea5 100644
--- a/pkgs/development/libraries/mpfr/default.nix
+++ b/pkgs/development/libraries/mpfr/default.nix
@@ -10,6 +10,8 @@ stdenv.mkDerivation rec {
 
   buildInputs = [ gmp ];
 
+  patches = [ ./patch01.patch ./patch02.patch ];
+
   doCheck = true;
 
   enableParallelBuilding = true;
diff --git a/pkgs/development/libraries/mpfr/patch01.patch b/pkgs/development/libraries/mpfr/patch01.patch
new file mode 100644
index 00000000000..2721517c428
--- /dev/null
+++ b/pkgs/development/libraries/mpfr/patch01.patch
@@ -0,0 +1,184 @@
+diff -Naurd mpfr-2.4.2-a/PATCHES mpfr-2.4.2-b/PATCHES
+--- mpfr-2.4.2-a/PATCHES	2009-12-07 13:37:12.000000000 +0000
++++ mpfr-2.4.2-b/PATCHES	2009-12-07 13:37:12.000000000 +0000
+@@ -0,0 +1 @@
++sin_cos_underflow
+diff -Naurd mpfr-2.4.2-a/VERSION mpfr-2.4.2-b/VERSION
+--- mpfr-2.4.2-a/VERSION	2009-11-30 02:43:08.000000000 +0000
++++ mpfr-2.4.2-b/VERSION	2009-12-07 13:37:12.000000000 +0000
+@@ -1 +1 @@
+-2.4.2
++2.4.2-p1
+diff -Naurd mpfr-2.4.2-a/mpfr.h mpfr-2.4.2-b/mpfr.h
+--- mpfr-2.4.2-a/mpfr.h	2009-11-30 02:43:08.000000000 +0000
++++ mpfr-2.4.2-b/mpfr.h	2009-12-07 13:37:12.000000000 +0000
+@@ -27,7 +27,7 @@
+ #define MPFR_VERSION_MAJOR 2
+ #define MPFR_VERSION_MINOR 4
+ #define MPFR_VERSION_PATCHLEVEL 2
+-#define MPFR_VERSION_STRING "2.4.2"
++#define MPFR_VERSION_STRING "2.4.2-p1"
+ 
+ /* Macros dealing with MPFR VERSION */
+ #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
+diff -Naurd mpfr-2.4.2-a/sin_cos.c mpfr-2.4.2-b/sin_cos.c
+--- mpfr-2.4.2-a/sin_cos.c	2009-11-30 02:43:09.000000000 +0000
++++ mpfr-2.4.2-b/sin_cos.c	2009-12-07 13:37:12.000000000 +0000
+@@ -82,17 +82,19 @@
+       if (y != x)
+         /* y and x differ, thus we can safely try to compute y first */
+         {
+-          MPFR_FAST_COMPUTE_IF_SMALL_INPUT (y, x, -2 * expx, 2, 0, rnd_mode,
+-                                            { inexy = _inexact;
+-                                              goto small_input; });
++          MPFR_FAST_COMPUTE_IF_SMALL_INPUT (
++            y, x, -2 * expx, 2, 0, rnd_mode,
++            { inexy = _inexact;
++              goto small_input; });
+           if (0)
+             {
+             small_input:
+               /* we can go here only if we can round sin(x) */
+-              MPFR_FAST_COMPUTE_IF_SMALL_INPUT (z, __gmpfr_one, -2 * expx,
+-                                                1, 0, rnd_mode,
+-                                                { inexz = _inexact;
+-                                                  goto end; });
++              MPFR_FAST_COMPUTE_IF_SMALL_INPUT (
++                z, __gmpfr_one, -2 * expx, 1, 0, rnd_mode,
++                { inexz = _inexact;
++                  MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, __gmpfr_flags);
++                  goto end; });
+             }
+ 
+           /* if we go here, one of the two MPFR_FAST_COMPUTE_IF_SMALL_INPUT
+@@ -101,18 +103,19 @@
+       else /* y and x are the same variable: try to compute z first, which
+               necessarily differs */
+         {
+-          MPFR_FAST_COMPUTE_IF_SMALL_INPUT (z, __gmpfr_one, -2 * expx,
+-                                            1, 0, rnd_mode,
+-                                            { inexz = _inexact;
+-                                              goto small_input2; });
++          MPFR_FAST_COMPUTE_IF_SMALL_INPUT (
++            z, __gmpfr_one, -2 * expx, 1, 0, rnd_mode,
++            { inexz = _inexact;
++              goto small_input2; });
+           if (0)
+             {
+             small_input2:
+               /* we can go here only if we can round cos(x) */
+-              MPFR_FAST_COMPUTE_IF_SMALL_INPUT (y, x, -2 * expx, 2, 0,
+-                                                rnd_mode,
+-                                                { inexy = _inexact;
+-                                                  goto end; });
++              MPFR_FAST_COMPUTE_IF_SMALL_INPUT (
++                y, x, -2 * expx, 2, 0, rnd_mode,
++                { inexy = _inexact;
++                  MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, __gmpfr_flags);
++                  goto end; });
+             }
+         }
+       m += 2 * (-expx);
+@@ -207,7 +210,6 @@
+   mpfr_clear (xr);
+ 
+  end:
+-  /* FIXME: update the underflow flag if need be. */
+   MPFR_SAVE_EXPO_FREE (expo);
+   mpfr_check_range (y, inexy, rnd_mode);
+   mpfr_check_range (z, inexz, rnd_mode);
+diff -Naurd mpfr-2.4.2-a/tests/tsin_cos.c mpfr-2.4.2-b/tests/tsin_cos.c
+--- mpfr-2.4.2-a/tests/tsin_cos.c	2009-11-30 02:43:08.000000000 +0000
++++ mpfr-2.4.2-b/tests/tsin_cos.c	2009-12-07 13:37:12.000000000 +0000
+@@ -382,23 +382,56 @@
+ consistency (void)
+ {
+   mpfr_t x, s1, s2, c1, c2;
++  mp_exp_t emin, emax;
+   mp_rnd_t rnd;
++  unsigned int flags_sin, flags_cos, flags, flags_before, flags_ref;
++  int inex_sin, inex_cos, inex, inex_ref;
+   int i;
+ 
++  emin = mpfr_get_emin ();
++  emax = mpfr_get_emax ();
++
+   for (i = 0; i <= 10000; i++)
+     {
+       mpfr_init2 (x, MPFR_PREC_MIN + (randlimb () % 8));
+       mpfr_inits2 (MPFR_PREC_MIN + (randlimb () % 8), s1, s2, c1, c2,
+                    (mpfr_ptr) 0);
+-      tests_default_random (x, 256, -5, 50);
+-      rnd = RND_RAND ();
+-      mpfr_sin (s1, x, rnd);
+-      mpfr_cos (c1, x, rnd);
+-      mpfr_sin_cos (s2, c2, x, rnd);
+-      if (!(mpfr_equal_p (s1, s2) && mpfr_equal_p (c1, c2)))
++      if (i < 8 * GMP_RND_MAX)
+         {
+-          printf ("mpfr_sin_cos and mpfr_sin/mpfr_cos disagree on %s,\nx = ",
+-                  mpfr_print_rnd_mode (rnd));
++          int j = i / GMP_RND_MAX;
++          if (j & 1)
++            mpfr_set_emin (MPFR_EMIN_MIN);
++          mpfr_set_si (x, (j & 2) ? 1 : -1, GMP_RNDN);
++          mpfr_set_exp (x, mpfr_get_emin ());
++          rnd = (mpfr_rnd_t) (i % GMP_RND_MAX);
++          flags_before = 0;
++          if (j & 4)
++            mpfr_set_emax (-17);
++        }
++      else
++        {
++          tests_default_random (x, 256, -5, 50);
++          rnd = RND_RAND ();
++          flags_before = (randlimb () & 1) ?
++            (unsigned int) (MPFR_FLAGS_ALL ^ MPFR_FLAGS_ERANGE) :
++            (unsigned int) 0;
++        }
++      __gmpfr_flags = flags_before;
++      inex_sin = mpfr_sin (s1, x, rnd);
++      flags_sin = __gmpfr_flags;
++      __gmpfr_flags = flags_before;
++      inex_cos = mpfr_cos (c1, x, rnd);
++      flags_cos = __gmpfr_flags;
++      __gmpfr_flags = flags_before;
++      inex = !!mpfr_sin_cos (s2, c2, x, rnd);
++      flags = __gmpfr_flags;
++      inex_ref = inex_sin || inex_cos;
++      flags_ref = flags_sin | flags_cos;
++      if (!(mpfr_equal_p (s1, s2) && mpfr_equal_p (c1, c2)) ||
++          inex != inex_ref || flags != flags_ref)
++        {
++          printf ("mpfr_sin_cos and mpfr_sin/mpfr_cos disagree on %s,"
++                  " i = %d\nx = ", mpfr_print_rnd_mode (rnd), i);
+           mpfr_dump (x);
+           printf ("s1 = ");
+           mpfr_dump (s1);
+@@ -408,9 +441,16 @@
+           mpfr_dump (c1);
+           printf ("c2 = ");
+           mpfr_dump (c2);
++          printf ("inex_sin = %d, inex_cos = %d, inex = %d (expected %d)\n",
++                  inex_sin, inex_cos, inex, inex_ref);
++          printf ("flags_sin = 0x%x, flags_cos = 0x%x, "
++                  "flags = 0x%x (expected 0x%x)\n",
++                  flags_sin, flags_cos, flags, flags_ref);
+           exit (1);
+         }
+       mpfr_clears (x, s1, s2, c1, c2, (mpfr_ptr) 0);
++      mpfr_set_emin (emin);
++      mpfr_set_emax (emax);
+     }
+ }
+ 
+diff -Naurd mpfr-2.4.2-a/version.c mpfr-2.4.2-b/version.c
+--- mpfr-2.4.2-a/version.c	2009-11-30 02:43:08.000000000 +0000
++++ mpfr-2.4.2-b/version.c	2009-12-07 13:37:12.000000000 +0000
+@@ -25,5 +25,5 @@
+ const char *
+ mpfr_get_version (void)
+ {
+-  return "2.4.2";
++  return "2.4.2-p1";
+ }
diff --git a/pkgs/development/libraries/mpfr/patch02.patch b/pkgs/development/libraries/mpfr/patch02.patch
new file mode 100644
index 00000000000..bc2f267acc0
--- /dev/null
+++ b/pkgs/development/libraries/mpfr/patch02.patch
@@ -0,0 +1,75 @@
+From http://www.mpfr.org/mpfr-2.4.2/:
+Due to a change in GCC 4.4 internals for MIPS, the MPFR build fails on MIPS processors with GCC 4.4 and later. The longlong.h  patch (written by Aurélien Jarno) solves this problem.
+[Changeset: 6638]
+
+diff -Naurd mpfr-2.4.2-a/PATCHES mpfr-2.4.2-b/PATCHES
+--- mpfr-2.4.2-a/PATCHES	2009-12-18 12:03:30.000000000 +0000
++++ mpfr-2.4.2-b/PATCHES	2009-12-18 12:05:19.000000000 +0000
+@@ -0,0 +1 @@
++longlong.h
+diff -Naurd mpfr-2.4.2-a/VERSION mpfr-2.4.2-b/VERSION
+--- mpfr-2.4.2-a/VERSION	2009-12-07 13:37:12.000000000 +0000
++++ mpfr-2.4.2-b/VERSION	2009-12-18 12:05:09.000000000 +0000
+@@ -1 +1 @@
+-2.4.2-p1
++2.4.2-p2
+diff -Naurd mpfr-2.4.2-a/mpfr-longlong.h mpfr-2.4.2-b/mpfr-longlong.h
+--- mpfr-2.4.2-a/mpfr-longlong.h	2009-11-30 02:43:08.000000000 +0000
++++ mpfr-2.4.2-b/mpfr-longlong.h	2009-12-18 12:04:29.000000000 +0000
+@@ -1011,7 +1011,15 @@
+ #endif /* __m88000__ */
+ 
+ #if defined (__mips) && W_TYPE_SIZE == 32
+-#if __GNUC__ > 2 || __GNUC_MINOR__ >= 7
++#if (__GNUC__ >= 5) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 4)
++#define umul_ppmm(w1, w0, u, v) \
++  do {									\
++    UDItype _r;							\
++    _r = (UDItype) u * v;						\
++    (w1) = _r >> 32;							\
++    (w0) = (USItype) _r;						\
++  } while (0)
++#elif __GNUC__ > 2 || __GNUC_MINOR__ >= 7
+ #define umul_ppmm(w1, w0, u, v) \
+   __asm__ ("multu %2,%3" : "=l" (w0), "=h" (w1) : "d" (u), "d" (v))
+ #else
+@@ -1024,7 +1032,16 @@
+ #endif /* __mips */
+ 
+ #if (defined (__mips) && __mips >= 3) && W_TYPE_SIZE == 64
+-#if __GNUC__ > 2 || __GNUC_MINOR__ >= 7
++#if (__GNUC__ >= 5) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 4)
++typedef unsigned int UTItype __attribute__ ((mode (TI)));
++#define umul_ppmm(w1, w0, u, v) \
++  do {									\
++    UTItype _r;							\
++    _r = (UTItype) u * v;						\
++    (w1) = _r >> 64;							\
++    (w0) = (UDItype) _r;						\
++  } while (0)
++#elif __GNUC__ > 2 || __GNUC_MINOR__ >= 7
+ #define umul_ppmm(w1, w0, u, v) \
+   __asm__ ("dmultu %2,%3" : "=l" (w0), "=h" (w1) : "d" (u), "d" (v))
+ #else
+diff -Naurd mpfr-2.4.2-a/mpfr.h mpfr-2.4.2-b/mpfr.h
+--- mpfr-2.4.2-a/mpfr.h	2009-12-07 13:37:12.000000000 +0000
++++ mpfr-2.4.2-b/mpfr.h	2009-12-18 12:05:09.000000000 +0000
+@@ -27,7 +27,7 @@
+ #define MPFR_VERSION_MAJOR 2
+ #define MPFR_VERSION_MINOR 4
+ #define MPFR_VERSION_PATCHLEVEL 2
+-#define MPFR_VERSION_STRING "2.4.2-p1"
++#define MPFR_VERSION_STRING "2.4.2-p2"
+ 
+ /* Macros dealing with MPFR VERSION */
+ #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
+diff -Naurd mpfr-2.4.2-a/version.c mpfr-2.4.2-b/version.c
+--- mpfr-2.4.2-a/version.c	2009-12-07 13:37:12.000000000 +0000
++++ mpfr-2.4.2-b/version.c	2009-12-18 12:05:09.000000000 +0000
+@@ -25,5 +25,5 @@
+ const char *
+ mpfr_get_version (void)
+ {
+-  return "2.4.2-p1";
++  return "2.4.2-p2";
+ }
diff --git a/pkgs/development/libraries/openssl/1.x.nix b/pkgs/development/libraries/openssl/1.x.nix
new file mode 100644
index 00000000000..eae32de30e4
--- /dev/null
+++ b/pkgs/development/libraries/openssl/1.x.nix
@@ -0,0 +1,45 @@
+{ stdenv, fetchurl, perl }:
+
+let
+  opensslCrossSystem = stdenv.lib.attrByPath [ "openssl" "system" ]
+    (throw "openssl needs its platform name cross building" null)
+    stdenv.cross;
+in
+
+stdenv.mkDerivation (rec {
+  name = "openssl-1.0.0";
+
+  src = fetchurl {
+    url = "http://www.openssl.org/source/${name}.tar.gz";
+    sha1 = "3f800ea9fa3da1c0f576d689be7dca3d55a4cb62";
+  };
+
+  buildNativeInputs = [ perl ];
+
+  configureScript = "./config";
+
+  configureFlags="--libdir=lib shared";
+
+  crossAttrs = {
+    preConfigure=''
+      export cross=$crossSystem-
+    '';
+    configureFlags="--libdir=lib ${opensslCrossSystem} shared";
+    buildPhase = ''
+      make CC=$crossConfig-gcc \
+        AR="$crossConfig-ar r" \
+        RANLIB=$crossConfig-ranlib
+    '';
+  };
+
+  meta = {
+    homepage = http://www.openssl.org/;
+    description = "A cryptographic library that implements the SSL and TLS protocols";
+  };
+}
+//
+(if stdenv.isDarwin then {
+  patches = ./darwin-arch.patch;
+}
+else { })
+)
diff --git a/pkgs/development/libraries/openssl/darwin-arch-1.patch b/pkgs/development/libraries/openssl/darwin-arch-1.patch
new file mode 100644
index 00000000000..ad8e86c6791
--- /dev/null
+++ b/pkgs/development/libraries/openssl/darwin-arch-1.patch
@@ -0,0 +1,16 @@
+The patch is specific to nix: MacOS gcc supports -arch.
+--- a/Configure
++++ b/Configure
+@@ -549,9 +549,9 @@ my %table=(
+ "rhapsody-ppc-cc","cc:-O3 -DB_ENDIAN::(unknown):MACOSX_RHAPSODY::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${no_asm}::",
+ "darwin-ppc-cc","cc:-arch ppc -O3 -DB_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc32_asm}:osx32:dlfcn:darwin-shared:-fPIC -fno-common:-arch ppc -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+ "darwin64-ppc-cc","cc:-arch ppc64 -O3 -DB_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc64_asm}:osx64:dlfcn:darwin-shared:-fPIC -fno-common:-arch ppc64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+-"darwin-i386-cc","cc:-arch i386 -O3 -fomit-frame-pointer -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:${x86_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+-"debug-darwin-i386-cc","cc:-arch i386 -g3 -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:${x86_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+-"darwin64-x86_64-cc","cc:-arch x86_64 -O3 -DL_ENDIAN -DMD32_REG_T=int -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch x86_64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
++"darwin-i386-cc","cc:-O3 -fomit-frame-pointer -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:${x86_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
++"debug-darwin-i386-cc","cc:-g3 -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:${x86_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
++"darwin64-x86_64-cc","cc:-O3 -DL_ENDIAN -DMD32_REG_T=int -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+ "debug-darwin-ppc-cc","cc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DB_ENDIAN -g -Wall -O::-D_REENTRANT:MACOSX::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc32_asm}:osx32:dlfcn:darwin-shared:-fPIC:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+
+ ##### A/UX
diff --git a/pkgs/development/libraries/openssl/darwin-arch.patch b/pkgs/development/libraries/openssl/darwin-arch.patch
index ad8e86c6791..f17a40395d6 100644
--- a/pkgs/development/libraries/openssl/darwin-arch.patch
+++ b/pkgs/development/libraries/openssl/darwin-arch.patch
@@ -1,16 +1,30 @@
-The patch is specific to nix: MacOS gcc supports -arch.
---- a/Configure
-+++ b/Configure
-@@ -549,9 +549,9 @@ my %table=(
- "rhapsody-ppc-cc","cc:-O3 -DB_ENDIAN::(unknown):MACOSX_RHAPSODY::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${no_asm}::",
- "darwin-ppc-cc","cc:-arch ppc -O3 -DB_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc32_asm}:osx32:dlfcn:darwin-shared:-fPIC -fno-common:-arch ppc -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
- "darwin64-ppc-cc","cc:-arch ppc64 -O3 -DB_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc64_asm}:osx64:dlfcn:darwin-shared:-fPIC -fno-common:-arch ppc64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
--"darwin-i386-cc","cc:-arch i386 -O3 -fomit-frame-pointer -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:${x86_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
--"debug-darwin-i386-cc","cc:-arch i386 -g3 -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:${x86_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
--"darwin64-x86_64-cc","cc:-arch x86_64 -O3 -DL_ENDIAN -DMD32_REG_T=int -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch x86_64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
-+"darwin-i386-cc","cc:-O3 -fomit-frame-pointer -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:${x86_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
-+"debug-darwin-i386-cc","cc:-g3 -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:${x86_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
-+"darwin64-x86_64-cc","cc:-O3 -DL_ENDIAN -DMD32_REG_T=int -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
- "debug-darwin-ppc-cc","cc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DB_ENDIAN -g -Wall -O::-D_REENTRANT:MACOSX::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc32_asm}:osx32:dlfcn:darwin-shared:-fPIC:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+Removed -arch flags for darwin as they are not supported by gcc-darwin.
 
- ##### A/UX
+diff -rc openssl-0.9.8n/Configure openssl-0.9.8n-new/Configure
+*** openssl-0.9.8n/Configure	Mon Nov  9 15:14:26 2009
+--- openssl-0.9.8n-new/Configure	Thu Apr 29 10:16:15 2010
+***************
+*** 523,533 ****
+  
+  ##### MacOS X (a.k.a. Rhapsody or Darwin) setup
+  "rhapsody-ppc-cc","cc:-O3 -DB_ENDIAN::(unknown):MACOSX_RHAPSODY::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${no_asm}::",
+! "darwin-ppc-cc","cc:-arch ppc -O3 -DB_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR::osx_ppc32.o::::::::::dlfcn:darwin-shared:-fPIC -fno-common:-arch ppc -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+! "darwin64-ppc-cc","cc:-arch ppc64 -O3 -DB_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR::osx_ppc64.o::::::::::dlfcn:darwin-shared:-fPIC -fno-common:-arch ppc64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+! "darwin-i386-cc","cc:-arch i386 -O3 -fomit-frame-pointer -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+! "debug-darwin-i386-cc","cc:-arch i386 -g3 -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+! "darwin64-x86_64-cc","cc:-arch x86_64 -O3 -fomit-frame-pointer -DL_ENDIAN -DMD32_REG_T=int -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-arch x86_64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+  "debug-darwin-ppc-cc","cc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DB_ENDIAN -g -Wall -O::-D_REENTRANT:MACOSX::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR::osx_ppc32.o::::::::::dlfcn:darwin-shared:-fPIC -fno-common:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+  
+  ##### A/UX
+--- 523,533 ----
+  
+  ##### MacOS X (a.k.a. Rhapsody or Darwin) setup
+  "rhapsody-ppc-cc","cc:-O3 -DB_ENDIAN::(unknown):MACOSX_RHAPSODY::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${no_asm}::",
+! "darwin-ppc-cc","cc:-O3 -DB_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR::osx_ppc32.o::::::::::dlfcn:darwin-shared:-fPIC -fno-common: -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+! "darwin64-ppc-cc","cc:-O3 -DB_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR::osx_ppc64.o::::::::::dlfcn:darwin-shared:-fPIC -fno-common:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+! "darwin-i386-cc","cc:-O3 -fomit-frame-pointer -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+! "debug-darwin-i386-cc","cc:-g3 -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+! "darwin64-x86_64-cc","cc:-O3 -fomit-frame-pointer -DL_ENDIAN -DMD32_REG_T=int -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+  "debug-darwin-ppc-cc","cc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DB_ENDIAN -g -Wall -O::-D_REENTRANT:MACOSX::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR::osx_ppc32.o::::::::::dlfcn:darwin-shared:-fPIC -fno-common:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+  
+  ##### A/UX
diff --git a/pkgs/development/libraries/openssl/default.nix b/pkgs/development/libraries/openssl/default.nix
index e483af7206e..6b1efd7bc03 100644
--- a/pkgs/development/libraries/openssl/default.nix
+++ b/pkgs/development/libraries/openssl/default.nix
@@ -30,6 +30,15 @@ stdenv.mkDerivation rec {
       # It's configure does not like --build or --host
       export configureFlags="--libdir=lib --cross-compile-prefix=${stdenv.cross.config}- shared ${opensslCrossSystem}"
     '';
+
+    postInstall = ''
+      # Openssl installs readonly files, which otherwise we can't strip.
+      # This could at some stdenv hash change be put out of crossAttrs, too
+      chmod -R +w $out
+
+      # Remove references to perl, to avoid depending on it at runtime
+      rm $out/bin/c_rehash $out/ssl/misc/CA.pl $out/ssl/misc/tsget
+    '';
     configureScript = "./Configure";
   };
 
diff --git a/pkgs/development/libraries/pcre/default.nix b/pkgs/development/libraries/pcre/default.nix
index 3d3385c83f8..f139bce100d 100644
--- a/pkgs/development/libraries/pcre/default.nix
+++ b/pkgs/development/libraries/pcre/default.nix
@@ -1,13 +1,13 @@
 {stdenv, fetchurl, unicodeSupport ? false, cplusplusSupport ? true}:
 
 stdenv.mkDerivation {
-  name = "pcre-7.8";
-  
+  name = "pcre-8.02";
+
   src = fetchurl {
-    url = mirror://sourceforge/pcre/pcre-7.8.tar.bz2;
-    sha256 = "1zsqk352mx2zklf9bgpg9d88ckfdssbbbiyslhrycfckw8m3qpvr";
+    url = mirror://sourceforge/pcre/pcre-8.02.tar.bz2;
+    sha256 = "1gafmkmkbpdqjbdl85q2z5774gw4gfqjf238icz7gqf3v4v90xd4";
   };
-  
+
   configureFlags = ''
     ${if unicodeSupport then "--enable-unicode-properties" else ""}
     ${if !cplusplusSupport then "--disable-cpp" else ""}
diff --git a/pkgs/development/libraries/ppl/default.nix b/pkgs/development/libraries/ppl/default.nix
index ed4cc7f2497..677d578e242 100644
--- a/pkgs/development/libraries/ppl/default.nix
+++ b/pkgs/development/libraries/ppl/default.nix
@@ -1,17 +1,23 @@
-{ fetchurl, stdenv, gmpxx, perl, gnum4 }:
+{ fetchurl, stdenv, gmpxx, perl, gnum4, static ? false }:
 
-let version = "0.10.2"; in
+let
+  version = "0.10.2";
+  staticFlags = if static then " --enable-static --disable-shared" else "";
+in
   stdenv.mkDerivation rec {
     name = "ppl-${version}";
 
     src = fetchurl {
-      url = "ftp://ftp.cs.unipr.it/pub/ppl/releases/${version}/${name}.tar.bz2";
-      sha256 = "0xz2f3lny4l9ji1ilg6pxv34sh4cbh535cnm68smynzp01wgnh7y";
+      url = "mirror://gcc/infrastructure/ppl-${version}.tar.gz";
+      sha256 = "0lly44sac4jd72klnhhil3wha15vak76r6gy88sh0zjsaww9hf6h";
     };
 
-    buildInputs = [ perl gnum4 ];
+    buildNativeInputs = [ perl gnum4 ];
     propagatedBuildInputs = [ gmpxx ];
 
+    dontDisableStatic = if static then true else false;
+    configureFlags = staticFlags;
+
     # Beware!  It took ~6 hours to compile PPL and run its tests on a 1.2 GHz
     # x86_64 box.  Nevertheless, being a dependency of GCC, it probably ought
     # to be tested.
diff --git a/pkgs/development/tools/misc/binutils/as-pr10856.patch b/pkgs/development/tools/misc/binutils/as-pr10856.patch
deleted file mode 100644
index 695d3e35670..00000000000
--- a/pkgs/development/tools/misc/binutils/as-pr10856.patch
+++ /dev/null
@@ -1,83 +0,0 @@
-Fix a regression in GNU as:
-http://sourceware.org/bugzilla/show_bug.cgi?id=10856 .
-
-The bug appears to be responsible for invalid code generated for
-Crypto++:
-http://groups.google.com/group/cryptopp-users/browse_thread/thread/7ce734e479586640/29c6649b7c7adee2?#29c6649b7c7adee2 .
-
-diff -u -r1.77.2.1 -r1.77.2.2
---- a/gas/expr.c	2009/09/11 15:28:43	1.77.2.1
-+++ b/gas/expr.c	2009/10/28 08:23:48	1.77.2.2
-@@ -1997,6 +1997,7 @@
-   /* Help out with CSE.  */
-   valueT final_val = expressionP->X_add_number;
-   symbolS *add_symbol = expressionP->X_add_symbol;
-+  symbolS *orig_add_symbol = add_symbol;
-   symbolS *op_symbol = expressionP->X_op_symbol;
-   operatorT op = expressionP->X_op;
-   valueT left, right;
-@@ -2078,6 +2079,7 @@
- 	      left = right;
- 	      seg_left = seg_right;
- 	      add_symbol = op_symbol;
-+	      orig_add_symbol = expressionP->X_op_symbol;
- 	      op = O_symbol;
- 	      break;
- 	    }
-@@ -2122,18 +2124,19 @@
- 	    {
- 	      if (op == O_bit_exclusive_or || op == O_bit_inclusive_or)
- 		{
--		  if (seg_right != absolute_section || right != 0)
-+		  if (!(seg_right == absolute_section && right == 0))
- 		    {
- 		      seg_left = seg_right;
- 		      left = right;
- 		      add_symbol = op_symbol;
-+		      orig_add_symbol = expressionP->X_op_symbol;
- 		    }
- 		  op = O_symbol;
- 		  break;
- 		}
- 	      else if (op == O_left_shift || op == O_right_shift)
- 		{
--		  if (seg_left != absolute_section || left != 0)
-+		  if (!(seg_left == absolute_section && left == 0))
- 		    {
- 		      op = O_symbol;
- 		      break;
-@@ -2149,6 +2152,7 @@
- 	      seg_left = seg_right;
- 	      left = right;
- 	      add_symbol = op_symbol;
-+	      orig_add_symbol = expressionP->X_op_symbol;
- 	      op = O_symbol;
- 	      break;
- 	    }
-@@ -2158,11 +2162,11 @@
- 	      op = O_symbol;
- 	      break;
- 	    }
--	  else if (left != right
--		   || ((seg_left != reg_section || seg_right != reg_section)
--		       && (seg_left != undefined_section
--			   || seg_right != undefined_section
--			   || add_symbol != op_symbol)))
-+	  else if (!(left == right
-+		     && ((seg_left == reg_section && seg_right == reg_section)
-+			 || (seg_left == undefined_section
-+			     && seg_right == undefined_section
-+			     && add_symbol == op_symbol))))
- 	    return 0;
- 	  else if (op == O_bit_and || op == O_bit_inclusive_or)
- 	    {
-@@ -2233,7 +2237,8 @@
- 	op = O_constant;
-       else if (seg_left == reg_section && final_val == 0)
- 	op = O_register;
--      else if (add_symbol != expressionP->X_add_symbol)
-+      else if (seg_left == undefined_section
-+	       && add_symbol != orig_add_symbol)
- 	final_val += left;
-       expressionP->X_add_symbol = add_symbol;
-     }
diff --git a/pkgs/development/tools/misc/binutils/default.nix b/pkgs/development/tools/misc/binutils/default.nix
index 1bb110e35fd..3e3dedd1e83 100644
--- a/pkgs/development/tools/misc/binutils/default.nix
+++ b/pkgs/development/tools/misc/binutils/default.nix
@@ -1,14 +1,14 @@
 {stdenv, fetchurl, noSysDirs, cross ? null}:
 
 let
-    basename = "binutils-2.20";
+    basename = "binutils-2.20.1";
 in
 stdenv.mkDerivation rec {
   name = basename + stdenv.lib.optionalString (cross != null) "-${cross.config}";
 
   src = fetchurl {
     url = "mirror://gnu/binutils/${basename}.tar.bz2";
-    sha256 = "1c3m789p5rwmmnck5ms4zcnc40axss3gxzivz571al1vmbq0kpz1";
+    sha256 = "1y7nwsprhr4hvx9ps2l0l0ivb6k41rcrx1invmzqxs475mr892r2";
   };
 
   patches = [
@@ -16,8 +16,6 @@ stdenv.mkDerivation rec {
     # RUNPATH instead of RPATH on binaries.  This is important because
     # RUNPATH can be overriden using LD_LIBRARY_PATH at runtime.
     ./new-dtags.patch
-
-    ./as-pr10856.patch
   ];
 
   inherit noSysDirs;
diff --git a/pkgs/development/tools/misc/binutils/snapshot.nix b/pkgs/development/tools/misc/binutils/snapshot.nix
new file mode 100644
index 00000000000..2563f998265
--- /dev/null
+++ b/pkgs/development/tools/misc/binutils/snapshot.nix
@@ -0,0 +1,59 @@
+{stdenv, fetchurl, noSysDirs, cross ? null}:
+
+let
+    basename = "binutils-2.20.51";
+in
+stdenv.mkDerivation rec {
+  name = basename + stdenv.lib.optionalString (cross != null) "-${cross.config}";
+
+  src = fetchurl {
+    url = "file:///root/binutils/${basename}.tar.bz2";
+    sha256 = "1f0na8c31sccbipzk8xiyd7n7ydh5gg09kirbs28vcb2714cxws0";
+  };
+
+  patches = [
+    # Turn on --enable-new-dtags by default to make the linker set
+    # RUNPATH instead of RPATH on binaries.  This is important because
+    # RUNPATH can be overriden using LD_LIBRARY_PATH at runtime.
+    ./new-dtags.patch
+  ];
+
+  inherit noSysDirs;
+
+  preConfigure = ''
+    # Clear the default library search path.
+    if test "$noSysDirs" = "1"; then
+	echo 'NATIVE_LIB_DIRS=' >> ld/configure.tgt
+    fi
+
+    # Use symlinks instead of hard links to save space ("strip" in the
+    # fixup phase strips each hard link separately).
+    for i in binutils/Makefile.in gas/Makefile.in ld/Makefile.in; do
+        substituteInPlace $i --replace 'ln ' 'ln -s '
+    done
+  '';
+
+  configureFlags = "--disable-werror" # needed for dietlibc build
+      + stdenv.lib.optionalString (stdenv.system == "ict_loongson-2_v0.3_fpu_v0.1-linux")
+        " --enable-fix-loongson2f-nop"
+      + stdenv.lib.optionalString (cross != null) " --target=${cross.config}";
+
+  meta = {
+    description = "GNU Binutils, tools for manipulating binaries (linker, assembler, etc.)";
+
+    longDescription = ''
+      The GNU Binutils are a collection of binary tools.  The main
+      ones are `ld' (the GNU linker) and `as' (the GNU assembler).
+      They also include the BFD (Binary File Descriptor) library,
+      `gprof', `nm', `strip', etc.
+    '';
+
+    homepage = http://www.gnu.org/software/binutils/;
+
+    license = "GPLv3+";
+
+    /* Give binutils a lower priority than gcc-wrapper to prevent a
+       collision due to the ld/as wrappers/symlinks in the latter. */
+    priority = "10";
+  };
+}
diff --git a/pkgs/development/tools/misc/cscope/default.nix b/pkgs/development/tools/misc/cscope/default.nix
index 1c6d1dacc7f..2a9e77bd05b 100644
--- a/pkgs/development/tools/misc/cscope/default.nix
+++ b/pkgs/development/tools/misc/cscope/default.nix
@@ -17,7 +17,8 @@ stdenv.mkDerivation rec {
 
   configureFlags = "--with-ncurses=${ncurses}";
 
-  buildInputs = [ ncurses pkgconfig emacs ];
+  buildInputs = [ ncurses emacs ];
+  buildNativeInputs = [ pkgconfig ];
 
   postInstall = ''
     # Install Emacs mode.
@@ -31,6 +32,11 @@ stdenv.mkDerivation rec {
     cp xcscope.el{,c} "$out/share/emacs/site-lisp"
   '';
 
+  crossAttrs = {
+    postInstall = "";
+    propagatedBuildInputs = [ ncurses.hostDrv ];
+  };
+
   meta = {
     description = "Cscope, a developer's tool for browsing source code";
 
diff --git a/pkgs/development/tools/misc/gnum4/default.nix b/pkgs/development/tools/misc/gnum4/default.nix
index 0c73ba1f738..717a48f11e6 100644
--- a/pkgs/development/tools/misc/gnum4/default.nix
+++ b/pkgs/development/tools/misc/gnum4/default.nix
@@ -1,11 +1,11 @@
 {stdenv, fetchurl}:
 
 stdenv.mkDerivation {
-  name = "gnum4-1.4.13";
+  name = "gnum4-1.4.14";
 
   src = fetchurl {
-    url = mirror://gnu/m4/m4-1.4.13.tar.bz2;
-    sha256 = "01pcrajrk2rqhxbrij3j07ywyxlq7ih43a8pzvhdlxhlwfazxipw";
+    url = mirror://gnu/m4/m4-1.4.14.tar.bz2;
+    sha256 = "1ljddxjqw1642b26qzk87fahkv9rsv2cn2ygn6b3ldan6alzz188";
   };
 
   doCheck = !stdenv.isDarwin;
diff --git a/pkgs/development/tools/misc/patchelf/0.6.nix b/pkgs/development/tools/misc/patchelf/0.6.nix
index dfd0b077411..3774c44480d 100644
--- a/pkgs/development/tools/misc/patchelf/0.6.nix
+++ b/pkgs/development/tools/misc/patchelf/0.6.nix
@@ -4,8 +4,8 @@ stdenv.mkDerivation rec {
   name = "patchelf-0.6pre22275";
   
   src = fetchurl {
-    url = "http://hydra.nixos.org/build/479721/download/3/patchelf-0.6pre22275.tar.gz";
-    sha256 = "ccce84285d145b300e5727b1562f4f334c53721fc7b388928c3fb5b9a90c7d80";
+    url = "http://hydra.nixos.org/build/504657/download/2/patchelf-0.6pre22813.tar.bz2";
+    sha256 = "1ml86wyl35ik3lixkcz2vlzvbcancj0dygwfh5ambjmazp2q19mh";
   };
 
   meta = {
diff --git a/pkgs/games/prboom/default.nix b/pkgs/games/prboom/default.nix
new file mode 100644
index 00000000000..f66e2295a22
--- /dev/null
+++ b/pkgs/games/prboom/default.nix
@@ -0,0 +1,20 @@
+{stdenv, fetchurl, SDL, SDL_mixer, SDL_net, mesa}:
+
+stdenv.mkDerivation {
+  name = "prboom-2.5.0";
+  src = fetchurl {
+    url = mirror://sourceforge/prboom/prboom-2.5.0.tar.gz;
+    sha256 = "1bjb04q8dk232956k30qlpq6q0hxb904yh1nflr87jcc1x3iqv12";
+  };
+
+  buildInputs = [ SDL SDL_mixer SDL_net mesa ];
+  crossAttrs = {
+    propagatedBuildInputs = [ SDL.hostDrv SDL_mixer.hostDrv SDL_net.hostDrv ];
+    configureFlags = "--disable-gl --disable-cpu-opt --without-x --disable-sdltest
+      ac_cv_type_uid_t=yes ac_cv_type_gid_t=yes";
+
+    postInstall = ''
+      mv $out/games/ $out/bin
+    '';
+  };
+}
diff --git a/pkgs/games/scummvm/default.nix b/pkgs/games/scummvm/default.nix
index d6912d5c3c0..ad03906888c 100644
--- a/pkgs/games/scummvm/default.nix
+++ b/pkgs/games/scummvm/default.nix
@@ -10,6 +10,18 @@ stdenv.mkDerivation {
   
   buildInputs = [SDL zlib mpeg2dec];
 
+  crossAttrs = {
+    preConfigure = ''
+      # Remove the --build flag set by the gcc cross wrapper setup
+      # hook
+      export configureFlags="--host=${stdenv.cross.config}"
+    '';
+    postConfigure = ''
+      # They use 'install -s', that calls the native strip instead of the cross
+      sed -i 's/-c -s/-c/' ports.mk;
+    '';
+  };
+
   meta = {
     description = "Program to run certain classic graphical point-and-click adventure games (such as Monkey Island)";
     homepage = http://www.scummvm.org/;
diff --git a/pkgs/lib/platforms.nix b/pkgs/lib/platforms.nix
index 635b195e1d6..095281145d2 100644
--- a/pkgs/lib/platforms.nix
+++ b/pkgs/lib/platforms.nix
@@ -2,7 +2,8 @@ let lists = import ./lists.nix; in
 
 rec {
   gnu = linux; /* ++ hurd ++ kfreebsd ++ ... */
-  linux = ["i686-linux" "x86_64-linux" "powerpc-linux" "armv5tel-linux" ];
+  linux = ["i686-linux" "x86_64-linux" "powerpc-linux" "armv5tel-linux"
+    "ict_loongson-2_v0.3_fpu_v0.1-linux"];
   darwin = ["i686-darwin" "powerpc-darwin" "x86_64-darwin"];
   freebsd = ["i686-freebsd" "x86_64-freebsd" "powerpc-freebsd"];
   openbsd = ["i686-openbsd" "x86_64-openbsd"];
diff --git a/pkgs/misc/busybox/default.nix b/pkgs/misc/busybox/default.nix
index 1d190cf661d..1ae51d64e30 100644
--- a/pkgs/misc/busybox/default.nix
+++ b/pkgs/misc/busybox/default.nix
@@ -1,13 +1,41 @@
-{stdenv, fetchurl, enableStatic ? false}:
+{stdenv, fetchurl, enableStatic ? false, extraConfig ? null}:
 
 let
-  basicConfigure = ''
-    make defconfig
-    sed -i 's,.*CONFIG_PREFIX.*,CONFIG_PREFIX="'$out'",' .config
-    sed -i 's,.*CONFIG_INSTALL_NO_USR.*,CONFIG_INSTALL_NO_USR=y,' .config
-  '' +
-    (if enableStatic then ''
-      sed -i 's,.*CONFIG_STATIC.*,CONFIG_STATIC=y,' .config
+  configParser = ''
+    function parseconfig {
+        set -x
+        while read LINE; do
+            NAME=`echo "$LINE" | cut -d \  -f 1`
+            OPTION=`echo "$LINE" | cut -d \  -f 2`
+
+            if test -z "$NAME"; then
+                continue
+            fi
+
+            if test "$NAME" == "CLEAR"; then
+                echo "parseconfig: CLEAR"
+                echo > .config
+            fi
+
+            echo "parseconfig: removing $NAME"
+            sed -i /^$NAME=/d .config
+
+            if test "$OPTION" != n; then
+                echo "parseconfig: setting $NAME=$OPTION"
+                echo "$NAME=$OPTION" >> .config
+            fi
+        done
+        set +x
+    }
+  '';
+
+  nixConfig = ''
+    CONFIG_PREFIX "$out"
+    CONFIG_INSTALL_NO_USR n
+  '';
+
+  staticConfig = (if enableStatic then ''
+      CONFIG_STATIC y
     '' else "");
 
 in
@@ -20,14 +48,24 @@ stdenv.mkDerivation {
     sha256 = "1n738zk01yi2sjrx2y36hpzxbslas8b91vzykcifr0p1j7ym0lim";
   };
 
-  configurePhase = basicConfigure;
+  configurePhase = ''
+    make defconfig
+    ${configParser}
+    cat << EOF | parseconfig
+    ${staticConfig}
+    ${extraConfig}
+    ${nixConfig}
+    $extraCrossConfig
+    EOF
+    make oldconfig
+  '';
 
   crossAttrs = {
-    configurePhase = basicConfigure + ''
-      sed -i 's,.*CONFIG_CROSS_COMPILER_PREFIX.*,CONFIG_CROSS_COMPILER_PREFIX="'$crossConfig-'",' .config
+    extraCrossConfig = ''
+      CONFIG_CROSS_COMPILER_PREFIX "${stdenv.cross.config}-"
     '' +
       (if (stdenv.cross.platform.kernelMajor == "2.4") then ''
-        sed -i 's,.*CONFIG_IONICE.*,CONFIG_IONICE=n,' .config
+        CONFIG_IONICE n
       '' else "");
   };
 }
diff --git a/pkgs/misc/uboot/nanonote.nix b/pkgs/misc/uboot/nanonote.nix
new file mode 100644
index 00000000000..9e39501a7a3
--- /dev/null
+++ b/pkgs/misc/uboot/nanonote.nix
@@ -0,0 +1,58 @@
+{stdenv, fetchurl, fetchgit}:
+
+# We should enable this check once we have the cross target system information
+# assert stdenv.system == "armv5tel-linux" || crossConfig == "armv5tel-linux";
+
+# All this file is made for the Marvell Sheevaplug
+   
+stdenv.mkDerivation {
+  name = "uboot-qb-2010.06";
+   
+  src = fetchurl {
+    url = "ftp://ftp.denx.de/pub/u-boot/u-boot-2010.06.tar.bz2";
+    sha256 = "1j0bl8x5i5m1pn62z450gbw30pbrj7sgs3fjp2l2giczv49cn33r";
+  };
+
+  srcPatches = fetchgit {
+    url = "git://projects.qi-hardware.com/openwrt-xburst.git";
+    rev = "3244d5ef9f93802f9b9b6f4405636424abf6fa83";
+    sha256 = "8ae25853028930b418fad90637e0e68f9888285ba3ad1f720be45f08823ee855";
+  };
+
+  patchPhase = ''
+    cp -R $srcPatches/package/uboot-xburst/files/* .
+    for a in $srcPatches/package/uboot-xburst/patches/*; do
+        patch -p1 < $a
+    done
+    chmod +w -R *
+  '';
+
+  # Remove the cross compiler prefix, and add reiserfs support
+  configurePhase = ''
+    make mrproper
+    make qi_lb60_config
+    sed -i /CROSS_COMPILE/d include/config.mk
+  '';
+
+  buildPhase = ''
+    # A variable named 'src' used to affect the build in some uboot...
+    unset src
+    if test -z "$crossConfig"; then
+        make clean all
+    else
+        make clean all ARCH=mips CROSS_COMPILE=$crossConfig-
+    fi
+  '';
+
+  dontStrip = true;
+  NIX_STRIP_DEBUG = false;
+
+  installPhase = ''
+    ensureDir $out
+    cp u-boot-nand.bin $out
+    cp u-boot u-boot.map $out
+
+    ensureDir $out/bin
+    cp tools/{envcrc,mkimage} $out/bin
+  '';
+}
diff --git a/pkgs/os-specific/linux/alsa-lib/default.nix b/pkgs/os-specific/linux/alsa-lib/default.nix
index 727db1c9642..aaa714d8d59 100644
--- a/pkgs/os-specific/linux/alsa-lib/default.nix
+++ b/pkgs/os-specific/linux/alsa-lib/default.nix
@@ -14,6 +14,12 @@ stdenv.mkDerivation rec {
   postPatch = ''
     sed -i -e 's|//int snd_pcm_mixer_element(snd_pcm_t \*pcm, snd_mixer_t \*mixer, snd_mixer_elem_t \*\*elem);|/\*int snd_pcm_mixer_element(snd_pcm_t \*pcm, snd_mixer_t \*mixer, snd_mixer_elem_t \*\*elem);\*/|' include/pcm.h
   '';
+
+  crossAttrs = {
+    patchPhase = ''
+      sed -i s/extern/static/g include/iatomic.h
+    '';
+  };
   
   meta = {
     description = "ALSA, the Advanced Linux Sound Architecture libraries";
diff --git a/pkgs/os-specific/linux/kbd/default.nix b/pkgs/os-specific/linux/kbd/default.nix
index 77d53adeb81..c9618bf07e6 100644
--- a/pkgs/os-specific/linux/kbd/default.nix
+++ b/pkgs/os-specific/linux/kbd/default.nix
@@ -1,19 +1,22 @@
 { stdenv, fetchurl, bison, flex, autoconf, automake }:
 
 stdenv.mkDerivation rec {
-  name = "kbd-1.15.1";
+  name = "kbd-1.15.2";
 
   src = fetchurl {
     url = "ftp://ftp.altlinux.org/pub/people/legion/kbd/${name}.tar.gz";
-    sha256 = "1klrxas8vjikx6jm6m2lcpmn88lhxb6p3whwgdwq9d9flf1qrf4i";
+    sha256 = "19pb44m5m0mcgjkmgkjx4fn8j2m4xwqx4g7w2y1nlypg3qcjsq5k";
   };
 
   buildInputs = [ bison flex autoconf automake  ];
 
-  # We get a warning in armv5tel-linux, so we disable -Werror in it
-  patchPhase = if (stdenv.system == "armv5tel-linux") then ''
-    sed -i s/-Werror// src/Makefile.am
-  '' else "";
+  # We get a warning in armv5tel-linux and the fuloong2f,
+  # so we disable -Werror in it
+  patchPhase = if (stdenv.system == "armv5tel-linux" ||
+    stdenv.system == "ict_loongson-2_v0.3_fpu_v0.1-linux")
+    then ''
+      sed -i s/-Werror// src/Makefile.am
+    '' else "";
 
   # Grrr, kbd 1.15.1 doesn't include a configure script.
   preConfigure = "autoreconf";
diff --git a/pkgs/os-specific/linux/kernel-headers/2.6.28.nix b/pkgs/os-specific/linux/kernel-headers/2.6.28.nix
index 82840f8a51f..a85e6f79bf1 100644
--- a/pkgs/os-specific/linux/kernel-headers/2.6.28.nix
+++ b/pkgs/os-specific/linux/kernel-headers/2.6.28.nix
@@ -20,6 +20,7 @@ stdenv.mkDerivation {
     if stdenv.system == "x86_64-linux" then "x86_64" else
     if stdenv.system == "powerpc-linux" then "powerpc" else
     if stdenv.system == "armv5tel-linux" then "arm" else
+    if stdenv.system == "mips64-linux" then "mips" else
     abort "don't know what the kernel include directory is called for this platform";
 
   buildInputs = [perl];
diff --git a/pkgs/os-specific/linux/kernel-headers/2.6.32.nix b/pkgs/os-specific/linux/kernel-headers/2.6.32.nix
index 936ef5ec40d..a4e86658193 100644
--- a/pkgs/os-specific/linux/kernel-headers/2.6.32.nix
+++ b/pkgs/os-specific/linux/kernel-headers/2.6.32.nix
@@ -26,6 +26,7 @@ stdenv.mkDerivation {
     if stdenv.system == "x86_64-linux" then "x86_64" else
     if stdenv.system == "powerpc-linux" then "powerpc" else
     if stdenv.system == "armv5tel-linux" then "arm" else
+    if stdenv.platform ? kernelArch then stdenv.platform.kernelArch else
     abort "don't know what the kernel include directory is called for this platform";
 
   buildInputs = [perl];
diff --git a/pkgs/os-specific/linux/kernel/builder.sh b/pkgs/os-specific/linux/kernel/builder.sh
index e7d25e86883..bb030abaa6c 100644
--- a/pkgs/os-specific/linux/kernel/builder.sh
+++ b/pkgs/os-specific/linux/kernel/builder.sh
@@ -68,81 +68,88 @@ installPhase() {
     if test "$arch" = um; then
         ensureDir $out/bin
         cp linux $out/bin
-    else
+    elif test "$kernelTarget" != "vmlinux"; then
+        # In any case we copy the 'vmlinux' ELF in the next lines
         cp arch/$archDir/boot/$kernelTarget $out
     fi
 
     cp vmlinux $out
 
-    # Install the modules in $out/lib/modules with matching paths
-    # in modules.dep (i.e., refererring to $out/lib/modules, not
-    # /lib/modules).  The depmod_opts= is to prevent the kernel
-    # from passing `-b PATH' to depmod.
-    export MODULE_DIR=$out/lib/modules/
-    substituteInPlace Makefile --replace '-b $(INSTALL_MOD_PATH)' ''
-    make modules_install \
-        DEPMOD=$module_init_tools/sbin/depmod depmod_opts= \
-        $makeFlags "${makeFlagsArray[@]}" \
-        $installFlags "${installFlagsArray[@]}"
-
-    if test -z "$dontStrip"; then
-        # Strip the kernel modules.
-	echo "Stripping kernel modules..."
-	if [ -z "$crossConfig" ]; then
-            find $out -name "*.ko" -print0 | xargs -0 strip -S
-	else
-            find $out -name "*.ko" -print0 | xargs -0 $crossConfig-strip -S
-	fi
+    if grep -q "CONFIG_MODULES=y" .config; then
+        # Install the modules in $out/lib/modules with matching paths
+        # in modules.dep (i.e., refererring to $out/lib/modules, not
+        # /lib/modules).  The depmod_opts= is to prevent the kernel
+        # from passing `-b PATH' to depmod.
+        export MODULE_DIR=$out/lib/modules/
+        substituteInPlace Makefile --replace '-b $(INSTALL_MOD_PATH)' ''
+        make modules_install \
+            DEPMOD=$module_init_tools/sbin/depmod depmod_opts= \
+            $makeFlags "${makeFlagsArray[@]}" \
+            $installFlags "${installFlagsArray[@]}"
+
+        if test -z "$dontStrip"; then
+            # Strip the kernel modules.
+        echo "Stripping kernel modules..."
+        if [ -z "$crossConfig" ]; then
+                find $out -name "*.ko" -print0 | xargs -0 strip -S
+        else
+                find $out -name "*.ko" -print0 | xargs -0 $crossConfig-strip -S
+        fi
+        fi
+
+        # move this to install later on
+        # largely copied from early FC3 kernel spec files
+        version=$(cd $out/lib/modules && ls -d *)
+
+        # remove symlinks and create directories
+        rm -f $out/lib/modules/$version/build
+        rm -f $out/lib/modules/$version/source
+        mkdir $out/lib/modules/$version/build
+
+        # copy config
+        cp .config $out/lib/modules/$version/build/.config
+        ln -s $out/lib/modules/$version/build/.config $out/config
+
+        if test "$arch" != um; then
+            # copy all Makefiles and Kconfig files
+            ln -s $out/lib/modules/$version/build $out/lib/modules/$version/source
+            cp --parents `find  -type f -name Makefile -o -name "Kconfig*"` $out/lib/modules/$version/build
+            cp Module.symvers $out/lib/modules/$version/build
+
+        if test "$dontStrip" = "1"; then
+            # copy any debugging info that can be found
+            cp --parents -rv `find -name \*.debug -o -name debug.a`	\
+               "$out/lib/modules/$version/build"
+        fi
+
+            # weed out unneeded stuff
+            rm -rf $out/lib/modules/$version/build/Documentation
+            rm -rf $out/lib/modules/$version/build/scripts
+            rm -rf $out/lib/modules/$version/build/include
+
+            # copy architecture dependent files
+            cp -a arch/$archDir/scripts $out/lib/modules/$version/build/ || true
+            cp -a arch/$archDir/*lds $out/lib/modules/$version/build/ || true
+            cp -a arch/$archDir/Makefile*.cpu $out/lib/modules/$version/build/arch/$archDir/ || true
+            cp -a --parents arch/$archDir/kernel/asm-offsets.s $out/lib/modules/$version/build/arch/$archDir/kernel/ || true
+
+            # copy scripts
+            rm -f scripts/*.o
+            rm -f scripts/*/*.o
+            cp -a scripts $out/lib/modules/$version/build
+
+            # copy include files
+            includeDir=$out/lib/modules/$version/build/include
+            mkdir -p $includeDir
+            (cd include && cp -a * $includeDir)
+        (cd arch/$archDir/include && cp -a * $includeDir || true)
+        (cd arch/$archDir/include && cp -a asm/* $includeDir/asm/ || true)
+        (cd arch/$archDir/include/asm/mach-generic && cp -a * $includeDir/ || true)
+        fi
     fi
 
-    # move this to install later on
-    # largely copied from early FC3 kernel spec files
-    version=$(cd $out/lib/modules && ls -d *)
-
-    # remove symlinks and create directories
-    rm -f $out/lib/modules/$version/build
-    rm -f $out/lib/modules/$version/source
-    mkdir $out/lib/modules/$version/build
-
-    # copy config
-    cp .config $out/lib/modules/$version/build/.config
-    ln -s $out/lib/modules/$version/build/.config $out/config
-
-    if test "$arch" != um; then
-        # copy all Makefiles and Kconfig files
-        ln -s $out/lib/modules/$version/build $out/lib/modules/$version/source
-        cp --parents `find  -type f -name Makefile -o -name "Kconfig*"` $out/lib/modules/$version/build
-        cp Module.symvers $out/lib/modules/$version/build
-
-	if test "$dontStrip" = "1"; then
-	    # copy any debugging info that can be found
-	    cp --parents -rv `find -name \*.debug -o -name debug.a`	\
-	       "$out/lib/modules/$version/build"
-	fi
-
-        # weed out unneeded stuff
-        rm -rf $out/lib/modules/$version/build/Documentation
-        rm -rf $out/lib/modules/$version/build/scripts
-        rm -rf $out/lib/modules/$version/build/include
-
-        # copy architecture dependent files
-        cp -a arch/$archDir/scripts $out/lib/modules/$version/build/ || true
-        cp -a arch/$archDir/*lds $out/lib/modules/$version/build/ || true
-        cp -a arch/$archDir/Makefile*.cpu $out/lib/modules/$version/build/arch/$archDir/ || true
-        cp -a --parents arch/$archDir/kernel/asm-offsets.s $out/lib/modules/$version/build/arch/$archDir/kernel/ || true
-
-        # copy scripts
-        rm -f scripts/*.o
-        rm -f scripts/*/*.o
-        cp -a scripts $out/lib/modules/$version/build
-
-        # copy include files
-        includeDir=$out/lib/modules/$version/build/include
-        mkdir -p $includeDir
-        (cd include && cp -a * $includeDir)
-	(cd arch/$archDir/include && cp -a * $includeDir || true)
-	(cd arch/$archDir/include && cp -a asm/* $includeDir/asm/ || true)
-	(cd arch/$archDir/include/asm/mach-generic && cp -a * $includeDir/ || true)
+    if test -n "$postInstall"; then 
+        eval "$postInstall"; 
     fi
 }
 
diff --git a/pkgs/os-specific/linux/kernel/generic.nix b/pkgs/os-specific/linux/kernel/generic.nix
index 40860384122..f5dd09a2ccc 100644
--- a/pkgs/os-specific/linux/kernel/generic.nix
+++ b/pkgs/os-specific/linux/kernel/generic.nix
@@ -37,11 +37,12 @@
 , preConfigure ? ""
 , extraMeta ? {}
 , ubootChooser ? null
+, postInstall ? ""
 , ...
 }:
 
 assert stdenv.system == "i686-linux" || stdenv.system == "x86_64-linux"
-  || stdenv.system == "armv5tel-linux";
+  || stdenv.system == "armv5tel-linux" || stdenv.system == "ict_loongson-2_v0.3_fpu_v0.1-linux";
 
 assert stdenv.platform.name == "sheevaplug" -> stdenv.platform.uboot != null;
 
@@ -72,7 +73,7 @@ stdenv.mkDerivation {
 
   generateConfig = ./generate-config.pl;
 
-  inherit preConfigure src module_init_tools localVersion;
+  inherit preConfigure src module_init_tools localVersion postInstall;
 
   patches = map (p: p.patch) kernelPatches;
 
@@ -98,6 +99,7 @@ stdenv.mkDerivation {
     if stdenv.system == "i686-linux" then "i386" else
     if stdenv.system == "x86_64-linux" then "x86_64" else
     if stdenv.system == "armv5tel-linux" then "arm" else
+    if stdenv.system == "ict_loongson-2_v0.3_fpu_v0.1-linux" then "mips" else
     abort "Platform ${stdenv.system} is not supported.";
 
   crossAttrs = let
diff --git a/pkgs/os-specific/linux/kernel/linux-nanonote-jz-2.6.34.nix b/pkgs/os-specific/linux/kernel/linux-nanonote-jz-2.6.34.nix
new file mode 100644
index 00000000000..0eb291d5b55
--- /dev/null
+++ b/pkgs/os-specific/linux/kernel/linux-nanonote-jz-2.6.34.nix
@@ -0,0 +1,241 @@
+args @ { stdenv, fetchurl, fetchsvn, userModeLinux ? false, extraConfig ? ""
+, ... }:
+
+let
+  configWithPlatform = kernelPlatform :
+    ''
+      # Don't include any debug features.
+      DEBUG_KERNEL n
+
+      # Support drivers that need external firmware.
+      STANDALONE n
+
+      # Make /proc/config.gz available.
+      IKCONFIG_PROC y
+
+      # Optimize with -O2, not -Os.
+      CC_OPTIMIZE_FOR_SIZE n
+
+      # Enable the kernel's built-in memory tester.
+      MEMTEST y
+
+      # Include the CFQ I/O scheduler in the kernel, rather than as a
+      # module, so that the initrd gets a good I/O scheduler.
+      IOSCHED_CFQ y
+
+      # Disable some expensive (?) features.
+      FTRACE n
+      KPROBES n
+      NUMA? n
+      PM_TRACE_RTC n
+
+      # Enable various subsystems.
+      ACCESSIBILITY y # Accessibility support
+      AUXDISPLAY y # Auxiliary Display support
+      DONGLE y # Serial dongle support
+      HIPPI y
+      MTD_COMPLEX_MAPPINGS y # needed for many devices
+      NET_POCKET y # enable pocket and portable adapters
+      SCSI_LOWLEVEL y # enable lots of SCSI devices
+      SCSI_LOWLEVEL_PCMCIA y
+      SPI y # needed for many devices
+      SPI_MASTER y
+      WAN y
+
+      # Networking options.
+      IP_PNP n
+      IPV6_PRIVACY y
+      NETFILTER_ADVANCED y
+      IP_VS_PROTO_TCP y
+      IP_VS_PROTO_UDP y
+      IP_VS_PROTO_ESP y
+      IP_VS_PROTO_AH y
+      IP_DCCP_CCID3 n # experimental
+      CLS_U32_PERF y
+      CLS_U32_MARK y
+
+      # Wireless networking.
+      IPW2100_MONITOR y # support promiscuous mode
+      IPW2200_MONITOR y # support promiscuous mode
+      IWL4965 y # Intel Wireless WiFi 4965AGN
+      IWL5000 y # Intel Wireless WiFi 5000AGN
+      HOSTAP_FIRMWARE y # Support downloading firmware images with Host AP driver
+      HOSTAP_FIRMWARE_NVRAM y
+
+      # Some settings to make sure that fbcondecor works - in particular,
+      # disable tileblitting and the drivers that need it.
+
+      # Enable various FB devices.
+      FB y
+      FB_EFI y
+      FB_NVIDIA_I2C y # Enable DDC Support
+      FB_RIVA_I2C y
+      FB_ATY_CT y # Mach64 CT/VT/GT/LT (incl. 3D RAGE) support
+      FB_ATY_GX y # Mach64 GX support
+      FB_SAVAGE_I2C y
+      FB_SAVAGE_ACCEL y
+      FB_SIS_300 y
+      FB_SIS_315 y
+      FB_3DFX_ACCEL y
+      FB_GEODE y
+
+      # Video configuration
+      # The intel drivers already require KMS
+      DRM_I915_KMS y
+
+      # Sound.
+      SND_AC97_POWER_SAVE y # AC97 Power-Saving Mode
+      SND_HDA_INPUT_BEEP y # Support digital beep via input layer
+      SND_USB_CAIAQ_INPUT y
+      PSS_MIXER y # Enable PSS mixer (Beethoven ADSP-16 and other compatible)
+
+      # USB serial devices.
+      USB_SERIAL_GENERIC y # USB Generic Serial Driver
+      USB_SERIAL_KEYSPAN_MPR y # include firmware for various USB serial devices
+      USB_SERIAL_KEYSPAN_USA28 y
+      USB_SERIAL_KEYSPAN_USA28X y
+      USB_SERIAL_KEYSPAN_USA28XA y
+      USB_SERIAL_KEYSPAN_USA28XB y
+      USB_SERIAL_KEYSPAN_USA19 y
+      USB_SERIAL_KEYSPAN_USA18X y
+      USB_SERIAL_KEYSPAN_USA19W y
+      USB_SERIAL_KEYSPAN_USA19QW y
+      USB_SERIAL_KEYSPAN_USA19QI y
+      USB_SERIAL_KEYSPAN_USA49W y
+      USB_SERIAL_KEYSPAN_USA49WLC y
+
+      # Filesystem options - in particular, enable extended attributes and
+      # ACLs for all filesystems that support them.
+      EXT2_FS_XATTR y # Ext2 extended attributes
+      EXT2_FS_POSIX_ACL y # Ext2 POSIX Access Control Lists
+      EXT2_FS_SECURITY y # Ext2 Security Labels
+      EXT2_FS_XIP y # Ext2 execute in place support
+      EXT4_FS_POSIX_ACL y
+      EXT4_FS_SECURITY y
+      REISERFS_FS_XATTR y
+      REISERFS_FS_POSIX_ACL y
+      REISERFS_FS_SECURITY y
+      JFS_POSIX_ACL y
+      JFS_SECURITY y
+      XFS_QUOTA y
+      XFS_POSIX_ACL y
+      XFS_RT y # XFS Realtime subvolume support
+      OCFS2_DEBUG_MASKLOG n
+      BTRFS_FS_POSIX_ACL y
+      UBIFS_FS_XATTR y
+      UBIFS_FS_ADVANCED_COMPR y
+      NFSD_V2_ACL y
+      NFSD_V3 y
+      NFSD_V3_ACL y
+      NFSD_V4 y
+      CIFS_XATTR y
+      CIFS_POSIX y
+
+      # Security related features.
+      STRICT_DEVMEM y # Filter access to /dev/mem
+      SECURITY_SELINUX_BOOTPARAM_VALUE 0 # disable SELinux by default
+
+      # Misc. options.
+      8139TOO_8129 y
+      8139TOO_PIO n # PIO is slower
+      AIC79XX_DEBUG_ENABLE n
+      AIC7XXX_DEBUG_ENABLE n
+      AIC94XX_DEBUG n
+      B43_PCMCIA y
+      BLK_DEV_BSG n
+      BLK_DEV_CMD640_ENHANCED y # CMD640 enhanced support
+      BLK_DEV_IDEACPI y # IDE ACPI support
+      BLK_DEV_INTEGRITY y
+      BSD_PROCESS_ACCT_V3 y
+      BT_HCIUART_BCSP y
+      BT_HCIUART_H4 y # UART (H4) protocol support
+      BT_HCIUART_LL y
+      BT_RFCOMM_TTY y # RFCOMM TTY support
+      CPU_FREQ_DEBUG n
+      CRASH_DUMP n
+      DMAR? n # experimental
+      DVB_DYNAMIC_MINORS y # we use udev
+      FUSION y # Fusion MPT device support
+      IDE_GD_ATAPI y # ATAPI floppy support
+      IRDA_ULTRA y # Ultra (connectionless) protocol
+      JOYSTICK_IFORCE_232 y # I-Force Serial joysticks and wheels
+      JOYSTICK_IFORCE_USB y # I-Force USB joysticks and wheels
+      JOYSTICK_XPAD_FF y # X-Box gamepad rumble support
+      JOYSTICK_XPAD_LEDS y # LED Support for Xbox360 controller 'BigX' LED
+      KALLSYMS_EXTRA_PASS n
+      LDM_PARTITION y # Windows Logical Disk Manager (Dynamic Disk) support
+      LEDS_TRIGGER_IDE_DISK y # LED IDE Disk Trigger
+      LOGIRUMBLEPAD2_FF y # Logitech Rumblepad 2 force feedback
+      LOGO n # not needed
+      MEDIA_ATTACH y
+      MEGARAID_NEWGEN y
+      MICROCODE_AMD y
+      MODVERSIONS y
+      MOUSE_PS2_ELANTECH y # Elantech PS/2 protocol extension
+      MTRR_SANITIZER y
+      NET_FC y # Fibre Channel driver support
+      PPP_MULTILINK y # PPP multilink support
+      REGULATOR y # Voltage and Current Regulator Support
+      SCSI_LOGGING y # SCSI logging facility
+      SERIAL_8250 y # 8250/16550 and compatible serial support
+      SLIP_COMPRESSED y # CSLIP compressed headers
+      SLIP_SMART y
+      THERMAL_HWMON y # Hardware monitoring support
+      USB_DEBUG n
+      USB_EHCI_ROOT_HUB_TT y # Root Hub Transaction Translators
+      X86_CHECK_BIOS_CORRUPTION y
+      X86_MCE y
+
+      ${if kernelPlatform ? kernelExtraConfig then kernelPlatform.kernelExtraConfig else ""}
+      ${extraConfig}
+    '';
+in
+
+import ./generic.nix (
+
+  rec {
+    version = "qi_lb60-2.6.34.1-openwrt-22513";
+  
+    src = fetchurl {
+      url = "mirror://kernel/linux/kernel/v2.6/linux-2.6.34.1.tar.bz2";
+      sha256 = "0v78yvkwr100v7bnrkkabxmpv5hjg1ngrjbr5d0kkzsw4d7bmm5x";
+    };
+
+    srcPatch = fetchsvn {
+      url = "svn://svn.openwrt.org/openwrt/trunk/target/linux";
+      rev = 22513;
+      sha256 = "0b7wzgqnbq8sq32z9ik08n1b7fnc9v9d91zwvb6qz7vj3dlrxw3g";
+    };
+
+    preConfigure = ''
+      cp -R ${srcPatch}/generic/files/* .
+      chmod +w -R *
+      GLOBIGNORE='.:..:*preinit_as_init*'
+      for a in ${srcPatch}/generic/patches-2.6.34/* ${srcPatch}/xburst/patches-2.6.34/* ; do
+        echo applying patch $a
+        patch -p1 < $a
+      done
+      unset GLOBIGNORE
+      cat ${srcPatch}/generic/config-2.6.34 ${srcPatch}/xburst/config-2.6.34 \
+          ${srcPatch}/xburst/qi_lb60/config-2.6.34 > arch/mips/configs/qi_lb60_defconfig
+    '';
+
+    postInstall = ''
+      set -x
+      gzip -9 -c $out/vmlinux.bin > $out/vmlinux.bin.gz
+      KERNEL_ENTRY="0x`$crossConfig-nm $out/vmlinux 2>/dev/null |
+        grep " kernel_entry" | cut -f1 -d ' '`"
+      mkimage -A mips -O linux -T kernel -a 0x80010000 -C gzip \
+          -e $KERNEL_ENTRY -n "MIPS Nix Linux-2.6.34" \
+          -d $out/vmlinux.bin.gz $out/uImage
+      set +x
+    '';
+
+    config = configWithPlatform stdenv.platform;
+    configCross = configWithPlatform stdenv.cross.platform;
+
+    features.iwlwifi = true;
+  }
+
+  // removeAttrs args ["extraConfig"]
+)
diff --git a/pkgs/os-specific/linux/kernel/linux-nanonote-jz-2.6.35.nix b/pkgs/os-specific/linux/kernel/linux-nanonote-jz-2.6.35.nix
new file mode 100644
index 00000000000..ac0b000f9cd
--- /dev/null
+++ b/pkgs/os-specific/linux/kernel/linux-nanonote-jz-2.6.35.nix
@@ -0,0 +1,241 @@
+args @ { stdenv, fetchurl, fetchsvn, userModeLinux ? false, extraConfig ? ""
+, ... }:
+
+let
+  configWithPlatform = kernelPlatform :
+    ''
+      # Don't include any debug features.
+      DEBUG_KERNEL n
+
+      # Support drivers that need external firmware.
+      STANDALONE n
+
+      # Make /proc/config.gz available.
+      IKCONFIG_PROC y
+
+      # Optimize with -O2, not -Os.
+      CC_OPTIMIZE_FOR_SIZE n
+
+      # Enable the kernel's built-in memory tester.
+      MEMTEST y
+
+      # Include the CFQ I/O scheduler in the kernel, rather than as a
+      # module, so that the initrd gets a good I/O scheduler.
+      IOSCHED_CFQ y
+
+      # Disable some expensive (?) features.
+      FTRACE n
+      KPROBES n
+      NUMA? n
+      PM_TRACE_RTC n
+
+      # Enable various subsystems.
+      ACCESSIBILITY y # Accessibility support
+      AUXDISPLAY y # Auxiliary Display support
+      DONGLE y # Serial dongle support
+      HIPPI y
+      MTD_COMPLEX_MAPPINGS y # needed for many devices
+      NET_POCKET y # enable pocket and portable adapters
+      SCSI_LOWLEVEL y # enable lots of SCSI devices
+      SCSI_LOWLEVEL_PCMCIA y
+      SPI y # needed for many devices
+      SPI_MASTER y
+      WAN y
+
+      # Networking options.
+      IP_PNP n
+      IPV6_PRIVACY y
+      NETFILTER_ADVANCED y
+      IP_VS_PROTO_TCP y
+      IP_VS_PROTO_UDP y
+      IP_VS_PROTO_ESP y
+      IP_VS_PROTO_AH y
+      IP_DCCP_CCID3 n # experimental
+      CLS_U32_PERF y
+      CLS_U32_MARK y
+
+      # Wireless networking.
+      IPW2100_MONITOR y # support promiscuous mode
+      IPW2200_MONITOR y # support promiscuous mode
+      IWL4965 y # Intel Wireless WiFi 4965AGN
+      IWL5000 y # Intel Wireless WiFi 5000AGN
+      HOSTAP_FIRMWARE y # Support downloading firmware images with Host AP driver
+      HOSTAP_FIRMWARE_NVRAM y
+
+      # Some settings to make sure that fbcondecor works - in particular,
+      # disable tileblitting and the drivers that need it.
+
+      # Enable various FB devices.
+      FB y
+      FB_EFI y
+      FB_NVIDIA_I2C y # Enable DDC Support
+      FB_RIVA_I2C y
+      FB_ATY_CT y # Mach64 CT/VT/GT/LT (incl. 3D RAGE) support
+      FB_ATY_GX y # Mach64 GX support
+      FB_SAVAGE_I2C y
+      FB_SAVAGE_ACCEL y
+      FB_SIS_300 y
+      FB_SIS_315 y
+      FB_3DFX_ACCEL y
+      FB_GEODE y
+
+      # Video configuration
+      # The intel drivers already require KMS
+      DRM_I915_KMS y
+
+      # Sound.
+      SND_AC97_POWER_SAVE y # AC97 Power-Saving Mode
+      SND_HDA_INPUT_BEEP y # Support digital beep via input layer
+      SND_USB_CAIAQ_INPUT y
+      PSS_MIXER y # Enable PSS mixer (Beethoven ADSP-16 and other compatible)
+
+      # USB serial devices.
+      USB_SERIAL_GENERIC y # USB Generic Serial Driver
+      USB_SERIAL_KEYSPAN_MPR y # include firmware for various USB serial devices
+      USB_SERIAL_KEYSPAN_USA28 y
+      USB_SERIAL_KEYSPAN_USA28X y
+      USB_SERIAL_KEYSPAN_USA28XA y
+      USB_SERIAL_KEYSPAN_USA28XB y
+      USB_SERIAL_KEYSPAN_USA19 y
+      USB_SERIAL_KEYSPAN_USA18X y
+      USB_SERIAL_KEYSPAN_USA19W y
+      USB_SERIAL_KEYSPAN_USA19QW y
+      USB_SERIAL_KEYSPAN_USA19QI y
+      USB_SERIAL_KEYSPAN_USA49W y
+      USB_SERIAL_KEYSPAN_USA49WLC y
+
+      # Filesystem options - in particular, enable extended attributes and
+      # ACLs for all filesystems that support them.
+      EXT2_FS_XATTR y # Ext2 extended attributes
+      EXT2_FS_POSIX_ACL y # Ext2 POSIX Access Control Lists
+      EXT2_FS_SECURITY y # Ext2 Security Labels
+      EXT2_FS_XIP y # Ext2 execute in place support
+      EXT4_FS_POSIX_ACL y
+      EXT4_FS_SECURITY y
+      REISERFS_FS_XATTR y
+      REISERFS_FS_POSIX_ACL y
+      REISERFS_FS_SECURITY y
+      JFS_POSIX_ACL y
+      JFS_SECURITY y
+      XFS_QUOTA y
+      XFS_POSIX_ACL y
+      XFS_RT y # XFS Realtime subvolume support
+      OCFS2_DEBUG_MASKLOG n
+      BTRFS_FS_POSIX_ACL y
+      UBIFS_FS_XATTR y
+      UBIFS_FS_ADVANCED_COMPR y
+      NFSD_V2_ACL y
+      NFSD_V3 y
+      NFSD_V3_ACL y
+      NFSD_V4 y
+      CIFS_XATTR y
+      CIFS_POSIX y
+
+      # Security related features.
+      STRICT_DEVMEM y # Filter access to /dev/mem
+      SECURITY_SELINUX_BOOTPARAM_VALUE 0 # disable SELinux by default
+
+      # Misc. options.
+      8139TOO_8129 y
+      8139TOO_PIO n # PIO is slower
+      AIC79XX_DEBUG_ENABLE n
+      AIC7XXX_DEBUG_ENABLE n
+      AIC94XX_DEBUG n
+      B43_PCMCIA y
+      BLK_DEV_BSG n
+      BLK_DEV_CMD640_ENHANCED y # CMD640 enhanced support
+      BLK_DEV_IDEACPI y # IDE ACPI support
+      BLK_DEV_INTEGRITY y
+      BSD_PROCESS_ACCT_V3 y
+      BT_HCIUART_BCSP y
+      BT_HCIUART_H4 y # UART (H4) protocol support
+      BT_HCIUART_LL y
+      BT_RFCOMM_TTY y # RFCOMM TTY support
+      CPU_FREQ_DEBUG n
+      CRASH_DUMP n
+      DMAR? n # experimental
+      DVB_DYNAMIC_MINORS y # we use udev
+      FUSION y # Fusion MPT device support
+      IDE_GD_ATAPI y # ATAPI floppy support
+      IRDA_ULTRA y # Ultra (connectionless) protocol
+      JOYSTICK_IFORCE_232 y # I-Force Serial joysticks and wheels
+      JOYSTICK_IFORCE_USB y # I-Force USB joysticks and wheels
+      JOYSTICK_XPAD_FF y # X-Box gamepad rumble support
+      JOYSTICK_XPAD_LEDS y # LED Support for Xbox360 controller 'BigX' LED
+      KALLSYMS_EXTRA_PASS n
+      LDM_PARTITION y # Windows Logical Disk Manager (Dynamic Disk) support
+      LEDS_TRIGGER_IDE_DISK y # LED IDE Disk Trigger
+      LOGIRUMBLEPAD2_FF y # Logitech Rumblepad 2 force feedback
+      LOGO n # not needed
+      MEDIA_ATTACH y
+      MEGARAID_NEWGEN y
+      MICROCODE_AMD y
+      MODVERSIONS y
+      MOUSE_PS2_ELANTECH y # Elantech PS/2 protocol extension
+      MTRR_SANITIZER y
+      NET_FC y # Fibre Channel driver support
+      PPP_MULTILINK y # PPP multilink support
+      REGULATOR y # Voltage and Current Regulator Support
+      SCSI_LOGGING y # SCSI logging facility
+      SERIAL_8250 y # 8250/16550 and compatible serial support
+      SLIP_COMPRESSED y # CSLIP compressed headers
+      SLIP_SMART y
+      THERMAL_HWMON y # Hardware monitoring support
+      USB_DEBUG n
+      USB_EHCI_ROOT_HUB_TT y # Root Hub Transaction Translators
+      X86_CHECK_BIOS_CORRUPTION y
+      X86_MCE y
+
+      ${if kernelPlatform ? kernelExtraConfig then kernelPlatform.kernelExtraConfig else ""}
+      ${extraConfig}
+    '';
+in
+
+import ./generic.nix (
+
+  rec {
+    version = "qi_lb60-2.6.35-openwrt-22513";
+  
+    src = fetchurl {
+      url = "mirror://kernel/linux/kernel/v2.6/linux-2.6.35.tar.bz2";
+      sha256 = "1kxz87nwksx4hvq1i45i9w1zq1fb09rvf8i6jin3cbh36v1y5chq";
+    };
+
+    srcPatch = fetchsvn {
+      url = "svn://svn.openwrt.org/openwrt/trunk/target/linux";
+      rev = 22530;
+      sha256 = "1j5ls7dg0pvdxh6isczmq4r0lkwhz1c1s46mvdkcjsm3qq633fpc";
+    };
+
+    preConfigure = ''
+      cp -R ${srcPatch}/generic/files/* .
+      chmod +w -R *
+      GLOBIGNORE='.:..:*preinit_as_init*'
+      for a in ${srcPatch}/generic/patches-2.6.35/* ${srcPatch}/xburst/patches-2.6.35/* ; do
+        echo applying patch $a
+        patch -p1 < $a
+      done
+      unset GLOBIGNORE
+      cat ${srcPatch}/generic/config-2.6.35 ${srcPatch}/xburst/config-2.6.35 \
+          ${srcPatch}/xburst/qi_lb60/config-2.6.35 > arch/mips/configs/qi_lb60_defconfig
+    '';
+
+    postInstall = ''
+      set -x
+      gzip -9 -c $out/vmlinux.bin > $out/vmlinux.bin.gz
+      KERNEL_ENTRY="0x`$crossConfig-nm $out/vmlinux 2>/dev/null |
+        grep " kernel_entry" | cut -f1 -d ' '`"
+      mkimage -A mips -O linux -T kernel -a 0x80010000 -C gzip \
+          -e $KERNEL_ENTRY -n "MIPS Nix Linux-2.6.35" \
+          -d $out/vmlinux.bin.gz $out/uImage
+      set +x
+    '';
+
+    config = configWithPlatform stdenv.platform;
+    configCross = configWithPlatform stdenv.cross.platform;
+
+    features.iwlwifi = true;
+  }
+
+  // removeAttrs args ["extraConfig"]
+)
diff --git a/pkgs/os-specific/linux/klibc/default.nix b/pkgs/os-specific/linux/klibc/default.nix
index c3967f4f1ab..5a27816472d 100644
--- a/pkgs/os-specific/linux/klibc/default.nix
+++ b/pkgs/os-specific/linux/klibc/default.nix
@@ -1,26 +1,47 @@
-{stdenv, fetchurl, perl, bison, mktemp, linuxHeaders}:
+{stdenv, fetchurl, perl, bison, mktemp, linuxHeaders, linuxHeadersCross}:
 
 assert stdenv.isLinux;
 
-let version = "1.5.15"; in
+let
+  version = "1.5.18";
+  baseMakeFlags = ["V=1" "prefix=$out" "SHLIBDIR=$out/lib"];
+in
 
 stdenv.mkDerivation {
   name = "klibc-${version}";
 
   src = fetchurl {
-    url = "mirror://kernel/linux/libs/klibc/klibc-${version}.tar.bz2";
-    sha256 = "1x401wmjca6zkyikf9xz45b3wb1hnj0m2s9in1sg6xdhi3pk8lwb";
+    url = "mirror://kernel/linux/libs/klibc/1.5/klibc-${version}.tar.bz2";
+    sha256 = "0ik4ddkfzjrrhpb50i31f2zihqlcnm82yqnl5ci59wx56j5ly474";
   };
   
-  makeFlags = ["V=1" "prefix=$out" "SHLIBDIR=$out/lib"];
+  makeFlags = baseMakeFlags;
+
+  inherit linuxHeaders;
+
+  crossAttrs = {
+    makeFlags = baseMakeFlags ++ [ "CROSS_COMPILE=${stdenv.cross.config}-"
+        "KLIBCARCH=${stdenv.cross.arch}" ];
+
+    patchPhase = ''
+      sed -i 's/-fno-pic -mno-abicalls/& -mabi=32/' usr/klibc/arch/mips/MCONFIG
+      sed -i /KLIBCKERNELSRC/d scripts/Kbuild.install
+      # Wrong check for __mips64 in klibc
+      sed -i s/__mips64__/__mips64/ usr/include/fcntl.h
+    '';
+
+    linuxHeaders = linuxHeadersCross;
+  };
   
+  # The AEABI option concerns only arm systems, and does not affect the build for
+  # other systems.
   preBuild = ''
     sed -i /CONFIG_AEABI/d defconfig
     echo "CONFIG_AEABI=y" >> defconfig
     makeFlags=$(eval "echo $makeFlags")
 
     mkdir linux
-    cp -prsd ${linuxHeaders}/include linux/
+    cp -prsd $linuxHeaders/include linux/
     chmod -R u+w linux/include/
   ''; # */
   
@@ -32,5 +53,5 @@ stdenv.mkDerivation {
     cp usr/dash/sh $dir/
   '';
   
-  buildInputs = [perl bison mktemp];
+  buildNativeInputs = [ perl bison mktemp ];
 }
diff --git a/pkgs/os-specific/linux/lvm2/default.nix b/pkgs/os-specific/linux/lvm2/default.nix
index cffb7e8353d..9a2dc2d28ac 100644
--- a/pkgs/os-specific/linux/lvm2/default.nix
+++ b/pkgs/os-specific/linux/lvm2/default.nix
@@ -9,7 +9,7 @@ stdenv.mkDerivation {
   
   src = fetchurl {
     url = "ftp://sources.redhat.com/pub/lvm2/old/LVM2.${v}.tgz";
-    sha256 =  "2a4157b91b7ad5ea84359e8548b64947611beea01862e010be71f54b649e7ad1";
+    sha256 = "1lbskrj4pxbipq8f0qhql3p1nqa796v4i1cy6n2fmmbs3fwmfh9a";
   };
   
   configureFlags = "--disable-readline --enable-udev_rules --enable-udev_sync";
diff --git a/pkgs/os-specific/linux/pam/default.nix b/pkgs/os-specific/linux/pam/default.nix
index f27c6af31bb..0053d89b605 100644
--- a/pkgs/os-specific/linux/pam/default.nix
+++ b/pkgs/os-specific/linux/pam/default.nix
@@ -9,7 +9,9 @@ stdenv.mkDerivation {
   };
 
   buildInputs = [ flex cracklib ]
-    ++ stdenv.lib.optional (stdenv.system != "armv5tel-linux") libxcrypt;
+    ++ stdenv.lib.optional
+      (stdenv.system != "armv5tel-linux" && stdenv.system != "ict_loongson-2_v0.3_fpu_v0.1-linux")
+      libxcrypt;
 
   postInstall = ''
     mv -v $out/sbin/unix_chkpwd{,.orig}
diff --git a/pkgs/os-specific/linux/uclibc/default.nix b/pkgs/os-specific/linux/uclibc/default.nix
index 83de2ae38ef..5c941f06410 100644
--- a/pkgs/os-specific/linux/uclibc/default.nix
+++ b/pkgs/os-specific/linux/uclibc/default.nix
@@ -1,4 +1,4 @@
-{stdenv, fetchurl, linuxHeaders, cross ? null, gccCross ? null}:
+{stdenv, fetchurl, linuxHeaders, libiconv, cross ? null, gccCross ? null}:
 
 assert stdenv.isLinux;
 assert cross != null -> gccCross != null;
@@ -31,15 +31,21 @@ stdenv.mkDerivation {
     sha256 = "0f1fpdwampbw7pf79i64ipj0azk4kbc9wl81ynlp19p92k4klz0h";
   };
 
+  # 'ftw' needed to build acl, a coreutils dependency
   configurePhase = ''
     make defconfig ${archMakeFlag}
     sed -e s@/usr/include@${linuxHeaders}/include@ \
       -e 's@^RUNTIME_PREFIX.*@RUNTIME_PREFIX="/"@' \
       -e 's@^DEVEL_PREFIX.*@DEVEL_PREFIX="/"@' \
       -e 's@.*UCLIBC_HAS_WCHAR.*@UCLIBC_HAS_WCHAR=y@' \
+      -e 's@.*UCLIBC_HAS_FTW.*@UCLIBC_HAS_FTW=y@' \
       -e 's@.*UCLIBC_HAS_RPC.*@UCLIBC_HAS_RPC=y@' \
       -e 's@.*DO_C99_MATH.*@DO_C99_MATH=y@' \
       -e 's@.*UCLIBC_HAS_PROGRAM_INVOCATION_NAME.*@UCLIBC_HAS_PROGRAM_INVOCATION_NAME=y@' \
+      -e 's@.*CONFIG_MIPS_ISA_1.*@#CONFIG_MIPS_ISA_1=y@' \
+      -e 's@.*CONFIG_MIPS_ISA_3.*@CONFIG_MIPS_ISA_3=y@' \
+      -e 's@.*CONFIG_MIPS_O32_ABI.*@#CONFIG_MIPS_O32_ABI=y@' \
+      -e 's@.*CONFIG_MIPS_N32_ABI.*@CONFIG_MIPS_N32_ABI=y@' \
       ${configArmEABI} \
       ${configBigEndian} \
       -i .config
@@ -59,6 +65,11 @@ stdenv.mkDerivation {
     (cd $out/include && ln -s $(ls -d ${linuxHeaders}/include/* | grep -v "scsi$") .)
     sed -i s@/lib/@$out/lib/@g $out/lib/libc.so
   '';
+
+  passthru = {
+    # Derivations may check for the existance of this attribute, to know what to link to.
+    inherit libiconv;
+  };
   
   meta = {
     homepage = http://www.uclibc.org/;
diff --git a/pkgs/os-specific/linux/util-linux-ng/default.nix b/pkgs/os-specific/linux/util-linux-ng/default.nix
index ca21deb6489..60ffeb70737 100644
--- a/pkgs/os-specific/linux/util-linux-ng/default.nix
+++ b/pkgs/os-specific/linux/util-linux-ng/default.nix
@@ -1,11 +1,11 @@
 { stdenv, fetchurl, ncurses ? null }:
 
 stdenv.mkDerivation rec {
-  name = "util-linux-ng-2.17.2";
+  name = "util-linux-ng-2.18";
 
   src = fetchurl {
-    url = "mirror://kernel/linux/utils/util-linux-ng/v2.17/${name}.tar.bz2";
-    sha256 = "13qifk3i1x59q45fpdz8qnnm7vrhd2zshy5295vhpcjsd8dq1bn9";
+    url = "mirror://kernel/linux/utils/util-linux-ng/v2.18/${name}.tar.bz2";
+    sha256 = "1k1in1ba9kvh0kplri9765wh0yk68qrkk1a55dqsm21qfryc1idq";
   };
 
   configureFlags = ''
diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix
index 0075820a5ad..16597d70c1a 100644
--- a/pkgs/stdenv/adapters.nix
+++ b/pkgs/stdenv/adapters.nix
@@ -179,7 +179,9 @@ rec {
         in buildDrv // {
             inherit hostDrv buildDrv;
         };
-    } // { inherit cross; };
+    } // {
+      inherit cross gccCross binutilsCross;
+    };
 
     
   /* Modify a stdenv so that the specified attributes are added to
diff --git a/pkgs/stdenv/default.nix b/pkgs/stdenv/default.nix
index 40acb8cfece..037a60da7e6 100644
--- a/pkgs/stdenv/default.nix
+++ b/pkgs/stdenv/default.nix
@@ -55,6 +55,7 @@ rec {
     if stdenvType == "i686-linux" then stdenvLinux else
     if stdenvType == "x86_64-linux" then stdenvLinux else
     if stdenvType == "armv5tel-linux" then stdenvLinux else
+    if stdenvType == "ict_loongson-2_v0.3_fpu_v0.1-linux" then stdenvLinux else
     if stdenvType == "powerpc-linux" then /* stdenvLinux */ stdenvNative else
     if stdenvType == "i686-mingw" then stdenvMinGW else
     if stdenvType == "i686-darwin" then stdenvNix else
diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix
index 1d7aaae7ccd..27450a84500 100644
--- a/pkgs/stdenv/generic/default.nix
+++ b/pkgs/stdenv/generic/default.nix
@@ -94,7 +94,8 @@ let
         isLinux = result.system == "i686-linux"
                || result.system == "x86_64-linux"
                || result.system == "powerpc-linux"
-               || result.system == "armv5tel-linux";
+               || result.system == "armv5tel-linux"
+               || result.system == "ict_loongson-2_v0.3_fpu_v0.1-linux";
         isSunOS = result.system == "i386-sunos";
         isCygwin = result.system == "i686-cygwin";
         isi686 = result.system == "i686-linux"
diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh
index 948b6ca3ad6..ba06666ca89 100644
--- a/pkgs/stdenv/generic/setup.sh
+++ b/pkgs/stdenv/generic/setup.sh
@@ -231,6 +231,9 @@ if test "$NIX_NO_SELF_RPATH" != "1"; then
     if test -n "$NIX_LIB64_IN_SELF_RPATH"; then
         export NIX_LDFLAGS="-rpath $out/lib64 $NIX_LDFLAGS"
     fi
+    if test -n "$NIX_LIB32_IN_SELF_RPATH"; then
+        export NIX_LDFLAGS="-rpath $out/lib32 $NIX_LDFLAGS"
+    fi
 fi
 
 
diff --git a/pkgs/stdenv/linux/bootstrap/loongson2f/bzip2 b/pkgs/stdenv/linux/bootstrap/loongson2f/bzip2
new file mode 100755
index 00000000000..f86964d119c
--- /dev/null
+++ b/pkgs/stdenv/linux/bootstrap/loongson2f/bzip2
Binary files differdiff --git a/pkgs/stdenv/linux/bootstrap/loongson2f/cpio b/pkgs/stdenv/linux/bootstrap/loongson2f/cpio
new file mode 100755
index 00000000000..bf6fd66be23
--- /dev/null
+++ b/pkgs/stdenv/linux/bootstrap/loongson2f/cpio
Binary files differdiff --git a/pkgs/stdenv/linux/bootstrap/loongson2f/curl.bz2 b/pkgs/stdenv/linux/bootstrap/loongson2f/curl.bz2
new file mode 100755
index 00000000000..f227a24bf71
--- /dev/null
+++ b/pkgs/stdenv/linux/bootstrap/loongson2f/curl.bz2
Binary files differdiff --git a/pkgs/stdenv/linux/bootstrap/loongson2f/default.nix b/pkgs/stdenv/linux/bootstrap/loongson2f/default.nix
new file mode 100644
index 00000000000..a87f07e00ce
--- /dev/null
+++ b/pkgs/stdenv/linux/bootstrap/loongson2f/default.nix
@@ -0,0 +1,13 @@
+{
+  sh = ./sh;
+  bzip2 = ./bzip2;
+  mkdir = ./mkdir;
+  cpio = ./cpio;
+  ln = ./ln;
+  curl = ./curl.bz2;
+
+  bootstrapTools = {
+    url = "file:///root/cross-bootstrap-tools.cpio.bz2";
+    sha256 = "00aavbk76qjj2gdlmpaaj66r8nzl4d7pyl8cv1gigyzgpbr5vv3j";
+  };
+}
diff --git a/pkgs/stdenv/linux/bootstrap/loongson2f/ln b/pkgs/stdenv/linux/bootstrap/loongson2f/ln
new file mode 100755
index 00000000000..d8afd276424
--- /dev/null
+++ b/pkgs/stdenv/linux/bootstrap/loongson2f/ln
Binary files differdiff --git a/pkgs/stdenv/linux/bootstrap/loongson2f/mkdir b/pkgs/stdenv/linux/bootstrap/loongson2f/mkdir
new file mode 100755
index 00000000000..3a95ccf18d6
--- /dev/null
+++ b/pkgs/stdenv/linux/bootstrap/loongson2f/mkdir
Binary files differdiff --git a/pkgs/stdenv/linux/bootstrap/loongson2f/sh b/pkgs/stdenv/linux/bootstrap/loongson2f/sh
new file mode 100755
index 00000000000..f8ef0a74d6b
--- /dev/null
+++ b/pkgs/stdenv/linux/bootstrap/loongson2f/sh
Binary files differdiff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix
index 71aee5912e7..04009fd5bee 100644
--- a/pkgs/stdenv/linux/default.nix
+++ b/pkgs/stdenv/linux/default.nix
@@ -14,6 +14,7 @@ rec {
     else if system == "x86_64-linux" then import ./bootstrap/x86_64
     else if system == "powerpc-linux" then import ./bootstrap/powerpc
     else if system == "armv5tel-linux" then import ./bootstrap/armv5tel
+    else if system == "ict_loongson-2_v0.3_fpu_v0.1-linux" then import ./bootstrap/loongson2f
     else abort "unsupported platform for the pure Linux stdenv";
 
 
@@ -22,6 +23,7 @@ rec {
       export NIX_ENFORCE_PURITY=1
       havePatchELF=1
       ${if system == "x86_64-linux" then "NIX_LIB64_IN_SELF_RPATH=1" else ""}
+      ${if system == "ict_loongson-2_v0.3_fpu_v0.1-linux" then "NIX_LIB32_IN_SELF_RPATH=1" else ""}
     '';
 
 
@@ -184,6 +186,18 @@ rec {
     bootStdenv = stdenvLinuxBoot2;
   };
 
+  gccWithStaticLibs = stdenvLinuxBoot2Pkgs.gcc.gcc.override (rec {
+        ppl = stdenvLinuxBoot2Pkgs.ppl.override {
+          static = true;
+          gmpxx = stdenvLinuxBoot2Pkgs.gmpxx.override {
+            static = true;
+          };
+        };
+        cloogppl = stdenvLinuxBoot2Pkgs.cloogppl.override {
+          inherit ppl;
+          static = true;
+        };
+      });
 
   # 6) Construct a third stdenv identical to the second, except that
   #    this one uses the dynamically linked GCC and Binutils from step
@@ -194,7 +208,7 @@ rec {
       inherit (stdenvLinuxBoot2Pkgs) binutils;
       coreutils = bootstrapTools;
       libc = stdenvLinuxGlibc;
-      gcc = stdenvLinuxBoot2Pkgs.gcc.gcc;
+      gcc = gccWithStaticLibs;
       name = "";
     };
     overrides = {
@@ -232,7 +246,7 @@ rec {
       inherit (stdenvLinuxBoot2Pkgs) binutils;
       inherit (stdenvLinuxBoot3Pkgs) coreutils;
       libc = stdenvLinuxGlibc;
-      gcc = stdenvLinuxBoot2Pkgs.gcc.gcc;
+      gcc = gccWithStaticLibs;
       shell = stdenvLinuxBoot3Pkgs.bash + "/bin/bash";
       name = "";
     };
diff --git a/pkgs/stdenv/linux/make-bootstrap-tools.nix b/pkgs/stdenv/linux/make-bootstrap-tools.nix
index 3f68738c310..9a337de9b21 100644
--- a/pkgs/stdenv/linux/make-bootstrap-tools.nix
+++ b/pkgs/stdenv/linux/make-bootstrap-tools.nix
@@ -80,7 +80,7 @@ rec {
         cp ${bzip2}/bin/bzip2 $out/bin
         cp -d ${gnumake}/bin/* $out/bin
         cp -d ${patch}/bin/* $out/bin
-        cp ${patchelf05}/bin/* $out/bin
+        cp ${patchelf}/bin/* $out/bin
         cp ${replace}/bin/* $out/bin
 
         cp -d ${gnugrep.pcre}/lib/libpcre*.so* $out/lib # needed by grep
diff --git a/pkgs/stdenv/linux/scripts/unpack-bootstrap-tools.sh b/pkgs/stdenv/linux/scripts/unpack-bootstrap-tools.sh
index 2399e48b026..b3f5dbb546d 100644
--- a/pkgs/stdenv/linux/scripts/unpack-bootstrap-tools.sh
+++ b/pkgs/stdenv/linux/scripts/unpack-bootstrap-tools.sh
@@ -3,31 +3,49 @@ set -e
 # Unpack the bootstrap tools tarball.
 echo Unpacking the bootstrap tools...
 $mkdir $out
-$bzip2 -d < $tarball | (cd $out && $cpio -V -i)
+$bzip2 -d < $tarball | (cd $out && $cpio -i)
 
 # Set the ELF interpreter / RPATH in the bootstrap binaries.
 echo Patching the bootstrap tools...
 
+if test -f $out/lib/ld.so.?; then
+   # MIPS case
+   LD_BINARY=$out/lib/ld.so.?
+else
+   # i686, x86_64 and armv5tel
+   LD_BINARY=$out/lib/ld-*so.?
+fi
+
 # On x86_64, ld-linux-x86-64.so.2 barfs on patchelf'ed programs.  So
 # use a copy of patchelf.
-LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.? $out/bin/cp $out/bin/patchelf .
+LD_LIBRARY_PATH=$out/lib $LD_BINARY $out/bin/cp $out/bin/patchelf .
 
 for i in $out/bin/* $out/libexec/gcc/*/*/*; do
     echo patching $i
     if ! test -L $i; then
-         LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.? \
-             $out/bin/patchelf --set-interpreter $out/lib/ld-linux*.so.? --set-rpath $out/lib --force-rpath $i
-         LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.? \
-             $out/bin/patchelf --set-interpreter $out/lib/ld-linux*.so.? --set-rpath $out/lib --force-rpath $i
+         LD_LIBRARY_PATH=$out/lib $LD_BINARY \
+             $out/bin/patchelf --set-interpreter $LD_BINARY --set-rpath $out/lib --force-rpath $i
+         LD_LIBRARY_PATH=$out/lib $LD_BINARY \
+             $out/bin/patchelf --set-interpreter $LD_BINARY --set-rpath $out/lib --force-rpath $i
     fi
 done
 for i in $out/lib/librt* ; do
     echo patching $i
     if ! test -L $i; then
-         LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.? \
-             $out/bin/patchelf --set-interpreter $out/lib/ld-linux*.so.? --set-rpath $out/lib --force-rpath $i
-         LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.? \
-             $out/bin/patchelf --set-interpreter $out/lib/ld-linux*.so.? --set-rpath $out/lib --force-rpath $i
+         LD_LIBRARY_PATH=$out/lib $LD_BINARY \
+             $out/bin/patchelf --set-interpreter $LD_BINARY --set-rpath $out/lib --force-rpath $i
+         LD_LIBRARY_PATH=$out/lib $LD_BINARY \
+             $out/bin/patchelf --set-interpreter $LD_BINARY --set-rpath $out/lib --force-rpath $i
+    fi
+done
+
+for i in $out/lib/libgmp* $out/lib/libppl* $out/lib/libcloog* $out/lib/libmpc*; do
+    echo trying to patch $i
+    if test -f $i -a ! -L $i; then
+         LD_LIBRARY_PATH=$out/lib $LD_BINARY \
+             $out/bin/patchelf --set-rpath $out/lib --force-rpath $i
+         LD_LIBRARY_PATH=$out/lib $LD_BINARY \
+             $out/bin/patchelf --set-rpath $out/lib --force-rpath $i
     fi
 done
 
diff --git a/pkgs/tools/archivers/gnutar/default.nix b/pkgs/tools/archivers/gnutar/default.nix
index a49b4de52b0..a74b60d9517 100644
--- a/pkgs/tools/archivers/gnutar/default.nix
+++ b/pkgs/tools/archivers/gnutar/default.nix
@@ -1,14 +1,12 @@
 {stdenv, fetchurl}:
 
 stdenv.mkDerivation rec {
-  name = "gnutar-1.22";
-  
+  name = "gnutar-1.23";
+
   src = fetchurl {
-    url = "mirror://gnu/tar/tar-1.22.tar.bz2";
-    sha256 = "0kdaadflxa6wznbbrp0xlxk9926hrr4yg7wr6m98ygvs35zvdvrw";
+    url = "mirror://gnu/tar/tar-1.23.tar.bz2";
+    sha256 = "0dmyxsh0171m6nv8aw74dps1l4b1r7pkqkly9kcv3yv2vdr86cn9";
   };
-  
-  patches = [./implausible.patch];
 
   meta = {
     homepage = http://www.gnu.org/software/tar/;
@@ -30,5 +28,8 @@ stdenv.mkDerivation rec {
     '';
 
     license = "GPLv3+";
+
+    maintainers = [ stdenv.lib.maintainers.ludo ];
+    platforms = stdenv.lib.platforms.all;
   };
 }
diff --git a/pkgs/tools/archivers/gnutar/implausible.patch b/pkgs/tools/archivers/gnutar/implausible.patch
deleted file mode 100644
index a3522c74350..00000000000
--- a/pkgs/tools/archivers/gnutar/implausible.patch
+++ /dev/null
@@ -1,20 +0,0 @@
-diff -rc tar-1.16.1-orig/src/extract.c tar-1.16.1/src/extract.c
-*** tar-1.16.1-orig/src/extract.c	2006-12-07 14:26:00.000000000 +0100
---- tar-1.16.1/src/extract.c	2007-05-24 11:39:47.000000000 +0200
-***************
-*** 194,200 ****
-  static void
-  check_time (char const *file_name, struct timespec t)
-  {
-!   if (t.tv_sec <= 0)
-      WARN ((0, 0, _("%s: implausibly old time stamp %s"),
-  	   file_name, tartime (t, true)));
-    else if (timespec_cmp (volume_start_time, t) < 0)
---- 194,200 ----
-  static void
-  check_time (char const *file_name, struct timespec t)
-  {
-!   if (0 /* t.tv_sec <= 0 */)
-      WARN ((0, 0, _("%s: implausibly old time stamp %s"),
-  	   file_name, tartime (t, true)));
-    else if (timespec_cmp (volume_start_time, t) < 0)
diff --git a/pkgs/tools/compression/bzip2/default.nix b/pkgs/tools/compression/bzip2/default.nix
index 0523067cbad..e8ac6c6418c 100644
--- a/pkgs/tools/compression/bzip2/default.nix
+++ b/pkgs/tools/compression/bzip2/default.nix
@@ -10,6 +10,16 @@ stdenv.mkDerivation {
     sha256 = "08py2s9vw6dgw457lbklh1vsr3b8x8dlv7d8ygdfaxlx61l57gzp";
   };
 
+  crossAttrs = {
+    patchPhase = ''
+      sed -i -e 's/CC=gcc/CC=${stdenv.cross.config}-gcc/' \
+        -e 's/AR=ar/AR=${stdenv.cross.config}-ar/' \
+        -e 's/RANLIB=ranlib/RANLIB=${stdenv.cross.config}-ranlib/' \
+        -e 's/bzip2recover test/bzip2recover/' \
+        Makefile*
+    '';
+  };
+
   sharedLibrary =
     !stdenv.isDarwin && !(stdenv ? isDietLibC) && !(stdenv ? isStatic) && stdenv.system != "i686-cygwin" && !linkStatic;
 
diff --git a/pkgs/tools/misc/coreutils/default.nix b/pkgs/tools/misc/coreutils/default.nix
index 8052ce9fa56..2d1052e3a0f 100644
--- a/pkgs/tools/misc/coreutils/default.nix
+++ b/pkgs/tools/misc/coreutils/default.nix
@@ -1,10 +1,8 @@
-{ stdenv, fetchurl, aclSupport ? false, acl ? null, perl, gmp ? null
-, cross ? null, gccCross ? null }:
+{ stdenv, fetchurl, aclSupport ? false, acl ? null, perl, gmp ? null}:
 
 assert aclSupport -> acl != null;
-assert cross != null -> gccCross != null;
 
-stdenv.mkDerivation (rec {
+stdenv.mkDerivation rec {
   name = "coreutils-8.4";
 
   src = fetchurl {
@@ -13,16 +11,25 @@ stdenv.mkDerivation (rec {
   };
 
   buildNativeInputs = [ perl ];
-  buildInputs =
-       stdenv.lib.optional (gmp != null) gmp
-    ++ stdenv.lib.optional aclSupport acl
-    ++ stdenv.lib.optional (gccCross != null) gccCross;
+  buildInputs = [ gmp ] ++ stdenv.lib.optional aclSupport acl;
+
+  crossAttrs = {
+    buildInputs = [ gmp ]
+      ++ stdenv.lib.optional aclSupport acl.hostDrv
+      ++ stdenv.lib.optional (stdenv.gccCross.libc ? libiconv)
+        stdenv.gccCross.libc.libiconv.hostDrv;
+
+    # Needed for fstatfs()
+    # I don't know why it is not properly detected cross building with glibc.
+    configureFlags = [ "fu_cv_sys_stat_statfs2_bsize=yes" ];
+    doCheck = false;
+  };
 
   # The tests are known broken on Cygwin
   # (http://thread.gmane.org/gmane.comp.gnu.core-utils.bugs/19025),
   # Darwin (http://thread.gmane.org/gmane.comp.gnu.core-utils.bugs/19351),
   # and {Open,Free}BSD.
-  doCheck = (stdenv ? glibc) && (cross == null);
+  doCheck = (stdenv ? glibc);
 
   enableParallelBuilding = true;
 
@@ -42,9 +49,3 @@ stdenv.mkDerivation (rec {
     maintainers = [ stdenv.lib.maintainers.ludo ];
   };
 }
-
-//
-
-(if cross != null
- then { crossConfig = cross.config; }
- else { }))
diff --git a/pkgs/tools/misc/findutils/default.nix b/pkgs/tools/misc/findutils/default.nix
index 2350ab26049..11ed1cf07b5 100644
--- a/pkgs/tools/misc/findutils/default.nix
+++ b/pkgs/tools/misc/findutils/default.nix
@@ -1,14 +1,14 @@
 {stdenv, fetchurl, coreutils}:
 
 stdenv.mkDerivation rec {
-  name = "findutils-4.4.1";
+  name = "findutils-4.4.2";
 
   src = fetchurl {
     url = "mirror://gnu/findutils/${name}.tar.gz";
-    sha256 = "0f61phan4q8w5i1lz768q973c1spfqgvc470jc89rpg0gxfvi9bp";
+    sha256 = "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks3";
   };
 
-  buildInputs = [coreutils];
+  buildNativeInputs = [coreutils];
 
   patches = [ ./findutils-path.patch ./change_echo_path.patch ]
     # Note: the dietlibc patch is just to get findutils to compile.
@@ -17,6 +17,11 @@ stdenv.mkDerivation rec {
 
   doCheck = true;
 
+  crossAttrs = {
+    # http://osdir.com/ml/bug-findutils-gnu/2009-08/msg00026.html
+    configureFlags = [ "gl_cv_func_wcwidth_works=yes" ];
+  };
+
   meta = {
     homepage = http://www.gnu.org/software/findutils/;
     description = "GNU Find Utilities, the basic directory searching utilities of the GNU operating system";
diff --git a/pkgs/tools/package-management/nix/0001-Added-support-for-passing-an-impure-NIX_BUILD_CORES-.patch b/pkgs/tools/package-management/nix/0001-Added-support-for-passing-an-impure-NIX_BUILD_CORES-.patch
new file mode 100644
index 00000000000..e5c4ba1b01e
--- /dev/null
+++ b/pkgs/tools/package-management/nix/0001-Added-support-for-passing-an-impure-NIX_BUILD_CORES-.patch
@@ -0,0 +1,126 @@
+From 9c655f52be055d06cbeb3144e14d6135a8d408e0 Mon Sep 17 00:00:00 2001
+From: Peter Simons <simons@cryp.to>
+Date: Tue, 22 Jun 2010 16:59:03 +0200
+Subject: [PATCH] Added support for passing an (impure) NIX_BUILD_CORES variable to build expressions.
+
+This patch adds the configuration file variable "build-cores" and the
+command line argument "--cores". These settings specify the number of
+CPU cores to utilize for parallel building within a job, i.e. by passing
+an appropriate "-j" flag to GNU Make. The default value is 1, which
+means that parallel building is *disabled*. If the number of build cores
+is specified as 0 (synonymously: "guess" or "auto"), then the actual
+value is supposed to be auto-detected by builders at run-time, i.e by
+calling the nproc(1) utility from coreutils.
+
+The environment variable $NIX_BUILD_CORES is available to builders, but
+the contents of that variable does *not* influence the hash that goes
+into the $out store path, i.e. the number of build cores to be utilized
+can be changed at will without requiring any re-builds.
+---
+ nix.conf.example        |   12 ++++++++++++
+ src/libmain/shared.cc   |   14 ++++++++++++++
+ src/libstore/build.cc   |    3 +++
+ src/libstore/globals.cc |    1 +
+ src/libstore/globals.hh |    5 +++++
+ 5 files changed, 35 insertions(+), 0 deletions(-)
+
+diff --git a/nix.conf.example b/nix.conf.example
+index e17cf3c..6175d86 100644
+--- a/nix.conf.example
++++ b/nix.conf.example
+@@ -59,6 +59,18 @@
+ #build-max-jobs = 1
+ 
+ 
++### Option `build-cores'
++#
++# This option defines the number of CPU cores to utilize in parallel
++# within a build job, i.e. by passing an appropriate `-jN' flag to
++# GNU make. The default is 1, meaning that parallel building within
++# jobs is disabled. Passing the special values `0', `auto', or
++# `guess' causes Nix to try and auto-detect the number of available
++# cores on the local host. This setting can be overridden using the
++# `--cores' command line switch.
++#build-cores = 1
++
++
+ ### Option `build-max-silent-time'
+ #
+ # This option defines the maximum number of seconds that a builder can
+diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc
+index 3fbec4b..19aa1e7 100644
+--- a/src/libmain/shared.cc
++++ b/src/libmain/shared.cc
+@@ -135,6 +135,12 @@ static void initAndRun(int argc, char * * argv)
+     /* Get some settings from the configuration file. */
+     thisSystem = querySetting("system", SYSTEM);
+     maxBuildJobs = queryIntSetting("build-max-jobs", 1);
++    string tmp = querySetting("build-cores", "/UNDEFINED");
++    std::transform(tmp.begin(), tmp.end(), tmp.begin(), tolower);
++    if (tmp == "auto" || tmp == "guess")
++      buildCores = 0;
++    else
++      buildCores = queryIntSetting("build-cores", 1);
+     maxSilentTime = queryIntSetting("build-max-silent-time", 0);
+ 
+     /* Catch SIGINT. */
+@@ -226,6 +232,14 @@ static void initAndRun(int argc, char * * argv)
+             tryFallback = true;
+         else if (arg == "--max-jobs" || arg == "-j")
+             maxBuildJobs = getIntArg<unsigned int>(arg, i, args.end());
++        else if (arg == "--cores") {
++            string tmp = *(++i);
++            std::transform(tmp.begin(), tmp.end(), tmp.begin(), tolower);
++            if (tmp == "auto" || tmp == "guess")
++              buildCores = 0u;
++            else
++              buildCores = getIntArg<unsigned int>(arg, --i, args.end());
++        }
+         else if (arg == "--readonly-mode")
+             readOnlyMode = true;
+         else if (arg == "--max-silent-time")
+diff --git a/src/libstore/build.cc b/src/libstore/build.cc
+index f901c1f..a53c23b 100644
+--- a/src/libstore/build.cc
++++ b/src/libstore/build.cc
+@@ -1411,6 +1411,9 @@ void DerivationGoal::startBuilder()
+        in the store or in the build directory). */
+     env["NIX_STORE"] = nixStore;
+ 
++    /* The maximum number of cores to utilize for parallel building. */
++    env["NIX_BUILD_CORES"] = (format("%d") % buildCores).str();
++
+     /* Add all bindings specified in the derivation. */
+     foreach (StringPairs::iterator, i, drv.env)
+         env[i->first] = i->second;
+diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
+index cc0e44e..75d2f69 100644
+--- a/src/libstore/globals.cc
++++ b/src/libstore/globals.cc
+@@ -22,6 +22,7 @@ bool keepGoing = false;
+ bool tryFallback = false;
+ Verbosity buildVerbosity = lvlInfo;
+ unsigned int maxBuildJobs = 1;
++unsigned int buildCores = 1;
+ bool readOnlyMode = false;
+ string thisSystem = "unset";
+ time_t maxSilentTime = 0;
+diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh
+index d3388e3..a74a741 100644
+--- a/src/libstore/globals.hh
++++ b/src/libstore/globals.hh
+@@ -55,6 +55,11 @@ extern Verbosity buildVerbosity;
+ /* Maximum number of parallel build jobs.  0 means unlimited. */
+ extern unsigned int maxBuildJobs;
+ 
++/* Number of CPU cores to utilize in parallel within a build, i.e. by passing
++   this number to Make via '-j'. 0 means that the number of actual CPU cores on
++   the local host ought to be auto-detected. */
++extern unsigned int buildCores;
++
+ /* Read-only mode.  Don't copy stuff to the store, don't change the
+    database. */
+ extern bool readOnlyMode;
+-- 
+1.7.1
+
diff --git a/pkgs/tools/text/diffutils/default.nix b/pkgs/tools/text/diffutils/default.nix
index 44b7715607c..4fde88d9262 100644
--- a/pkgs/tools/text/diffutils/default.nix
+++ b/pkgs/tools/text/diffutils/default.nix
@@ -1,15 +1,15 @@
 {stdenv, fetchurl, coreutils ? null}:
 
 stdenv.mkDerivation {
-  name = "diffutils-2.8.1";
+  name = "diffutils-3.0";
   
   src = fetchurl {
-    url = mirror://gnu/diffutils/diffutils-2.8.1.tar.gz;
-    md5 = "71f9c5ae19b60608f6c7f162da86a428";
+    url = mirror://gnu/diffutils/diffutils-3.0.tar.gz;
+    sha256 = "02g8i6jv0j0vr5nl13ns50lv2dbjy9kkk8jvp11n0g5fpdjizf9g";
   };
   
   /* If no explicit coreutils is given, use the one from stdenv. */
-  buildInputs = [coreutils];
+  buildNativeInputs = [coreutils];
 
   meta = {
     homepage = http://www.gnu.org/software/diffutils/diffutils.html;
diff --git a/pkgs/tools/text/gnugrep/default.nix b/pkgs/tools/text/gnugrep/default.nix
index 609213aaa67..1cd73a8814c 100644
--- a/pkgs/tools/text/gnugrep/default.nix
+++ b/pkgs/tools/text/gnugrep/default.nix
@@ -1,13 +1,15 @@
 {stdenv, fetchurl, pcre}:
 
-let version = "2.5.4"; in
+let version = "2.6.3"; in
 
 stdenv.mkDerivation {
   name = "gnugrep-${version}";
   
+  patches = [ ./malloc.patch ];
+  
   src = fetchurl {
-    url = "mirror://gnu/grep/grep-${version}.tar.bz2";
-    sha256 = "0800lj1ywf43x5jnjyga56araak0f601sd9k5q1vv3s5057cdgha";
+    url = "mirror://gnu/grep/grep-${version}.tar.gz";
+    sha256 = "0rnnljzcpb2sl5zabww7gbzk9r6kp8kycsqrf909d6jdak8yah53";
   };
   
   buildInputs = [pcre];
diff --git a/pkgs/tools/text/gnugrep/malloc.patch b/pkgs/tools/text/gnugrep/malloc.patch
new file mode 100644
index 00000000000..b645c64a09e
--- /dev/null
+++ b/pkgs/tools/text/gnugrep/malloc.patch
@@ -0,0 +1,15 @@
+http://www.mail-archive.com/bug-grep@gnu.org/msg02537.html
+
+diff --git a/src/kwset.c b/src/kwset.c
+index 050562e..995be79 100644
+--- a/src/kwset.c
++++ b/src/kwset.c
+@@ -40,7 +40,7 @@
+ #ifdef GREP
+ # include "xalloc.h"
+ # undef malloc
+-# define malloc(s) xmalloc(s)
++# define malloc xmalloc
+ #endif
+
+ #define NCHAR (UCHAR_MAX + 1)
diff --git a/pkgs/tools/text/gnupatch/default.nix b/pkgs/tools/text/gnupatch/default.nix
index 513a98fdf07..ff469ddad25 100644
--- a/pkgs/tools/text/gnupatch/default.nix
+++ b/pkgs/tools/text/gnupatch/default.nix
@@ -8,8 +8,8 @@ stdenv.mkDerivation rec {
     then fetchurl {
       # Temporary fix for
       # http://lists.gnu.org/archive/html/bug-patch/2010-01/msg00004.html .
-      url = "http://nixos.org/tarballs/patch-2.6.1-2-g2c4e3ec.tar.gz";
-      sha256 = "1rspyzrik5cnav3m2fxr8146bsq4mc0yw4x0r8nkl2x7i052yr2c";
+      url = "ftp://alpha.gnu.org/gnu/patch/patch-2.6.1.87-94d8.tar.gz";
+      sha256 = "0jnw8p0nvkmwi1a2z56bssqik8fvkb71zd2cpzl1sklnrg1g3b6p";
     } else fetchurl {
       url = "mirror://gnu/patch/${name}.tar.gz";
       sha256 = "1fc1jyq80nswkf492fiqdbl2bhvlw2wb44ghqlfd3zngx4qkfmni";
@@ -17,6 +17,10 @@ stdenv.mkDerivation rec {
 
   buildInputs = (stdenv.lib.optional doCheck ed);
 
+  crossAttrs = {
+    configureFlags = [ "ac_cv_func_strnlen_working=yes" ];
+  };
+
   doCheck = true;
 
   meta = {
diff --git a/pkgs/tools/text/gnused/default.nix b/pkgs/tools/text/gnused/default.nix
index cea26999be0..66fcb3d1929 100644
--- a/pkgs/tools/text/gnused/default.nix
+++ b/pkgs/tools/text/gnused/default.nix
@@ -1,15 +1,12 @@
 {stdenv, fetchurl}:
 
 stdenv.mkDerivation {
-  name = "gnused-4.1.5";
-  
+  name = "gnused-4.2.1";
+
   src = fetchurl {
-    url = mirror://gnu/sed/sed-4.1.5.tar.gz;
-    md5 = "7a1cbbbb3341287308e140bd4834c3ba";
+    url = mirror://gnu/sed/sed-4.2.1.tar.gz;
+    sha256 = "0q1hzjvr6pzhaagidg7pj76k1fzz5nl15np7p72w9zcpw0f58ww7";
   };
-  
-  # !!! hack: this should go away in gnused > 4.1.5
-  patches = [./gettext-fix.patch];
 
   meta = {
     homepage = http://www.gnu.org/software/sed/;
@@ -24,6 +21,9 @@ stdenv.mkDerivation {
       multiple occurrences of a string within a file.
     '';
 
-    license = "GPLv2+";
+    license = "GPLv3+";
+
+    platforms = stdenv.lib.platforms.all;
+    maintainers = [ stdenv.lib.maintainers.ludo ];
   };
 }
diff --git a/pkgs/tools/text/gnused/gettext-fix.patch b/pkgs/tools/text/gnused/gettext-fix.patch
deleted file mode 100644
index 8ef7e8b5ce4..00000000000
--- a/pkgs/tools/text/gnused/gettext-fix.patch
+++ /dev/null
@@ -1,32 +0,0 @@
-diff -rc sed-4.1.5-orig/configure sed-4.1.5/configure
-*** sed-4.1.5-orig/configure	Fri Feb  3 10:24:40 2006
---- sed-4.1.5/configure	Fri Jul 14 12:50:13 2006
-***************
-*** 11265,11277 ****
-        esac
-      done ;;
-      gettext-fix )
-!   sed -e '/^mkinstalldirs *=/a\' \
-!       -e "install_sh=$install_sh" \
-        -e 's/^mkinstalldirs *=.*/mkinstalldirs=$(MKINSTALLDIRS)/' \
-        intl/Makefile > intl/Makefile.tmp
-    mv intl/Makefile.tmp intl/Makefile
-!   sed -e '/^mkinstalldirs *=/a\' \
-!       -e "install_sh=$install_sh" \
-        -e 's/^mkinstalldirs *=.*/mkinstalldirs=$(MKINSTALLDIRS)/' \
-        po/Makefile > po/Makefile.tmp
-    mv po/Makefile.tmp po/Makefile ;;
---- 11265,11277 ----
-        esac
-      done ;;
-      gettext-fix )
-!   sed -e "/^mkinstalldirs *=/a\\
-! install_sh=$install_sh" \
-        -e 's/^mkinstalldirs *=.*/mkinstalldirs=$(MKINSTALLDIRS)/' \
-        intl/Makefile > intl/Makefile.tmp
-    mv intl/Makefile.tmp intl/Makefile
-!   sed -e "/^mkinstalldirs *=/a\\
-! install_sh=$install_sh" \
-        -e 's/^mkinstalldirs *=.*/mkinstalldirs=$(MKINSTALLDIRS)/' \
-        po/Makefile > po/Makefile.tmp
-    mv po/Makefile.tmp po/Makefile ;;
diff --git a/pkgs/tools/text/replace/default.nix b/pkgs/tools/text/replace/default.nix
index 0182a3bb48d..339bf510c4b 100644
--- a/pkgs/tools/text/replace/default.nix
+++ b/pkgs/tools/text/replace/default.nix
@@ -10,6 +10,10 @@ stdenv.mkDerivation {
 
   makeFlags = ["TREE=\$(out)"];
 
+  crossAttrs = {
+    makeFlags = [ "TREE=\$(out)" "CC=${stdenv.cross.config}-gcc" ];
+  };
+
   postInstall = "mv \$out/bin/replace \$out/bin/replace-literal";
 
   patches = [./malloc.patch];
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 298c380f5f0..4c8a1da089e 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -187,7 +187,7 @@ let
     gccCrossStageFinal;
 
   stdenv =
-    if bootStdenv != null then bootStdenv else
+    if bootStdenv != null then (bootStdenv // {inherit platform;}) else
       let changer = getConfig ["replaceStdenv"] null;
       in if changer != null then
         changer {
@@ -1424,7 +1424,7 @@ let
 
   gambit = callPackage ../development/compilers/gambit { };
 
-  gcc = gcc44;
+  gcc = gcc45;
 
   gcc295 = wrapGCC (import ../development/compilers/gcc-2.95 {
     inherit fetchurl stdenv noSysDirs;
@@ -1460,8 +1460,6 @@ let
     profiledCompiler = false;
   });
 
-  gcc44 = gcc44_real;
-
   gcc43 = lowPrio (wrapGCC (makeOverridable (import ../development/compilers/gcc-4.3) {
     inherit stdenv fetchurl texinfo gmp mpfr noSysDirs;
     profiledCompiler = true;
@@ -1479,7 +1477,7 @@ let
 
   gcc44_realCross = lib.addMetaAttrs { platforms = []; }
     (makeOverridable (import ../development/compilers/gcc-4.4) {
-      inherit stdenv fetchurl texinfo gmp mpfr ppl cloogppl noSysDirs
+      inherit stdenv fetchurl texinfo gmp mpfr /* ppl cloogppl */ noSysDirs
           gettext which;
       binutilsCross = binutilsCross;
       libcCross = libcCross;
@@ -1489,6 +1487,8 @@ let
       cross = assert crossSystem != null; crossSystem;
     });
 
+  gcc45 = gcc45_real;
+
   gcc45_realCross = lib.addMetaAttrs { platforms = []; }
     (makeOverridable (import ../development/compilers/gcc-4.5) {
       inherit fetchurl stdenv texinfo gmp mpfr mpc libelf zlib
@@ -1547,17 +1547,19 @@ let
     enableMultilib = true;
   }));
 
-  gcc44_real = lowPrio (wrapGCC (makeOverridable (import ../development/compilers/gcc-4.4) {
+  gcc44 = lowPrio (wrapGCC (makeOverridable (import ../development/compilers/gcc-4.4) {
     inherit fetchurl stdenv texinfo gmp mpfr /* ppl cloogppl */
       gettext which noSysDirs;
     profiledCompiler = true;
   }));
 
-  gcc45 = lowPrio (wrapGCC (makeOverridable (import ../development/compilers/gcc-4.5) {
+  gcc45_real = lowPrio (wrapGCC (makeOverridable (import ../development/compilers/gcc-4.5) {
     inherit fetchurl stdenv texinfo gmp mpfr mpc libelf zlib perl
       ppl cloogppl
       gettext which noSysDirs;
-    profiledCompiler = true;
+    # bootstrapping a profiled compiler does not work in the sheevaplug:
+    # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43944
+    profiledCompiler = if stdenv.system == "armv5tel-linux" then false else true;
   }));
 
   gccApple =
@@ -1571,7 +1573,7 @@ let
     texinfo = texinfo49;
   });
 
-  gfortran = gfortran43;
+  gfortran = gfortran45;
 
   gfortran40 = wrapGCC (gcc40.gcc.override {
     langFortran = true;
@@ -1603,7 +1605,15 @@ let
     profiledCompiler = false;
   });
 
-  gfortran44 = wrapGCC (gcc44_real.gcc.override {
+  gfortran44 = wrapGCC (gcc44.gcc.override {
+    name = "gfortran";
+    langFortran = true;
+    langCC = false;
+    langC = false;
+    profiledCompiler = false;
+  });
+
+  gfortran45 = wrapGCC (gcc45_real.gcc.override {
     name = "gfortran";
     langFortran = true;
     langCC = false;
@@ -1613,7 +1623,7 @@ let
 
   gcj = gcj45;
 
-  gcj44 = wrapGCC (gcc44_real.gcc.override {
+  gcj44 = wrapGCC (gcc44.gcc.override {
     name = "gcj";
     langJava = true;
     langFortran = false;
@@ -1641,9 +1651,22 @@ let
       libXrandr xproto renderproto xextproto inputproto randrproto;
   });
 
-  gnat = gnat44;
+  gnat = gnat45;
+
+  gnat44 = wrapGCC (gcc44.gcc.override {
+    name = "gnat";
+    langCC = false;
+    langC = true;
+    langAda = true;
+    profiledCompiler = false;
+    inherit gnatboot;
+    # We can't use the ppl stuff, because we would have
+    # libstdc++ problems.
+    cloogppl = null;
+    ppl = null;
+  });
 
-  gnat44 = wrapGCC (gcc44_real.gcc.override {
+  gnat45 = wrapGCC (gcc45_real.gcc.override {
     name = "gnat";
     langCC = false;
     langC = true;
@@ -1840,9 +1863,7 @@ let
   # commented out because it's using the new configuration style proposal which is unstable
   hugs = callPackage ../development/compilers/hugs { };
 
-  path64 = callPackage ../development/compilers/path64 {
-    stdenv = stdenv2;
-  };
+  path64 = callPackage ../development/compilers/path64 { };
 
   openjdkDarwin = callPackage ../development/compilers/openjdk-darwin { };
 
@@ -1968,14 +1989,6 @@ let
 
   wrapGCC = wrapGCCWith (import ../build-support/gcc-wrapper) glibc;
 
-  # To be removed on stdenv-updates
-  # By now this has at least the fix of setting the proper rpath when a file "libbla.so"
-  # is passed directly to the linker.
-  # This is of interest to programs built by cmake, because this is a common practice
-  # in cmake builds.
-  wrapGCC2 = wrapGCCWith (import ../build-support/gcc-wrapper/default2.nix) glibc;
-  stdenv2 = if (gcc.nativeTools) then stdenv else (overrideGCC stdenv (wrapGCC2 gcc.gcc));
-
   wrapGCCCross =
     {gcc, libc, binutils, cross, shell ? "", name ? "gcc-cross-wrapper"}:
 
@@ -2268,10 +2281,17 @@ let
 
   avrdude = callPackage ../development/tools/misc/avrdude { };
 
-  binutils = callPackage ../development/tools/misc/binutils {
+  binutils_release = callPackage ../development/tools/misc/binutils {
+    inherit noSysDirs;
+  };
+
+  binutils_snapshot = callPackage ../development/tools/misc/binutils/snapshot.nix {
     inherit noSysDirs;
   };
 
+  binutils = if stdenv.system == "ict_loongson-2_v0.3_fpu_v0.1-linux" then binutils_snapshot
+    else binutils_release;
+
   binutilsCross = forceBuildDrv (import ../development/tools/misc/binutils {
       inherit stdenv fetchurl;
       noSysDirs = true;
@@ -2617,7 +2637,6 @@ let
   clanlib = callPackage ../development/libraries/clanlib { };
 
   clapack = callPackage ../development/libraries/clapack {
-    stdenv = stdenv2;
   };
 
   classads = callPackage ../development/libraries/classads { };
@@ -2792,9 +2811,6 @@ let
 
   gettext = callPackage ../development/libraries/gettext { };
 
-  # XXX: Remove me when `stdenv-updates' is merged.
-  gettext_0_18 = callPackage ../development/libraries/gettext/0.18.nix { };
-
   gd = callPackage ../development/libraries/gd { };
 
   gdal = callPackage ../development/libraries/gdal { };
@@ -2906,14 +2922,16 @@ let
   gmm = callPackage ../development/libraries/gmm { };
 
   gmp =
-    if stdenv.system == "i686-darwin" then
+    if false then # XXX: stdenv.system == "i686-darwin" then
       # GMP 4.3.2 is broken on Darwin, so use 4.3.1.
       makeOverridable (import ../development/libraries/gmp/4.3.1.nix) {
         inherit stdenv fetchurl m4;
         cxx = false;
       }
     else
-      makeOverridable (import ../development/libraries/gmp) {
+      # We temporarily leave gmp 4 here, waiting for a new ppl/cloog-ppl that
+      # would build well with gmp 5.
+      makeOverridable (import ../development/libraries/gmp/4.nix) {
         inherit stdenv fetchurl m4;
         cxx = false;
       };
@@ -3553,7 +3571,6 @@ let
   opencv = callPackage ../development/libraries/opencv {
       inherit (gtkLibs) gtk glib;
       inherit (gst_all) gstreamer;
-      stdenv = stdenv2;
   };
 
   # this ctl version is needed by openexr_viewers
@@ -3695,8 +3712,9 @@ let
   schroedinger = callPackage ../development/libraries/schroedinger { };
 
   SDL = callPackage ../development/libraries/SDL {
-    openglSupport = mesaSupported;
+    openglSupport = false; #mesaSupported;
     alsaSupport = true;
+    x11Support = false;
     pulseaudioSupport = false; # better go through ALSA
   };
 
@@ -4141,7 +4159,7 @@ let
     ps = procps; /* !!! Linux only */
   };
 
-  mysql = mysql5;
+  mysql = mysql51;
 
   mysql_jdbc = callPackage ../servers/sql/mysql/jdbc { };
 
@@ -4395,7 +4413,7 @@ let
 
   libcroup = callPackage ../os-specific/linux/libcg { };
 
-  linuxHeaders = linuxHeaders_2_6_28;
+  linuxHeaders = linuxHeaders_2_6_32;
 
   linuxHeaders26Cross = forceBuildDrv (import ../os-specific/linux/kernel-headers/2.6.32.nix {
     inherit stdenv fetchurl perl;
@@ -4542,6 +4560,16 @@ let
       ];
   };
 
+  linux_nanonote_jz_2_6_34 = makeOverridable
+    (import ../os-specific/linux/kernel/linux-nanonote-jz-2.6.34.nix) {
+      inherit fetchurl fetchsvn stdenv perl mktemp module_init_tools ubootChooser;
+    };
+
+  linux_nanonote_jz_2_6_35 = makeOverridable
+    (import ../os-specific/linux/kernel/linux-nanonote-jz-2.6.35.nix) {
+      inherit fetchurl fetchsvn stdenv perl mktemp module_init_tools ubootChooser;
+    };
+
   linux_2_6_35_oldI686 = linux_2_6_35.override {
       extraConfig = ''
           HIGHMEM64G? n
@@ -4655,6 +4683,8 @@ let
   linuxPackages_2_6_33 = recurseIntoAttrs (linuxPackagesFor linux_2_6_33 pkgs.linuxPackages_2_6_33);
   linuxPackages_2_6_34 = recurseIntoAttrs (linuxPackagesFor linux_2_6_34 pkgs.linuxPackages_2_6_34);
   linuxPackages_2_6_35 = recurseIntoAttrs (linuxPackagesFor linux_2_6_35 pkgs.linuxPackages_2_6_35);
+  linuxPackages_nanonote_jz_2_6_34 = recurseIntoAttrs (linuxPackagesFor linux_nanonote_jz_2_6_34 pkgs.linuxPackages_nanonote_jz_2_6_34); 
+  linuxPackages_nanonote_jz_2_6_35 = recurseIntoAttrs (linuxPackagesFor linux_nanonote_jz_2_6_35 pkgs.linuxPackages_nanonote_jz_2_6_35); 
 
   # The current default kernel / kernel modules.
   linux = linux_2_6_32;
@@ -4837,16 +4867,19 @@ let
 
   ubootChooser = name : if (name == "upstream") then ubootUpstream
     else if (name == "sheevaplug") then ubootSheevaplug
+    else if (name == "nanonote") then ubootNanonote
     else throw "Unknown uboot";
 
   ubootUpstream = callPackage ../misc/uboot { };
 
   ubootSheevaplug = callPackage ../misc/uboot/sheevaplug.nix { };
 
+  ubootNanonote = callPackage ../misc/uboot/nanonote.nix { };
+
   uclibc = callPackage ../os-specific/linux/uclibc { };
 
   uclibcCross = import ../os-specific/linux/uclibc {
-    inherit fetchurl stdenv;
+    inherit fetchurl stdenv libiconv;
     linuxHeaders = linuxHeadersCross;
     gccCross = gccCrossStageStatic;
     cross = assert crossSystem != null; crossSystem;
@@ -5098,7 +5131,6 @@ let
 
   avidemux = callPackage ../applications/video/avidemux {
     inherit (gtkLibs) gtk;
-    stdenv = stdenv2;
   };
 
   awesome = callPackage ../applications/window-managers/awesome {
@@ -5144,15 +5176,13 @@ let
 
   blender = callPackage ../applications/misc/blender/2.49.nix {
     python = python26Base;
-    stdenv = stdenv2;
   };
 
   blender_2_50 = lowPrio (import ../applications/misc/blender {
-    inherit fetchurl cmake mesa gettext libjpeg libpng zlib openal SDL openexr
+    inherit stdenv fetchurl cmake mesa gettext libjpeg libpng zlib openal SDL openexr
       libsamplerate libtiff ilmbase;
     inherit (xlibs) libXi;
     python = python31Base;
-    stdenv = stdenv2;
   });
 
   bmp = callPackage ../applications/audio/bmp {
@@ -5640,7 +5670,6 @@ let
   };
 
   hugin = callPackage ../applications/graphics/hugin {
-    stdenv = stdenv2;
   };
 
   i810switch = callPackage ../os-specific/linux/i810switch { };
@@ -5889,7 +5918,6 @@ let
     inherit (perlPackages) ArchiveZip CompressZlib;
     inherit (gnome) GConf ORBit2;
     neon = neon029;
-    stdenv = stdenv2;
   };
 
   go_oo = callPackage ../applications/office/openoffice/go-oo.nix {
@@ -5897,7 +5925,6 @@ let
     inherit (perlPackages) ArchiveZip CompressZlib;
     inherit (gnome) GConf ORBit2;
     neon = neon029;
-    stdenv = stdenv2;
   };
 
   opera = callPackage ../applications/networking/browsers/opera {
@@ -5918,7 +5945,6 @@ let
   };
 
   paraview = callPackage ../applications/graphics/paraview {
-    stdenv = stdenv2;
   };
 
   partitionManager = callPackage ../tools/misc/partition-manager {
@@ -6467,6 +6493,8 @@ let
     inherit (gtkLibs) gtk /*glib gtkmm*/;
   };
 
+  prboom = callPackage ../games/prboom { };
+
   quake3demo = callPackage ../games/quake3/wrapper {
     name = "quake3-demo-${quake3game.name}";
     description = "Demo of Quake 3 Arena, a classic first-person shooter";
@@ -6609,7 +6637,7 @@ let
 
   kde44 = makeOverridable (import ../desktops/kde-4.4) (pkgs // {
     qt4 = qt46;
-    stdenv = stdenv2;
+    inherit stdenv;
   });
 
   kde45 = callPackage ../desktops/kde-4.5 {
@@ -6617,7 +6645,6 @@ let
       pyqt4 = pyqt4.override { qt4 = qt47; };
       libdbusmenu_qt = libdbusmenu_qt.override { qt4 = qt47; };
       shared_desktop_ontologies = shared_desktop_ontologies.override { v = "0.5"; };
-      stdenv = stdenv2;
     } // pkgs.kde45);
   };
 
@@ -6757,9 +6784,7 @@ let
 
   golly = callPackage ../applications/science/misc/golly { };
 
-  simgrid = callPackage ../applications/science/misc/simgrid {
-    stdenv = stdenv2;
-  };
+  simgrid = callPackage ../applications/science/misc/simgrid { };
 
   tulip = callPackage ../applications/science/misc/tulip {
     qt = qt4;
@@ -6767,7 +6792,6 @@ let
 
   vite = callPackage ../applications/science/misc/vite {
     qt = qt4;
-    stdenv = stdenv2;
   };
 
   ### MISC
diff --git a/pkgs/top-level/platforms.nix b/pkgs/top-level/platforms.nix
index cb35db579b7..c3d9b1005f7 100644
--- a/pkgs/top-level/platforms.nix
+++ b/pkgs/top-level/platforms.nix
@@ -152,4 +152,57 @@ rec {
     uboot = "upstream";
     ubootConfig = "integratorcp_config";
   };
+
+  fuloong2f_n32 = {
+    name = "fuloong2f_n32";
+    kernelMajor = "2.6";
+    kernelHeadersBaseConfig = "fuloong2e_defconfig";
+    kernelBaseConfig = "lemote2f_defconfig";
+    kernelArch = "mips";
+    kernelAutoModules = false;
+    kernelExtraConfig =
+      ''
+        BLK_DEV_RAM y
+        BLK_DEV_INITRD y
+        BLK_DEV_CRYPTOLOOP m
+        BLK_DEV_DM m
+        DM_CRYPT m
+        MD y
+        REISERFS_FS m
+        EXT4_FS m
+        USB_STORAGE_CYPRESS_ATACB m
+
+        IP_PNP y
+        NFS_FS y
+        ROOT_NFS y
+        TUN m
+        NFS_V4 y
+        NFS_V4_1 y
+        NFS_FSCACHE y
+        NFSD m
+        NFSD_V2_ACL y
+        NFSD_V3 y
+        NFSD_V3_ACL y
+        NFSD_V4 y
+
+        # Fail to build
+        DRM n
+        SCSI_ADVANSYS n
+        USB_ISP1362_HCD n
+        SND_SOC n
+        SND_ALI5451 n
+        FB_SAVAGE n
+        SCSI_NSP32 n
+        ATA_SFF n
+        SUNGEM n
+        IRDA n
+        ATM_HE n
+        SCSI_ACARD n
+        BLK_DEV_CMD640_ENHANCED n
+
+        FUSE_FS m
+      '';
+    kernelTarget = "vmlinux";
+    uboot = null;
+  };
 }
diff --git a/pkgs/top-level/release-lib.nix b/pkgs/top-level/release-lib.nix
index a470098529f..0345ebba0c4 100644
--- a/pkgs/top-level/release-lib.nix
+++ b/pkgs/top-level/release-lib.nix
@@ -28,14 +28,14 @@ rec {
   crossMaintainers = with pkgs.lib.maintainers; [ viric ];
 
   /* Set the Hydra scheduling priority for a job.  The default
-     priority (100) should be used for most jobs.  A different
+     priority (10) should be used for most jobs.  A different
      priority should only be used for a few particularly interesting
      jobs (in terms of giving feedback to developers), such as stdenv.
   */
   prio = level: job: toJob job // { schedulingPriority = level; };
 
   toJob = x: if builtins.isAttrs x then x else
-    { type = "job"; systems = x; schedulingPriority = 10; };
+    { type = "job"; systems = x; schedulingPriority = 5; };
 
   /* Perform a job on the given set of platforms.  The function `f' is
      called by Hydra for each platform, and should return some job