/[gentoo-x86]/eclass/games-mods.eclass
Gentoo

Contents of /eclass/games-mods.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.44 - (show annotations) (download)
Tue Dec 27 17:55:12 2011 UTC (2 years, 8 months ago) by fauli
Branch: MAIN
CVS Tags: HEAD
Changes since 1.43: +2 -2 lines
Update copyright years in headers

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

  ViewVC Help
Powered by ViewVC 1.1.20