1 # Copyright 1999-2022 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 inherit desktop flag-o-matic toolchain-funcs
8 DESCRIPTION="The ultimate old-school single player dungeon exploration game"
9 HOMEPAGE="https://www.nethack.org/"
10 SRC_URI="https://nethack.org/download/${PV}/nethack-${PV//.}-src.tgz -> ${P}.tar.gz"
11 S="${WORKDIR}/NetHack-${PV}"
15 KEYWORDS="~amd64 ~arm ~arm64 ~hppa ~ppc ~ppc64 ~riscv ~x86"
30 X? ( x11-base/xorg-proto )
42 "${FILESDIR}/${PN}-3.6.3-recover.patch"
43 "${FILESDIR}/${PN}-3.6.6-clang16.patch"
49 cp "${FILESDIR}/${PN}-3.6.3-hint-$(usex X x11 tty)" hint || die "Failed to copy hint file"
50 sys/unix/setup.sh hint || die "Failed to run setup.sh"
54 append-cflags -std=gnu89 # old codebase, incompatible with c2x
55 append-cflags -I../include -DDLB -DSECURE -DTIMED_DELAY -DVISION_TABLES -DDUMPLOG -DSCORE_ON_BOTL
56 append-cflags '-DCOMPRESS=\"${EPREFIX}/bin/gzip\"' '-DCOMPRESS_EXTENSION=\".gz\"'
57 append-cflags "-DHACKDIR=\\\"${EPREFIX}/usr/$(get_libdir)/nethack\\\"" "-DVAR_PLAYGROUND=\\\"${EPREFIX}/var/games/nethack\\\""
58 append-cflags "-DDEF_PAGER=\\\"${PAGER}\\\""
59 append-cflags -DSYSCF "-DSYSCF_FILE=\\\"${EPREFIX}/etc/nethack.sysconf\\\""
62 append-cflags -DX11_GRAPHICS -DUSE_XPM
64 # XtErrorHandler usage seems right, but headers "may" add ((noreturn))
65 # giving an incompatible type error with clang-16 (could alternatively
66 # use private _X_NORETURN but this may be fragile)
67 append-cflags -Wno-error=incompatible-pointer-types #874462
71 CC="$(tc-getCC)" CFLAGS="${CFLAGS}" LFLAGS="${LDFLAGS}"
72 WINTTYLIB="$($(tc-getPKG_CONFIG) --libs ncurses)"
73 HACKDIR="${EPREFIX}/usr/$(get_libdir)/nethack" INSTDIR="${ED}/usr/$(get_libdir)/nethack"
74 SHELLDIR="${ED}/usr/bin" VARDIR="${ED}/var/games/nethack"
77 emake "${LOCAL_MAKEOPTS[@]}" nethack recover Guidebook spec_levs
79 # Upstream still has some parallel compilation bugs
80 emake -j1 "${LOCAL_MAKEOPTS[@]}" all
84 emake "${LOCAL_MAKEOPTS[@]}" install
86 mv "${ED}/usr/$(get_libdir)/nethack/recover" "${ED}/usr/bin/recover-nethack" || die "Failed to move recover-nethack"
89 newman doc/recover.6 recover-nethack.6
90 dodoc doc/Guidebook.txt
93 newins sys/unix/sysconf nethack.sysconf
96 newins "${FILESDIR}/${PN}-3.6.0-nethackrc" .nethackrc
99 cd "${S}/win/X11" || die "Failed to enter win/X11 directory"
101 mkdir -p "${ED}/etc/X11/app-defaults/" || die "Failed to make app-defaults directory"
102 mv "${ED}/usr/$(get_libdir)/nethack/NetHack.ad" "${ED}/etc/X11/app-defaults/" || die "Failed to move NetHack.ad"
104 newicon nh_icon.xpm nethack.xpm
105 make_desktop_entry ${PN} Nethack
107 # install nethack fonts
108 bdftopcf -o nh10.pcf nh10.bdf || die "Converting fonts failed"
109 bdftopcf -o ibm.pcf ibm.bdf || die "Converting fonts failed"
110 insinto "/usr/$(get_libdir)/nethack/fonts"
112 mkfontdir "${ED}/usr/$(get_libdir)/nethack/fonts" || die "mkfontdir failed"
115 rm -r "${ED}/var/games/nethack" || die "Failed to clean var/games/nethack"
116 keepdir /var/games/nethack/save
120 fowners root:gamestat /var/games/nethack /var/games/nethack/save
121 fperms 2770 /var/games/nethack /var/games/nethack/save
123 fowners root:gamestat "/usr/$(get_libdir)/nethack/nethack"
124 fperms g+s "/usr/$(get_libdir)/nethack/nethack"
128 cd "${EROOT}/var/games/nethack" || die "Failed to enter ${EROOT}/var/games/nethack directory"
130 # Transition mechanism for <nethack-3.6.1 ebuilds. It's perfectly safe, so we'll just run it unconditionally.
131 chmod 2770 . save || die "Failed to chmod statedir"
133 # Those files can't be created earlier because we don't want portage to wipe them during upgrades
134 ( umask 007 && touch logfile perm record xlogfile ) || die "Failed to create log files"
136 # Instead of using a proper version header in its save files, nethack checks for incompatibilities
137 # by comparing the mtimes of save files and its own binary. This would require admin interaction even
138 # during upgrades which don't change the file format, so we'll just touch the files and warn the admin
139 # manually in case of compatibility issues.
142 local saves=( bones* save/* )
143 [[ -n "${saves[*]}" ]] && touch -c "${saves[@]}"
146 elog "A minimal default .nethackrc has been placed in /etc/skel/"
147 elog "The sysconf file is at /etc/nethack.sysconf"