From b33446b7c3b0b14816ff359747a8049f84295dfd Mon Sep 17 00:00:00 2001 From: Kei Kebreau Date: Mon, 6 Jun 2016 15:56:45 -0400 Subject: [PATCH] gnu: Add nethack. * gnu/packages/patches/nethack-correct-directories-and-permissions.patch: New file. * gnu/local.mk (dist_patch_DATA): Add it. * gnu/packages/games.scm (nethack): New variable. --- gnu/local.mk | 1 + gnu/packages/games.scm | 111 +++++++++++++++++++++ ...thack-correct-directories-and-permissions.patch | 40 ++++++++ 3 files changed, 152 insertions(+) create mode 100644 gnu/packages/patches/nethack-correct-directories-and-permissions.patch diff --git a/gnu/local.mk b/gnu/local.mk index c130901..c9facb9 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -636,6 +636,7 @@ dist_patch_DATA = \ gnu/packages/patches/mutt-store-references.patch \ gnu/packages/patches/net-tools-bitrot.patch \ gnu/packages/patches/netcdf-config-date.patch \ + gnu/packages/patches/nethack-correct-directories-and-permissions.patch \ gnu/packages/patches/ngircd-handle-zombies.patch \ gnu/packages/patches/ngircd-no-dns-in-tests.patch \ gnu/packages/patches/ninja-tests.patch \ diff --git a/gnu/packages/games.scm b/gnu/packages/games.scm index fc16862..43aa9e5 100644 --- a/gnu/packages/games.scm +++ b/gnu/packages/games.scm @@ -49,10 +49,12 @@ #:use-module (gnu packages autotools) #:use-module (gnu packages backup) #:use-module (gnu packages base) + #:use-module (gnu packages bison) #:use-module (gnu packages admin) #:use-module (gnu packages audio) #:use-module (gnu packages avahi) #:use-module (gnu packages boost) + #:use-module (gnu packages flex) #:use-module (gnu packages fribidi) #:use-module (gnu packages game-development) #:use-module (gnu packages gettext) @@ -2243,3 +2245,112 @@ Red Eclipse provides fast paced and accessible gameplay.") license:cc-by-sa3.0 license:cc-by3.0 license:cc0))))) + +(define-public nethack + (package + (name "nethack") + (version "3.6.0") + (source (origin + (method url-fetch) + (uri (string-append "mirror://sourceforge/" name "/" name "-" + (string-join (string-split version #\.) "") + "-src.tgz")) + (sha256 + (base32 + "12mi5kgqw3q029y57pkg3gnp930p7yvlqi118xxdif2qhj6nkphs")) + (patches + (search-patches + "nethack-correct-directories-and-permissions.patch")))) + (build-system gnu-build-system) + (arguments + `(#:tests? #f ; no check target + #:make-flags '("CC=gcc" "LEX=flex" "YACC=bison -y") + #:phases + (modify-phases %standard-phases + (replace 'configure + (lambda* (#:key inputs outputs #:allow-other-keys) + (let ((out (assoc-ref outputs "out"))) + (substitute* "sys/unix/hints/linux" + (("^PREFIX=.*$") + (string-append "PREFIX=" out "\n")) + (("^HACKDIR=.*$") + (string-append "HACKDIR=" out "/var/hackdir\n")) + (("^SHELLDIR=.*$") + (string-append "SHELLDIR=" out "/var\n")) + (("/bin/gzip") (which "gzip"))) + (substitute* "sys/unix/setup.sh" + (("/bin/sh") (which "bash")))) + (zero? (system* "sh" "sys/unix/setup.sh" "sys/unix/hints/linux")))) + (add-after 'install 'post-install + (lambda* (#:key inputs outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out"))) + (mkdir-p (string-append out "/var/nethack/save")) + (chdir (string-append out "/var/hackdir")) + (delete-file-recursively "save") + + ; unnecessary script, the one wrapped below runs fine + (delete-file-recursively (string-append out "/games")) + (install-file "recover" (string-append out "/bin")) + (delete-file "recover") + (for-each (lambda (file) + (install-file file + (string-append + out + "/var/nethack")) + (delete-file file)) + '("logfile" "perm" "record" "xlogfile")) + #t))) + (add-after 'post-install 'wrap-program + (lambda* (#:key inputs outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out")) + (bin (string-append out "/bin")) + (nethack-user-dir "~/.nethack")) + (with-directory-excursion bin + (call-with-output-file "nethack" + (lambda (port) + (format port "#!~a/bin/sh -e +# Create NetHack directory in user's $HOME if it isn't there +if [ ! -d ~a ]; then + mkdir -p ~a + cp -r ~a/* ~a + chmod -R +w ~a +fi + +RUNDIR=$(mktemp -d) + +cleanup() { + rm -rf $RUNDIR +} +trap cleanup EXIT + +cd $RUNDIR +for i in ~a/*; do + ln -s $i $(basename $i) +done +for i in ~a/*; do + ln -s $i $(basename $i) +done +./nethack~%" + (assoc-ref inputs "bash") ;implicit input + (string-append nethack-user-dir) + (string-append nethack-user-dir) + (string-append + out "/var/nethack") + (string-append nethack-user-dir) + (string-append nethack-user-dir) + (string-append nethack-user-dir) + (string-append out "/var/hackdir") + (string-append out)))) + (chmod "nethack" #o555))) + #t))))) + (native-inputs + `(("bison" ,bison) + ("flex" ,flex))) + (inputs `(("ncurses" ,ncurses))) + (home-page "http://nethack.org") + (synopsis "Single player dungeon exploration game") + (description + "Nethack is a roguelike game that emphasizes discovery of details in the +dungeon. The random number generator provides an unlimited number of +variations of the dungeon.") + (license (license:fsf-free "http://nethack.org/common/license.html")))) diff --git a/gnu/packages/patches/nethack-correct-directories-and-permissions.patch b/gnu/packages/patches/nethack-correct-directories-and-permissions.patch new file mode 100644 index 0000000..9154712 --- /dev/null +++ b/gnu/packages/patches/nethack-correct-directories-and-permissions.patch @@ -0,0 +1,40 @@ +Patch by Kei Kebreau +Keeping "#define CHDIR" makes NetHack unable to find its scoreboard record. +The other two modifications enable building on Linux and building with the +ncurses library, respectively. + +diff -r -u nethack-3.6.0.orig/include/config.h nethack-3.6.0/include/config.h +--- nethack-3.6.0.orig/include/config.h 2016-05-27 17:20:03.062318307 -0400 ++++ nethack-3.6.0/include/config.h 2016-05-31 16:48:04.283642766 -0400 +@@ -308,7 +308,6 @@ + #define INSURANCE /* allow crashed game recovery */ + + #ifndef MAC +-#define CHDIR /* delete if no chdir() available */ + #endif + + #ifdef CHDIR +diff -r -u nethack-3.6.0.orig/include/unixconf.h nethack-3.6.0/include/unixconf.h +--- nethack-3.6.0.orig/include/unixconf.h 2016-05-27 17:20:03.062318307 -0400 ++++ nethack-3.6.0/include/unixconf.h 2016-05-30 20:33:52.132273630 -0400 +@@ -36,7 +36,7 @@ + #define NETWORK /* if running on a networked system */ + /* e.g. Suns sharing a playground through NFS */ + /* #define SUNOS4 */ /* SunOS 4.x */ +-/* #define LINUX */ /* Another Unix clone */ ++#define LINUX /* Another Unix clone */ + /* #define CYGWIN32 */ /* Unix on Win32 -- use with case sensitive defines */ + /* #define GENIX */ /* Yet Another Unix Clone */ + /* #define HISX */ /* Bull Unix for XPS Machines */ +diff -r -u nethack-3.6.0.orig/sys/unix/Makefile.src nethack-3.6.0/sys/unix/Makefile.src +--- nethack-3.6.0.orig/sys/unix/Makefile.src 2016-05-27 17:20:03.082318966 -0400 ++++ nethack-3.6.0/sys/unix/Makefile.src 2016-06-05 12:30:33.301505514 -0400 +@@ -238,7 +238,7 @@ + # WINTTYLIB = -ltermcap + # WINTTYLIB = -lcurses + # WINTTYLIB = -lcurses16 +-# WINTTYLIB = -lncurses ++WINTTYLIB = -lncurses + #WINTTYLIB = -ltermlib + # + # libraries for X11 -- 2.8.3