summaryrefslogtreecommitdiff
blob: 8aab4d6bab93ff9c8e37e41aee1e8b99aea9ae82 (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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI="2"

inherit eutils flag-o-matic toolchain-funcs games

DATA_PV="1.19a"
HW_PV="0.15"
MY_PN="hexen2"
DEMO_PV="1.4.3"

DESCRIPTION="Hexen 2 port - Hammer of Thyrion"
HOMEPAGE="http://uhexen2.sourceforge.net/"
SRC_URI="mirror://sourceforge/${PN}/${MY_PN}source-${PV}.tgz
	mirror://sourceforge/u${MY_PN}/gamedata-all-${DATA_PV}.tgz
	hexenworld? ( mirror://sourceforge/u${MY_PN}/hexenworld-pakfiles-${HW_PV}.tgz )"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64 ~ppc ~x86"
IUSE="alsa asm cdaudio debug dedicated demo dynamic hexenworld gtk lights
midi opengl optimize-cflags oss sdlaudio sdlcd tools"

QA_EXECSTACK="${GAMES_BINDIR:1}/hexen2
	${GAMES_BINDIR:1}/glhexen2
	${GAMES_BINDIR:1}/hexen2-demo
	${GAMES_BINDIR:1}/glhexen2-demo
	${GAMES_BINDIR:1}/hwcl
	${GAMES_BINDIR:1}/glhwcl
	${GAMES_BINDIR:1}/hwcl-demo
	${GAMES_BINDIR:1}/glhwcl-demo"

UIDEPEND=">=media-libs/libsdl-1.2.7
	alsa? ( >=media-libs/alsa-lib-1.0.7 )
	midi? ( >=media-libs/sdl-mixer-1.2.5[timidity] )
	!midi? ( >=media-libs/sdl-mixer-1.2.5 )
	opengl? ( virtual/opengl )"

# Launcher depends from GTK+ libs
LNCHDEPEND="gtk? ( x11-libs/gtk+:2 )"

# xdelta is needed to manually run the patch script
RDEPEND="${UIDEPEND}
	${LNCHDEPEND}
	demo? ( >=games-fps/hexen2-demodata-${DEMO_PV} )
	lights? ( games-fps/hexen2-lights )
	>=dev-util/xdelta-1.1.3-r1"
DEPEND="${UIDEPEND}
	${LNCHDEPEND}
	x86? ( asm? ( >=dev-lang/nasm-0.98.38 ) )"

S="${WORKDIR}/hexen2source-${PV}"
dir="${GAMES_DATADIR}/${MY_PN}"

pkg_setup() {
	games_pkg_setup

	if ! use midi ; then
		ewarn "MIDI support disabled! MIDI music won't be played at all."
		ewarn "If you want to hear it, recompile this package"
		ewarn "with \"midi\" USE flag enabled."
	fi

	use alsa || ewarn "alsa is the recommended sound driver."
}

src_prepare() {
	cd hexen2
	epatch "${S}/00_Patches/external-music-file-support.diff"
	cd ..

	# Whether to use the demo directory
	local demo
	use demo && demo="/demo"

	# Use default basedir - has 2 variations
	sed -i \
		-e "s:parms.basedir = cwd;:parms.basedir = \"${dir}${demo}\";:" \
		-e "s:parms.basedir = \".\";:parms.basedir = \"${dir}${demo}\";:" \
		{hexen2,hexen2/server,hexenworld/{Client,Server}}/sys_unix.c \
		|| die "sed sys_unix.c failed"

	# Change default sndspeed from 22050 to 44100,
	# to improve the quality/reliability.
	sed -i \
		-e "s:desired_speed = 22050:desired_speed = 44100:" \
		{hexen2,hexenworld/Client}/snd_dma.c || die "sed snd_dma.c failed"

	# Change patch script to be suitable
	sed -i \
		-e "s:chmod :#chmod :" \
		-e 's:"xdelta113":"/usr/bin/xdelta":' \
		-e "s:./xdelta113:xdelta": \
		"${WORKDIR}"/update_xdelta.sh || die "sed update_xdelta.sh failed"

	# Honour Portage CFLAGS also when debuggins is enabled
	use debug && append-flags "-g2"
	for u in `grep -lr '\-g \-Wall' *`; do
		sed -i \
			-e "s/^CFLAGS \:\= \-g \-Wall/CFLAGS \:\= ${CFLAGS}/" \
			${u} || die "sed ${u} failed"
	done

	if use demo ; then
		# Allow lightmaps in demo
		sed -i \
			-e "s:!override_pack:0:" \
			hexen2/common.c || die "sed common.c demo failed"
	fi

	if use gtk ; then
		# Tweak the default games data dir for graphical launcher
		sed -i \
			-e "/int basedir_nonstd/s:= 0:= 1:" \
			-e "/game_basedir\[0\]/d" \
			launcher/config_file.c || die "sed config_file.c failed"
		# Tweak the default name for binary executables,if DEMO version is enabled
		if use demo ; then
			sed -i \
				-e "/BINARY_NAME/s:\"$:-demo\":" \
				launcher/games.h || die "sed games.h failed"
		fi
	fi

	rm -rf docs/{activision,COMPILE,COPYING,LICENSE,README.win32}
}

src_compile() {

	local h2bin="h2" hwbin="hw" link_gl_libs="no" opts
	local \
		h2bin="h2" hwbin="hw" \
		USE_ALSA="no" \
		USE_CDAUDIO="no" \
		LINK_GL_LIBS="no" \
		USE_MIDI="no" \
		OPT_EXTRA="no" \
		USE_OSS="no" \
		USE_SDLCD="no" \
		X86_ASM="no" \
		opts

	if use opengl ; then
		h2bin="${h2bin} gl${h2bin}"
		hwbin="${hwbin} gl${hwbin}"
		use dynamic && LINK_GL_LIBS="yes"
	fi

	use debug && opts="${opts} DEBUG=1"
	use demo && opts="${opts} DEMO=1"

	use alsa && USE_ALSA="yes"
	use cdaudio && USE_CDAUDIO="yes"
	use optimize-cflags && OPT_EXTRA="yes"
	use oss && USE_OSS="yes"
	use sdlcd && USE_SDLCD="yes"
	use midi && USE_MIDI="yes"
	use x86 && use asm && X86_ASM="yes"

	if use gtk ; then
	# Build launcher
		cd "${S}/launcher"
		einfo "Building graphical launcher"
		emake \
			AUTOTOOLS=1 \
			${opts} \
			CPUFLAGS="${CFLAGS}" \
			CC="$(tc-getCC)" \
			|| die "emake launcher failed"
	fi

	if use tools ; then
		# Build Hexen2 utils
		cd "${S}/utils"
		einfo "Building utils"
		local utils_list="hcc maputils genmodel qfiles dcc jsh2color hcc_old texutils/bsp2wal texutils/lmp2pcx"
		for x in ${utils_list}
		do
			emake -C ${x} \
				${opts} \
				CPUFLAGS="${CFLAGS}" \
				CC="$(tc-getCC)" \
				|| die "emake ${x} failed"
		done
	fi

	if use dedicated ; then
		# Dedicated Server
		cd "${S}/${MY_PN}"
		einfo "Building Dedicated Server"
		emake \
			${opts} \
			OPT_EXTRA=${OPT_EXTRA} \
			CPUFLAGS="${CFLAGS}" \
			CC="$(tc-getCC)" \
			-f Makefile.sv \
			|| die "emake Dedicated server failed"
	fi

	if use hexenworld ; then
		if use tools; then
			# Hexenworld utils
			local hw_utils="hwmquery hwrcon"
			einfo "Building Hexenworld utils"
			cd "${S}/hw_utils"
			for x in ${hw_utils} ; do
				emake \
					${opts} \
					CPUFLAGS="${CFLAGS}" \
					CC="$(tc-getCC)" \
					-C ${x} \
					|| die "emake ${x} failed"
			done
		fi

		# Hexenworld
		einfo "Building Hexenworld servers"
		cd "${S}"/hexenworld
		# Hexenworld servers
		emake \
			${opts} \
			CPUFLAGS="${CFLAGS}" \
			CC="$(tc-getCC)" \
			-C Server \
			|| die "emake HexenWorld Server failed"
		emake \
			${opts} \
			CPUFLAGS="${CFLAGS}" \
			CC="$(tc-getCC)" \
			-C Master \
			|| die "emake HexenWorld Master failed"

		# Hexenworld client
		einfo "Building Hexenworld client(s)"
		for m in ${hwbin} ; do
			emake -C Client clean
			emake \
				${opts} \
				USE_ALSA=${USE_ALSA} \
				USE_OSS=${USE_OSS} \
				USE_CDAUDIO=${USE_CDAUDIO} \
				USE_MIDI=${USE_MIDI} \
				USE_SDLAUDIO=${USE_SDLAUDIO} \
				USE_SDLCD=${USE_SDLCD} \
				USE_X86_ASM=${X86_ASM} \
				OPT_EXTRA=${OPT_EXTRA} \
				LINK_GL_LIBS=${LINK_GL_LIBS} \
				USE_3DFXGAMMA=no \
				CPUFLAGS="${CFLAGS}" \
				CC="$(tc-getCC)" \
				${m} \
				-C Client \
				|| die "emake Hexenworld Client (${m}) failed"
		done
	fi

	# Hexen 2 game executable
	cd "${S}/${MY_PN}"

	einfo "Building UHexen2 game executable(s)"
	for m in ${h2bin} ; do
		emake clean
		emake \
			${opts} \
			USE_ALSA=${USE_ALSA} \
			USE_OSS=${USE_OSS} \
			USE_CDAUDIO=${USE_CDAUDIO} \
			USE_MIDI=${USE_MIDI} \
			USE_SDLAUDIO=${USE_SDLAUDIO} \
			USE_SDLCD=${USE_SDLCD} \
			USE_X86_ASM=${X86_ASM} \
			OPT_EXTRA=${OPT_EXTRA} \
			LINK_GL_LIBS=${LINK_GL_LIBS} \
			USE_3DFXGAMMA=no \
			CPUFLAGS="${CFLAGS}" \
			CC="$(tc-getCC)" \
			${m} \
			|| die "emake Hexen2 (${m}) failed"
	done

}

src_install() {
	local demo demo_title demo_suffix
	use demo && demo="-demo" && demo_title=" (Demo)" && demo_suffix="demo"

	newicon hexen2/icons/h2_32x32x4.png ${PN}.png || die

	make_desktop_entry "${MY_PN}${demo}" "Hexen 2${demo_title}" ${PN}.png
	newgamesbin "${MY_PN}/${MY_PN}" "${MY_PN}${demo}" \
		|| die "newgamesbin ${MY_PN} failed"

	if use opengl ; then
		make_desktop_entry "gl${MY_PN}${demo}" "GLHexen 2${demo_title}" ${PN}.png
		newgamesbin "${MY_PN}/gl${MY_PN}" "gl${MY_PN}${demo}" \
			|| die "newgamesbin gl${MY_PN} failed"
	fi

	if use dedicated ; then
		newgamesbin "${MY_PN}"/h2ded "${MY_PN}${demo}-ded" \
			|| die "newgamesbin h2ded failed"
	fi

	if use hexenworld ; then
		if use tools; then
			# Hexenworld utils
			dobin hw_utils/hwmquery/hwmquery || die "dobin hwmquery failed"
			dobin hw_utils/hwrcon/{hwrcon,hwterm} || die "dobin hwrcon/hwterm failed"

			dodoc hw_utils/hwmquery/hwmquery.txt || die "dodoc hwmquery.txt failed"
			dodoc hw_utils/hwrcon/{hwrcon,hwterm}.txt \
			|| die "dodoc hwrcon/hwterm.txt failed"
		fi

		# Hexenworld Servers
		newgamesbin hexenworld/Server/hwsv hwsv${demo} \
			|| die "newgamesbin hwsv failed"

		newgamesbin hexenworld/Master/hwmaster hwmaster${demo} \
			|| die "newgamesbin hwmaster failed"

		# HexenWorld client(s)
		newicon hexenworld/icons/hw2_32x32x8.png hwcl.png || die

		make_desktop_entry \
			"hwcl${demo}" "Hexen 2${demo_title} Hexenworld Client" hwcl.png
		newgamesbin "hexenworld/Client/hwcl" "hwcl${demo}" \
			|| die "newgamesbin hwcl failed"

		if use opengl ; then
			make_desktop_entry \
				"glhwcl${demo}" "GLHexen 2${demo_title} Hexenworld Client" hwcl.png
			newgamesbin "hexenworld/Client/glhwcl" "glhwcl${demo}" \
				|| die "newgamesbin glhwcl failed"
		fi

		insinto "${dir}"/${demo_suffix}
		doins -r "${WORKDIR}"/hw || die "doins hexenworld pak failed"
	fi

	if use gtk ; then
		# GTK launcher
		local lnch_name="h2launcher"
		use demo && lnch_name="h2demo"
		newgamesbin launcher/${lnch_name} h2launcher \
			|| die "newgamesbin h2launcher failed"
		make_desktop_entry \
			"h2launcher" "Hexen 2${demo_title} Launcher" ${PN}.png
	fi

	# Forge a new useful document 8)
	head -22 "00_Patches/external-music-file-support.diff" > \
	"docs/external_music.README" || die "make readme failed"

	dodoc docs/* || die "dodoc failed"

	if ! use demo ; then
		# Install updated game data
		insinto "${dir}"
		doins -r "${WORKDIR}"/{data1,patchdata,portals,siege} || die
		# Patching should really be done by a future "hexen2-data" ebuild.
		# But this works for now.
		doins "${WORKDIR}"/update_xdelta.sh || die
		dodoc "${WORKDIR}"/*.txt || die
	fi

	if use tools ; then
		dobin \
			utils/bin/{bsp2wal,bspinfo,dhcc,genmodel,hcc} \
			|| die "dobin utils part 1 failed"
		dobin \
			utils/bin/{jsh2colour,light,lmp2pcx,qbsp,qfiles,vis} \
			|| die "dobin utils part 2 failed"
		newbin utils/hcc_old/hcc hcc_old || die "newbin hcc_old failed"
		docinto utils
		dodoc utils/README || die "dodoc README failed"
		newdoc utils/dcc/README README.dcc || die "newdoc dcc failed"
		dodoc utils/dcc/dcc.txt || die "dodoc dcc.txt failed"
		newdoc utils/hcc/README README.hcc || die "newdoc hcc failed"
		newdoc utils/hcc_old/README hcc_old.txt || die "newdoc hcc_old failed"
		newdoc utils/jsh2color/README README.jsh2color \
			|| die "newdoc README.jsh2color failed"
		newdoc utils/jsh2color/ChangeLog ChangeLog.jsh2color \
			|| die "newdoc Changelog.jsh2color failed"
	fi

	prepgamesdirs
}

pkg_postinst() {
	games_pkg_postinst

	if use demo ; then
		einfo "uhexen2 has been compiled specifically to play the demo maps."
		einfo "Example command-line:"
		einfo "   hexen2-demo -width 1024 -height 768 -conwidth 640"
		einfo
	else
		elog "To play the demo, emerge with the 'demo' USE flag."
		elog
		elog "For the Hexen 2 original game..."
		elog "Put the following files into "${dir}"/data1 before playing:"
		elog "   pak0.pak pak1.pak"
		elog "Then to play:  hexen2"
		elog
		elog "For the 'Portal of Praevus' mission pack..."
		elog "Put the following file into "${dir}"/portals before playing:"
		elog "   pak3.pak"
		elog "Then to play:  hexen2 -portals"
		elog
		elog "To ensure the data files from the CD are patched, run as root:"
		elog "   cd "${dir}" && sh update_xdelta.sh"
		elog
		elog "Example command-line:"
		elog "   hexen2 -width 1024 -height 768 -conwidth 640"
		einfo
	fi
	if use gtk ; then
		einfo "You've also installed a nice graphical launcher. Simply run:"
		einfo
		einfo "   h2launcher"
		einfo
		einfo "to enjoy it :)"
		einfo
	fi
	if use tools ; then
		if use hexenworld; then
			einfo "You've also installed some Hexenworld utility:"
			einfo
			einfo " - hwmquery (console app to query HW master servers)"
			einfo " - hwrcon (remote interface to HW rcon command)"
			einfo " - hwterm (HW remote console terminal)"
			einfo
		fi
		einfo "You've also installed some Hexen2 utility"
		einfo "(useful for mod developing)"
		einfo
		einfo " - dhcc (old progs.dat compiler/decompiler)"
		einfo " - genmodel (3-D model grabber)"
		einfo " - hcc (HexenC compiler)"
		einfo " - hcc_old (old version of HexenC compiler)"
		einfo " - jsh2color (light colouring utility)"
		einfo " - maputils (Map compiling tools: bspinfo, light, qbsp, vis)"
		einfo " - qfiles (build pak files and regenerate bsp models)"
		einfo " - bsp2wal (extract all textures from a bsp file)"
		einfo " - lmp2pcx (convert hexen2 texture data into pcx and tga)"
		einfo
		einfo "See relevant documentation for further informations"
		einfo
	fi
}