From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kei Kebreau Subject: Re: [PATCH] gnu: Add nethack. Date: Mon, 6 Jun 2016 16:25:41 -0400 Message-ID: <20160606162541.5254ed6c@openmailbox.org> References: <20160531175630.0bfd76ff@openmailbox.org> <87y46kwt82.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; boundary="Sig_/MBOQu1TRp_7VlJwVy9slKf9"; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:37844) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bA169-00017e-3H for guix-devel@gnu.org; Mon, 06 Jun 2016 16:26:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bA163-0002tI-Ng for guix-devel@gnu.org; Mon, 06 Jun 2016 16:26:07 -0400 In-Reply-To: <87y46kwt82.fsf@gnu.org> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Ludovic =?UTF-8?B?Q291cnTDqHM=?= Cc: guix-devel@gnu.org --Sig_/MBOQu1TRp_7VlJwVy9slKf9 Content-Type: multipart/mixed; boundary="MP_/AhT0ILRg+Rz7iAw6NhKGPii" --MP_/AhT0ILRg+Rz7iAw6NhKGPii Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Sat, 04 Jun 2016 23:15:57 +0200 ludo@gnu.org (Ludovic Court=C3=A8s) wrote: > Hi! >=20 > Kei Kebreau skribis: >=20 > > From b728e078408f17136e8a4c3344b606e8f152b9e4 Mon Sep 17 00:00:00 > > 2001 From: Kei Kebreau > > Date: Tue, 31 May 2016 17:42:28 -0400 > > Subject: [PATCH] gnu: Add nethack. > > > > * gnu/packages/games.scm (nethack): New variable. =20 >=20 > You need to mention the new .patch file here (see =E2=80=98git log=E2=80= =99 for > examples.) >=20 > You also need to add the .patch file to gnu/local.mk, and to mention > the change to gnu/local.mk in the commit log. >=20 > [...] >=20 > > + (replace 'configure > > + (lambda* (#:key inputs outputs #:allow-other-keys) > > + (let ((out (assoc-ref outputs "out"))) > > + (substitute* "sys/unix/hints/linux" > > + (("^PREFIX=3D.*$") > > + (string-append "PREFIX=3D" out "\n")) > > + (("/bin/gzip") (which "gzip"))) > > + (substitute* "sys/unix/setup.sh" > > + (("/bin/sh") (which "bash")))) > > + (system* "sh" "sys/unix/setup.sh" > > "sys/unix/hints/linux"))) =20 >=20 > Should be: (zero? (system* =E2=80=A6)), which returns #t on success (a ph= ase > must return a true value to be considered successful.) >=20 > > + (add-after 'install 'move-state-files > > + (lambda* (#:key inputs outputs #:allow-other-keys) > > + (let* ((out (assoc-ref outputs "out"))) > > + (mkdir (string-append out > > "/games/lib/nethack-state-files")) > > + (chdir (string-append out "/games/lib/nethackdir")) > > + (for-each (lambda (file) > > + (system* "mv" file > > + (string-append > > + out > > "/games/lib/nethack-state-files"))) =20 >=20 > Instead of using the =E2=80=98mv=E2=80=99 command (or any other Coreutils= command, for > that matter), use the Scheme equivalent. Here it would be: >=20 > (install-file file directory) >=20 > Besides, =E2=80=9C/games=E2=80=9D is unusual in the file system hierarchy= . Usually, > state files go to the localstatedir, i.e., the var/PACKAGE > subdirectory. >=20 > Thus, what about putting state files in OUT/var/nethack? >=20 > But again, OUT is immutable, so these files cannot be modified, so > they=E2=80=99re not really =E2=80=9Cstate.=E2=80=9D >=20 > > + '("logfile" "perm" "record" "save" > > "xlogfile"))))) =20 >=20 > For clarity, have the phase return #t. >=20 > > + (add-after 'move-state-files 'wrap-program > > + (lambda* (#:key inputs outputs #:allow-other-keys) > > + (let* ((out (assoc-ref outputs "out")) > > + (bin (string-append out "/bin")) > > + (nethack-user-dir "~/.nethack")) > > + (mkdir bin) > > + (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=3D$(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~%" =20 >=20 > Do we really need this wrapper? Can=E2=80=99t we instead take it as a pa= tch > from Debian or something? I=E2=80=99m not a fan of inline Bash code, and= not > very confident of scripts that do =E2=80=98rm -rf=E2=80=99. :-) >=20 >=20 > > +--- 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 =20 >=20 > Patches must always start with a line or two indicating what they do > and what their upstream status or origin is. >=20 > > +@@ -308,7 +308,6 @@ > > + #define INSURANCE /* allow crashed game recovery */ > > +=20 > > + #ifndef MAC > > +-#define CHDIR /* delete if no chdir() available */ > > + #endif =20 >=20 > Why? >=20 > > +-# CC =3D gcc > > ++CC =3D gcc > > + # > > + # For Bull DPX/2 systems at B.O.S. 2.0 or higher use the > > following: > > + # > > +@@ -104,11 +104,11 @@ > > +=20 > > + # yacc/lex programs to use to generate *_comp.h, *_lex.c, and > > *_yacc.c. > > + # if, instead of yacc/lex you have bison/flex, comment/uncomment > > the following. +-YACC =3D yacc > > +-LEX =3D lex > > +-# YACC =3D bison -y > > ++# YACC =3D yacc > > ++# LEX =3D lex > > ++YACC =3D bison -y > > + # YACC =3D byacc > > +-# LEX =3D flex > > ++LEX =3D flex =20 >=20 > Would it work to, instead, do: >=20 > #:make-flags '("CC=3Dgcc" "LEX=3Dflex" =E2=80=A6) >=20 > If it does, I think it=E2=80=99s preferable. >=20 > Could you send an updated patch? >=20 > Thanks for working on this tricky package! ;-) >=20 > Ludo=E2=80=99. Unfortunately, Debian doesn't have any related patches because it's state files are writable in the equivalent of our store directories. It seems like the bash script will have to stay for the sake of functionality unless someone comes up with something cleaner, though I prefer to avoid them. Long ago, I lost a GNU/Linux installation to "rm -rf"... I've added comments to the patch file and replaced the calls to coreutils with their Scheme equivalent (and cleaned up nethack's store folder along the way). --=20 Kei (GPG Key: 4096R/E6A5EE3C19467A0D) --MP_/AhT0ILRg+Rz7iAw6NhKGPii Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=0001-gnu-Add-nethack.patch =46rom 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-pe= rmissions.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 =3D \ 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 game= play.") 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=3Dgcc" "LEX=3Dflex" "YACC=3Dbison -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=3D.*$") + (string-append "PREFIX=3D" out "\n")) + (("^HACKDIR=3D.*$") + (string-append "HACKDIR=3D" out "/var/hackdir\n")) + (("^SHELLDIR=3D.*$") + (string-append "SHELLDIR=3D" 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/linu= x")))) + (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=3D$(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-permissio= ns.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/confi= g.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 */ +=20 + #ifndef MAC +-#define CHDIR /* delete if no chdir() available */ + #endif +=20 + #ifdef CHDIR +diff -r -u nethack-3.6.0.orig/include/unixconf.h nethack-3.6.0/include/uni= xconf.h +--- nethack-3.6.0.orig/include/unixconf.h 2016-05-27 17:20:03.062318307 -0= 400 ++++ 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 define= s */ + /* #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 =3D -ltermcap + # WINTTYLIB =3D -lcurses + # WINTTYLIB =3D -lcurses16 +-# WINTTYLIB =3D -lncurses ++WINTTYLIB =3D -lncurses + #WINTTYLIB =3D -ltermlib + # + # libraries for X11 --=20 2.8.3 --MP_/AhT0ILRg+Rz7iAw6NhKGPii-- --Sig_/MBOQu1TRp_7VlJwVy9slKf9 Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJXVdxFAAoJEOal7jwZRnoNLfcQAI+nsDcCzTnyZg9q/XyPz/0r oasYEglp7VpIcCppVpqZi0yEEG5v3bALlhhvRRDnp9swjYfxuVgdbKvrug2LPjce gZc8zVdMNl/4otgqs9/tfiuiGaB3FLssLmMSEIz0DiWUaCK7ecgcQ/2kNc4UUgAg o1g0FP3vPysy0WxHVvfgGvaOo76gD5Ih/sB2mpqyUPnHS1B5dRwwTLcscgDgJmQT fmCnoGcUjHZN/KZvvQApF1U088OCbcD7DKBK18rvy5Z6Ckd3jF7keHi65qKZKz/u 2O1ebtsdMKd7eMCAhgfR5DZIMj3ZBy+A4+2o+YnG8XabBpHLdNaTV5hTCB/YxLpb lIUEzmD6jmANL546kbdl5tjhXjLMPOc0rHsh1yB0U1Pr+zxOq5xovP04shODV8CC JIxUC3uRJpEMICsINcGYopB1PMw5F7Oy9x1SaCrvvPM3D3wxm+MZ+ow/iylIglzr KBujeEWzEIBTPErR7VRHgzte7HxIxjbYOX/h2fG7+czS71cpZfklQHZVYDpxnKtG vsaD5RsVKvh0fN0Kgmja0D1EpGnR1nzy3+LxDvPmMSs8Vix5KokBTzvAKxbD5pL6 l+Xj1FzzLsu36SJZHWGykcuiFqPWtDVxLE4qI22IlcoDGcRkTa7a3VCl9iy2Xl1Q dbWTNHoXhoSt6cngm5zP =SIZQ -----END PGP SIGNATURE----- --Sig_/MBOQu1TRp_7VlJwVy9slKf9--