app-editors/zed: add 0.144.3, drop 0.143.7
[gentoo-zh.git] / games-roguelike / nethack / nethack-3.6.7.ebuild
blobc3725cb50a0aff36b222d97661d28abccfb8ba0c
1 # Copyright 1999-2022 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 EAPI=7
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}"
13 LICENSE="nethack"
14 SLOT="0"
15 KEYWORDS="~amd64 ~arm ~arm64 ~hppa ~ppc ~ppc64 ~riscv ~x86"
16 IUSE="X"
18 RDEPEND="
19         acct-group/gamestat
20         sys-libs/ncurses:0=
21         X? (
22                 x11-libs/libX11
23                 x11-libs/libXaw
24                 x11-libs/libXpm
25                 x11-libs/libXt
26         )
28 DEPEND="
29         ${RDEPEND}
30         X? ( x11-base/xorg-proto )
32 BDEPEND="
33         virtual/pkgconfig
34         app-alternatives/yacc
35         X? (
36                 x11-apps/bdftopcf
37                 x11-apps/mkfontscale
38         )
41 PATCHES=(
42         "${FILESDIR}/${PN}-3.6.3-recover.patch"
43         "${FILESDIR}/${PN}-3.6.6-clang16.patch"
46 src_prepare() {
47         default
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"
53 src_compile() {
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\\\""
61         if use X; then
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
68         fi
70         LOCAL_MAKEOPTS=(
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"
75                 )
77         emake "${LOCAL_MAKEOPTS[@]}" nethack recover Guidebook spec_levs
79         # Upstream still has some parallel compilation bugs
80         emake -j1 "${LOCAL_MAKEOPTS[@]}" all
83 src_install() {
84         emake "${LOCAL_MAKEOPTS[@]}" install
86         mv "${ED}/usr/$(get_libdir)/nethack/recover" "${ED}/usr/bin/recover-nethack" || die "Failed to move recover-nethack"
88         doman doc/nethack.6
89         newman doc/recover.6 recover-nethack.6
90         dodoc doc/Guidebook.txt
92         insinto /etc
93         newins sys/unix/sysconf nethack.sysconf
95         insinto /etc/skel
96         newins "${FILESDIR}/${PN}-3.6.0-nethackrc" .nethackrc
98         if use X ; then
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"
111                 doins *.pcf
112                 mkfontdir "${ED}/usr/$(get_libdir)/nethack/fonts" || die "mkfontdir failed"
113         fi
115         rm -r "${ED}/var/games/nethack" || die "Failed to clean var/games/nethack"
116         keepdir /var/games/nethack/save
119 pkg_preinst() {
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"
127 pkg_postinst() {
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.
140         (
141                 shopt -s nullglob
142                 local saves=( bones* save/* )
143                 [[ -n "${saves[*]}" ]] && touch -c "${saves[@]}"
144         ) # non-fatal
146         elog "A minimal default .nethackrc has been placed in /etc/skel/"
147         elog "The sysconf file is at /etc/nethack.sysconf"