3
0
Fork 0
forked from mirrors/nixpkgs

Big fixes in the cross build:

- Before this changes, cflags and ldflags for the native and the cross compiler
  got mixed. Not all the gcc-wrapper/gcc-cross-wrapper variables are
  independant now, but enough, I think.
- Fixed the generic stdenv expression, which did a big mess on buildInputs and
  buildNativeInputs. Now it distinguishes when there is a stdenvCross or not.
  Maybe we should have a single stdenv and forget about the stdenvCross
  adapter - this could end in a stdenv a bit complex, but simpler than the
  generic stdenv + adapter.
- Added basic support in pkgconfig for cross-builds: a single PKG_CONFIG_PATH
  now works for both the cross and the native compilers, but I think this
  should work well for most cases I can think of.
- I tried to fix the guile expression to cross-biuld; guile is built, but not
  its manual, so the derivation still fails. Guile requires patching to
  cross-build, as far as I understnad.
- Made the glibcCross build to be done through the usage of a
  gcc-cross-wrapper over the gcc-cross-stage-static, instead of using it
  directly.
- Trying to make physfs (a neverball dependency) cross build.
- Updated the gcc expression to support building a cross compiler without getting
  derivation variables mixed with those of the stdenvCross.

svn path=/nixpkgs/branches/stdenv-updates/; revision=18534
This commit is contained in:
Lluís Batlle i Rossell 2009-11-22 19:51:45 +00:00
parent 9dcff09187
commit 585ba8c27f
18 changed files with 119 additions and 66 deletions

View file

@ -1,5 +1,5 @@
export NIX_CFLAGS_COMPILE="@cflagsCompile@ $NIX_CFLAGS_COMPILE"
export NIX_CFLAGS_LINK="@cflagsLink@ $NIX_CFLAGS_LINK"
export NIX_LDFLAGS="@ldflags@ $NIX_LDFLAGS"
export NIX_LDFLAGS_BEFORE="@ldflagsBefore@ $NIX_LDFLAGS_BEFORE"
export NIX_GLIBC_FLAGS_SET=1
export NIX_CROSS_CFLAGS_COMPILE="@cflagsCompile@ $NIX_CROSS_CFLAGS_COMPILE"
export NIX_CROSS_CFLAGS_LINK="@cflagsLink@ $NIX_CROSS_CFLAGS_LINK"
export NIX_CROSS_LDFLAGS="@ldflags@ $NIX_CROSS_LDFLAGS"
export NIX_CROSS_LDFLAGS_BEFORE="@ldflagsBefore@ $NIX_CROSS_LDFLAGS_BEFORE"
export NIX_CROSS_GLIBC_FLAGS_SET=1

View file

@ -6,7 +6,7 @@
# variables so that the compiler and the linker just "work".
{ name ? "", stdenv, nativeTools, nativeLibc, noLibc ? false, nativePrefix ? ""
, gcc ? null, libc ? null, binutils ? null, shell ? "", cross ? ""
, gcc ? null, libc ? null, binutils ? null, shell ? "", cross
}:
assert nativeTools -> nativePrefix != "";
@ -32,6 +32,6 @@ stdenv.mkDerivation {
};
passthru = {
inherit cross;
target = cross;
};
}

View file

@ -4,7 +4,7 @@ if test -n "$NIX_GCC_WRAPPER_START_HOOK"; then
source "$NIX_GCC_WRAPPER_START_HOOK"
fi
if test -z "$NIX_GLIBC_FLAGS_SET"; then
if test -z "$NIX_CROSS_GLIBC_FLAGS_SET"; then
source @out@/nix-support/add-flags
fi
@ -63,28 +63,28 @@ fi
# Add the flags for the C compiler proper.
extraAfter=($NIX_CFLAGS_COMPILE)
extraAfter=($NIX_CROSS_CFLAGS_COMPILE)
extraBefore=()
if test "$dontLink" != "1"; then
# Add the flags that should only be passed to the compiler when
# linking.
extraAfter=(${extraAfter[@]} $NIX_CFLAGS_LINK)
extraAfter=(${extraAfter[@]} $NIX_CROSS_CFLAGS_LINK)
# Add the flags that should be passed to the linker (and prevent
# `ld-wrapper' from adding NIX_LDFLAGS again).
for i in $NIX_LDFLAGS_BEFORE; do
# `ld-wrapper' from adding NIX_CROSS_LDFLAGS again).
for i in $NIX_CROSS_LDFLAGS_BEFORE; do
extraBefore=(${extraBefore[@]} "-Wl,$i")
done
for i in $NIX_LDFLAGS; do
for i in $NIX_CROSS_LDFLAGS; do
if test "${i:0:3}" = "-L/"; then
extraAfter=(${extraAfter[@]} "$i")
else
extraAfter=(${extraAfter[@]} "-Wl,$i")
fi
done
export NIX_LDFLAGS_SET=1
export NIX_CROSS_LDFLAGS_SET=1
if test "$NIX_STRIP_DEBUG" = "1"; then
# Add executable-stripping flags.

View file

@ -4,7 +4,7 @@ if test -n "$NIX_LD_WRAPPER_START_HOOK"; then
source "$NIX_LD_WRAPPER_START_HOOK"
fi
if test -z "$NIX_GLIBC_FLAGS_SET"; then
if test -z "$NIX_CROSS_GLIBC_FLAGS_SET"; then
source @out@/nix-support/add-flags
fi
@ -14,7 +14,7 @@ source @out@/nix-support/utils
# 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
-a \( -z "$NIX_IGNORE_LD_THROUGH_GCC" -o -z "$NIX_CROSS_LDFLAGS_SET" \); then
rest=()
n=0
while test $n -lt ${#params[*]}; do
@ -44,9 +44,9 @@ fi
extra=()
extraBefore=()
if test -z "$NIX_LDFLAGS_SET"; then
extra=(${extra[@]} $NIX_LDFLAGS)
extraBefore=(${extraBefore[@]} $NIX_LDFLAGS_BEFORE)
if test -z "$NIX_CROSS_LDFLAGS_SET"; then
extra=(${extra[@]} $NIX_CROSS_LDFLAGS)
extraBefore=(${extraBefore[@]} $NIX_CROSS_LDFLAGS_BEFORE)
fi

View file

@ -1,14 +1,14 @@
addCVars () {
crossAddCVars () {
if test -d $1/include; then
export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I$1/include"
export NIX_CROSS_CFLAGS_COMPILE="$NIX_CROSS_CFLAGS_COMPILE -I$1/include"
fi
if test -d $1/lib; then
export NIX_LDFLAGS="$NIX_LDFLAGS -L$1/lib"
export NIX_CROSS_LDFLAGS="$NIX_CROSS_LDFLAGS -L$1/lib"
fi
}
crossEnvHooks=(${crossEnvHooks[@]} addCVars)
crossEnvHooks=(${crossEnvHooks[@]} crossAddCVars)
# Note: these come *after* $out in the PATH (see setup.sh).
@ -22,10 +22,18 @@ fi
if test -n "@libc@"; then
PATH=$PATH:@libc@/bin
addCVars @libc@
crossAddCVars @libc@
fi
configureFlags="$configureFlags --build=$system --host=$crossConfig"
# Disabling the tests when cross compiling, as usually the tests are meant for
# native compilations.
doCheck=""
# Add the output as an rpath.
if test "$NIX_NO_SELF_RPATH" != "1"; then
export NIX_CROSS_LDFLAGS="-rpath $out/lib -rpath-link $out/lib $NIX_CROSS_LDFLAGS"
if test -n "$NIX_LIB64_IN_SELF_RPATH"; then
export NIX_CROSS_LDFLAGS="-rpath $out/lib64 -rpath-link $out/lib $NIX_CROSS_LDFLAGS"
fi
fi

View file

@ -40,7 +40,7 @@ if test "$noSysDirs" = "1"; then
export NIX_EXTRA_LDFLAGS="$NIX_EXTRA_LDFLAGS -Wl,$i"
done
if test -n "$crossConfig"; then
if test -n "$targetConfig"; then
if test -z "$crossStageStatic"; then
extraXCFlags="-B${glibcCross}/lib -idirafter ${glibcCross}/include"
extraXLDFlags="-L${glibcCross}/lib"
@ -71,7 +71,7 @@ if test "$noSysDirs" = "1"; then
)
fi
if test -n "$crossConfig" -a "$crossStageStatic" == 1; then
if test -n "$targetConfig" -a "$crossStageStatic" == 1; then
# We don't want the gcc build to assume there will be a libc providing
# limits.h in this stagae
makeFlagsArray=( \
@ -86,7 +86,7 @@ if test "$noSysDirs" = "1"; then
fi
fi
if test -n "$crossConfig"; then
if test -n "$targetConfig"; then
# The host strip will destroy everything in the target binaries otherwise
dontStrip=1
fi
@ -127,7 +127,7 @@ postInstall() {
}
if test -z "$crossConfig"; then
if test -z "$targetConfig"; then
if test -z "$profiledCompiler"; then
buildFlags="bootstrap $buildFlags"
else

View file

@ -78,7 +78,7 @@ stdenv.mkDerivation ({
inherit noSysDirs profiledCompiler staticCompiler crossStageStatic
binutilsCross glibcCross;
crossConfig = if (cross != null) then cross.config else null;
targetConfig = if (cross != null) then cross.config else null;
buildInputs = [texinfo gmp mpfr]
++ (optionals langTreelang [bison flex])

View file

@ -9,19 +9,26 @@ stdenv.mkDerivation rec {
};
buildNativeInputs = [ makeWrapper ];
propagatedBuildInputs = [ libtool gmp ];
propagatedBuildNativeInputs = [readline gawk];
buildInputs = [ libtool ];
propagatedBuildInputs = [ readline gmp libtool ];
propagatedBuildNativeInputs = [ gawk ];
postInstall = ''
wrapProgram $out/bin/guile-snarf --prefix PATH : "${gawk}/bin"
'';
NIX_DEBUG=1;
preBuild = ''
sed -e '/lt_dlinit/a lt_dladdsearchdir("'$out/lib'");' -i libguile/dynl.c
'';
# Guile needs patching to preset results for the configure tests
# about pthreads, which work only in native builds.
preConfigure = ''
if test -n "$crossConfig"; then
configureFlags="--with-threads=no $configureFlags"
fi
'';
doCheck = true;
setupHook = ./setup-hook.sh;

View file

@ -1,10 +1,11 @@
{ stdenv, fetchurl, kernelHeaders
, installLocales ? true
, profilingLibraries ? false
, cross ? null
, gccCross ? null
}:
let
cross = if gccCross != null then gccCross.target else null;
in
stdenv.mkDerivation rec {
name = "glibc-2.9" +
stdenv.lib.optionalString (cross != null) "-${cross.config}";
@ -67,8 +68,6 @@ stdenv.mkDerivation rec {
"--with-headers=${kernelHeaders}/include"
(if profilingLibraries then "--enable-profile" else "--disable-profile")
] ++ stdenv.lib.optionals (cross != null) [
"--host=${cross.config}"
"--build=${stdenv.system}"
"--with-tls"
"--enable-kernel=2.6.0"
"--without-fp"
@ -79,7 +78,7 @@ stdenv.mkDerivation rec {
"--without-fp"
] else []);
buildInputs = stdenv.lib.optionals (cross != null) [ gccCross ];
buildNativeInputs = stdenv.lib.optionals (cross != null) [ gccCross ];
preInstall = ''
ensureDir $out/lib

View file

@ -8,7 +8,7 @@ stdenv.mkDerivation rec {
sha256 = "072hqprni4vf4ax6b659s2xxrbz0y6iziarsczawbhi69m4azpyb";
};
buildInputs = [ cmake ];
buildNativeInputs = [ cmake ];
meta = {
homepage = http://icculus.org/physfs/;

View file

@ -32,6 +32,13 @@ cmakeConfigurePhase()
cmakeFlags="-DCMAKE_INSTALL_PREFIX=$prefix $cmakeFlags"
fi
if test -n "$crossConfig"; then
# By now it supports linux builds only. We should set the proper
# CMAKE_SYSTEM_NAME otherwise.
# http://www.cmake.org/Wiki/CMake_Cross_Compiling
cmakeFlags="-DCMAKE_CXX_COMPILER=$crossConfig-g++ -DCMAKE_C_COMPILER=$crossConfig-gcc $cmakeFlags"
fi
echo "cmake flags: $cmakeFlags ${cmakeFlagsArray[@]}"
cmake ${cmakeDir:-.} $cmakeFlags ${cmakeFlagsArray[@]}
@ -43,4 +50,8 @@ if test -z "$dontUseCmakeConfigure"; then
configurePhase=cmakeConfigurePhase
fi
envHooks=(${envHooks[@]} addCMakeParams)
if test -n "$crossConfig"; then
crossEnvHooks=(${crossEnvHooks[@]} addCMakeParams)
else
envHooks=(${envHooks[@]} addCMakeParams)
fi

View file

@ -3,4 +3,8 @@ addPkgConfigPath () {
addToSearchPath PKG_CONFIG_PATH $1/share/pkgconfig
}
envHooks=(${envHooks[@]} addPkgConfigPath)
if test -n "$crossConfig"; then
crossEnvHooks=(${crossEnvHooks[@]} addPkgConfigPath)
else
envHooks=(${envHooks[@]} addPkgConfigPath)
fi

View file

@ -14,7 +14,7 @@ stdenv.mkDerivation {
sha256 = "0hifjh75sinifr5138v22zwbpqln6lhn65k8b57a1dyzlqca7cl9";
};
crossConfig = if (cross != null) then cross.config else null;
targetConfig = if (cross != null) then cross.config else null;
platform =
if cross != null then cross.arch else
@ -37,7 +37,7 @@ stdenv.mkDerivation {
'';
buildPhase = ''
if test -n "$crossConfig"; then
if test -n "$targetConfig"; then
export ARCH=$platform
fi
make mrproper headers_check

View file

@ -30,6 +30,7 @@ in
libxcb = attrs : attrs // {
# I only remove python from the original, and add xproto. I don't know how
# to achieve that referring to attrs.buildInputs.
# I should use: builtins.unsafeDiscardStringContext
buildInputs = [args.pkgconfig args.libxslt xorg.libpthreadstubs /*xorg.python*/
xorg.libXau xorg.xcbproto xorg.libXdmcp ] ++ [ xorg.xproto ];
buildNativeInputs = [ args.python ];

View file

@ -130,12 +130,21 @@ rec {
# And the same for propagatedBuildInputs.
buildDrv = stdenv.mkDerivation args;
# Temporary expression until the cross_renaming, to handle the
# case of pkgconfig given as buildInput, but to be used as
# buildNativeInput.
hostAsBuildDrv = drv: builtins.unsafeDiscardStringContext
drv.buildDrv.drvPath == builtins.unsafeDiscardStringContext
drv.hostDrv.drvPath;
nativeInputsFromBuildInputs = stdenv.lib.filter (hostAsBuildDrv) buildInputs;
# We should overwrite the input attributes in hostDrv, to overwrite
# the defaults for only-native builds in the base stdenv
hostDrv = if (cross == null) then buildDrv else
stdenv.mkDerivation (args // {
name = name + "-" + cross.config;
buildNativeInputs = buildNativeInputsDrvs
++ nativeInputsFromBuildInputs
++ [ gccCross binutilsCross ] ++
stdenv.lib.optional selfNativeBuildInput buildDrv;
buildInputs = buildInputsDrvs;

View file

@ -55,6 +55,8 @@ let
propagatedBuildNativeInputs = if attrs ?
propagatedBuildNativeInputs then
attrs.propagatedBuildNativeInputs else [];
crossConfig = if (attrs ? crossConfig) then attrs.crossConfig else
null;
in
{
builder = if attrs ? realBuilder then attrs.realBuilder else shell;
@ -64,12 +66,14 @@ let
system = result.system;
# That build by the cross compiler
buildInputs = [];
propagatedBuildInputs = [];
buildInputs = lib.optionals (crossConfig != null) buildInputs;
propagatedBuildInputs = lib.optionals (crossConfig != null)
propagatedBuildInputs;
# That build by the usual native compiler
buildNativeInputs = buildInputs ++ buildNativeInputs;
propagatedBuildNativeInputs = propagatedBuildInputs ++
propagatedBuildNativeInputs;
buildNativeInputs = buildNativeInputs ++ lib.optionals
(crossConfig == null) buildInputs;
propagatedBuildNativeInputs = propagatedBuildNativeInputs ++
lib.optionals (crossConfig == null) propagatedBuildInputs;
}))
)
# The meta attribute is passed in the resulting attribute set,

View file

@ -124,6 +124,7 @@ if test -z "$SHELL"; then echo "SHELL not set"; exit 1; fi
# Hack: run gcc's setup hook.
envHooks=()
crossEnvHooks=()
if test -f $NIX_GCC/nix-support/setup-hook; then
source $NIX_GCC/nix-support/setup-hook
fi
@ -203,10 +204,16 @@ for i in $nativePkgs; do
addToNativeEnv $i
done
crossEnvHooks=()
addToCrossEnv() {
local pkg=$1
# Some programs put important build scripts (freetype-config and similar)
# into their hostDrv bin path. Intentionally these should go after
# the nativePkgs in PATH.
if test -d $1/bin; then
addToSearchPath _PATH $1/bin
fi
# Run the package-specific hooks set by the setup-hook scripts.
for i in "${crossEnvHooks[@]}"; do
$i $pkg

View file

@ -183,6 +183,8 @@ let
}
else stdenvCross;
forceBuildDrv = drv : drv // { hostDrv = drv.buildDrv; };
# A stdenv capable of building 32-bit binaries. On x86_64-linux,
# it uses GCC compiled with multilib support; on i686-linux, it's
# just the plain stdenv.
@ -1776,7 +1778,6 @@ let
}));
gcc43_realCross = cross : makeOverridable (import ../development/compilers/gcc-4.3) {
#stdenv = overrideGCC stdenv (wrapGCCWith (import ../build-support/gcc-wrapper) glibc_multi gcc);
inherit stdenv fetchurl texinfo gmp mpfr noSysDirs cross;
binutilsCross = binutilsCross cross;
glibcCross = glibcCross cross;
@ -1786,18 +1787,18 @@ let
};
gccCrossStageStatic = cross: wrapGCCCross {
gcc = (gcc43_realCross cross).override {
gcc = forceBuildDrv ((gcc43_realCross cross).override {
crossStageStatic = true;
langCC = false;
glibcCross = null;
};
});
libc = null;
binutils = binutilsCross cross;
inherit cross;
};
gccCrossStageFinal = cross: wrapGCCCross {
gcc = gcc43_realCross cross;
gcc = forceBuildDrv (gcc43_realCross cross);
libc = glibcCross cross;
binutils = binutilsCross cross;
inherit cross;
@ -2220,12 +2221,12 @@ let
wrapGCCCross =
{gcc, libc, binutils, cross, shell ? "", name ? "gcc-cross-wrapper"}:
import ../build-support/gcc-cross-wrapper {
forceBuildDrv (import ../build-support/gcc-cross-wrapper {
nativeTools = false;
nativeLibc = false;
noLibc = (libc == null);
inherit stdenv gcc binutils libc shell name cross;
};
});
# FIXME: This is a specific hack for GCC-UPC. Eventually, we may
# want to merge `gcc-upc-wrapper' and `gcc-wrapper'.
@ -2605,10 +2606,10 @@ let
inherit fetchurl stdenv noSysDirs;
});
binutilsCross = cross : import ../development/tools/misc/binutils {
binutilsCross = cross : forceBuildDrv (import ../development/tools/misc/binutils {
inherit stdenv fetchurl cross;
noSysDirs = true;
};
});
bison = bison23;
@ -2885,7 +2886,7 @@ let
cross_renaming: we should make all programs use pkgconfig as
buildNativeInput after the renaming.
*/
pkgconfig = pkgconfigReal // { hostDrv = pkgconfigReal.buildDrv; };
pkgconfig = forceBuildDrv pkgconfigReal;
radare = import ../development/tools/analysis/radare {
inherit stdenv fetchurl pkgconfig libusb readline gtkdialog python
@ -3427,26 +3428,28 @@ let
installLocales = getPkgConfig "glibc" "locales" false;
};
glibc29Cross = cross : makeOverridable (import ../development/libraries/glibc-2.9) {
inherit stdenv fetchurl cross;
glibc29Cross = cross: forceBuildDrv (makeOverridable (import ../development/libraries/glibc-2.9) {
inherit stdenv fetchurl;
gccCross = gccCrossStageStatic cross;
kernelHeaders = kernelHeadersCross cross;
installLocales = getPkgConfig "glibc" "locales" false;
};
});
glibcCross = cross: glibc29Cross cross;
glibc211 = makeOverridable (import ../development/libraries/glibc-2.11) {
inherit fetchurl stdenv kernelHeaders;
installLocales = getPkgConfig "glibc" "locales" false;
};
glibc211Cross = cross : makeOverridable (import ../development/libraries/glibc-2.11) {
glibc211CrossReal = cross : forceBuildDrv (makeOverridable (import ../development/libraries/glibc-2.11) {
inherit stdenv fetchurl cross;
gccCross = gccCrossStageStatic cross;
kernelHeaders = kernelHeadersCross cross;
installLocales = getPkgConfig "glibc" "locales" false;
};
});
glibcCross = cross: glibc29Cross cross;
glibc211Cross = cross : forceBuildDrv (glibc211CrossReal cross);
eglibc = import ../development/libraries/eglibc {
inherit fetchsvn stdenv kernelHeaders;
@ -5395,9 +5398,9 @@ let
kernelHeaders = kernelHeaders_2_6_28;
kernelHeadersCross = cross : import ../os-specific/linux/kernel-headers/2.6.28.nix {
kernelHeadersCross = cross : forceBuildDrv (import ../os-specific/linux/kernel-headers/2.6.28.nix {
inherit stdenv fetchurl cross perl;
};
});
kernelHeaders_2_6_18 = import ../os-specific/linux/kernel-headers/2.6.18.5.nix {
inherit fetchurl stdenv unifdef;