diff --git a/pkgs/build-support/gcc-cross-wrapper/default.nix b/pkgs/build-support/gcc-cross-wrapper/default.nix index 74d15660da8..d811d82c85b 100644 --- a/pkgs/build-support/gcc-cross-wrapper/default.nix +++ b/pkgs/build-support/gcc-cross-wrapper/default.nix @@ -24,7 +24,7 @@ stdenv.mkDerivation { name = if name == "" then gcc.name else name; langC = if nativeTools then true else gcc.langC; langCC = if nativeTools then true else gcc.langCC; - langF77 = if nativeTools then false else gcc.langF77; + langF77 = if nativeTools then false else gcc ? langFortran; shell = if shell == "" then stdenv.shell else shell; meta = if gcc != null then gcc.meta else { description = "System C compiler wrapper"; diff --git a/pkgs/development/compilers/gcc-4.3/builder.sh b/pkgs/development/compilers/gcc-4.3/builder.sh index 2bc011e3e6e..c2f917ee6da 100644 --- a/pkgs/development/compilers/gcc-4.3/builder.sh +++ b/pkgs/development/compilers/gcc-4.3/builder.sh @@ -87,10 +87,12 @@ postInstall() { } -if test -z "$profiledCompiler"; then - buildFlags="bootstrap $buildFlags" -else - buildFlags="profiledbootstrap $buildFlags" +if test -n "$cross"; then + if test -z "$profiledCompiler"; then + buildFlags="bootstrap $buildFlags" + else + buildFlags="profiledbootstrap $buildFlags" + fi fi genericBuild diff --git a/pkgs/development/compilers/gcc-4.3/default.nix b/pkgs/development/compilers/gcc-4.3/default.nix index 9823fc82051..476108298f9 100644 --- a/pkgs/development/compilers/gcc-4.3/default.nix +++ b/pkgs/development/compilers/gcc-4.3/default.nix @@ -10,16 +10,22 @@ , zlib ? null, boehmgc ? null , enableMultilib ? false , name ? "gcc" +, cross ? null +, binutilsCross ? null +, glibcHeadersCross ? null }: assert langTreelang -> bison != null && flex != null; +assert cross != null -> profiledCompiler == false && enableMultilib == true; + with stdenv.lib; let version = "4.3.4"; in stdenv.mkDerivation ({ - name = "${name}-${version}"; + name = "${name}-${version}" + + stdenv.lib.optionalString (cross != null) "-${cross}"; builder = ./builder.sh; @@ -53,6 +59,7 @@ stdenv.mkDerivation ({ ++ (optionals langTreelang [bison flex]) ++ (optional (zlib != null) zlib) ++ (optional (boehmgc != null) boehmgc) + ++ (optionals (cross != null) [binutilsCross]) ; configureFlags = " @@ -71,7 +78,16 @@ stdenv.mkDerivation ({ ) } ${if stdenv.isi686 then "--with-arch=i686" else ""} + ${if cross != null then "--disable-libssp --disable-nls" + + " --with-headers=${glibcHeadersCross}/include --target=${cross}" + + " --disable-shared" else ""} "; + #Above I added a hack on making the build different than the host. + + # Needed for the cross compilation to work + AR = "ar"; + LD = "ld"; + CC = "gcc"; NIX_EXTRA_LDFLAGS = if staticCompiler then "-static" else ""; diff --git a/pkgs/development/libraries/glibc-2.9/default.nix b/pkgs/development/libraries/glibc-2.9/default.nix index 33f93befb21..44d36296f03 100644 --- a/pkgs/development/libraries/glibc-2.9/default.nix +++ b/pkgs/development/libraries/glibc-2.9/default.nix @@ -1,10 +1,14 @@ { stdenv, fetchurl, kernelHeaders , installLocales ? true , profilingLibraries ? false +, cross ? null +, binutilsCross ? null +, gccCross ? null }: stdenv.mkDerivation rec { - name = "glibc-2.9"; + name = "glibc-2.9" + + stdenv.lib.optionalString (cross != null) "-${cross}"; builder = ./builder.sh; @@ -60,12 +64,16 @@ stdenv.mkDerivation rec { "--enable-add-ons" "--with-headers=${kernelHeaders}/include" (if profilingLibraries then "--enable-profile" else "--disable-profile") + ] ++ stdenv.lib.optionals (cross != null) [ + "--target=${cross}" ] ++ (if (stdenv.system == "armv5tel-linux") then [ "--host=arm-linux-gnueabi" "--build=arm-linux-gnueabi" "--without-fp" ] else []); + buildInputs = stdenv.lib.optionals (cross != null) [ binutilsCross gccCross ]; + preInstall = '' ensureDir $out/lib ln -s ${stdenv.gcc.gcc}/lib/libgcc_s.so.1 $out/lib/libgcc_s.so.1 diff --git a/pkgs/development/libraries/glibc-2.9/headers.nix b/pkgs/development/libraries/glibc-2.9/headers.nix new file mode 100644 index 00000000000..adb9a22f481 --- /dev/null +++ b/pkgs/development/libraries/glibc-2.9/headers.nix @@ -0,0 +1,63 @@ +{ stdenv, fetchurl, kernelHeaders +, profilingLibraries ? false +}: + +stdenv.mkDerivation rec { + name = "glibc-headers-2.9"; + + builder = ./headersbuilder.sh; + + src = fetchurl { + url = http://ftp.gnu.org/gnu/glibc/glibc-2.9.tar.bz2; + sha256 = "0v53m7flx6qcx7cvrvvw6a4dx4x3y6k8nvpc4wfv5xaaqy2am2q9"; + }; + + srcPorts = fetchurl { + url = http://ftp.gnu.org/gnu/glibc/glibc-ports-2.9.tar.bz2; + sha256 = "0r2sn527wxqifi63di7ns9wbjh1cainxn978w178khhy7yw9fk42"; + }; + + inherit kernelHeaders; + + inherit (stdenv) is64bit; + + patches = [ + /* Support GNU Binutils 2.20 and above. */ + ./binutils-2.20.patch + ]; + + configureFlags = [ + "--enable-add-ons" + "--with-headers=${kernelHeaders}/include" + "--disable-sanity-checks" + "--enable-hacker-mode" + (if profilingLibraries then "--enable-profile" else "--disable-profile") + ] ++ (if (stdenv.system == "armv5tel-linux") then [ + "--host=arm-linux-gnueabi" + "--build=arm-linux-gnueabi" + "--without-fp" + ] else []); + + buildPhase = "true"; + + # I took some tricks from crosstool-0.43 + installPhase = '' + make cross-compiling=yes CFLAGS=-DBOOTSTRAP_GCC install-headers + mkdir -p $out/include/gnu + touch $out/include/gnu/stubs.h + cp ../include/features.h $out/include/features.h + (cd $out/include && ln -s $kernelHeaders/include/* .) || exit 1 + ''; + + # Workaround for this bug: + # http://sourceware.org/bugzilla/show_bug.cgi?id=411 + # I.e. when gcc is compiled with --with-arch=i686, then the + # preprocessor symbol `__i686' will be defined to `1'. This causes + # the symbol __i686.get_pc_thunk.dx to be mangled. + NIX_CFLAGS_COMPILE = "-U__i686"; + + meta = { + homepage = http://www.gnu.org/software/libc/; + description = "The GNU C Library"; + }; +} diff --git a/pkgs/development/libraries/glibc-2.9/headersbuilder.sh b/pkgs/development/libraries/glibc-2.9/headersbuilder.sh new file mode 100644 index 00000000000..23f4bd4cc61 --- /dev/null +++ b/pkgs/development/libraries/glibc-2.9/headersbuilder.sh @@ -0,0 +1,38 @@ +# Glibc cannot have itself in its RPATH. +export NIX_NO_SELF_RPATH=1 + +source $stdenv/setup + +# Explicitly tell glibc to use our pwd, not /bin/pwd. +export PWD_P=$(type -tP pwd) + +# Needed to install share/zoneinfo/zone.tab. Set to impure /bin/sh to +# prevent a retained dependency on the bootstrap tools in the +# stdenv-linux bootstrap. +export BASH_SHELL=/bin/sh + + +preConfigure() { + + for i in configure io/ftwtest-sh; do + # Can't use substituteInPlace here because replace hasn't been + # built yet in the bootstrap. + sed -i "$i" -e "s^/bin/pwd^$PWD_P^g" + done + + # In the glibc 2.6/2.7 tarballs C-translit.h is a little bit older + # than C-translit.h.in, forcing Make to rebuild it unnecessarily. + # This wouldn't be problem except that it requires Perl, which we + # don't want as a dependency in the Nixpkgs bootstrap. So force + # the output file to be newer. + touch locale/C-translit.h + + tar xvjf "$srcPorts" + + mkdir build + cd build + + configureScript=../configure +} + +genericBuild diff --git a/pkgs/development/tools/misc/binutils/default.nix b/pkgs/development/tools/misc/binutils/default.nix index 4987dafd511..d1178d12bcd 100644 --- a/pkgs/development/tools/misc/binutils/default.nix +++ b/pkgs/development/tools/misc/binutils/default.nix @@ -1,10 +1,13 @@ -{stdenv, fetchurl, noSysDirs}: +{stdenv, fetchurl, noSysDirs, cross ? null}: +let + basename = "binutils-2.20"; +in stdenv.mkDerivation rec { - name = "binutils-2.20"; + name = basename + stdenv.lib.optionalString (cross != null) "-${cross}"; src = fetchurl { - url = "mirror://gnu/binutils/${name}.tar.bz2"; + url = "mirror://gnu/binutils/${basename}.tar.bz2"; sha256 = "1c3m789p5rwmmnck5ms4zcnc40axss3gxzivz571al1vmbq0kpz1"; }; @@ -24,7 +27,8 @@ stdenv.mkDerivation rec { fi ''; - configureFlags = "--disable-werror"; # needed for dietlibc build + configureFlags = "--disable-werror" # needed for dietlibc build + + stdenv.lib.optionalString (cross != null) " --target=${cross}"; meta = { description = "GNU Binutils, tools for manipulating binaries (linker, assembler, etc.)"; 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 37891e6325b..4591fee1497 100644 --- a/pkgs/os-specific/linux/kernel-headers/2.6.28.nix +++ b/pkgs/os-specific/linux/kernel-headers/2.6.28.nix @@ -1,4 +1,4 @@ -{stdenv, fetchurl, perl}: +{stdenv, fetchurl, perl, cross ? null}: assert stdenv.isLinux; @@ -12,7 +12,9 @@ stdenv.mkDerivation { sha256 = "0hifjh75sinifr5138v22zwbpqln6lhn65k8b57a1dyzlqca7cl9"; }; + platform = + if cross == "armv5tel-unknown-linux-gnueabi" then "arm" else if stdenv.system == "i686-linux" then "i386" else if stdenv.system == "x86_64-linux" then "x86_64" else if stdenv.system == "powerpc-linux" then "powerpc" else diff --git a/pkgs/stdenv/default.nix b/pkgs/stdenv/default.nix index ed8f0e39f5f..19bbb371a31 100644 --- a/pkgs/stdenv/default.nix +++ b/pkgs/stdenv/default.nix @@ -10,7 +10,7 @@ # system, e.g., cygwin and mingw builds on i686-cygwin. Most people # can ignore it. -{system, stdenvType ? system, allPackages ? import ../..}: +{system, stdenvType ? system, allPackages ? import ../.., cross ? null}: assert system != "i686-cygwin" -> system == stdenvType; @@ -41,7 +41,7 @@ rec { # Linux standard environment. - stdenvLinux = (import ./linux {inherit system allPackages;}).stdenvLinux; + stdenvLinux = (import ./linux {inherit system allPackages cross;}).stdenvLinux; # MinGW/MSYS standard environment. diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix index 05f92825733..53fac3a0316 100644 --- a/pkgs/stdenv/linux/default.nix +++ b/pkgs/stdenv/linux/default.nix @@ -5,7 +5,8 @@ # ensuring purity of components produced by it. # The function defaults are for easy testing. -{system ? "i686-linux", allPackages ? import ../../top-level/all-packages.nix}: +{system ? "i686-linux", allPackages ? import ../../top-level/all-packages.nix, +cross ? null}: rec { @@ -197,7 +198,22 @@ rec { bootStdenv = stdenvLinuxBoot3; }; - + wrapGCCCross = + {gcc, libc, binutils, shell ? "", name ? "bootstrap-gcc-wrapper"}: + + import ../../build-support/gcc-cross-wrapper { + nativeTools = false; + nativeLibc = false; + inherit gcc binutils libc shell name cross; + stdenv = stdenvLinuxBoot3; + }; + + gccCross = wrapGCCCross rec { + gcc = stdenvLinuxBoot3Pkgs.gccCross cross; + binutils = stdenvLinuxBoot3Pkgs.gccCross cross; + libc = stdenvLinuxBoot3Pkgs.glibcCross cross; + }; + # 8) Construct the final stdenv. It uses the Glibc, GCC and # Binutils built above, and adds in dynamically linked versions # of all other tools. @@ -205,7 +221,8 @@ rec { # When updating stdenvLinux, make sure that the result has no # dependency (`nix-store -qR') on bootstrapTools. stdenvLinux = import ../generic { - name = "stdenv-linux"; + name = "stdenv-linux" + + stdenvLinuxBoot3Pkgs.lib.optionalString (cross != null) "-${cross}"; inherit system; @@ -213,7 +230,10 @@ rec { initialPath = ((import ../common-path.nix) {pkgs = stdenvLinuxBoot3Pkgs;}) - ++ [stdenvLinuxBoot3Pkgs.patchelf]; + ++ [stdenvLinuxBoot3Pkgs.patchelf] + ++ stdenvLinuxBoot3Pkgs.lib.optionals (cross != null) + [ (stdenvLinuxBoot3Pkgs.binutilsCross cross) + gccCross ]; gcc = wrapGCC rec { inherit (stdenvLinuxBoot2Pkgs) binutils; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 33a57b49bcb..2278cd82b1c 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -213,8 +213,15 @@ let allPackages = args: import ./all-packages.nix ({ inherit config; } // args); }; + allStdenvsCross = cross : import ../stdenv { + inherit system stdenvType cross; + allPackages = args: import ./all-packages.nix ({ inherit config; } // args); + }; + defaultStdenv = allStdenvs.stdenv; + stdenvCross = cross : (allStdenvsCross cross).stdenv; + stdenv = if bootStdenv != null then bootStdenv else let changer = getConfig ["replaceStdenv"] null; @@ -1785,6 +1792,11 @@ let inherit fetchurl stdenv bison; }; + bashRealArm = makeOverridable (import ../shells/bash) { + inherit fetchurl bison; + stdenv = stdenvCross "armv5tel-unknown-linux-gnueabi"; + }; + bashInteractive = appendToName "interactive" (bashReal.override { inherit readline texinfo; interactive = true; @@ -1884,6 +1896,16 @@ let profiledCompiler = true; })); + gcc43_realCross = cross : makeOverridable (import ../development/compilers/gcc-4.3) { + inherit fetchurl stdenv texinfo gmp mpfr noSysDirs cross; + binutilsCross = binutilsCross cross; + glibcHeadersCross = glibcHeadersCross cross; + profiledCompiler = false; + enableMultilib = true; + }; + + gccCross = cross: gcc43_realCross cross; + gcc43_multi = lowPrio (wrapGCCWith (import ../build-support/gcc-wrapper) glibc_multi (gcc43_real.gcc.override { stdenv = overrideGCC stdenv (wrapGCCWith (import ../build-support/gcc-wrapper) glibc_multi gcc); profiledCompiler = false; @@ -2672,6 +2694,11 @@ let inherit fetchurl stdenv noSysDirs; }); + binutilsCross = cross : import ../development/tools/misc/binutils { + inherit stdenv fetchurl cross; + noSysDirs = true; + }; + bison = bison23; bison1875 = import ../development/tools/parsing/bison/bison-1.875.nix { @@ -3483,6 +3510,23 @@ let installLocales = getPkgConfig "glibc" "locales" false; }; + glibc29HeadersCross = cross: import ../development/libraries/glibc-2.9/headers.nix { + inherit fetchurl stdenv; + kernelHeaders = kernelHeadersCross cross; + }; + + glibcHeadersCross = cross: glibc29HeadersCross cross; + + glibc29Cross = cross : makeOverridable (import ../development/libraries/glibc-2.9) { + inherit fetchurl stdenv cross; + binutilsCross = binutilsCross cross; + gccCross = gccCross cross; + kernelHeaders = kernelHeadersCross cross; + installLocales = getPkgConfig "glibc" "locales" false; + }; + + glibcCross = cross: glibc29Cross cross; + eglibc = import ../development/libraries/eglibc { inherit fetchsvn stdenv kernelHeaders; installLocales = getPkgConfig "glibc" "locales" false; @@ -5447,6 +5491,10 @@ let kernelHeaders = kernelHeaders_2_6_28; + kernelHeadersCross = cross : import ../os-specific/linux/kernel-headers/2.6.28.nix { + inherit fetchurl stdenv perl cross; + }; + kernelHeaders_2_6_18 = import ../os-specific/linux/kernel-headers/2.6.18.5.nix { inherit fetchurl stdenv unifdef; };