nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at netboot-syslinux-multiplatform 154 lines 5.3 kB view raw
1{ stdenv, lib, fetchurl, coreutils, ncurses, gzip, flex, bison 2, less 3, buildPackages 4, x11Mode ? false, qtMode ? false, libXaw, libXext, libXpm, bdftopcf, mkfontdir, pkg-config, qt5 5}: 6 7let 8 platform = 9 if stdenv.hostPlatform.isUnix then "unix" 10 else throw "Unknown platform for NetHack: ${stdenv.hostPlatform.system}"; 11 unixHint = 12 if x11Mode then "linux-x11" 13 else if qtMode then "linux-qt4" 14 else if stdenv.hostPlatform.isLinux then "linux" 15 else if stdenv.hostPlatform.isDarwin then "macosx10.10" 16 # We probably want something different for Darwin 17 else "unix"; 18 userDir = "~/.config/nethack"; 19 binPath = lib.makeBinPath [ coreutils less ]; 20 21in stdenv.mkDerivation rec { 22 version = "3.6.7"; 23 pname = if x11Mode then "nethack-x11" 24 else if qtMode then "nethack-qt" 25 else "nethack"; 26 27 src = fetchurl { 28 url = "https://nethack.org/download/${version}/nethack-${lib.replaceStrings ["."] [""] version}-src.tgz"; 29 sha256 = "sha256-mM9n323r+WaKYXRaqEwJvKs2Ll0z9blE7FFV1E0qrLI="; 30 }; 31 32 buildInputs = [ ncurses ] 33 ++ lib.optionals x11Mode [ libXaw libXext libXpm ] 34 ++ lib.optionals qtMode [ gzip qt5.qtbase.bin qt5.qtmultimedia.bin ]; 35 36 nativeBuildInputs = [ flex bison ] 37 ++ lib.optionals x11Mode [ mkfontdir bdftopcf ] 38 ++ lib.optionals qtMode [ 39 pkg-config mkfontdir qt5.qtbase.dev 40 qt5.qtmultimedia.dev qt5.wrapQtAppsHook 41 bdftopcf 42 ]; 43 44 makeFlags = [ "PREFIX=$(out)" ]; 45 46 postPatch = '' 47 sed -e '/^ *cd /d' -i sys/unix/nethack.sh 48 sed \ 49 -e 's/^YACC *=.*/YACC = bison -y/' \ 50 -e 's/^LEX *=.*/LEX = flex/' \ 51 -i sys/unix/Makefile.utl 52 sed \ 53 -e 's,^WINQT4LIB =.*,WINQT4LIB = `pkg-config Qt5Gui --libs` \\\ 54 `pkg-config Qt5Widgets --libs` \\\ 55 `pkg-config Qt5Multimedia --libs`,' \ 56 -i sys/unix/Makefile.src 57 sed \ 58 -e 's,^CFLAGS=-g,CFLAGS=,' \ 59 -e 's,/bin/gzip,${gzip}/bin/gzip,g' \ 60 -e 's,^WINTTYLIB=.*,WINTTYLIB=-lncurses,' \ 61 -i sys/unix/hints/linux 62 sed \ 63 -e 's,^CC=.*$,CC=${stdenv.cc.targetPrefix}cc,' \ 64 -e 's,^HACKDIR=.*$,HACKDIR=\$(PREFIX)/games/lib/\$(GAME)dir,' \ 65 -e 's,^SHELLDIR=.*$,SHELLDIR=\$(PREFIX)/games,' \ 66 -e 's,^CFLAGS=-g,CFLAGS=,' \ 67 -i sys/unix/hints/macosx10.10 68 sed -e '/define CHDIR/d' -i include/config.h 69 ${lib.optionalString qtMode '' 70 sed \ 71 -e 's,^QTDIR *=.*,QTDIR=${qt5.qtbase.dev},' \ 72 -e 's,CFLAGS.*QtGui.*,CFLAGS += `pkg-config Qt5Gui --cflags`,' \ 73 -e 's,CFLAGS+=-DCOMPRESS.*,CFLAGS+=-DCOMPRESS=\\"${gzip}/bin/gzip\\" \\\ 74 -DCOMPRESS_EXTENSION=\\".gz\\",' \ 75 -e 's,moc-qt4,moc,' \ 76 -i sys/unix/hints/linux-qt4 77 ''} 78 ${lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) 79 # If we're cross-compiling, replace the paths to the data generation tools 80 # with the ones from the build platform's nethack package, since we can't 81 # run the ones we've built here. 82 '' 83 ${buildPackages.perl}/bin/perl -p \ 84 -e 's,[a-z./]+/(makedefs|dgn_comp|lev_comp|dlb)(?!\.),${buildPackages.nethack}/libexec/nethack/\1,g' \ 85 -i sys/unix/Makefile.* 86 ''} 87 sed -i -e '/rm -f $(MAKEDEFS)/d' sys/unix/Makefile.src 88 # Fix building on darwin where otherwise __has_attribute fails with an empty parameter 89 sed -e 's/define __warn_unused_result__ .*/define __warn_unused_result__ __unused__/' -i include/tradstdc.h 90 sed -e 's/define warn_unused_result .*/define warn_unused_result __unused__/' -i include/tradstdc.h 91 ''; 92 93 configurePhase = '' 94 pushd sys/${platform} 95 ${lib.optionalString (platform == "unix") '' 96 sh setup.sh hints/${unixHint} 97 ''} 98 popd 99 ''; 100 101 enableParallelBuilding = true; 102 103 preFixup = lib.optionalString qtMode '' 104 wrapQtApp "$out/games/nethack" 105 ''; 106 107 postInstall = '' 108 mkdir -p $out/games/lib/nethackuserdir 109 for i in xlogfile logfile perm record save; do 110 mv $out/games/lib/nethackdir/$i $out/games/lib/nethackuserdir 111 done 112 113 mkdir -p $out/bin 114 cat <<EOF >$out/bin/nethack 115 #! ${stdenv.shell} -e 116 PATH=${binPath}:\$PATH 117 118 if [ ! -d ${userDir} ]; then 119 mkdir -p ${userDir} 120 cp -r $out/games/lib/nethackuserdir/* ${userDir} 121 chmod -R +w ${userDir} 122 fi 123 124 RUNDIR=\$(mktemp -d) 125 126 cleanup() { 127 rm -rf \$RUNDIR 128 } 129 trap cleanup EXIT 130 131 cd \$RUNDIR 132 for i in ${userDir}/*; do 133 ln -s \$i \$(basename \$i) 134 done 135 for i in $out/games/lib/nethackdir/*; do 136 ln -s \$i \$(basename \$i) 137 done 138 $out/games/nethack 139 EOF 140 chmod +x $out/bin/nethack 141 ${lib.optionalString x11Mode "mv $out/bin/nethack $out/bin/nethack-x11"} 142 ${lib.optionalString qtMode "mv $out/bin/nethack $out/bin/nethack-qt"} 143 install -Dm 555 util/{makedefs,dgn_comp,lev_comp} -t $out/libexec/nethack/ 144 ${lib.optionalString (!(x11Mode || qtMode)) "install -Dm 555 util/dlb -t $out/libexec/nethack/"} 145 ''; 146 147 meta = with lib; { 148 description = "Rogue-like game"; 149 homepage = "http://nethack.org/"; 150 license = "nethack"; 151 platforms = if x11Mode then platforms.linux else platforms.unix; 152 maintainers = with maintainers; [ abbradar ]; 153 }; 154}