107 lines
2.4 KiB
Nix
107 lines
2.4 KiB
Nix
{
|
|
# callPackage,
|
|
fetchFromGitHub,
|
|
autoPatchelfHook,
|
|
zlib,
|
|
curl,
|
|
SDL2,
|
|
hexdump,
|
|
stdenv,
|
|
writeTextFile,
|
|
lib,
|
|
bash,
|
|
python3,
|
|
sm64baserom,
|
|
|
|
enableTextureFix ? true,
|
|
enableDiscord ? false,
|
|
enableCoopNet ? true,
|
|
}:
|
|
let
|
|
libc_hack = writeTextFile {
|
|
name = "libc-hack";
|
|
# https://stackoverflow.com/questions/21768542/libc-h-no-such-file-or-directory-when-compiling-nanomsg-pipeline-sample
|
|
text = ''
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <pthread.h>
|
|
'';
|
|
destination = "/include/libc.h";
|
|
};
|
|
target = stdenv.targetPlatform;
|
|
bits =
|
|
if target.is64bit then
|
|
"64"
|
|
else if target.is32bit then
|
|
"32"
|
|
else
|
|
throw "unspported bits";
|
|
pname = "sm64coopdx";
|
|
version = "1.0.3";
|
|
in
|
|
stdenv.mkDerivation {
|
|
inherit pname version;
|
|
|
|
src = fetchFromGitHub {
|
|
owner = "coop-deluxe";
|
|
repo = pname;
|
|
rev = "v${version}";
|
|
hash = "sha256-cIH3escLFMcHgtFxeSKIo5nZXvaknti+EVt72uB4XXc=";
|
|
};
|
|
|
|
buildInputs = [
|
|
python3
|
|
zlib
|
|
curl
|
|
libc_hack
|
|
SDL2
|
|
hexdump
|
|
];
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
# Normally there's no need to set TARGET_ARCH, but if we don't it adds -march=native which is impure
|
|
makeFlags = [
|
|
"BREW_PREFIX=/not-exist"
|
|
"DISCORD_SDK=${if enableDiscord then "1" else "0"}"
|
|
"TEXTURE_FIX=${if enableTextureFix then "1" else "0"}"
|
|
"COOPNET=${if enableCoopNet then "1" else "0"}"
|
|
];
|
|
|
|
preBuild = ''
|
|
ln -s ${sm64baserom} baserom.us.z64
|
|
substituteInPlace Makefile \
|
|
--replace-fail ' -march=$(TARGET_ARCH) ' ' '
|
|
# workaround a bug in the build
|
|
# see https://github.com/coop-deluxe/sm64coopdx/issues/186#issuecomment-2216163935
|
|
# this can likely be removed when the next version releases
|
|
make build/us_pc/sound/sequences.bin
|
|
'';
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
|
|
local built=$PWD/build/us_pc
|
|
|
|
share=$out/share/${pname}
|
|
mkdir -p $share
|
|
cp $built/${pname} $share/${pname}-unwrapped
|
|
cp -r $built/{dynos,lang,mods,palettes} $share
|
|
ln -s ${sm64baserom} $share/baserom.us.z64
|
|
|
|
${lib.optionalString enableDiscord ''
|
|
cp $built/libdiscord_game_sdk* $share
|
|
''}
|
|
|
|
mkdir -p $out/bin
|
|
(
|
|
echo '#!${bash}/bin/bash'
|
|
echo "cd $out/share/${pname}"
|
|
echo 'exec ./${pname}-unwrapped "$@"'
|
|
) > $out/bin/${pname}
|
|
chmod a+x $out/bin/${pname}
|
|
|
|
runHook postInstall
|
|
'';
|
|
}
|