summaryrefslogtreecommitdiff
blob: 4a8c2c3ed4ff908f810c247c84212cbeb11e25b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Copyright 1999-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=7

inherit toolchain-funcs

DEB_PATCH_VER=28
DESCRIPTION="Collection of games from NetBSD"
HOMEPAGE="https://www.polyomino.org.uk/computer/software/bsd-games/"
#SRC_URI="https://www.polyomino.org.uk/computer/software/bsd-games/${PN}-$(ver_cut 1-2).tar.gz"
SRC_URI="http://deb.debian.org/debian/pool/main/b/bsdgames/bsdgames_2.17.orig.tar.gz"
SRC_URI+=" mirror://debian/pool/main/b/bsdgames/bsdgames_$(ver_cut 1-2)-${DEB_PATCH_VER}.debian.tar.xz"
S="${WORKDIR}/${PN}-$(ver_cut 1-2)"

LICENSE="BSD"
SLOT="0"
KEYWORDS="~alpha ~amd64 ~x86"

DEPEND="
	sys-apps/miscfiles
	sys-libs/ncurses:0
	app-misc/banner
	!games-misc/wtf
	!games-puzzle/hangman
"
RDEPEND="
	${DEPEND}
	acct-group/gamestat
"
BDEPEND="
	sys-devel/bison
	sys-devel/flex
	virtual/pkgconfig
"

# Set GAMES_TO_BUILD variable to whatever you want
GAMES_TO_BUILD=${GAMES_TO_BUILD:=adventure arithmetic atc
backgammon banner battlestar bcd boggle caesar canfield countmail cribbage
dab dm fish gomoku hack hangman hunt mille monop morse
number phantasia pig pom primes ppt quiz rain random robots sail snake
tetris trek wargames worm worms wtf}

src_prepare() {
	local debian_patch_dir="${WORKDIR}"/debian/patches
	for patch in $(<"${debian_patch_dir}"/series) ; do
		eapply "${debian_patch_dir}"/${patch}
	done

	# Additional patches on top of Debian patchset
	eapply "${FILESDIR}"/${PN}-2.17-64bitutmp.patch
	eapply "${FILESDIR}"/${PN}-2.17-bg.patch
	eapply "${FILESDIR}"/${PN}-2.17-gcc4.patch
	eapply "${FILESDIR}"/${PN}-2.17-rename-getdate-clash.patch

	default

	# Use pkg-config to query Libs: from ncurses.pc (for eg. -ltinfo) wrt #459652
	sed -i \
		-e "/ncurses_lib/s:-lncurses:'$($(tc-getPKG_CONFIG) --libs-only-l ncurses)':" \
		configure || die

	sed -i \
		-e "s:/usr/games:/usr/bin:" \
		wargames/wargames || die

	sed -i \
		-e '/^CC :=/d' \
		-e '/^CXX :=/d' \
		-e '/^CFLAGS/s/OPTIMIZE/CFLAGS/' \
		-e '/^CXXFLAGS/s/OPTIMIZE/CXXFLAGS/' \
		-e '/^LDFLAGS/s/LDFLAGS := /LDFLAGS := \$(LDFLAGS) /' \
		Makeconfig.in || die

	# Used by config.params
	export GAMES_BINDIR=/usr/bin
	export GAMES_DATADIR=/usr/share
	export GAMES_STATEDIR=/var/games
	cp "${FILESDIR}"/config.params-gentoo config.params || die

	echo bsd_games_cfg_usrlibdir=\"$(get_libdir)\" >> ./config.params || die
	echo bsd_games_cfg_build_dirs=\"${GAMES_TO_BUILD}\" >> ./config.params || die
	echo bsd_games_cfg_docdir=\"/usr/share/doc/${PF}\" >> ./config.params || die
}

src_compile() {
	tc-export CC CXX

	emake
}

src_test() {
	addwrite /dev/full
	emake -j1 check
}

src_install() {
	# TODO: ${PN} or no?
	dodir /var/games /usr/share/man/man{1,6}
	emake -j1 DESTDIR="${D}" install

	dodoc AUTHORS BUGS ChangeLog ChangeLog.0 \
		README PACKAGING SECURITY THANKS TODO YEAR2000

	_build_game() {
		has ${1} ${GAMES_TO_BUILD}
	}

	_do_statefile() {
		touch "${ED}"/var/games/${1} || die
		chmod ug+rw "${ED}"/var/games/${1} || die
	}

	# set some binaries to run as games group (+S)
	_build_game atc && fperms g+s /usr/bin/atc
	_build_game battlestar && fperms g+s /usr/bin/battlestar
	_build_game canfield && fperms g+s /usr/bin/canfield
	_build_game cribbage && fperms g+s /usr/bin/cribbage
	_build_game phantasia && fperms g+s /usr/bin/phantasia
	_build_game robots && fperms g+s /usr/bin/robots
	_build_game sail && fperms g+s /usr/bin/sail
	_build_game snake && fperms g+s /usr/bin/snake
	_build_game tetris && fperms g+s /usr/bin/tetris-bsd

	elog "Renaming monop to monop-bsd to avoid collision with dev-lang/mono"
	mv "${ED}"/usr/bin/monop "${ED}"/usr/bin/monop-bsd || die

	# state files
	_build_game atc && _do_statefile atc_score
	_build_game battlestar && _do_statefile battlestar.log
	_build_game canfield && _do_statefile cfscores
	_build_game cribbage && _do_statefile criblog
	_build_game hack && keepdir /var/games/hack
	_build_game robots && _do_statefile robots_roll
	_build_game sail && _do_statefile sail/saillog
	_build_game snake && _do_statefile snake.log && _do_statefile snakerawscores
	_build_game tetris && _do_statefile tetris-bsd.scores

	# extra docs
	_build_game atc && { docinto atc ; dodoc atc/BUGS; }
	_build_game boggle && { docinto boggle ; dodoc boggle/README; }
	_build_game hack && { docinto hack ; dodoc hack/{OWNER,Original_READ_ME,READ_ME,help}; }
	_build_game hunt && { docinto hunt ; dodoc hunt/README; }
	_build_game phantasia && { docinto phantasia ; dodoc phantasia/{OWNER,README}; }

	# All of this needs to be owned by the gamestat group
	fowners -R :gamestat /var/games/
	# ... and so do the binaries
	fowners -R :gamestat /usr/bin/

	# State dirs
	chmod -R ug+rw "${ED}"/var/games/ || die
}