2021-05-06 04:15:34 +00:00
|
|
|
{ stdenvNoCC, lib, buildPackages, fetchurl, perl, elf-header
|
|
|
|
, bison ? null, flex ? null, python ? null, rsync ? null
|
|
|
|
}:
|
|
|
|
|
|
|
|
assert stdenvNoCC.hostPlatform.isAndroid ->
|
|
|
|
(flex != null && bison != null && python != null && rsync != null);
|
2018-01-13 21:28:11 +00:00
|
|
|
|
|
|
|
let
|
2019-05-23 08:36:27 +00:00
|
|
|
makeLinuxHeaders = { src, version, patches ? [] }: stdenvNoCC.mkDerivation {
|
|
|
|
inherit src;
|
2018-01-13 21:28:11 +00:00
|
|
|
|
2019-08-31 11:41:23 +00:00
|
|
|
pname = "linux-headers";
|
|
|
|
inherit version;
|
2018-01-13 21:28:11 +00:00
|
|
|
|
2021-01-23 01:33:55 +00:00
|
|
|
ARCH = stdenvNoCC.hostPlatform.linuxArch;
|
2018-01-13 21:28:11 +00:00
|
|
|
|
2022-05-21 16:58:22 +00:00
|
|
|
strictDeps = true;
|
2022-05-14 01:13:49 +00:00
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
2018-01-13 21:28:11 +00:00
|
|
|
# It may look odd that we use `stdenvNoCC`, and yet explicit depend on a cc.
|
|
|
|
# We do this so we have a build->build, not build->host, C compiler.
|
|
|
|
depsBuildBuild = [ buildPackages.stdenv.cc ];
|
2018-10-26 00:24:32 +00:00
|
|
|
# `elf-header` is null when libc provides `elf.h`.
|
2021-05-06 04:15:34 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
perl elf-header
|
|
|
|
] ++ lib.optionals stdenvNoCC.hostPlatform.isAndroid [
|
|
|
|
flex bison python rsync
|
|
|
|
];
|
2018-01-13 21:28:11 +00:00
|
|
|
|
2022-04-10 08:59:20 +00:00
|
|
|
extraIncludeDirs = lib.optional (with stdenvNoCC.hostPlatform; isPower && is32bit && isBigEndian) ["ppc"];
|
2018-01-13 21:28:11 +00:00
|
|
|
|
|
|
|
inherit patches;
|
|
|
|
|
2018-01-26 22:40:40 +00:00
|
|
|
hardeningDisable = lib.optional stdenvNoCC.buildPlatform.isDarwin "format";
|
|
|
|
|
|
|
|
makeFlags = [
|
2018-01-26 22:40:40 +00:00
|
|
|
"SHELL=bash"
|
|
|
|
# Avoid use of runtime build->host compilers for checks. These
|
|
|
|
# checks only cared to work around bugs in very old compilers, so
|
|
|
|
# these changes should be safe.
|
|
|
|
"cc-version:=9999"
|
|
|
|
"cc-fullversion:=999999"
|
|
|
|
# `$(..)` expanded by make alone
|
2020-04-28 04:08:48 +00:00
|
|
|
"HOSTCC:=$(CC_FOR_BUILD)"
|
|
|
|
"HOSTCXX:=$(CXX_FOR_BUILD)"
|
2018-01-26 22:40:40 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
# Skip clean on darwin, case-sensitivity issues.
|
2018-01-26 22:40:40 +00:00
|
|
|
buildPhase = lib.optionalString (!stdenvNoCC.buildPlatform.isDarwin) ''
|
2018-01-26 22:40:40 +00:00
|
|
|
make mrproper $makeFlags
|
2021-05-06 04:15:34 +00:00
|
|
|
'' + (if stdenvNoCC.hostPlatform.isAndroid then ''
|
|
|
|
make defconfig
|
|
|
|
make headers_install
|
|
|
|
'' else ''
|
2020-02-01 04:35:14 +00:00
|
|
|
make headers $makeFlags
|
2021-05-06 04:15:34 +00:00
|
|
|
'');
|
2018-01-26 22:40:40 +00:00
|
|
|
|
2018-01-26 22:40:40 +00:00
|
|
|
checkPhase = ''
|
2018-01-26 22:40:40 +00:00
|
|
|
make headers_check $makeFlags
|
2018-01-13 21:28:11 +00:00
|
|
|
'';
|
|
|
|
|
2020-02-11 01:41:58 +00:00
|
|
|
# The following command requires rsync:
|
|
|
|
# make headers_install INSTALL_HDR_PATH=$out $makeFlags
|
|
|
|
# but rsync depends on popt which does not compile on aarch64 without
|
|
|
|
# updateAutotoolsGnuConfigScriptsHook which is not enabled in stage2,
|
|
|
|
# so we replicate it with cp. This also reduces bootstrap closure size.
|
2018-01-26 22:40:40 +00:00
|
|
|
installPhase = ''
|
2020-02-11 01:41:58 +00:00
|
|
|
mkdir -p $out
|
|
|
|
cp -r usr/include $out
|
|
|
|
find $out -type f ! -name '*.h' -delete
|
2018-10-26 00:24:32 +00:00
|
|
|
''
|
|
|
|
# Some builds (e.g. KVM) want a kernel.release.
|
|
|
|
+ ''
|
2020-02-01 04:35:14 +00:00
|
|
|
mkdir -p $out/include/config
|
|
|
|
echo "${version}-default" > $out/include/config/kernel.release
|
2018-01-13 21:28:11 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
description = "Header files and scripts for Linux kernel";
|
|
|
|
license = licenses.gpl2;
|
|
|
|
platforms = platforms.linux;
|
|
|
|
};
|
2018-01-26 22:40:40 +00:00
|
|
|
};
|
2018-01-13 21:28:11 +00:00
|
|
|
in {
|
2019-05-23 08:36:27 +00:00
|
|
|
inherit makeLinuxHeaders;
|
2018-01-13 21:28:11 +00:00
|
|
|
|
2022-03-22 07:56:52 +00:00
|
|
|
linuxHeaders = let version = "5.17"; in
|
2019-05-23 08:36:27 +00:00
|
|
|
makeLinuxHeaders {
|
|
|
|
inherit version;
|
|
|
|
src = fetchurl {
|
2020-02-01 04:35:14 +00:00
|
|
|
url = "mirror://kernel/linux/kernel/v5.x/linux-${version}.tar.xz";
|
2022-03-22 07:56:52 +00:00
|
|
|
sha256 = "1cdi43x4c3l4chznh57gm55szycj4wjlxl1dss1ilnfvvmhyypsm";
|
2019-05-23 08:36:27 +00:00
|
|
|
};
|
|
|
|
patches = [
|
|
|
|
./no-relocs.patch # for building x86 kernel headers on non-ELF platforms
|
|
|
|
];
|
|
|
|
};
|
2018-01-13 21:28:11 +00:00
|
|
|
}
|