summaryrefslogtreecommitdiff
blob: 087e75408fa1bee1862ad283807b2ff27b76b283 (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
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/php-ext-source-r2.eclass,v 1.11 2011/07/22 09:19:15 olemarkus Exp $
#
# Author: Tal Peer <coredumb@gentoo.org>
# Author: Stuart Herbert <stuart@gentoo.org>
# Author: Luca Longinotti <chtekk@gentoo.org>
# Author: Jakub Moc <jakub@gentoo.org> (documentation)
# Author: Ole Markus With <olemarkus@gentoo.org>

# @ECLASS: php-ext-source-r2.eclass
# @MAINTAINER:
# Gentoo PHP team <php-bugs@gentoo.org>
# @BLURB: A unified interface for compiling and installing standalone PHP extensions.
# @DESCRIPTION:
# This eclass provides a unified interface for compiling and installing standalone
# PHP extensions (modules).

inherit flag-o-matic autotools

EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install

# @ECLASS-VARIABLE: PHP_EXT_NAME
# @DESCRIPTION:
# The extension name. This must be set, otherwise the eclass dies.
# Only automagically set by php-ext-pecl-r1.eclass, so unless your ebuild
# inherits that eclass, you must set this manually before inherit.
[[ -z "${PHP_EXT_NAME}" ]] && die "No module name specified for the php-ext-source-r2 eclass"

DEPEND=">=sys-devel/m4-1.4.3
		>=sys-devel/libtool-1.5.18"
RDEPEND=""

# Because of USE deps, we require at least EAPI 2
case ${EAPI} in
	2|3) ;;
	*)
		die "php-ext-source-r2 is not compatible with EAPI=${EAPI}"
esac

# @ECLASS-VARIABLE: PHP_EXT_NAME
# @DESCRIPTION:
# The extension name. This must be set, otherwise the eclass dies.
# Only automagically set by php-ext-pecl-r2.eclass, so unless your ebuild
# inherits that eclass, you must set this manually before inherit.
[[ -z "${PHP_EXT_NAME}" ]] && die "No module name specified for the php-ext-source-r2 eclass"

# @ECLASS-VARIABLE: PHP_EXT_INI
# @DESCRIPTION:
# Controls whether or not to add a line to php.ini for the extension.
# Defaults to "yes" and should not be changed in most cases.
[[ -z "${PHP_EXT_INI}" ]] && PHP_EXT_INI="yes"

# @ECLASS-VARIABLE: PHP_EXT_ZENDEXT
# @DESCRIPTION:
# Controls whether the extension is a ZendEngine extension or not.
# Defaults to "no" and if you don't know what is it, you don't need it.
[[ -z "${PHP_EXT_ZENDEXT}" ]] && PHP_EXT_ZENDEXT="no"

# @ECLASS-VARIABLE: USE_PHP
# @DESCRIPTION:
# Lists the PHP slots compatibile the extension is compatibile with
[[ -z "${USE_PHP}" ]] && USE_PHP="php5-3 php5-2"

# @ECLASS-VARIABLE: PHP_EXT_OPTIONAL_USE
# @DESCRIPTION:
# If set, this is the USE flag that the PHP dependencies are behind
# Most commonly set as PHP_EXT_OPTIONAL_USE=php to get the dependencies behind
# USE=php.

# @ECLASS-VARIABLE: PHP_EXT_S
# @DESCRIPTION:
# The relative location of the temporary build directory for the PHP extension within
# the source package. This is useful for packages that bundle the PHP extension.
# Defaults to ${S}
[[ -z "${PHP_EXT_S}" ]] && PHP_EXT_S="${S}"

#Make sure at least one target is installed. Abuses USE dependencies.
for target in ${USE_PHP}; do
	IUSE="${IUSE} php_targets_${target}"
	target=${target/+}
	SELFDEPEND="${SELFDEPEND} =${CATEGORY}/${PF}[php_targets_${target}]"
	slot=${target/php}
	slot=${slot/-/.}
	PHPDEPEND="${PHPDEPEND}
	php_targets_${target}? ( dev-lang/php:${slot} )"
done

RDEPEND="${RDEPEND}
	${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }
	|| ( ${SELFDEPEND} )
	${PHPDEPEND}
	${PHP_EXT_OPTIONAL_USE:+ )}"


# @FUNCTION: php-ext-source-r2_src_unpack
# @DESCRIPTION:
# runs standard src_unpack + _phpize
#
# @VARIABLE: PHP_EXT_SKIP_PHPIZE
# @DESCRIPTION:
# phpize will be run by default for all ebuilds that use
# php-ext-source-r2_src_unpack
# Set PHP_EXT_SKIP_PHPIZE="yes" in your ebuild if you do not want to run phpize.
php-ext-source-r2_src_unpack() {
	unpack ${A}
	local slot orig_s="${PHP_EXT_S}"
	for slot in $(php_get_slots); do
		cp -r "${orig_s}" "${WORKDIR}/${slot}"
	done
}

php-ext-source-r2_src_prepare() {
	local slot orig_s="${PHP_EXT_S}"
	for slot in $(php_get_slots); do
		php_init_slot_env ${slot}
		php-ext-source-r2_phpize
	done
}

# @FUNCTION php-ext-source-r2_phpize
# @DESCRIPTION:
# Runs phpize and autotools in addition to the standard src_unpack
php-ext-source-r2_phpize() {
	if [[ "${PHP_EXT_SKIP_PHPIZE}" != 'yes' ]] ; then
		# Create configure out of config.m4
		# I wish I could run this to solve #329071, but I cannot
		#autotools_run_tool ${PHPIZE} 
		${PHPIZE}
		# force run of libtoolize and regeneration of related autotools
		# files (bug 220519)
		rm aclocal.m4
		eautoreconf
	fi
}

# @FUNCTION: php-ext-source-r2_src_configure
# @DESCRIPTION:
# Takes care of standard configure for PHP extensions (modules).
#
# @VARIABLE: my_conf
# @DESCRIPTION:
# Set this in the ebuild to pass configure options to econf.
php-ext-source-r2_src_configure() {
	local slot
	for slot in $(php_get_slots); do
		php_init_slot_env ${slot}
		# Set the correct config options
		# We cannot use econf here, phpize/php-config deals with setting
		# --prefix etc to whatever the php slot was configured to use
		echo ./configure --with-php-config=${PHPCONFIG} ${my_conf}
		./configure --with-php-config=${PHPCONFIG} ${my_conf}  || die "Unable to configure code to compile"
	done
}

# @FUNCTION: php-ext-source-r2_src_compile
# @DESCRIPTION:
# Takes care of standard compile for PHP extensions (modules).
php-ext-source-r2_src_compile() {
	# net-snmp creates this file #324739
	addpredict /usr/share/snmp/mibs/.index
	# shm extension createss a semaphore file #173574
	addpredict /session_mm_cli0.sem
	local slot
	for slot in $(php_get_slots); do
		php_init_slot_env ${slot}
		emake || die "Unable to make code"

	done
}

# @FUNCTION: php-ext-source-r1_src_install
# @DESCRIPTION:
# Takes care of standard install for PHP extensions (modules).

# @VARIABLE: DOCS
# @DESCRIPTION:
# Set in ebuild if you wish to install additional, package-specific documentation.
php-ext-source-r2_src_install() {
	local slot
	for slot in $(php_get_slots); do
		php_init_slot_env ${slot}

		# Let's put the default module away
		insinto "${EXT_DIR}"
		newins "modules/${PHP_EXT_NAME}.so" "${PHP_EXT_NAME}.so" || die "Unable to install extension"

		local doc
		for doc in ${DOCS} ; do
			[[ -s ${doc} ]] && dodoc ${doc}
		done

	done
	php-ext-source-r2_createinifiles
}


php_get_slots() {
	local s slot
	for slot in ${USE_PHP}; do
		use php_targets_${slot} && s+=" ${slot/-/.}"
	done
	echo $s
}

php_init_slot_env() {
	libdir=$(get_libdir)

	PHPIZE="/usr/${libdir}/${1}/bin/phpize"
	PHPCONFIG="/usr/${libdir}/${1}/bin/php-config"
	PHPCLI="/usr/${libdir}/${1}/bin/php"
	PHPCGI="/usr/${libdir}/${1}/bin/php-cgi"
	PHP_PKG="$(best_version =dev-lang/php-${1:3}*)"
	PHPPREFIX="/usr/${libdir}/${slot}"
	EXT_DIR="$(${PHPCONFIG} --extension-dir 2>/dev/null)"
	PHP_CURRENTSLOT=${1:3}

	PHP_EXT_S="${WORKDIR}/${1}"
	cd "${PHP_EXT_S}"
}

php-ext-source-r2_buildinilist() {
	# Work out the list of <ext>.ini files to edit/add to
	if [[ -z "${PHPSAPILIST}" ]] ; then
		PHPSAPILIST="apache2 cli cgi fpm"
	fi

	local x
	for x in ${PHPSAPILIST} ; do
		if [[ -f "/etc/php/${x}-${1}/php.ini" ]] ; then
			PHPINIFILELIST="${PHPINIFILELIST} etc/php/${x}-${1}/ext/${PHP_EXT_NAME}.ini"
		fi
	done
}

# @FUNCTION: php-ext-source-r2_createinifiles
# @DESCRIPTION:
# Builds ini files for every enabled slot and SAPI
php-ext-source-r2_createinifiles() {
	local slot
	for slot in $(php_get_slots); do
		php_init_slot_env ${slot}
		# Pull in the PHP settings

		# Build the list of <ext>.ini files to edit/add to
		php-ext-source-r2_buildinilist ${slot}

		# Add the needed lines to the <ext>.ini files
		if [[ "${PHP_EXT_INI}" = "yes" ]] ; then
			php-ext-source-r2_addextension "${PHP_EXT_NAME}.so"
		fi

		# Symlink the <ext>.ini files from ext/ to ext-active/
		for inifile in ${PHPINIFILELIST} ; do
			inidir="${inifile/${PHP_EXT_NAME}.ini/}"
			inidir="${inidir/ext/ext-active}"
			dodir "/${inidir}"
			dosym "/${inifile}" "/${inifile/ext/ext-active}"
		done

		# Add support for installing PHP files into a version dependant directory
		PHP_EXT_SHARED_DIR="/usr/share/php/${PHP_EXT_NAME}"
	done
}

php-ext-source-r2_addextension() {
	if [[ "${PHP_EXT_ZENDEXT}" = "yes" ]] ; then
		# We need the full path for ZendEngine extensions
		# and we need to check for debugging enabled!
		if has_version "dev-lang/php:${PHP_CURRENTSLOT}[threads]" ; then
			if has_version "dev-lang/php:${PHP_CURRENTSLOT}[debug]" ; then
				ext_type="zend_extension_debug_ts"
			else
				ext_type="zend_extension_ts"
			fi
			ext_file="${EXT_DIR}/${1}"
		else
			if has_version "dev-lang/php:${PHP_CURRENTSLOT}[debug]"; then
				ext_type="zend_extension_debug"
			else
				ext_type="zend_extension"
			fi
			ext_file="${EXT_DIR}/${1}"
		fi

		# php-5.3 unifies zend_extension loading and just requires the
		# zend_extension keyword with no suffix
		# TODO: drop previous code and this check once <php-5.3 support is
		# discontinued
		if has_version '>=dev-lang/php-5.3' ; then
			ext_type="zend_extension"
		fi
	else
		# We don't need the full path for normal extensions!
		ext_type="extension"
		ext_file="${1}"
	fi

	php-ext-source-r2_addtoinifiles "${ext_type}" "${ext_file}" "Extension added"
}

# $1 - Setting name
# $2 - Setting value
# $3 - File to add to
# $4 - Sanitized text to output
php-ext-source-r2_addtoinifile() {
	if [[ ! -d $(dirname ${3}) ]] ; then
		mkdir -p $(dirname ${3})
	fi

	# Are we adding the name of a section?
	if [[ ${1:0:1} == "[" ]] ; then
		echo "${1}" >> "${3}"
		my_added="${1}"
	else
		echo "${1}=${2}" >> "${3}"
		my_added="${1}=${2}"
	fi

	if [[ -z "${4}" ]] ; then
		einfo "Added '${my_added}' to /${3}"
	else
		einfo "${4} to /${3}"
	fi

	insinto /$(dirname ${3})
	doins "${3}"
}

# @FUNCTION: php-ext-source-r2_addtoinifiles
# @USAGE: <setting name> <setting value> [message to output]; or just [section name]
# @DESCRIPTION:
# Add value settings to php.ini file installed by the extension (module).
# You can also add a [section], see examples below.
#
# @CODE
# Add some settings for the extension:
#
# php-ext-source-r2_addtoinifiles "zend_optimizer.optimization_level" "15"
# php-ext-source-r2_addtoinifiles "zend_optimizer.enable_loader" "0"
# php-ext-source-r2_addtoinifiles "zend_optimizer.disable_licensing" "0"
#
# Adding values to a section in php.ini file installed by the extension:
#
# php-ext-source-r2_addtoinifiles "[Debugger]"
# php-ext-source-r2_addtoinifiles "debugger.enabled" "on"
# php-ext-source-r2_addtoinifiles "debugger.profiler_enabled" "on"
# @CODE
php-ext-source-r2_addtoinifiles() {
	local x
	for x in ${PHPINIFILELIST} ; do
		php-ext-source-r2_addtoinifile "${1}" "${2}" "${x}" "${3}"
	done
}