ecm.eclass: Set correct KFMIN default for kde-frameworks/*
[gentoo.git] / eclass / games-mods.eclass
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @DEAD
5 # All consumers are gone.
6 # Bug #156882, #574642, #637740.  Removal in 14 days.
7
8 # Variables to specify in an ebuild which uses this eclass:
9 # GAME - (doom3, quake4 or ut2004, etc), unless ${PN} starts with e.g. "doom3-"
10 # MOD_DESC - Description for the mod
11 # MOD_NAME - Creates a command-line wrapper and desktop icon for the mod
12 # MOD_DIR - Subdirectory name for the mod, if applicable
13 # MOD_ICON - Custom icon for the mod, instead of the default
14
15 inherit eutils games
16
17 EXPORT_FUNCTIONS src_install pkg_postinst
18
19 [[ -z ${GAME} ]] && GAME=${PN%%-*}
20
21 case ${GAME} in
22         doom3)
23                 GAME_PKGS="games-fps/doom3"
24                 GAME_DIRS=( "${GAMES_PREFIX_OPT}"/doom3 )
25                 GAME_NAME="Doom 3"
26                 GAME_BIN="doom3"
27                 GAME_ICON="doom3"
28                 DED_PKGS=""
29                 DED_BIN="doom3-ded"
30                 DED_OPTS="+set dedicated 1 +exec server.cfg"
31                 DED_CFG_DIR=".doom3"
32                 SELECT_MOD="+set fs_game "
33                 ;;
34         enemy-territory)
35                 GAME_PKGS="games-fps/enemy-territory"
36                 GAME_DIRS=( "${GAMES_PREFIX_OPT}"/enemy-territory )
37                 GAME_NAME="Enemy Territory"
38                 GAME_BIN="et"
39                 GAME_ICON="ET"
40                 DED_PKGS=""
41                 DED_BIN="et-ded"
42                 DED_OPTS="+set dedicated 1 +exec server.cfg"
43                 DED_CFG_DIR=".etwolf"
44                 SELECT_MOD="+set fs_game "
45                 ;;
46         quake3)
47                 GAME_PKGS="games-fps/quake3 games-fps/quake3-bin"
48                 GAME_DIRS=( "${GAMES_DATADIR}"/quake3 "${GAMES_PREFIX_OPT}"/quake3 )
49                 GAME_NAME="Quake III"
50                 GAME_BIN="quake3"
51                 GAME_ICON="quake3"
52                 DED_PKGS=""
53                 DED_BIN="quake3-ded"
54                 DED_OPTS="+set dedicated 1 +exec server.cfg"
55                 DED_CFG_DIR=".q3a"
56                 SELECT_MOD="+set fs_game "
57                 ;;
58         quake4)
59                 GAME_PKGS="games-fps/quake4-bin"
60                 GAME_DIRS=( "${GAMES_PREFIX_OPT}"/quake4 )
61                 GAME_NAME="Quake 4"
62                 GAME_BIN="quake4"
63                 GAME_ICON="/usr/share/pixmaps/quake4.bmp"
64                 DED_PKGS=""
65                 DED_BIN="quake4-ded"
66                 DED_OPTS="+set dedicated 1 +exec server.cfg"
67                 DED_CFG_DIR=".quake4"
68                 SELECT_MOD="+set fs_game "
69                 ;;
70         ut2003)
71                 GAME_PKGS="games-fps/ut2003"
72                 GAME_DIRS=( "${GAMES_PREFIX_OPT}"/ut2003 )
73                 GAME_NAME="UT2003"
74                 GAME_BIN="ut2003"
75                 GAME_ICON="ut2003"
76                 DED_PKGS=""
77                 DED_BIN="ucc"
78                 DED_OPTS=""
79                 DED_CFG_DIR=""
80                 SELECT_MOD="-mod="
81                 ;;
82         ut2004)
83                 GAME_PKGS="games-fps/ut2004"
84                 GAME_DIRS=( "${GAMES_PREFIX_OPT}"/{ut2004,ut2004-ded} )
85                 GAME_NAME="UT2004"
86                 GAME_BIN="ut2004"
87                 GAME_ICON="ut2004"
88                 DED_PKGS="games-server/ut2004-ded"
89                 DED_BIN="ut2004-ded"
90                 DED_OPTS=""
91                 DED_CFG_DIR=""
92                 SELECT_MOD="-mod="
93                 ;;
94         *)
95                 eerror "This game is either not supported or you must set the GAME"
96                 eerror "variable to the proper game."
97                 die "games-mods.eclass: unsupported GAME"
98                 ;;
99 esac
100
101 MOD_BIN="${GAME_BIN}-${PN/${GAME}-}"
102 MOD_DED_BIN="${MOD_BIN}-ded"
103
104 games-mods_get_rdepend() {
105         local pkgs
106
107         if [[ ${1} == "--ded" ]] ; then
108                 pkgs=( ${DED_PKGS} ${GAME_PKGS} )
109         else
110                 pkgs=( ${GAME_PKGS} )
111         fi
112
113         [[ ${#pkgs[@]} -gt 1 ]] && echo -n "|| ( "
114
115         case ${EAPI:-0} in
116                 0|1) echo -n "${pkgs[@]}" ;;
117                 [23456])
118                         local p
119                         if [[ ${1} == "--ded" ]] ; then
120                                 echo -n "${DED_PKGS}"
121                                 for p in ${GAME_PKGS} ; do
122                                         echo -n " ${p}[dedicated]"
123                                 done
124                         else
125                                 for p in ${GAME_PKGS} ; do
126                                         echo -n " || ( ${p}[opengl] ${p}[-dedicated] )"
127                                 done
128                         fi
129                         ;;
130                 *) die "EAPI ${EAPI} not supported"
131         esac
132
133         [[ ${#pkgs[@]} -gt 1 ]] && echo -n " )"
134 }
135
136 DESCRIPTION="${GAME_NAME} ${MOD_NAME} - ${MOD_DESC}"
137
138 SLOT="0"
139 IUSE="dedicated opengl"
140 RESTRICT="bindist mirror strip"
141
142 DEPEND="app-arch/unzip"
143 RDEPEND="dedicated? ( $(games-mods_get_rdepend --ded) )
144         opengl? ( $(games-mods_get_rdepend) )
145         !dedicated? ( !opengl? ( $(games-mods_get_rdepend) ) )"
146
147 S=${WORKDIR}
148
149 INS_DIR=${GAMES_DATADIR}/${GAME}
150
151 games-mods_use_opengl() {
152         [[ -z ${MOD_DIR} ]] && return 1
153
154         if use opengl || ! use dedicated ; then
155                 # Use opengl by default
156                 return 0
157         fi
158
159         return 1
160 }
161
162 games-mods_use_dedicated() {
163         [[ -z ${MOD_DIR} ]] && return 1
164
165         use dedicated && return 0 || return 1
166 }
167
168 games-mods_dosyms() {
169         # We are installing everything for these mods into ${INS_DIR},
170         # ${GAMES_DATADIR}/${GAME} in most cases, and symlinking it
171         # into ${GAMES_PREFIX_OPT}/${GAME} for each game.  This should
172         # allow us to support both binary and source-based games easily.
173         local dir
174         for dir in "${GAME_DIRS[@]}" ; do
175                 [[ -z ${dir} || ${INS_DIR} == ${dir} ]] && continue
176                 pushd "${D}/${INS_DIR}" > /dev/null || die "pushd failed"
177                 local i
178                 for i in * ; do
179                         if [[ -d ${i} ]] ; then
180                                 if [[ ${i} == ${MOD_DIR} ]] ; then
181                                         dosym "${INS_DIR}/${i}" "${dir}/${i}" \
182                                                 || die "dosym ${i} failed"
183                                 else
184                                         local f
185                                         while read f ; do
186                                                 dosym "${INS_DIR}/${f}" "${dir}/${f}" \
187                                                         || die "dosym ${f} failed"
188                                         done < <(find "${i}" -type f)
189                                 fi
190                         elif [[ -f ${i} ]] ; then
191                                 dosym "${INS_DIR}/${i}" "${dir}/${i}" \
192                                         || die "dosym ${i} failed"
193                         else
194                                 die "${i} shouldn't be there"
195                         fi
196                 done
197                 popd > /dev/null || die "popd failed"
198         done
199 }
200
201 games-mods_make_initd() {
202         cat <<EOF > "${T}"/${MOD_DED_BIN}
203 #!/sbin/openrc-run
204 # Copyright 1999-2016 Gentoo Foundation
205 # Distributed under the terms of the GNU General Public License v2
206 # Generated by games-mods.eclass
207
208 depend() {
209         need net
210 }
211
212 start() {
213         ebegin "Starting ${MOD_DED_BIN}"
214         start-stop-daemon --start --quiet --background --make-pidfile \\
215                 --pidfile /var/run/${MOD_DED_BIN}.pid \\
216                 --chuid \${${MOD_DED_BIN//-/_}_user}:\${${MOD_DED_BIN//-/_}_group} \\
217                 --env HOME="\${${MOD_DED_BIN//-/_}_home}" \\
218                 --exec "${GAMES_BINDIR}/${MOD_DED_BIN}" \\
219                 -- \${${MOD_DED_BIN//-/_}_opts}
220         eend \$?
221 }
222
223 stop() {
224         ebegin "Stopping ${MOD_DED_BIN}"
225         start-stop-daemon --stop \\
226                 --pidfile /var/run/${MOD_DED_BIN}.pid
227         eend \$?
228 }
229 EOF
230
231         doinitd "${T}"/${MOD_DED_BIN} || die "doinitd failed"
232 }
233
234 games-mods_make_confd() {
235         cat <<-EOF > "${T}"/${MOD_DED_BIN}
236         # User and group the server should run as
237         ${MOD_DED_BIN//-/_}_user="${GAMES_USER_DED}"
238         ${MOD_DED_BIN//-/_}_group="${GAMES_GROUP}"
239
240         # Directory to use for HOME
241         ${MOD_DED_BIN//-/_}_home="${GAMES_PREFIX}"
242
243         # Any extra options you want to pass to the dedicated server
244         ${MOD_DED_BIN//-/_}_opts=""
245         EOF
246
247         doconfd "${T}"/${MOD_DED_BIN} || die "doconfd failed"
248 }
249
250 games-mods_src_install() {
251         if games-mods_use_opengl ; then
252                 if [[ -n ${MOD_ICON} ]] ; then
253                         # Install custom icon
254                         local ext=${MOD_ICON##*.}
255                         if [[ -f ${MOD_ICON} ]] ; then
256                                 newicon "${MOD_ICON}" ${PN}.${ext} || die "newicon failed"
257                         else
258                                 newicon ${MOD_DIR}/"${MOD_ICON}" ${PN}.${ext} \
259                                         || die "newicon failed"
260                         fi
261                         case ${ext} in
262                                 bmp|ico)
263                                         MOD_ICON=/usr/share/pixmaps/${PN}.${ext}
264                                         ;;
265                                 *)
266                                         MOD_ICON=${PN}
267                                         ;;
268                         esac
269                 else
270                         # Use the game's standard icon
271                         MOD_ICON=${GAME_ICON}
272                 fi
273
274                 games_make_wrapper ${MOD_BIN} "${GAME_BIN} ${SELECT_MOD}${MOD_DIR}"
275                 make_desktop_entry ${MOD_BIN} "${GAME_NAME} - ${MOD_NAME}" "${MOD_ICON}"
276                 # Since only quake3 has both a binary and a source-based install,
277                 # we only look for quake3 here.
278                 case ${GAME} in
279                         quake3)
280                                 if has_version games-fps/quake3-bin ; then
281                                         games_make_wrapper ${GAME_BIN}-bin-${PN/${GAME}-} \
282                                                 "${GAME_BIN}-bin ${SELECT_MOD}${MOD_DIR}"
283                                 fi
284                                 make_desktop_entry ${GAME_BIN}-bin-${PN/${GAME}-} \
285                                         "${GAME_NAME} - ${MOD_NAME} (binary)" "${MOD_ICON}"
286                                 ;;
287                 esac
288         fi
289
290         # We expect anything not wanted to have been deleted by the ebuild
291         insinto "${INS_DIR}"
292         doins -r * || die "doins -r failed"
293         games-mods_dosyms
294
295         if games-mods_use_dedicated ; then
296                 if [[ -f ${FILESDIR}/server.cfg ]] ; then
297                         insinto "${GAMES_SYSCONFDIR}"/${GAME}/${MOD_DIR}
298                         doins "${FILESDIR}"/server.cfg || die "doins server.cfg failed"
299                         dosym "${GAMES_SYSCONFDIR}"/${GAME}/${MOD_DIR}/server.cfg \
300                                 "${GAMES_PREFIX}"/${DED_CFG_DIR}/${MOD_DIR}/server.cfg \
301                                 || die "dosym server.cfg failed"
302                 fi
303                 games_make_wrapper ${MOD_DED_BIN} \
304                         "\"${GAMES_BINDIR}/${DED_BIN}\" ${SELECT_MOD}${MOD_DIR} ${DED_OPTS}"
305                 games-mods_make_initd
306                 games-mods_make_confd
307         fi
308
309         prepgamesdirs
310 }
311
312 games-mods_pkg_postinst() {
313         games_pkg_postinst
314         if games-mods_use_opengl ; then
315                 elog "To play this mod run:"
316                 elog "  ${MOD_BIN}"
317         fi
318         if games-mods_use_dedicated ; then
319                 elog "To launch a dedicated server run:"
320                 elog "  ${MOD_DED_BIN}"
321                 elog "To launch the server at startup run:"
322                 elog "  rc-update add ${MOD_DED_BIN} default"
323         fi
324 }