2021-05-28 09:39:13 +00:00
|
|
|
{ stdenvNoCC, lib, buildPackages, fetchurl, perl, elf-header
|
2023-02-16 17:41:37 +00:00
|
|
|
, bison, flex, rsync
|
2022-11-04 12:27:35 +00:00
|
|
|
, writeTextFile
|
2021-05-28 09:39:13 +00:00
|
|
|
}:
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
let
|
2022-11-04 12:27:35 +00:00
|
|
|
|
|
|
|
# As part of building a hostPlatform=mips kernel, Linux creates and runs a
|
|
|
|
# tiny utility `arch/mips/boot/tools/relocs_main.c` for the buildPlatform.
|
|
|
|
# This utility references a glibc-specific header `byteswap.h`. There is a
|
|
|
|
# compatibility header in gnulib for most BSDs, but not for Darwin, so we
|
|
|
|
# synthesize one here.
|
|
|
|
darwin-endian-h = writeTextFile {
|
|
|
|
name = "endian-h";
|
|
|
|
text = ''
|
|
|
|
#include <byteswap.h>
|
|
|
|
'';
|
|
|
|
destination = "/include/endian.h";
|
|
|
|
};
|
|
|
|
darwin-byteswap-h = writeTextFile {
|
|
|
|
name = "byteswap-h";
|
|
|
|
text = ''
|
|
|
|
#pragma once
|
|
|
|
#include <libkern/OSByteOrder.h>
|
|
|
|
#define bswap_16 OSSwapInt16
|
|
|
|
#define bswap_32 OSSwapInt32
|
|
|
|
#define bswap_64 OSSwapInt64
|
|
|
|
'';
|
|
|
|
destination = "/include/byteswap.h";
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
makeLinuxHeaders = { src, version, patches ? [] }: stdenvNoCC.mkDerivation {
|
|
|
|
inherit src;
|
|
|
|
|
|
|
|
pname = "linux-headers";
|
|
|
|
inherit version;
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
ARCH = stdenvNoCC.hostPlatform.linuxArch;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
strictDeps = true;
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
2020-04-24 23:36:52 +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 ];
|
|
|
|
# `elf-header` is null when libc provides `elf.h`.
|
2021-05-28 09:39:13 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
perl elf-header
|
|
|
|
] ++ lib.optionals stdenvNoCC.hostPlatform.isAndroid [
|
2023-02-16 17:41:37 +00:00
|
|
|
bison flex rsync
|
2022-11-04 12:27:35 +00:00
|
|
|
] ++ lib.optionals (stdenvNoCC.buildPlatform.isDarwin &&
|
|
|
|
stdenvNoCC.hostPlatform.isMips) [
|
|
|
|
darwin-endian-h
|
|
|
|
darwin-byteswap-h
|
2021-05-28 09:39:13 +00:00
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-10-30 15:09:59 +00:00
|
|
|
extraIncludeDirs = lib.optionals (with stdenvNoCC.hostPlatform; isPower && is32bit && isBigEndian) ["ppc"];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
inherit patches;
|
|
|
|
|
|
|
|
hardeningDisable = lib.optional stdenvNoCC.buildPlatform.isDarwin "format";
|
|
|
|
|
|
|
|
makeFlags = [
|
|
|
|
"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-06-18 07:06:33 +00:00
|
|
|
"HOSTCC:=$(CC_FOR_BUILD)"
|
|
|
|
"HOSTCXX:=$(CXX_FOR_BUILD)"
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
# Skip clean on darwin, case-sensitivity issues.
|
|
|
|
buildPhase = lib.optionalString (!stdenvNoCC.buildPlatform.isDarwin) ''
|
|
|
|
make mrproper $makeFlags
|
2021-05-28 09:39:13 +00:00
|
|
|
'' + (if stdenvNoCC.hostPlatform.isAndroid then ''
|
|
|
|
make defconfig
|
|
|
|
make headers_install
|
|
|
|
'' else ''
|
2020-04-24 23:36:52 +00:00
|
|
|
make headers $makeFlags
|
2021-05-28 09:39:13 +00:00
|
|
|
'');
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
checkPhase = ''
|
|
|
|
make headers_check $makeFlags
|
|
|
|
'';
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out
|
|
|
|
cp -r usr/include $out
|
|
|
|
find $out -type f ! -name '*.h' -delete
|
|
|
|
''
|
|
|
|
# Some builds (e.g. KVM) want a kernel.release.
|
|
|
|
+ ''
|
|
|
|
mkdir -p $out/include/config
|
|
|
|
echo "${version}-default" > $out/include/config/kernel.release
|
|
|
|
'';
|
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
description = "Header files and scripts for Linux kernel";
|
|
|
|
license = licenses.gpl2;
|
|
|
|
platforms = platforms.linux;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
inherit makeLinuxHeaders;
|
|
|
|
|
2023-03-15 16:39:30 +00:00
|
|
|
linuxHeaders = let version = "6.2"; in
|
2020-04-24 23:36:52 +00:00
|
|
|
makeLinuxHeaders {
|
|
|
|
inherit version;
|
|
|
|
src = fetchurl {
|
2022-10-30 15:09:59 +00:00
|
|
|
url = "mirror://kernel/linux/kernel/v${lib.versions.major version}.x/linux-${version}.tar.xz";
|
2023-03-15 16:39:30 +00:00
|
|
|
hash = "sha256-dIYvqKtA7a6FuzOFwLcf4QMoi85RhSbWMZeACzy97LE=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
patches = [
|
|
|
|
./no-relocs.patch # for building x86 kernel headers on non-ELF platforms
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|