summaryrefslogtreecommitdiff
blob: ce1ba82ba2d0673046a6ffe6c218213e37449b7b (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
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/depend.php.eclass,v 1.1 2005/09/04 10:54:53 stuart Exp $
#
# ========================================================================
#
# depend.php.eclass
#		functions to allow ebuilds to depend on php4 and/or php5
#
# Author:	Stuart Herbert
#			(stuart@gentoo.org)
#
# ========================================================================

inherit eutils

need_php4_cli()
{
	DEPEND="${DEPEND} =virtual/php-4*"
	RDEPEND="${RDEPEND} =virtual/php-4*"
	PHP_VERSION=4
}

need_php4_httpd()
{
	DEPEND="${DEPEND} =virtual/httpd-php-4*"
	RDEPEND="${RDEPEND} =virtual/httpd-php-4*"
	PHP_VERSION=4
}

need_php4()
{
	DEPEND="${DEPEND} =dev-lang/php-4*"
	RDEPEND="${RDEPEND} =dev-lang/php-4*"
	PHP_VERSION=4
	PHP_SHARED_CAT="php4"
}

# common settings go in here
uses_php4()
{
	# cache this
	libdir=$(get_libdir)

	PHPIZE="/usr/${libdir}/php4/bin/phpize"
	PHPCONFIG="/usr/${libdir}/php4/bin/php-config"
	PHPCLI="/usr/${libdir}/php4/bin/php"
	PHPCGI="/usr/${libdir}/php4/bin/php-cgi"
	PHP_PKG="`best_version =dev-lang/php-4*`"
	PHPPREFIX="/usr/${libdir}/php4"

	einfo
	einfo "Using ${PHP_PKG}"
	einfo
}

need_php5_cli()
{
	DEPEND="${DEPEND} =virtual/php-5*"
	RDEPEND="${RDEPEND} =virtual/php-5*"
	PHP_VERSION=5
}

need_php5_httpd()
{
	DEPEND="${DEPEND} =virtual/httpd-php-5*"
	RDEPEND="${RDEPEND} =virtual/httpd-php-5*"
	PHP_VERSION=5
}

need_php5()
{
	DEPEND="${DEPEND} =dev-lang/php-5*"
	RDEPEND="${RDEPEND} =dev-lang/php-5*"
	PHP_VERSION=5
	PHP_SHARED_CAT="php5"
}

# common settings go in here
uses_php5()
{
	# cache this
	libdir=$(get_libdir)

	PHPIZE="/usr/${libdir}/php5/bin/phpize"
	PHPCONFIG="/usr/${libdir}/php5/bin/php-config"
	PHPCLI="/usr/${libdir}/php5/bin/php"
	PHPCGI="/usr/${libdir}/php5/bin/php-cgi"
	PHP_PKG="`best_version =dev-lang/php-5*`"
	PHPPREFIX="/usr/${libdir}/php5"

	einfo
	einfo "Using ${PHP_PKG}"
	einfo
}

need_php()
{
	DEPEND="${DEPEND} dev-lang/php"
	RDEPEND="${RDEPEND} dev-lang/php"
	PHP_SHARED_CAT="php"
}

need_php_by_category()
{
	case "${CATEGORY}" in
		dev-php) need_php ;;
		dev-php4) need_php4 ;;
		dev-php5) need_php5 ;;
		*) die "I don't know which version of PHP packages in ${CATEGORY} require"
	esac
}

# call this function from pkg_setup if your PHP extension only works with
# specific SAPIs
#
# this function will disappear when USE-based deps are supported by
# Portage
#
# $1 ... a list of SAPI USE flags (eg cli, cgi, apache2)
# 
# returns if any one of the listed SAPIs has been installed
# dies if none of the listed SAPIs has been installed

require_php_sapi_from() {
	has_php

	local has_sapi=0
	local x

	einfo "Checking for compatible SAPI(s)"

	for x in $@ ; do
		if built_with_use =${PHP_PKG} ${x} ; then
			einfo "  Discovered compatible SAPI ${x}"
			has_sapi=1
		fi
	done

	if [[ ${has_sapi} == 1 ]]; then
		return
	fi

	eerror
	eerror "${PHP_PKG} needs to be re-installed with one of the following"
	eerror "USE flags enabled:"
	eerror
	eerror "  $@"
	eerror
	die "Re-install ${PHP_PKG}"
}

# call this function from pkg_setup if your package requires PHP compiled
# with specific USE flags
#
# this function will disappear when USE-based deps are supported by
# Portage
#
# $1 ... a list of USE flags
# 
# returns if all of the listed USE flags are set
# dies if any of the listed USE flags are not set

require_php_with_use() {
	has_php

	local missing_use=
	local x

	einfo "Checking for required PHP feature(s):"

	for x in $@ ; do
		if ! built_with_use =${PHP_PKG} ${x} ; then
			einfo "  Discovered missing USE flag ${x}"
			missing_use="${missing_use} ${x}"
		fi
	done

	if [[ -z ${missing_use} ]]; then
		return
	fi

	eerror
	eerror "${PHP_PKG} needs to be re-installed with all of the following"
	eerror "USE flags enabled:"
	eerror
	eerror "  $@"
	eerror
	die "Re-install ${PHP_PKG}"
}

# call this function from your src_compile & src_install methods
# if you need to know where the PHP binaries are installed

has_php()
{
	# if PHP_PKG is set, then we have remembered our PHP settings
	# from last time
	if [[ -n ${PHP_PKG} ]]; then
		return
	fi

	if [[ -z ${PHP_VERSION} ]]; then
		# detect which PHP version installed
		if has_version '=dev-lang/php-5*' ; then
			PHP_VERSION=5
		elif has_version '=dev-lang/php-4*' ; then
			PHP_VERSION=4
		else
			die "Unable to find an installed dev-lang/php package"
		fi
	fi

	# if we get here, then PHP_VERSION tells us which version of PHP we
	# want to use

	uses_php${PHP_VERSION}
}

# ========================================================================
# has_*() functions
#
# these functions return 0 if the condition is satisfied, or 1 otherwise
# ========================================================================

has_zts()
{
	has_php

	if built_with_use =${PHP_PKG} apache2 threads ; then
		return 0
	fi

	return 1
}

# ========================================================================
# require_*() functions
#
# These functions die() if PHP was built without the required USE flag(s)
# ========================================================================

require_pdo()
{
	has_php

	# do we have php5.1 installed?

	if [[ ${PHP_VERSION} == 4 ]] ; then
		eerror
		eerror "This package requires PDO. PDO is only available for PHP 5."
		eerror "Please install dev-lang/php-5*"
		eerror
		die "PHP 5 not installed"
	fi

	# was php5 compiled w/ pdo support?

	if built_with_use =${PHP_PKG} pdo ; then
		return
	fi

	# ok, maybe PDO was built as an external extension?

	if built_with_use =${PHP_PKG} pdo-external && has_version dev-php5/pecl-pdo ; then
		return
	fi

	# it suffices that pecl-pdo was installed to have PDO support

	if has_version dev-php5/pecl-pdo ; then
		return
	fi

	# if we get here, then we have no PDO support :(

	eerror
	eerror "No PDO extension for PHP found."
	eerror "Please note that PDO only exists for PHP 5."
	eerror "Please install a PDO extension for PHP 5,"
	eerror "you must install dev-lang/php-5.0* with"
	eerror "the 'pdo-external' USE flag or you must"
	eerror "install dev-lang/php-5.1* with either"
	eerror "the 'pdo' or the 'pdo-external' USE flags"
	eerror "turned on."
	eerror
	die "No PDO extension found for PHP"
}

# determines which installed PHP version has the CLI sapi
# useful for PEAR eclass, or anything which needs to run PHP
# scripts

require_php_cli()
{
	# if PHP_PKG is set, then we have remembered our PHP settings
	# from last time
	if [[ -n ${PHP_PKG} ]]; then
		return
	fi

	# detect which PHP version installed
	if has_version '=dev-lang/php-5*' ; then
		pkg="`best_version '=dev-lang/php-5*'`"
		if built_with_use =${pkg} cli ; then
			PHP_VERSION=5
		fi
	elif has_version '=dev-lang/php-4*' ; then
		pkg="`best_version '=dev-lang/php-4*'`"
		if built_with_use =${pkg} cli ; then
			PHP_VERSION=4
		fi
	else
		die "Unable to find an installed dev-lang/php package"
	fi

	if [[ -z ${PHP_VERSION} ]]; then
		die "No PHP CLI installed"
	fi

	# if we get here, then PHP_VERSION tells us which version of PHP we
	# want to use
	uses_php${PHP_VERSION}
}

# require a PHP built with sqlite support

require_sqlite()
{
	has_php

	# has our PHP been built w/ sqlite?
	if built_with_use =${PHP_PKG} sqlite ; then
		return
	fi

	# do we have pecl-sqlite installed for PHP4?
	if [[ ${PHP_VERSION} == 4 ]] ; then
		if has_version dev-php4/pecl-sqlite ; then
			return
		fi
	fi

	# if we get here, then we don't have any php/sqlite support installed
	eerror
	eerror "No sqlite extension for PHP found."
	eerror "Please install an sqlite extension for PHP,"
	eerror "this is done best by simply adding the"
	eerror "'sqlite' USE flag when emerging dev-lang/php."
	eerror
	die "No sqlite extension for PHP found"
}