nixpkgs/pkgs/games/nethack/default.nix

153 lines
4.9 KiB
Nix
Raw Normal View History

{ stdenv, lib, fetchurl, coreutils, ncurses, gzip, flex, bison
2018-07-15 23:06:59 +02:00
, less, makeWrapper
, buildPackages
, x11Mode ? false, qtMode ? false, libXaw, libXext, libXpm, bdftopcf, mkfontdir, pkgconfig, qt5
}:
2015-06-29 13:19:12 +02:00
let
platform =
2018-03-10 00:40:51 +01:00
if stdenv.hostPlatform.isUnix then "unix"
else throw "Unknown platform for NetHack: ${stdenv.hostPlatform.system}";
unixHint =
if x11Mode then "linux-x11"
2018-07-15 08:18:55 +02:00
else if qtMode then "linux-qt4"
else if stdenv.hostPlatform.isLinux then "linux"
2018-03-10 00:40:51 +01:00
else if stdenv.hostPlatform.isDarwin then "macosx10.10"
# We probably want something different for Darwin
else "unix";
2015-12-08 16:10:53 +01:00
userDir = "~/.config/nethack";
2017-04-06 15:27:36 +02:00
binPath = lib.makeBinPath [ coreutils less ];
2018-07-15 08:18:55 +02:00
in stdenv.mkDerivation rec {
version = "3.6.2";
2018-07-15 08:18:55 +02:00
name = if x11Mode then "nethack-x11-${version}"
else if qtMode then "nethack-qt-${version}"
else "nethack-${version}";
2015-06-29 13:19:12 +02:00
src = fetchurl {
url = "https://nethack.org/download/3.6.2/nethack-362-src.tgz";
sha256 = "07fvkm3v11a4pjrq2f66vjslljsvk6raal53skn4gqsfdbd0ml7v";
};
2018-07-15 08:18:55 +02:00
buildInputs = [ ncurses ]
++ lib.optionals x11Mode [ libXaw libXext libXpm ]
2018-07-15 08:18:55 +02:00
++ lib.optionals qtMode [ gzip qt5.qtbase.bin qt5.qtmultimedia.bin ];
2015-06-29 13:19:12 +02:00
2018-07-15 08:18:55 +02:00
nativeBuildInputs = [ flex bison ]
2018-09-20 20:01:36 +02:00
++ lib.optionals x11Mode [ mkfontdir bdftopcf ]
2018-07-15 08:18:55 +02:00
++ lib.optionals qtMode [
pkgconfig mkfontdir qt5.qtbase.dev
2018-07-15 23:06:59 +02:00
qt5.qtmultimedia.dev makeWrapper
2018-09-20 20:01:36 +02:00
bdftopcf
2018-07-15 08:18:55 +02:00
];
makeFlags = [ "PREFIX=$(out)" ];
postPatch = ''
2016-02-29 04:04:23 +01:00
sed -e '/^ *cd /d' -i sys/unix/nethack.sh
sed \
-e 's/^YACC *=.*/YACC = bison -y/' \
-e 's/^LEX *=.*/LEX = flex/' \
-i sys/unix/Makefile.utl
2018-07-15 08:18:55 +02:00
sed \
-e 's,^WINQT4LIB =.*,WINQT4LIB = `pkg-config Qt5Gui --libs` \\\
`pkg-config Qt5Widgets --libs` \\\
`pkg-config Qt5Multimedia --libs`,' \
-i sys/unix/Makefile.src
2016-02-29 04:04:23 +01:00
sed \
-e 's,^CFLAGS=-g,CFLAGS=,' \
2016-02-29 04:04:23 +01:00
-e 's,/bin/gzip,${gzip}/bin/gzip,g' \
-e 's,^WINTTYLIB=.*,WINTTYLIB=-lncurses,' \
-i sys/unix/hints/linux
sed \
-e 's,^CC=.*$,CC=cc,' \
-e 's,^HACKDIR=.*$,HACKDIR=\$(PREFIX)/games/lib/\$(GAME)dir,' \
-e 's,^SHELLDIR=.*$,SHELLDIR=\$(PREFIX)/games,' \
-e 's,^CFLAGS=-g,CFLAGS=,' \
2016-02-29 04:04:23 +01:00
-i sys/unix/hints/macosx10.10
sed -e '/define CHDIR/d' -i include/config.h
${lib.optionalString qtMode ''
2018-07-15 08:18:55 +02:00
sed \
-e 's,^QTDIR *=.*,QTDIR=${qt5.qtbase.dev},' \
-e 's,CFLAGS.*QtGui.*,CFLAGS += `pkg-config Qt5Gui --cflags`,' \
-e 's,CFLAGS+=-DCOMPRESS.*,CFLAGS+=-DCOMPRESS=\\"${gzip}/bin/gzip\\" \\\
-DCOMPRESS_EXTENSION=\\".gz\\",' \
-e 's,moc-qt4,moc,' \
2018-07-15 08:18:55 +02:00
-i sys/unix/hints/linux-qt4
''}
${lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform)
# If we're cross-compiling, replace the paths to the data generation tools
# with the ones from the build platform's nethack package, since we can't
# run the ones we've built here.
''
${buildPackages.perl}/bin/perl -p \
-e 's,[a-z./]+/(makedefs|dgn_comp|lev_comp|dlb)(?!\.),${buildPackages.nethack}/libexec/nethack/\1,g' \
-i sys/unix/Makefile.*
''}
sed -i -e '/rm -f $(MAKEDEFS)/d' sys/unix/Makefile.src
2016-02-29 04:04:23 +01:00
'';
configurePhase = ''
pushd sys/${platform}
${lib.optionalString (platform == "unix") ''
sh setup.sh hints/${unixHint}
''}
popd
2015-06-29 13:19:12 +02:00
'';
enableParallelBuilding = true;
2015-06-29 13:19:12 +02:00
postInstall = ''
mkdir -p $out/games/lib/nethackuserdir
for i in xlogfile logfile perm record save; do
mv $out/games/lib/nethackdir/$i $out/games/lib/nethackuserdir
2015-06-29 13:19:12 +02:00
done
mkdir -p $out/bin
2015-06-29 13:19:12 +02:00
cat <<EOF >$out/bin/nethack
2015-12-08 16:10:53 +01:00
#! ${stdenv.shell} -e
2017-04-06 15:27:36 +02:00
PATH=${binPath}:\$PATH
2015-06-29 13:19:12 +02:00
2015-12-08 16:10:53 +01:00
if [ ! -d ${userDir} ]; then
mkdir -p ${userDir}
cp -r $out/games/lib/nethackuserdir/* ${userDir}
chmod -R +w ${userDir}
fi
2015-06-29 13:19:12 +02:00
2016-02-29 04:04:23 +01:00
RUNDIR=\$(mktemp -d)
2015-06-29 13:19:12 +02:00
2015-12-08 16:10:53 +01:00
cleanup() {
rm -rf \$RUNDIR
}
trap cleanup EXIT
cd \$RUNDIR
for i in ${userDir}/*; do
ln -s \$i \$(basename \$i)
done
for i in $out/games/lib/nethackdir/*; do
ln -s \$i \$(basename \$i)
done
$out/games/nethack
2015-06-29 13:19:12 +02:00
EOF
chmod +x $out/bin/nethack
${lib.optionalString x11Mode "mv $out/bin/nethack $out/bin/nethack-x11"}
2018-07-15 08:18:55 +02:00
${lib.optionalString qtMode "mv $out/bin/nethack $out/bin/nethack-qt"}
install -Dm 555 util/{makedefs,dgn_comp,lev_comp} -t $out/libexec/nethack/
${lib.optionalString (!(x11Mode || qtMode)) "install -Dm 555 util/dlb -t $out/libexec/nethack/"}
2015-06-29 13:19:12 +02:00
'';
2018-07-15 23:06:59 +02:00
postFixup = lib.optionalString qtMode ''
wrapProgram $out/bin/nethack-qt \
--prefix QT_PLUGIN_PATH : "${qt5.qtbase}/${qt5.qtbase.qtPluginPrefix}"
'';
2015-06-29 13:19:12 +02:00
meta = with stdenv.lib; {
description = "Rogue-like game";
homepage = http://nethack.org/;
2015-06-29 13:19:12 +02:00
license = "nethack";
platforms = if x11Mode then platforms.linux else platforms.unix;
2015-06-29 13:19:12 +02:00
maintainers = with maintainers; [ abbradar ];
};
}