|
| 1 | +# Copyright 1999-2020 Gentoo Authors |
| 2 | +# Distributed under the terms of the GNU General Public License v2 |
| 3 | + |
| 4 | +EAPI=7 |
| 5 | +inherit desktop flag-o-matic toolchain-funcs |
| 6 | + |
| 7 | +DESCRIPTION="The ultimate old-school single player dungeon exploration game" |
| 8 | +HOMEPAGE="https://www.nethack.org/" |
| 9 | +SRC_URI="https://nethack.org/download/${PV}/nethack-${PV//.}-src.tgz -> ${P}.tar.gz" |
| 10 | + |
| 11 | +LICENSE="nethack" |
| 12 | +SLOT="0" |
| 13 | +KEYWORDS="~amd64 ~arm ~arm64 ~hppa ~ppc ~ppc64 ~x86" |
| 14 | +IUSE="X" |
| 15 | + |
| 16 | +RDEPEND="acct-group/gamestat |
| 17 | + sys-libs/ncurses:0= |
| 18 | + X? ( |
| 19 | + x11-libs/libXaw |
| 20 | + x11-libs/libXpm |
| 21 | + x11-libs/libXt |
| 22 | + )" |
| 23 | +DEPEND="${RDEPEND} |
| 24 | + X? ( x11-base/xorg-proto ) |
| 25 | + " |
| 26 | +BDEPEND="virtual/pkgconfig |
| 27 | + X? ( |
| 28 | + x11-apps/bdftopcf |
| 29 | + x11-apps/mkfontscale |
| 30 | + )" |
| 31 | + |
| 32 | +S="${WORKDIR}/NetHack-NetHack-${PV}_Released" |
| 33 | + |
| 34 | +src_prepare() { |
| 35 | + eapply "${FILESDIR}/${PN}-3.6.3-recover.patch" |
| 36 | + eapply_user |
| 37 | + |
| 38 | + cp "${FILESDIR}/${PN}-3.6.3-hint-$(usex X x11 tty)" hint || die "Failed to copy hint file" |
| 39 | + sys/unix/setup.sh hint || die "Failed to run setup.sh" |
| 40 | +} |
| 41 | + |
| 42 | +src_compile() { |
| 43 | + append-cflags -I../include -DDLB -DSECURE -DTIMED_DELAY -DVISION_TABLES -DDUMPLOG -DSCORE_ON_BOTL |
| 44 | + append-cflags '-DCOMPRESS=\"${EPREFIX}/bin/gzip\"' '-DCOMPRESS_EXTENSION=\".gz\"' |
| 45 | + append-cflags "-DHACKDIR=\\\"${EPREFIX}/usr/$(get_libdir)/nethack\\\"" "-DVAR_PLAYGROUND=\\\"${EPREFIX}/var/games/nethack\\\"" |
| 46 | + append-cflags "-DDEF_PAGER=\\\"${PAGER}\\\"" |
| 47 | + append-cflags -DSYSCF "-DSYSCF_FILE=\\\"${EPREFIX}/etc/nethack.sysconf\\\"" |
| 48 | + |
| 49 | + use X && append-cflags -DX11_GRAPHICS -DUSE_XPM |
| 50 | + |
| 51 | + LOCAL_MAKEOPTS=( |
| 52 | + CC="$(tc-getCC)" CFLAGS="${CFLAGS}" LFLAGS="${LDFLAGS}" |
| 53 | + WINTTYLIB="$($(tc-getPKG_CONFIG) --libs ncurses)" |
| 54 | + HACKDIR="${EPREFIX}/usr/$(get_libdir)/nethack" INSTDIR="${ED}/usr/$(get_libdir)/nethack" |
| 55 | + SHELLDIR="${ED}/usr/bin" VARDIR="${ED}/var/games/nethack" |
| 56 | + ) |
| 57 | + |
| 58 | + emake "${LOCAL_MAKEOPTS[@]}" nethack recover Guidebook spec_levs |
| 59 | + |
| 60 | + # Upstream still has some parallel compilation bugs |
| 61 | + emake -j1 "${LOCAL_MAKEOPTS[@]}" all |
| 62 | +} |
| 63 | + |
| 64 | +src_install() { |
| 65 | + emake "${LOCAL_MAKEOPTS[@]}" install |
| 66 | + |
| 67 | + mv "${ED}/usr/$(get_libdir)/nethack/recover" "${ED}/usr/bin/recover-nethack" || die "Failed to move recover-nethack" |
| 68 | + |
| 69 | + doman doc/nethack.6 |
| 70 | + newman doc/recover.6 recover-nethack.6 |
| 71 | + dodoc doc/Guidebook.txt |
| 72 | + |
| 73 | + insinto /etc |
| 74 | + newins sys/unix/sysconf nethack.sysconf |
| 75 | + |
| 76 | + insinto /etc/skel |
| 77 | + newins "${FILESDIR}/${PN}-3.6.0-nethackrc" .nethackrc |
| 78 | + |
| 79 | + if use X ; then |
| 80 | + cd "${S}/win/X11" || die "Failed to enter win/X11 directory" |
| 81 | + |
| 82 | + mkdir -p "${ED}/etc/X11/app-defaults/" || die "Failed to make app-defaults directory" |
| 83 | + mv "${ED}/usr/$(get_libdir)/nethack/NetHack.ad" "${ED}/etc/X11/app-defaults/" || die "Failed to move NetHack.ad" |
| 84 | + |
| 85 | + newicon nh_icon.xpm nethack.xpm |
| 86 | + make_desktop_entry ${PN} Nethack |
| 87 | + |
| 88 | + # install nethack fonts |
| 89 | + bdftopcf -o nh10.pcf nh10.bdf || die "Converting fonts failed" |
| 90 | + bdftopcf -o ibm.pcf ibm.bdf || die "Converting fonts failed" |
| 91 | + insinto "/usr/$(get_libdir)/nethack/fonts" |
| 92 | + doins *.pcf |
| 93 | + mkfontdir "${ED}/usr/$(get_libdir)/nethack/fonts" || die "mkfontdir failed" |
| 94 | + fi |
| 95 | + |
| 96 | + rm -r "${ED}/var/games/nethack" || die "Failed to clean var/games/nethack" |
| 97 | + keepdir /var/games/nethack/save |
| 98 | +} |
| 99 | + |
| 100 | +pkg_preinst() { |
| 101 | + fowners root:gamestat /var/games/nethack /var/games/nethack/save |
| 102 | + fperms 2770 /var/games/nethack /var/games/nethack/save |
| 103 | + |
| 104 | + fowners root:gamestat "/usr/$(get_libdir)/nethack/nethack" |
| 105 | + fperms g+s "/usr/$(get_libdir)/nethack/nethack" |
| 106 | +} |
| 107 | + |
| 108 | +pkg_postinst() { |
| 109 | + cd "${EROOT}/var/games/nethack" || die "Failed to enter ${EROOT}/var/games/nethack directory" |
| 110 | + |
| 111 | + # Transition mechanism for <nethack-3.6.1 ebuilds. It's perfectly safe, so we'll just run it unconditionally. |
| 112 | + chmod 2770 . save || die "Failed to chmod statedir" |
| 113 | + |
| 114 | + # Those files can't be created earlier because we don't want portage to wipe them during upgrades |
| 115 | + ( umask 007 && touch logfile perm record xlogfile ) || die "Failed to create log files" |
| 116 | + |
| 117 | + # Instead of using a proper version header in its save files, nethack checks for incompatibilities |
| 118 | + # by comparing the mtimes of save files and its own binary. This would require admin interaction even |
| 119 | + # during upgrades which don't change the file format, so we'll just touch the files and warn the admin |
| 120 | + # manually in case of compatibility issues. |
| 121 | + ( |
| 122 | + shopt -s nullglob |
| 123 | + local saves=( bones* save/* ) |
| 124 | + [[ -n "${saves[*]}" ]] && touch -c "${saves[@]}" |
| 125 | + ) # non-fatal |
| 126 | + |
| 127 | + elog "A minimal default .nethackrc has been placed in /etc/skel/" |
| 128 | + elog "The sysconf file is at /etc/nethack.sysconf" |
| 129 | +} |
0 commit comments