1 # Copyright 1999-2011 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: phpconfutils.eclass
7 # Gentoo PHP team <php-bugs@gentoo.org>
9 # Based on Stuart's work on the original confutils eclass
10 # Luca Longinotti <chtekk@gentoo.org>
11 # @BLURB: Provides utility functions to help with configuring PHP.
13 # This eclass provides utility functions to help with configuring PHP.
14 # It is only used by other php eclasses currently and the functions
15 # are not generally intended for direct use in ebuilds.
18 # ========================================================================
19 # List of USE flags that need deps that aren't yet in Portage
20 # or that can't be (fex. certain commercial apps)
22 # You must define PHPCONFUTILS_MISSING_DEPS if you need this
24 # ========================================================================
25 # phpconfutils_sort_flags()
27 # Sort and remove duplicates of the auto-enabled USE flags
30 phpconfutils_sort_flags() {
31 # Sort the list of auto-magically enabled USE flags
32 PHPCONFUTILS_AUTO_USE="$(echo ${PHPCONFUTILS_AUTO_USE} | tr '\040\010' '\012\012' | sort -u)"
35 # ========================================================================
38 # Call this function from your src_compile() function to initialise
43 # Define wheter we shall support shared extensions or not
44 if use "sharedext" ; then
50 phpconfutils_sort_flags
53 # ========================================================================
54 # phpconfutils_usecheck()
56 # Check if the USE flag we want enabled is part of the auto-magical ones
59 phpconfutils_usecheck() {
63 for x in ${PHPCONFUTILS_AUTO_USE} ; do
64 if [[ "${use}+" == "${x}+" ]] ; then
69 # If we get here, the USE is not among the auto-enabled ones
73 # ========================================================================
74 # phpconfutils_require_any()
76 # Use this function to ensure one or more of the specified USE flags have
77 # been enabled and output the results
79 # $1 - message to output everytime a flag is found
80 # $2 - message to output everytime a flag is not found
81 # $3 .. - flags to check
84 phpconfutils_require_any() {
85 local success_msg="$1"
90 local required_flags="$@"
91 local default_flag="$1"
94 while [[ -n "$1" ]] ; do
96 einfo "${success_msg} $1"
99 einfo "${fail_msg} $1"
104 # Did we find what we are looking for?
105 if [[ "${success}" == "1" ]] ; then
109 # If we get here, then none of the required USE flags were enabled
111 eerror "You should enable one or more of the following USE flags:"
112 eerror " ${required_flags}"
114 eerror "You can do this by enabling these flags in /etc/portage/package.use:"
115 eerror " =${CATEGORY}/${PN}-${PVR} ${required_flags}"
117 eerror "The ${default_flag} USE flag was automatically enabled now."
119 PHPCONFUTILS_AUTO_USE="${PHPCONFUTILS_AUTO_USE} ${default_flag}"
122 # ========================================================================
123 # phpconfutils_use_conflict()
125 # Use this function to automatically complain to the user if USE flags
126 # that directly conflict have been enabled
128 # $1 - flag that conflicts with other flags
129 # $2 .. - flags that conflict
132 phpconfutils_use_conflict() {
133 phpconfutils_sort_flags
135 if ! use "$1" && ! phpconfutils_usecheck "$1" ; then
145 while [[ "$1+" != "+" ]] ; do
146 if use "$1" || phpconfutils_usecheck "$1" ; then
147 my_present="${my_present} $1"
148 my_remove="${my_remove} -$1"
153 if [[ -n "${my_present}" ]] ; then
155 eerror "USE flag '${my_flag}' conflicts with these USE flag(s):"
156 eerror " ${my_present}"
158 eerror "You must disable these conflicting flags before you can emerge this package."
159 eerror "You can do this by disabling these flags in /etc/portage/package.use:"
160 eerror " =${CATEGORY}/${PN}-${PVR} ${my_remove}"
162 die "Conflicting USE flags found"
166 # ========================================================================
167 # phpconfutils_use_depend_all()
169 # Use this function to specify USE flags that depend on eachother,
170 # they will be automatically enabled and used for checks later
172 # $1 - flag that depends on other flags
173 # $2 .. - the flags that must be set for $1 to be valid
176 phpconfutils_use_depend_all() {
177 phpconfutils_sort_flags
179 if ! use "$1" && ! phpconfutils_usecheck "$1" ; then
188 while [[ "$1+" != "+" ]] ; do
189 if ! use "$1" && ! phpconfutils_usecheck "$1" ; then
190 my_missing="${my_missing} $1"
195 if [[ -n "${my_missing}" ]] ; then
196 PHPCONFUTILS_AUTO_USE="${PHPCONFUTILS_AUTO_USE} ${my_missing}"
198 ewarn "USE flag '${my_flag}' needs these additional flag(s) set:"
199 ewarn " ${my_missing}"
201 ewarn "'${my_missing}' was automatically enabled and the required extensions will be"
202 ewarn "built. In any case it is recommended to enable those flags for"
203 ewarn "future reference, by adding the following to /etc/portage/package.use:"
204 ewarn " =${CATEGORY}/${PN}-${PVR} ${my_missing}"
209 # ========================================================================
210 # phpconfutils_use_depend_any()
212 # Use this function to automatically complain to the user if a USE flag
213 # depends on another USE flag that hasn't been enabled
215 # $1 - flag that depends on other flags
216 # $2 - flag that is used as default if none is enabled
217 # $3 .. - flags that must be set for $1 to be valid
220 phpconfutils_use_depend_any() {
221 phpconfutils_sort_flags
223 if ! use "$1" && ! phpconfutils_usecheck "$1" ; then
230 local my_default_flag="$1"
236 while [[ "$1+" != "+" ]] ; do
237 if use "$1" || phpconfutils_usecheck "$1" ; then
238 my_found="${my_found} $1"
240 my_missing="${my_missing} $1"
245 if [[ -z "${my_found}" ]] ; then
246 PHPCONFUTILS_AUTO_USE="${PHPCONFUTILS_AUTO_USE} ${my_default_flag}"
248 ewarn "USE flag '${my_flag}' needs one of these additional flag(s) set:"
249 ewarn " ${my_missing}"
251 ewarn "'${my_default_flag}' was automatically selected and enabled."
252 ewarn "You can change that by enabling/disabling those flags accordingly"
253 ewarn "in /etc/portage/package.use."
258 # ========================================================================
259 # phpconfutils_extension_disable()
261 # Use this function to disable an extension that is enabled by default.
262 # This is provided for those rare configure scripts that don't support
263 # a --enable for the corresponding --disable
265 # $1 - extension name
267 # $3 - optional message to einfo() to the user
270 phpconfutils_extension_disable() {
271 if ! use "$2" && ! phpconfutils_usecheck "$2" ; then
272 my_conf="${my_conf} --disable-$1"
273 [[ -n "$3" ]] && einfo " Disabling $1"
275 [[ -n "$3" ]] && einfo " Enabling $1"
279 # ========================================================================
280 # phpconfutils_extension_enable()
282 # This function is like use_enable(), except that it knows about
283 # enabling modules as shared libraries, and it supports passing
284 # additional data with the switch
286 # $1 - extension name
288 # $3 - 1 = support shared, 0 = never support shared
289 # $4 - additional setting for configure
290 # $5 - additional message to einfo out to the user
293 phpconfutils_extension_enable() {
296 if [[ "$3" == "1" ]] ; then
297 if [[ "${shared}+" != "+" ]] ; then
298 my_shared="${shared}"
299 if [[ "$4+" != "+" ]] ; then
300 my_shared="${my_shared},$4"
302 elif [[ "$4+" != "+" ]] ; then
306 if [[ "$4+" != "+" ]] ; then
311 if use "$2" || phpconfutils_usecheck "$2" ; then
312 my_conf="${my_conf} --enable-$1${my_shared}"
315 my_conf="${my_conf} --disable-$1"
316 einfo " Disabling $1"
320 # ========================================================================
321 # phpconfutils_extension_without()
323 # Use this function to disable an extension that is enabled by default
324 # This function is provided for those rare configure scripts that support
325 # --without but not the corresponding --with
327 # $1 - extension name
329 # $3 - optional message to einfo() to the user
332 phpconfutils_extension_without() {
333 if ! use "$2" && ! phpconfutils_usecheck "$2" ; then
334 my_conf="${my_conf} --without-$1"
335 einfo " Disabling $1"
341 # ========================================================================
342 # phpconfutils_extension_with()
344 # This function is a replacement for use_with. It supports building
345 # extensions as shared libraries,
347 # $1 - extension name
349 # $3 - 1 = support shared, 0 = never support shared
350 # $4 - additional setting for configure
351 # $5 - optional message to einfo() out to the user
354 phpconfutils_extension_with() {
357 if [[ "$3" == "1" ]] ; then
358 if [[ "${shared}+" != "+" ]] ; then
359 my_shared="${shared}"
360 if [[ "$4+" != "+" ]] ; then
361 my_shared="${my_shared},$4"
363 elif [[ "$4+" != "+" ]] ; then
367 if [[ "$4+" != "+" ]] ; then
372 if use "$2" || phpconfutils_usecheck "$2" ; then
373 my_conf="${my_conf} --with-$1${my_shared}"
376 my_conf="${my_conf} --without-$1"
377 einfo " Disabling $1"
381 # ========================================================================
382 # phpconfutils_warn_about_external_deps()
384 # This will output a warning to the user if he enables commercial or other
385 # software not currently present in Portage
388 phpconfutils_warn_about_external_deps() {
389 phpconfutils_sort_flags
394 for x in ${PHPCONFUTILS_MISSING_DEPS} ; do
395 if use "${x}" || phpconfutils_usecheck "${x}" ; then
396 ewarn "USE flag ${x} enables support for software not present in Portage!"
401 if [[ "${my_found}" == "1" ]] ; then
403 ewarn "This ebuild will continue, but if you haven't already installed the"
404 ewarn "software required to satisfy the list above, this package will probably"
405 ewarn "fail to compile later on."
406 ewarn "*DO NOT* file bugs about compile failures or issues you're having"
407 ewarn "when using one of those flags, as we aren't able to support them."
408 ewarn "|=|=|=|=|=|=| You are on your own if you use them! |=|=|=|=|=|=|"
414 # ========================================================================
415 # phpconfutils_built_with_use()
417 # Sobstitute for built_with_use() to support the magically enabled USE flags
420 phpconfutils_built_with_use() {
422 [[ ${opt:0:1} = "-" ]] && shift || opt="-a"
424 local PHP_PKG=$(best_version $1)
427 local PHP_USEFILE="${ROOT}/var/lib/php-pkg/${PHP_PKG}/PHP_USEFILE"
429 [[ ! -e "${PHP_USEFILE}" ]] && return 0
431 local PHP_USE_BUILT=$(<${PHP_USEFILE})
432 while [[ $# -gt 0 ]] ; do
433 if [[ ${opt} = "-o" ]] ; then
434 has $1 ${PHP_USE_BUILT} && return 0
436 has $1 ${PHP_USE_BUILT} || return 1
443 # ========================================================================
444 # phpconfutils_generate_usefile()
446 # Generate the file used by phpconfutils_built_with_use() to check it's
450 phpconfutils_generate_usefile() {
451 phpconfutils_sort_flags
453 local PHP_USEFILE="${D}/var/lib/php-pkg/${CATEGORY}/${PN}-${PVR}/PHP_USEFILE"
455 # Write the auto-enabled USEs into the correct file
456 dodir "/var/lib/php-pkg/${CATEGORY}/${PN}-${PVR}/"
457 echo "${PHPCONFUTILS_AUTO_USE}" > "${PHP_USEFILE}"