openttd: fix cross-compilation

This commit is contained in:
Stefan Frijters 2025-06-02 14:27:18 +02:00
parent 045f0b2c79
commit 17effa31a8
No known key found for this signature in database
GPG key ID: 7619A6BC6E7DFA6F

View file

@ -34,6 +34,7 @@
alsa-lib,
libjack2,
makeWrapper,
buildPackages,
}:
let
@ -51,6 +52,18 @@ let
url = "https://cdn.openttd.org/openmsx-releases/0.4.2/openmsx-0.4.2-all.zip";
hash = "sha256-Cgrg2m+uTODFg39mKgX+hE8atV7v5bVyZd716vSZB8M=";
};
# OpenTTD builds and uses some of its own tools during the build and we need those to be available for cross-compilation.
# Build the tools for buildPlatform with minimal dependencies, using the "OPTION_TOOLS_ONLY" flag.
crossTools = buildPackages.openttd.overrideAttrs (oldAttrs: {
pname = "openttd-tools";
buildInputs = [ ];
cmakeFlags = oldAttrs.cmakeFlags or [ ] ++ [ (lib.cmakeBool "OPTION_TOOLS_ONLY" true) ];
installPhase = ''
install -Dm555 src/strgen/strgen -t $out/bin
install -Dm555 src/settingsgen/settingsgen -t $out/bin
'';
});
in
stdenv.mkDerivation (finalAttrs: {
pname = "openttd";
@ -71,11 +84,15 @@ stdenv.mkDerivation (finalAttrs: {
})
];
nativeBuildInputs = [
cmake
pkg-config
makeWrapper
];
nativeBuildInputs =
[
cmake
pkg-config
makeWrapper
]
++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
crossTools
];
buildInputs =
[