summaryrefslogtreecommitdiff
blob: 376a3d586225c5d9fb4b69f0dc9bbf7344d6991f (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
# Copyright 1999-2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI="2"

inherit eutils games toolchain-funcs check-reqs git

MY_PN="${PN^}"
DESCRIPTION="Fork of Nexuiz, Deathmatch FPS based on DarkPlaces, an advanced Quake 1 engine"
HOMEPAGE="http://www.xonotic.org/"
BASE_URI="git://git.${PN}.org/${PN}/"
EGIT_REPO_URI="${BASE_URI}${PN}.git"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS=""
IUSE="alsa debug dedicated opengl sdl +zip"

UIRDEPEND="
	media-libs/libogg
	media-libs/libtheora
	media-libs/libvorbis
	media-libs/libmodplug
	x11-libs/libX11
	x11-libs/libXau
	x11-libs/libXdmcp
	x11-libs/libXext
	x11-libs/libXxf86dga
	x11-libs/libXxf86vm
	virtual/opengl
	media-libs/freetype:2
	alsa? ( media-libs/alsa-lib )
	sdl? ( media-libs/libsdl[X,audio,joystick,opengl,video,alsa?] )
	"
UIDEPEND="
	x11-proto/xextproto
	x11-proto/xf86dgaproto
	x11-proto/xf86vidmodeproto
	x11-proto/xproto
	"
RDEPEND="
	sys-libs/zlib
	media-libs/jpeg
	media-libs/libpng
	net-misc/curl
	opengl? ( ${UIRDEPEND} )
	!dedicated? ( !opengl? ( ${UIRDEPEND} ) )
	"
DEPEND="${RDEPEND}
	zip? ( app-arch/p7zip )
	opengl? ( ${UIDEPEND} )
	!dedicated? ( !opengl? ( ${UIDEPEND} ) )
	"

pkg_setup() {
	ewarn "You need 1,5 Gb diskspace for distfiles."
	if use dedicated && use !opengl; then
		CHECKREQS_DISK_BUILD="1500"
	else
		if use zip; then
			CHECKREQS_DISK_BUILD="2650"
			CHECKREQS_DISK_USR="910"
		else
			CHECKREQS_DISK_BUILD="4800"
			CHECKREQS_DISK_USR="2400"
		fi
	fi
	check_reqs
}

git_pk3_unpack() {
	EGIT_REPO_URI="${BASE_URI}xonotic-${1}.pk3dir.git"
	EGIT_PROJECT="${PN}-${1}.pk3dir"
	S+="/data/${PN}-${1}.pk3dir"
	git_fetch
	S="${WORKDIR}/${P}"
}

src_unpack() {
	# root
	git_src_unpack

	# Engine
	EGIT_REPO_URI="${BASE_URI}darkplaces.git"
	EGIT_PROJECT="darkplaces"
	S+="/darkplaces"
	# comment next line if you prefer unstable
	EGIT_BRANCH="div0-stable" \
	git_fetch
	S="${WORKDIR}/${P}"

	# QC compiler
	EGIT_REPO_URI="git://github.com/Blub/qclib.git"
	EGIT_PROJECT="qclib"
	S+="/fteqcc"
	git_fetch
	S="${WORKDIR}/${P}"

	# Data
	git_pk3_unpack data
	git_pk3_unpack maps
	# needed only for client
	if use opengl || use !dedicated; then
		git_pk3_unpack music
		git_pk3_unpack nexcompat
	else
		rm -rf "${S}/data/font-dejavu.pk3dir" || die "rm failed"
	fi
}

src_prepare() {
	# for darkplaces and fteqcc
	tc-export CC

	# Engine
	pushd darkplaces
	sed -i \
		-e "/^EXE_/s:darkplaces:${PN}:" \
		-e "s:-O3:${CFLAGS}:" \
		-e "/-lm/s:$: ${LDFLAGS}:" \
		-e '/^STRIP/s/strip/true/' \
		makefile.inc || die "sed failed"

	if use !alsa; then
		sed -e "/DEFAULT_SNDAPI/s:ALSA:OSS:" \
			-i makefile || die "sed failed"
	fi

	# rebranding, suddenly it works fine
	for i in nexuiz.*; do
		mv -v "${i}" "${i/nexuiz/${PN}}" || die "mv failed"
	done
	sed -i \
		-e "s/nexuiz/${PN}/g" \
		-e "s/Nexuiz/${PN^}/g" \
		-e "s/NEXUIZ/${PN^^}/g" \
		$(find -type f ! -name '*makefile*') || die "sed failed"
	popd

	# QC compiler
	pushd fteqcc
	sed -i \
		-e '/^CC/d' \
		-e "s: -O3 : :g" \
		-e "s: -s : :g" \
		-e 's/-o fteqcc.bin/$(LDFLAGS) -o fteqcc.bin/' \
		Makefile || die "sed failed"
	popd

	# Data
	if use dedicated && use !opengl; then
		pushd data
		rm -rf \
			xonotic-data.pk3dir/gfx \
			xonotic-data.pk3dir/particles \
			xonotic-data.pk3dir/sound/cyberparcour01/rocket.txt \
			xonotic-data.pk3dir/textures \
			xonotic-maps.pk3dir/textures \
			|| die "rm failed"
		rm -f \
			$(find -type f -name '*.jpg') \
			$(find -type f -name '*.png' ! -name 'sky??.png') \
			$(find -type f -name '*.svg') \
			$(find -type f -name '*.tga') \
			$(find -type f -name '*.wav') \
			$(find -type f -name '*.ogg') \
			$(find -type f -name '*.ase') \
			$(find -type f -name '*.map') \
			$(find -type f -name '*.zym') \
			$(find -type f -name '*.obj') \
			$(find -type f -name '*.blend') \
			|| die "rm failed"
		find -type d \
			-exec rmdir '{}' &>/dev/null \;
		sed -i \
			-e '/^qc-recursive:/s/menu.dat//' \
			xonotic-data.pk3dir/Makefile || die "sed failed"
		popd
	fi
}

src_compile() {
	# Engine
	pushd darkplaces
	if use debug; then
		ENGINEOPTS="debug"
	else
		ENGINEOPTS="release"
	fi
	ENGINEOPTS+=" DP_LINK_TO_LIBJPEG=1 DP_FS_BASEDIR=${GAMES_DATADIR}/${PN}"

	if use opengl || ! use dedicated; then
		emake cl-${ENGINEOPTS} || die "emake cl-${ENGINEOPTS} failed"
		if use sdl; then
			emake sdl-${ENGINEOPTS} || die "emake sdl-${ENGINEOPTS} failed"
		fi
	fi

	if use dedicated; then
		emake sv-${ENGINEOPTS} || die "emake sv-${ENGINEOPTS} failed"
	fi
	popd

	# QC compiler
	pushd fteqcc
	emake BASE_CFLAGS="${CFLAGS} -Wall" || die "emake fteqcc failed"
	popd

	# Data
	pushd data/xonotic-data.pk3dir
	emake \
		FTEQCC="${S}/fteqcc/fteqcc.bin" \
		FTEQCCFLAGS_WATERMARK='' \
		|| die "emake data.pk3 failed"
	popd
}

src_install() {
	# Engine & docs
	pushd darkplaces
	if use opengl || use !dedicated; then
		dogamesbin ${PN}-glx || die "dogamesbin glx failed"
		newicon ../misc/logos/${PN}_icon.svg ${PN}.svg
		make_desktop_entry ${PN}-glx "${MY_PN} (GLX)"

		if use sdl; then
			dogamesbin ${PN}-sdl || die "dogamesbin sdl failed"
			make_desktop_entry ${PN}-sdl "${MY_PN} (SDL)"
			dosym ${PN}-sdl "${GAMES_BINDIR}"/${PN}
		else
			dosym ${PN}-glx "${GAMES_BINDIR}"/${PN}
		fi
	fi

	if use dedicated; then
		dogamesbin ${PN}-dedicated || die "dogamesbin dedicated failed"
	fi
	popd

	dodoc Docs/*.txt
	dohtml -r readme.html Docs

	insinto "${GAMES_DATADIR}/${PN}"

	if use dedicated; then
		doins -r server || die "doins server failed"
	fi

	# Data
	cd data
	rm -rf \
		$(find -name '.git*') \
		$(find -type d -name '.svn') \
		$(find -type d -name 'qcsrc') \
		$(find -type f -name '*.sh') \
		$(find -type f -name '*.pl') \
		$(find -type f -name 'Makefile') \
		|| die "rm failed"
	if use zip; then
		for d in *.pk3dir; do
			pushd "${d}"
			a="${d#xonotic-}"
			7za a -tzip -mx=9 "../${a%dir}" . || die "zip failed"
			popd
			rm -rf "${d}" || die "rm failed"
		done
	fi
	insinto "${GAMES_DATADIR}/${PN}/data"
	doins -r . || die "doins data failed"

	prepgamesdirs
}