summaryrefslogtreecommitdiff
blob: d416ce9fdf950d88509140aaeb81634994490b3d (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
454
455
456
457
458
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

# @ECLASS: phpconfutils.eclass
# @MAINTAINER:
# Gentoo PHP team <php-bugs@gentoo.org>
# @AUTHOR:
# Based on Stuart's work on the original confutils eclass
# Luca Longinotti <chtekk@gentoo.org>
# @BLURB: Provides utility functions to help with configuring PHP.
# @DESCRIPTION:
# This eclass provides utility functions to help with configuring PHP.
# It is only used by other php eclasses currently and the functions
# are not generally intended for direct use in ebuilds.


# ========================================================================
# List of USE flags that need deps that aren't yet in Portage
# or that can't be (fex. certain commercial apps)
#
# You must define PHPCONFUTILS_MISSING_DEPS if you need this

# ========================================================================
# phpconfutils_sort_flags()
#
# Sort and remove duplicates of the auto-enabled USE flags
#

phpconfutils_sort_flags() {
	# Sort the list of auto-magically enabled USE flags
	PHPCONFUTILS_AUTO_USE="$(echo ${PHPCONFUTILS_AUTO_USE} | tr '\040\010' '\012\012' | sort -u)"
}

# ========================================================================
# phpconfutils_init()
#
# Call this function from your src_compile() function to initialise
# this eclass first
#

phpconfutils_init() {
	# Define wheter we shall support shared extensions or not
	if use "sharedext" ; then
		shared="=shared"
	else
		shared=""
	fi

	phpconfutils_sort_flags
}

# ========================================================================
# phpconfutils_usecheck()
#
# Check if the USE flag we want enabled is part of the auto-magical ones
#

phpconfutils_usecheck() {
	local x
	local use="$1"

	for x in ${PHPCONFUTILS_AUTO_USE} ; do
		if [[ "${use}+" == "${x}+" ]] ; then
			return 0
		fi
	done

	# If we get here, the USE is not among the auto-enabled ones
	return 1
}

# ========================================================================
# phpconfutils_require_any()
#
# Use this function to ensure one or more of the specified USE flags have
# been enabled and output the results
#
# $1    - message to output everytime a flag is found
# $2    - message to output everytime a flag is not found
# $3 .. - flags to check
#

phpconfutils_require_any() {
	local success_msg="$1"
	shift
	local fail_msg="$1"
	shift

	local required_flags="$@"
	local default_flag="$1"
	local success="0"

	while [[ -n "$1" ]] ; do
		if use "$1" ; then
			einfo "${success_msg} $1"
			success="1"
		else
			einfo "${fail_msg} $1"
		fi
		shift
	done

	# Did we find what we are looking for?
	if [[ "${success}" == "1" ]] ; then
		return
	fi

	# If we get here, then none of the required USE flags were enabled
	eerror
	eerror "You should enable one or more of the following USE flags:"
	eerror "  ${required_flags}"
	eerror
	eerror "You can do this by enabling these flags in /etc/portage/package.use:"
	eerror "    =${CATEGORY}/${PN}-${PVR} ${required_flags}"
	eerror
	eerror "The ${default_flag} USE flag was automatically enabled now."
	eerror
	PHPCONFUTILS_AUTO_USE="${PHPCONFUTILS_AUTO_USE} ${default_flag}"
}

# ========================================================================
# phpconfutils_use_conflict()
#
# Use this function to automatically complain to the user if USE flags
# that directly conflict have been enabled
#
# $1	- flag that conflicts with other flags
# $2 .. - flags that conflict
#

phpconfutils_use_conflict() {
	phpconfutils_sort_flags

	if ! use "$1" && ! phpconfutils_usecheck "$1" ; then
		return
	fi

	local my_flag="$1"
	shift

	local my_present=""
	local my_remove=""

	while [[ "$1+" != "+" ]] ; do
		if use "$1" || phpconfutils_usecheck "$1" ; then
			my_present="${my_present} $1"
			my_remove="${my_remove} -$1"
		fi
		shift
	done

	if [[ -n "${my_present}" ]] ; then
		eerror
		eerror "USE flag '${my_flag}' conflicts with these USE flag(s):"
		eerror "  ${my_present}"
		eerror
		eerror "You must disable these conflicting flags before you can emerge this package."
		eerror "You can do this by disabling these flags in /etc/portage/package.use:"
		eerror "    =${CATEGORY}/${PN}-${PVR} ${my_remove}"
		eerror
		die "Conflicting USE flags found"
	fi
}

# ========================================================================
# phpconfutils_use_depend_all()
#
# Use this function to specify USE flags that depend on eachother,
# they will be automatically enabled and used for checks later
#
# $1	- flag that depends on other flags
# $2 .. - the flags that must be set for $1 to be valid
#

phpconfutils_use_depend_all() {
	phpconfutils_sort_flags

	if ! use "$1" && ! phpconfutils_usecheck "$1" ; then
		return
	fi

	local my_flag="$1"
	shift

	local my_missing=""

	while [[ "$1+" != "+" ]] ; do
		if ! use "$1" && ! phpconfutils_usecheck "$1" ; then
			my_missing="${my_missing} $1"
		fi
		shift
	done

	if [[ -n "${my_missing}" ]] ; then
		PHPCONFUTILS_AUTO_USE="${PHPCONFUTILS_AUTO_USE} ${my_missing}"
		ewarn
		ewarn "USE flag '${my_flag}' needs these additional flag(s) set:"
		ewarn "  ${my_missing}"
		ewarn
		ewarn "'${my_missing}' was automatically enabled and the required extensions will be"
		ewarn "built. In any case it is recommended to enable those flags for"
		ewarn "future reference, by adding the following to /etc/portage/package.use:"
		ewarn "    =${CATEGORY}/${PN}-${PVR} ${my_missing}"
		ewarn
	fi
}

# ========================================================================
# phpconfutils_use_depend_any()
#
# Use this function to automatically complain to the user if a USE flag
# depends on another USE flag that hasn't been enabled
#
# $1	- flag that depends on other flags
# $2	- flag that is used as default if none is enabled
# $3 .. - flags that must be set for $1 to be valid
#

phpconfutils_use_depend_any() {
	phpconfutils_sort_flags

	if ! use "$1" && ! phpconfutils_usecheck "$1" ; then
		return
	fi

	local my_flag="$1"
	shift

	local my_default_flag="$1"
	shift

	local my_found=""
	local my_missing=""

	while [[ "$1+" != "+" ]] ; do
		if use "$1" || phpconfutils_usecheck "$1" ; then
			my_found="${my_found} $1"
		else
			my_missing="${my_missing} $1"
		fi
		shift
	done

	if [[ -z "${my_found}" ]] ; then
		PHPCONFUTILS_AUTO_USE="${PHPCONFUTILS_AUTO_USE} ${my_default_flag}"
		ewarn
		ewarn "USE flag '${my_flag}' needs one of these additional flag(s) set:"
		ewarn "  ${my_missing}"
		ewarn
		ewarn "'${my_default_flag}' was automatically selected and enabled."
		ewarn "You can change that by enabling/disabling those flags accordingly"
		ewarn "in /etc/portage/package.use."
		ewarn
	fi
}

# ========================================================================
# phpconfutils_extension_disable()
#
# Use this function to disable an extension that is enabled by default.
# This is provided for those rare configure scripts that don't support
# a --enable for the corresponding --disable
#
# $1	- extension name
# $2	- USE flag
# $3	- optional message to einfo() to the user
#

phpconfutils_extension_disable() {
	if ! use "$2" && ! phpconfutils_usecheck "$2" ; then
		my_conf="${my_conf} --disable-$1"
		[[ -n "$3" ]] && einfo "  Disabling $1"
	else
		[[ -n "$3" ]] && einfo "  Enabling $1"
	fi
}

# ========================================================================
# phpconfutils_extension_enable()
#
# This function is like use_enable(), except that it knows about
# enabling modules as shared libraries, and it supports passing
# additional data with the switch
#
# $1	- extension name
# $2	- USE flag
# $3	- 1 = support shared, 0 = never support shared
# $4	- additional setting for configure
# $5	- additional message to einfo out to the user
#

phpconfutils_extension_enable() {
	local my_shared

	if [[ "$3" == "1" ]] ; then
		if [[ "${shared}+" != "+" ]] ; then
			my_shared="${shared}"
			if [[ "$4+" != "+" ]] ; then
				my_shared="${my_shared},$4"
			fi
		elif [[ "$4+" != "+" ]] ; then
			my_shared="=$4"
		fi
	else
		if [[ "$4+" != "+" ]] ; then
			my_shared="=$4"
		fi
	fi

	if use "$2" || phpconfutils_usecheck "$2" ; then
		my_conf="${my_conf} --enable-$1${my_shared}"
		einfo "  Enabling $1"
	else
		my_conf="${my_conf} --disable-$1"
		einfo "  Disabling $1"
	fi
}

# ========================================================================
# phpconfutils_extension_without()
#
# Use this function to disable an extension that is enabled by default
# This function is provided for those rare configure scripts that support
# --without but not the corresponding --with
#
# $1	- extension name
# $2	- USE flag
# $3	- optional message to einfo() to the user
#

phpconfutils_extension_without() {
	if ! use "$2" && ! phpconfutils_usecheck "$2" ; then
		my_conf="${my_conf} --without-$1"
		einfo "  Disabling $1"
	else
		einfo "  Enabling $1"
	fi
}

# ========================================================================
# phpconfutils_extension_with()
#
# This function is a replacement for use_with.  It supports building
# extensions as shared libraries,
#
# $1	- extension name
# $2	- USE flag
# $3	- 1 = support shared, 0 = never support shared
# $4	- additional setting for configure
# $5	- optional message to einfo() out to the user
#

phpconfutils_extension_with() {
	local my_shared

	if [[ "$3" == "1" ]] ; then
		if [[ "${shared}+" != "+" ]] ; then
			my_shared="${shared}"
			if [[ "$4+" != "+" ]] ; then
				my_shared="${my_shared},$4"
			fi
		elif [[ "$4+" != "+" ]] ; then
			my_shared="=$4"
		fi
	else
		if [[ "$4+" != "+" ]] ; then
			my_shared="=$4"
		fi
	fi

	if use "$2" || phpconfutils_usecheck "$2" ; then
		my_conf="${my_conf} --with-$1${my_shared}"
		einfo "  Enabling $1"
	else
		my_conf="${my_conf} --without-$1"
		einfo "  Disabling $1"
	fi
}

# ========================================================================
# phpconfutils_warn_about_external_deps()
#
# This will output a warning to the user if he enables commercial or other
# software not currently present in Portage
#

phpconfutils_warn_about_external_deps() {
	phpconfutils_sort_flags

	local x
	local my_found="0"

	for x in ${PHPCONFUTILS_MISSING_DEPS} ; do
		if use "${x}" || phpconfutils_usecheck "${x}" ; then
			ewarn "USE flag ${x} enables support for software not present in Portage!"
			my_found="1"
		fi
	done

	if [[ "${my_found}" == "1" ]] ; then
		ewarn
		ewarn "This ebuild will continue, but if you haven't already installed the"
		ewarn "software required to satisfy the list above, this package will probably"
		ewarn "fail to compile later on."
		ewarn "*DO NOT* file bugs about compile failures or issues you're having"
		ewarn "when using one of those flags, as we aren't able to support them."
		ewarn "|=|=|=|=|=|=| You are on your own if you use them! |=|=|=|=|=|=|"
		ewarn
		ebeep 5
	fi
}

# ========================================================================
# phpconfutils_built_with_use()
#
# Sobstitute for built_with_use() to support the magically enabled USE flags
#

phpconfutils_built_with_use() {
	local opt="$1"
	[[ ${opt:0:1} = "-" ]] && shift || opt="-a"

	local PHP_PKG=$(best_version $1)
	shift

	local PHP_USEFILE="${ROOT}/var/lib/php-pkg/${PHP_PKG}/PHP_USEFILE"

	[[ ! -e "${PHP_USEFILE}" ]] && return 0

	local PHP_USE_BUILT=$(<${PHP_USEFILE})
	while [[ $# -gt 0 ]] ; do
		if [[ ${opt} = "-o" ]] ; then
			has $1 ${PHP_USE_BUILT} && return 0
		else
			has $1 ${PHP_USE_BUILT} || return 1
		fi
		shift
	done
	[[ ${opt} = "-a" ]]
}

# ========================================================================
# phpconfutils_generate_usefile()
#
# Generate the file used by phpconfutils_built_with_use() to check it's
# USE flags
#

phpconfutils_generate_usefile() {
	phpconfutils_sort_flags

	local PHP_USEFILE="${D}/var/lib/php-pkg/${CATEGORY}/${PN}-${PVR}/PHP_USEFILE"

	# Write the auto-enabled USEs into the correct file
	dodir "/var/lib/php-pkg/${CATEGORY}/${PN}-${PVR}/"
	echo "${PHPCONFUTILS_AUTO_USE}" > "${PHP_USEFILE}"
}