linux-headers: Fix Darwin cross build
Carefully fake cc-version and cc-fullversion to avoid needing a compiler for the kernel itself to build the headers. For some reason, doing `make install_headers` twice, first without INSTALL_HDR_PATH=$out then with, is neccessary to get this to work.
This commit is contained in:
parent
88cd633ea4
commit
ab6bbdd5cd
|
@ -133,7 +133,9 @@ stdenv.mkDerivation ({
|
||||||
|
|
||||||
depsBuildBuild = [ buildPackages.stdenv.cc ];
|
depsBuildBuild = [ buildPackages.stdenv.cc ];
|
||||||
nativeBuildInputs = [ bison ];
|
nativeBuildInputs = [ bison ];
|
||||||
buildInputs = lib.optionals withGd [ gd libpng ];
|
# TODO make linuxHeaders unconditional next mass rebuild
|
||||||
|
buildInputs = lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) linuxHeaders
|
||||||
|
++ lib.optionals withGd [ gd libpng ];
|
||||||
|
|
||||||
# Needed to install share/zoneinfo/zone.tab. Set to impure /bin/sh to
|
# Needed to install share/zoneinfo/zone.tab. Set to impure /bin/sh to
|
||||||
# prevent a retained dependency on the bootstrap tools in the stdenv-linux
|
# prevent a retained dependency on the bootstrap tools in the stdenv-linux
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
{ stdenvNoCC, lib, buildPackages
|
{ stdenvNoCC, lib, buildPackages
|
||||||
, fetchurl, perl
|
, fetchurl, fetchpatch, perl
|
||||||
|
, elf-header
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
common = { version, sha256, patches ? null }: stdenvNoCC.mkDerivation {
|
common = { version, sha256, patches ? [] }: stdenvNoCC.mkDerivation ({
|
||||||
name = "linux-headers-${version}";
|
name = "linux-headers-${version}";
|
||||||
|
|
||||||
src = fetchurl {
|
src = fetchurl {
|
||||||
|
@ -16,7 +17,10 @@ let
|
||||||
# It may look odd that we use `stdenvNoCC`, and yet explicit depend on a cc.
|
# 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.
|
# We do this so we have a build->build, not build->host, C compiler.
|
||||||
depsBuildBuild = [ buildPackages.stdenv.cc ];
|
depsBuildBuild = [ buildPackages.stdenv.cc ];
|
||||||
nativeBuildInputs = [ perl ];
|
# TODO make unconditional next mass rebuild
|
||||||
|
nativeBuildInputs = [ perl ] ++ lib.optional
|
||||||
|
(stdenvNoCC.hostPlatform != stdenvNoCC.buildPlatform)
|
||||||
|
elf-header;
|
||||||
|
|
||||||
extraIncludeDirs = lib.optional stdenvNoCC.hostPlatform.isPowerPC ["ppc"];
|
extraIncludeDirs = lib.optional stdenvNoCC.hostPlatform.isPowerPC ["ppc"];
|
||||||
|
|
||||||
|
@ -24,12 +28,44 @@ let
|
||||||
# and causing mass rebuild
|
# and causing mass rebuild
|
||||||
inherit patches;
|
inherit patches;
|
||||||
|
|
||||||
buildPhase = ''
|
# TODO avoid native hack next rebuild
|
||||||
|
makeFlags = if stdenvNoCC.hostPlatform == stdenvNoCC.buildPlatform then null else [
|
||||||
|
"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
|
||||||
|
"HOSTCC:=$(BUILD_CC)"
|
||||||
|
"HOSTCXX:=$(BUILD_CXX)"
|
||||||
|
];
|
||||||
|
|
||||||
|
# TODO avoid native hack next rebuild
|
||||||
|
# Skip clean on darwin, case-sensitivity issues.
|
||||||
|
buildPhase = if stdenvNoCC.hostPlatform == stdenvNoCC.buildPlatform then ''
|
||||||
make mrproper headers_check SHELL=bash
|
make mrproper headers_check SHELL=bash
|
||||||
|
'' else lib.optionalString (!stdenvNoCC.buildPlatform.isDarwin) ''
|
||||||
|
make mrproper $makeFlags
|
||||||
|
''
|
||||||
|
# For some reason, doing `make install_headers` twice, first without
|
||||||
|
# INSTALL_HDR_PATH=$out then with, is neccessary to get this to work
|
||||||
|
# for darwin cross. @Ericson2314 has no idea why.
|
||||||
|
+ ''
|
||||||
|
make headers_install $makeFlags
|
||||||
'';
|
'';
|
||||||
|
|
||||||
installPhase = ''
|
# TODO avoid native hack next rebuild
|
||||||
|
checkPhase = if stdenvNoCC.hostPlatform == stdenvNoCC.buildPlatform then null else ''
|
||||||
|
make headers_check $makeFlags
|
||||||
|
'';
|
||||||
|
|
||||||
|
# TODO avoid native hack next rebuild
|
||||||
|
installPhase = (if stdenvNoCC.hostPlatform == stdenvNoCC.buildPlatform then ''
|
||||||
make INSTALL_HDR_PATH=$out headers_install
|
make INSTALL_HDR_PATH=$out headers_install
|
||||||
|
'' else ''
|
||||||
|
make headers_install INSTALL_HDR_PATH=$out $makeFlags
|
||||||
|
'') + ''
|
||||||
|
|
||||||
# Some builds (e.g. KVM) want a kernel.release.
|
# Some builds (e.g. KVM) want a kernel.release.
|
||||||
mkdir -p $out/include/config
|
mkdir -p $out/include/config
|
||||||
|
@ -41,11 +77,19 @@ let
|
||||||
license = licenses.gpl2;
|
license = licenses.gpl2;
|
||||||
platforms = platforms.linux;
|
platforms = platforms.linux;
|
||||||
};
|
};
|
||||||
};
|
} // lib.optionalAttrs (stdenvNoCC.hostPlatform != stdenvNoCC.buildPlatform) {
|
||||||
|
# TODO Make unconditional next mass rebuild
|
||||||
|
hardeningDisable = lib.optional stdenvNoCC.buildPlatform.isDarwin "format";
|
||||||
|
});
|
||||||
in {
|
in {
|
||||||
|
|
||||||
linuxHeaders = common {
|
linuxHeaders = common {
|
||||||
version = "4.15";
|
version = "4.15";
|
||||||
sha256 = "0sd7l9n9h7vf9c6gd6ciji28hawda60yj0llh17my06m0s4lf9js";
|
sha256 = "0sd7l9n9h7vf9c6gd6ciji28hawda60yj0llh17my06m0s4lf9js";
|
||||||
|
# TODO make unconditional next mass rebuild
|
||||||
|
patches = lib.optionals (stdenvNoCC.hostPlatform != stdenvNoCC.buildPlatform) [
|
||||||
|
./no-relocs.patch # for building x86 kernel headers on non-ELF platforms
|
||||||
|
./no-dynamic-cc-version-check.patch # so we can use `stdenvNoCC`, see `makeFlags` above
|
||||||
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
|
||||||
|
index 065324a8046f..d09c67194549 100644
|
||||||
|
--- a/scripts/Kbuild.include
|
||||||
|
+++ b/scripts/Kbuild.include
|
||||||
|
@@ -216,11 +216,8 @@ cc-disable-warning = $(call try-run-cached,\
|
||||||
|
cc-name = $(call shell-cached,$(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc)
|
||||||
|
|
||||||
|
# cc-version
|
||||||
|
-cc-version = $(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))
|
||||||
|
|
||||||
|
# cc-fullversion
|
||||||
|
-cc-fullversion = $(call shell-cached,$(CONFIG_SHELL) \
|
||||||
|
- $(srctree)/scripts/gcc-version.sh -p $(CC))
|
||||||
|
|
||||||
|
# cc-ifversion
|
||||||
|
# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)
|
|
@ -0,0 +1,13 @@
|
||||||
|
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
|
||||||
|
index fad55160dcb9..a48c8331cbb2 100644
|
||||||
|
--- a/arch/x86/Makefile
|
||||||
|
+++ b/arch/x86/Makefile
|
||||||
|
@@ -239,7 +239,7 @@ ifdef CONFIG_RETPOLINE
|
||||||
|
endif
|
||||||
|
|
||||||
|
archscripts: scripts_basic
|
||||||
|
- $(Q)$(MAKE) $(build)=arch/x86/tools relocs
|
||||||
|
+ $(Q)$(MAKE) $(build)=arch/x86/tools
|
||||||
|
|
||||||
|
###
|
||||||
|
# Syscall table generation
|
Loading…
Reference in New Issue