diff options
author | Shea Levy <shea@shealevy.com> | 2013-12-31 22:38:06 -0500 |
---|---|---|
committer | Shea Levy <shea@shealevy.com> | 2013-12-31 22:38:06 -0500 |
commit | 008992619f0ca5a61d6cd91394c818c5da345050 (patch) | |
tree | 418877d1803d19fb4b964d3ea827e7c24de560df /pkgs/os-specific/linux | |
parent | 58246936e4f44c744e08e2386d4c446d18a44b24 (diff) | |
download | nixpkgs-008992619f0ca5a61d6cd91394c818c5da345050.tar nixpkgs-008992619f0ca5a61d6cd91394c818c5da345050.tar.gz nixpkgs-008992619f0ca5a61d6cd91394c818c5da345050.tar.bz2 nixpkgs-008992619f0ca5a61d6cd91394c818c5da345050.tar.lz nixpkgs-008992619f0ca5a61d6cd91394c818c5da345050.tar.xz nixpkgs-008992619f0ca5a61d6cd91394c818c5da345050.tar.zst nixpkgs-008992619f0ca5a61d6cd91394c818c5da345050.zip |
linux/manual-config: Cross-compiling support
With this, I was able to successfully compile a defconfig kernel for the sheevaplug, though I didn't actually try to run it (not having a sheevaplug myself). For native compiles, the most significant difference is that the platform's kernel target is built directly rather than hoping the default make target will pull it in. Also some stylistic improvements along the way. Signed-off-by: Shea Levy <shea@shealevy.com>
Diffstat (limited to 'pkgs/os-specific/linux')
-rw-r--r-- | pkgs/os-specific/linux/kernel/manual-config.nix | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/pkgs/os-specific/linux/kernel/manual-config.nix b/pkgs/os-specific/linux/kernel/manual-config.nix index f097f2562d0..d96c8e5494c 100644 --- a/pkgs/os-specific/linux/kernel/manual-config.nix +++ b/pkgs/os-specific/linux/kernel/manual-config.nix @@ -1,4 +1,4 @@ -{ stdenv, runCommand, nettools, bc, perl, kmod, writeTextFile }: +{ stdenv, runCommand, nettools, bc, perl, kmod, writeTextFile, ubootChooser }: let inherit (stdenv.lib) @@ -58,10 +58,10 @@ in }: let - installkernel = name: writeTextFile { name = "installkernel"; executable=true; text = '' - #!/bin/sh - mkdir $4 - cp -av $2 $4/${name} + installkernel = writeTextFile { name = "installkernel"; executable=true; text = '' + #!${stdenv.shell} -e + mkdir -p $4 + cp -av $2 $4 cp -av $3 $4 '';}; @@ -72,9 +72,10 @@ let commonMakeFlags = [ "O=$(buildRoot)" - "INSTALL_PATH=$(out)" - ] ++ (optional isModular "INSTALL_MOD_PATH=$(out)") - ++ optional installsFirmware "INSTALL_FW_PATH=$(out)/lib/firmware"; + ]; + + # Some image types need special install targets (e.g. uImage is installed with make uinstall) + installTarget = target: [ (if target == "uImage" then "uinstall" else "install") ]; sourceRoot = stdenv.mkDerivation { name = "linux-${version}-source"; @@ -126,16 +127,34 @@ stdenv.mkDerivation { runHook postConfigure ''; - nativeBuildInputs = [ perl bc nettools ]; + nativeBuildInputs = [ perl bc nettools ] ++ optional (stdenv.platform.uboot != null) + (ubootChooser stdenv.platform.uboot); makeFlags = commonMakeFlags ++ [ - "INSTALLKERNEL=${installkernel stdenv.platform.kernelTarget}" + "ARCH=${stdenv.platform.kernelArch}" ]; - crossAttrs = { + buildFlags = [ stdenv.platform.kernelTarget ] ++ optional isModular "modules"; + + installFlags = [ + "INSTALLKERNEL=${installkernel}" + "INSTALL_PATH=$(out)" + ] ++ (optional isModular "INSTALL_MOD_PATH=$(out)") + ++ optional installsFirmware "INSTALL_FW_PATH=$(out)/lib/firmware"; + + installTargets = installTarget stdenv.platform.kernelTarget; + + crossAttrs = let cp = stdenv.cross.platform; in { + buildFlags = [ cp.kernelTarget ] ++ optional isModular "modules"; + makeFlags = commonMakeFlags ++ [ - "INSTALLKERNEL=${installkernel stdenv.cross.platform.kernelTarget}" + "ARCH=${cp.kernelArch}" + "CROSS_COMPILE=$(crossConfig)-" ]; + + installTargets = installTarget cp.kernelTarget; + + buildInputs = optional (cp.uboot != null) (ubootChooser cp.uboot).crossDrv; }; postInstall = optionalString installsFirmware '' @@ -143,7 +162,7 @@ stdenv.mkDerivation { '' + (if isModular then '' make modules_install $makeFlags "''${makeFlagsArray[@]}" \ $installFlags "''${installFlagsArray[@]}" - rm -f $out/lib/modules/${modDirVersion}/build + unlink $out/lib/modules/${modDirVersion}/build mkdir -p $dev/lib/modules/${modDirVersion} mv $out/lib/modules/${modDirVersion}/source $dev/lib/modules/${modDirVersion}/source mv $buildRoot $dev/lib/modules/${modDirVersion}/build @@ -154,7 +173,7 @@ stdenv.mkDerivation { postFixup = if isModular then '' if [ -z "$dontStrip" ]; then - find $out -name "*.ko" -print0 | xargs -0 -r strip -S + find $out -name "*.ko" -print0 | xargs -0 -r ''${crossConfig+$crossConfig-}strip -S # Remove all references to the source directory to avoid unneeded # runtime dependencies find $out -name "*.ko" -print0 | xargs -0 -r sed -i \ |