dwarf-fortress: supports darwin

This commit is contained in:
Matthew Bauer 2018-05-10 23:55:06 -05:00
parent b45552c35a
commit 236b89afeb
5 changed files with 69 additions and 25 deletions

View File

@ -1,4 +1,4 @@
{ pkgs, pkgsi686Linux }: { pkgs, pkgsi686Linux, stdenv }:
let let
callPackage = pkgs.newScope self; callPackage = pkgs.newScope self;
@ -13,7 +13,9 @@ let
soundSense = callPackage ./soundsense.nix { }; soundSense = callPackage ./soundsense.nix { };
dwarf-fortress-unfuck = callPackage ./unfuck.nix { }; # unfuck is linux-only right now, we will just use it there
dwarf-fortress-unfuck = if stdenv.isLinux then callPackage ./unfuck.nix { }
else null;
dwarf-fortress = callPackage ./wrapper { dwarf-fortress = callPackage ./wrapper {
themes = { themes = {

View File

@ -1,57 +1,93 @@
{ stdenv, lib, fetchurl { stdenv, lib, fetchurl
, SDL, dwarf-fortress-unfuck , SDL, dwarf-fortress-unfuck
# Our own "unfuck" libs for macOS
, ncurses, fmodex, gcc
}: }:
with lib;
let let
baseVersion = "44"; baseVersion = "44";
patchVersion = "09"; patchVersion = "10";
dfVersion = "0.${baseVersion}.${patchVersion}"; dfVersion = "0.${baseVersion}.${patchVersion}";
libpath = lib.makeLibraryPath [ stdenv.cc.cc stdenv.glibc dwarf-fortress-unfuck SDL ];
platform = libpath = makeLibraryPath [ stdenv.cc.cc stdenv.cc.libc dwarf-fortress-unfuck SDL ];
if stdenv.system == "x86_64-linux" then "linux"
else if stdenv.system == "i686-linux" then "linux32" homepage = http://www.bay12games.com/dwarves/;
else throw "Unsupported platform";
sha256 = # Other srcs are avilable like 32-bit mac & win, but I have only
if stdenv.system == "x86_64-linux" then "1haikynkg1pqyrzzqk1qxm19p36ww58qp8brh3fjxssp4x71rcdy" # included the ones most likely to be needed by Nixpkgs users.
else if stdenv.system == "i686-linux" then "0lmbrdf7wjdwj5yx0khnq871yxvhfwqxjjyfkqcdy5ik18lvlkj8" srcs = {
else throw "Unsupported platform"; "x86_64-linux" = fetchurl {
url = "${homepage}df_${baseVersion}_${patchVersion}_linux.tar.bz2";
sha256 = "1haikynkg1pqyrzzqk1qxm19p36ww58qp8brh3fjxssp4x71rcdy";
};
"i686-linux" = fetchurl {
url = "${homepage}df_${baseVersion}_${patchVersion}_linux32.tar.bz2";
sha256 = "0lmbrdf7wjdwj5yx0khnq871yxvhfwqxjjyfkqcdy5ik18lvlkj8";
};
"x86_64-darwin" = fetchurl {
url = "${homepage}df_${baseVersion}_${patchVersion}_osx.tar.bz2";
sha256 = "1wpa45d81q8f5mhqmaxvdkz93k6cm3pg7vpsqjjjsp5s961gd74g";
};
};
in in
assert dwarf-fortress-unfuck.dfVersion == dfVersion; assert dwarf-fortress-unfuck != null ->
dwarf-fortress-unfuck.dfVersion == dfVersion;
stdenv.mkDerivation { stdenv.mkDerivation {
name = "dwarf-fortress-original-${dfVersion}"; name = "dwarf-fortress-original-${dfVersion}";
src = fetchurl { src = if builtins.hasAttr stdenv.system srcs
url = "http://www.bay12games.com/dwarves/df_${baseVersion}_${patchVersion}_${platform}.tar.bz2"; then builtins.getAttr stdenv.system srcs
inherit sha256; else throw "Unsupported systems";
};
installPhase = '' installPhase = ''
mkdir -p $out mkdir -p $out
cp -r * $out cp -r * $out
rm $out/libs/lib* rm $out/libs/lib*
# Store the original hash exe=$out/${if stdenv.isLinux then "libs/Dwarf_Fortress"
md5sum $out/libs/Dwarf_Fortress | awk '{ print $1 }' > $out/hash.md5.orig else "dwarfort.exe"}
# Store the original hash
md5sum $exe | awk '{ print $1 }' > $out/hash.md5.orig
'' + optionalString stdenv.isLinux ''
patchelf \ patchelf \
--set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) \ --set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) \
--set-rpath "${libpath}" \ --set-rpath "${libpath}" \
$out/libs/Dwarf_Fortress $exe
'' + optionalString stdenv.isDarwin ''
# My custom unfucked dwarfort.exe for macOS. Can't use
# absolute paths because original doesn't have enough
# header space. Someone plz break into Tarn's house & put
# -headerpad_max_install_names into his LDFLAGS.
ln -s ${getLib ncurses}/lib/libncurses.dylib $out/libs
ln -s ${getLib gcc.cc}/lib/libstdc++.6.dylib $out/libs
ln -s ${getLib fmodex}/lib/libfmodex.dylib $out/libs
install_name_tool \
-change /usr/lib/libncurses.5.4.dylib \
@executable_path/libs/libncurses.dylib \
-change /usr/local/lib/x86_64/libstdc++.6.dylib \
@executable_path/libs/libstdc++.6.dylib \
$exe
'' + ''
# Store the new hash # Store the new hash
md5sum $out/libs/Dwarf_Fortress | awk '{ print $1 }' > $out/hash.md5 md5sum $exe | awk '{ print $1 }' > $out/hash.md5
''; '';
passthru = { inherit baseVersion patchVersion dfVersion; }; passthru = { inherit baseVersion patchVersion dfVersion; };
meta = with stdenv.lib; { meta = {
description = "A single-player fantasy game with a randomly generated adventure world"; description = "A single-player fantasy game with a randomly generated adventure world";
homepage = http://www.bay12games.com/dwarves; inherit homepage;
license = licenses.unfreeRedistributable; license = licenses.unfreeRedistributable;
platforms = platforms.linux; platforms = attrNames srcs;
maintainers = with maintainers; [ a1russell robbinch roconnor the-kenny abbradar ]; maintainers = with maintainers; [ a1russell robbinch roconnor the-kenny abbradar ];
}; };
} }

View File

@ -47,6 +47,8 @@ stdenv.mkDerivation rec {
name = "dwarf-fortress-init"; name = "dwarf-fortress-init";
src = ./dwarf-fortress-init.in; src = ./dwarf-fortress-init.in;
inherit env; inherit env;
exe = if stdenv.isLinux then "libs/Dwarf_Fortress"
else "dwarfort.exe";
}; };
runDF = ./dwarf-fortress.in; runDF = ./dwarf-fortress.in;

View File

@ -2,6 +2,7 @@ shopt -s extglob
[ -z "$DF_DIR" ] && DF_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/df_linux" [ -z "$DF_DIR" ] && DF_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/df_linux"
env_dir="@env@" env_dir="@env@"
exe="$env_dir/@exe@"
update_path() { update_path() {
local path="$1" local path="$1"

View File

@ -2,5 +2,8 @@
source @dfInit@ source @dfInit@
export DYLD_LIBRARY_PATH="$env_dir/libs"
export DYLD_FRAMEWORK_PATH="$env_dir/libs"
cd "$DF_DIR" cd "$DF_DIR"
exec "$env_dir/libs/Dwarf_Fortress" "$@" exec "$exe" "$@"