kernel: Enable cross compiling

This commit is contained in:
Ben Gamari
2018-01-15 11:55:06 -05:00
committed by Ben Wolsieffer
parent 5d8b359db7
commit 7a9b6ac39a
15 changed files with 53 additions and 94 deletions
+15 -35
View File
@@ -1,4 +1,4 @@
{ stdenv, perl, buildLinux
{ stdenv, buildPackages, perl, buildLinux
, # The kernel source tarball.
src
@@ -23,7 +23,7 @@
# symbolic name and `patch' is the actual patch. The patch may
# optionally be compressed with gzip or bzip2.
kernelPatches ? []
, ignoreConfigErrors ? stdenv.platform.name != "pc"
, ignoreConfigErrors ? hostPlatform.platform.name != "pc"
, extraMeta ? {}
, hostPlatform
, ...
@@ -58,37 +58,29 @@ let
in lib.concatStringsSep "\n" ([baseConfig] ++ configFromPatches);
configfile = stdenv.mkDerivation {
inherit ignoreConfigErrors;
#inherit ignoreConfigErrors;
name = "linux-config-${version}";
generateConfig = ./generate-config.pl;
kernelConfig = kernelConfigFun config;
nativeBuildInputs = [ perl ];
nativeBuildInputs = [ buildPackages.stdenv.cc perl ];
platformName = stdenv.platform.name;
kernelBaseConfig = stdenv.platform.kernelBaseConfig;
kernelTarget = stdenv.platform.kernelTarget;
autoModules = stdenv.platform.kernelAutoModules;
preferBuiltin = stdenv.platform.kernelPreferBuiltin or false;
arch = stdenv.platform.kernelArch;
platformName = hostPlatform.platform.name;
kernelBaseConfig = hostPlatform.platform.kernelBaseConfig;
kernelTarget = hostPlatform.platform.kernelTarget;
autoModules = hostPlatform.platform.kernelAutoModules;
preferBuiltin = hostPlatform.platform.kernelPreferBuiltin or false;
arch = hostPlatform.platform.kernelArch;
# TODO(@Ericson2314): No null next hash break
ignoreConfigErrors = if stdenv.hostPlatform == stdenv.buildPlatform then null else true;
crossAttrs = let
cp = hostPlatform.platform;
in {
arch = cp.kernelArch;
platformName = cp.name;
kernelBaseConfig = cp.kernelBaseConfig;
kernelTarget = cp.kernelTarget;
autoModules = cp.kernelAutoModules;
# Just ignore all options that don't apply (We are lazy).
ignoreConfigErrors = true;
kernelConfig = kernelConfigFun configCross;
inherit (kernel.crossDrv) src patches preUnpack;
};
prePatch = kernel.prePatch + ''
@@ -103,7 +95,7 @@ let
cd $buildRoot
# Get a basic config file for later refinement with $generateConfig.
make -C ../$sourceRoot O=$PWD $kernelBaseConfig ARCH=$arch
make HOSTCC=${buildPackages.stdenv.cc.targetPrefix}gcc -C ../$sourceRoot O=$PWD $kernelBaseConfig ARCH=$arch
# Create the config file.
echo "generating kernel configuration..."
@@ -122,11 +114,7 @@ let
configfile = configfile.nativeDrv or configfile;
crossConfigfile = configfile.crossDrv or configfile;
config = { CONFIG_MODULES = "y"; CONFIG_FW_LOADER = "m"; };
crossConfig = { CONFIG_MODULES = "y"; CONFIG_FW_LOADER = "m"; };
};
passthru = {
@@ -134,12 +122,4 @@ let
passthru = kernel.passthru // (removeAttrs passthru [ "passthru" ]);
};
addPassthru' = lib.extendDerivation true passthru;
nativeDrv = addPassthru' kernel.nativeDrv;
crossDrv = addPassthru' kernel.crossDrv;
in if kernel ? crossDrv
then nativeDrv // { inherit nativeDrv crossDrv; }
else addPassthru' kernel
in lib.extendDerivation true passthru kernel