| 1 |
# Copyright 1999-2012 Gentoo Foundation |
| 2 |
# Distributed under the terms of the GNU General Public License v2 |
| 3 |
# $Header: /var/cvsroot/gentoo-x86/eclass/confutils.eclass,v 1.22 2008/02/27 09:53:04 hollow Exp $ |
| 4 |
|
| 5 |
# @ECLASS: confutils.eclass |
| 6 |
# @MAINTAINER: |
| 7 |
# Benedikt Böhm <hollow@gentoo.org> |
| 8 |
# @BLURB: utility functions to help with configuring a package |
| 9 |
# @DESCRIPTION: |
| 10 |
# The confutils eclass contains functions to handle use flag dependencies and |
| 11 |
# extended --with-*/--enable-* magic. |
| 12 |
# |
| 13 |
# Based on the PHP5 eclass by Stuart Herbert <stuart@stuartherbert.com> |
| 14 |
|
| 15 |
inherit eutils |
| 16 |
|
| 17 |
# @VARIABLE: EBUILD_SUPPORTS_SHAREDEXT |
| 18 |
# @DESCRIPTION: |
| 19 |
# Set this variable to 1 if your ebuild supports shared extensions. You need to |
| 20 |
# call confutils_init() in pkg_setup() if you use this variable. |
| 21 |
if [[ ${EBUILD_SUPPORTS_SHAREDEXT} == 1 ]]; then |
| 22 |
IUSE="sharedext" |
| 23 |
fi |
| 24 |
|
| 25 |
# @FUNCTION: confutils_init |
| 26 |
# @USAGE: [value] |
| 27 |
# @DESCRIPTION: |
| 28 |
# Call this function from your pkg_setup() function to initialize this eclass |
| 29 |
# if EBUILD_SUPPORTS_SHAREDEXT is enabled. If no value is given `shared' is used |
| 30 |
# by default. |
| 31 |
confutils_init() { |
| 32 |
if [[ ${EBUILD_SUPPORTS_SHAREDEXT} == 1 ]] && use sharedext; then |
| 33 |
shared="=${1:-shared}" |
| 34 |
else |
| 35 |
shared= |
| 36 |
fi |
| 37 |
} |
| 38 |
|
| 39 |
# @FUNCTION: confutils_require_one |
| 40 |
# @USAGE: <flag> [more flags ...] |
| 41 |
# @DESCRIPTION: |
| 42 |
# Use this function to ensure exactly one of the specified USE flags have been |
| 43 |
# enabled |
| 44 |
confutils_require_one() { |
| 45 |
local required_flags="$@" |
| 46 |
local success=0 |
| 47 |
|
| 48 |
for flag in ${required_flags}; do |
| 49 |
use ${flag} && ((success++)) |
| 50 |
done |
| 51 |
|
| 52 |
[[ ${success} -eq 1 ]] && return |
| 53 |
|
| 54 |
echo |
| 55 |
eerror "You *must* enable *exactly* one of the following USE flags:" |
| 56 |
eerror " ${required_flags}" |
| 57 |
eerror |
| 58 |
eerror "You can do this by enabling *one* of these flag in /etc/portage/package.use:" |
| 59 |
|
| 60 |
set -- ${required_flags} |
| 61 |
eerror " =${CATEGORY}/${PN}-${PVR} ${1}" |
| 62 |
shift |
| 63 |
|
| 64 |
for flag in $@; do |
| 65 |
eerror " OR =${CATEGORY}/${PN}-${PVR} ${flag}" |
| 66 |
done |
| 67 |
|
| 68 |
echo |
| 69 |
die "Missing or conflicting USE flags" |
| 70 |
} |
| 71 |
|
| 72 |
# @FUNCTION: confutils_require_any |
| 73 |
# @USAGE: <flag> [more flags ...] |
| 74 |
# @DESCRIPTION: |
| 75 |
# Use this function to ensure one or more of the specified USE flags have been |
| 76 |
# enabled |
| 77 |
confutils_require_any() { |
| 78 |
local required_flags="$@" |
| 79 |
local success=0 |
| 80 |
|
| 81 |
for flag in ${required_flags}; do |
| 82 |
use ${flag} && success=1 |
| 83 |
done |
| 84 |
|
| 85 |
[[ ${success} -eq 1 ]] && return |
| 86 |
|
| 87 |
echo |
| 88 |
eerror "You *must* enable one or more of the following USE flags:" |
| 89 |
eerror " ${required_flags}" |
| 90 |
eerror |
| 91 |
eerror "You can do this by enabling these flags in /etc/portage/package.use:" |
| 92 |
eerror " =${CATEGORY}/${PN}-${PVR} ${required_flags}" |
| 93 |
echo |
| 94 |
die "Missing USE flags" |
| 95 |
} |
| 96 |
|
| 97 |
# @FUNCTION: confutils_require_built_with_all |
| 98 |
# @USAGE: <foreign> <flag> [more flags ...] |
| 99 |
# @DESCRIPTION: |
| 100 |
# Use this function to ensure all of the specified USE flags have been enabled |
| 101 |
# in the specified foreign package |
| 102 |
confutils_require_built_with_all() { |
| 103 |
local foreign=$1 && shift |
| 104 |
local required_flags="$@" |
| 105 |
|
| 106 |
built_with_use ${foreign} ${required_flags} && return |
| 107 |
|
| 108 |
echo |
| 109 |
eerror "You *must* enable all of the following USE flags in ${foreign}:" |
| 110 |
eerror " ${required_flags}" |
| 111 |
eerror |
| 112 |
eerror "You can do this by enabling these flags in /etc/portage/package.use:" |
| 113 |
eerror " ${foreign} ${required_flags}" |
| 114 |
echo |
| 115 |
die "Missing USE flags in ${foreign}" |
| 116 |
} |
| 117 |
|
| 118 |
# @FUNCTION: confutils_require_built_with_any |
| 119 |
# @USAGE: <foreign> <flag> [more flags ...] |
| 120 |
# @DESCRIPTION: |
| 121 |
# Use this function to ensure one or more of the specified USE flags have been |
| 122 |
# enabled in the specified foreign package |
| 123 |
confutils_require_built_with_any() { |
| 124 |
local foreign=$1 && shift |
| 125 |
local required_flags="$@" |
| 126 |
local success=0 |
| 127 |
|
| 128 |
for flag in ${required_flags}; do |
| 129 |
built_with_use ${foreign} ${flag} && success=1 |
| 130 |
done |
| 131 |
|
| 132 |
[[ ${success} -eq 1 ]] && return |
| 133 |
|
| 134 |
echo |
| 135 |
eerror "You *must* enable one or more of the following USE flags in ${foreign}:" |
| 136 |
eerror " ${required_flags}" |
| 137 |
eerror |
| 138 |
eerror "You can do this by enabling these flags in /etc/portage/package.use:" |
| 139 |
eerror " ${foreign} ${required_flags}" |
| 140 |
echo |
| 141 |
die "Missing USE flags in ${foreign}" |
| 142 |
} |
| 143 |
|
| 144 |
# @FUNCTION: confutils_use_conflict |
| 145 |
# @USAGE: <enabled flag> <conflicting flag> [more conflicting flags ...] |
| 146 |
# @DESCRIPTION: |
| 147 |
# Use this function to automatically complain to the user if conflicting USE |
| 148 |
# flags have been enabled |
| 149 |
confutils_use_conflict() { |
| 150 |
use $1 || return |
| 151 |
|
| 152 |
local my_flag="$1" && shift |
| 153 |
local my_present= |
| 154 |
local my_remove= |
| 155 |
|
| 156 |
for flag in "$@"; do |
| 157 |
if use ${flag}; then |
| 158 |
my_present="${my_present} ${flag}" |
| 159 |
my_remove="${my_remove} -${flag}" |
| 160 |
fi |
| 161 |
done |
| 162 |
|
| 163 |
[[ -z "${my_present}" ]] && return |
| 164 |
|
| 165 |
echo |
| 166 |
eerror "USE flag '${my_flag}' conflicts with these USE flag(s):" |
| 167 |
eerror " ${my_present}" |
| 168 |
eerror |
| 169 |
eerror "You must disable these conflicting flags before you can emerge this package." |
| 170 |
eerror "You can do this by disabling these flags in /etc/portage/package.use:" |
| 171 |
eerror " =${CATEGORY}/${PN}-${PVR} ${my_remove}" |
| 172 |
eerror |
| 173 |
eerror "You could disable this flag instead in /etc/portage/package.use:" |
| 174 |
eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}" |
| 175 |
echo |
| 176 |
die "Conflicting USE flags" |
| 177 |
} |
| 178 |
|
| 179 |
# @FUNCTION: confutils_use_depend_all |
| 180 |
# @USAGE: <enabled flag> <needed flag> [more needed flags ...] |
| 181 |
# @DESCRIPTION: |
| 182 |
# Use this function to automatically complain to the user if a USE flag depends |
| 183 |
# on another USE flag that hasn't been enabled |
| 184 |
confutils_use_depend_all() { |
| 185 |
use $1 || return |
| 186 |
|
| 187 |
local my_flag="$1" && shift |
| 188 |
local my_missing= |
| 189 |
|
| 190 |
for flag in "$@"; do |
| 191 |
use ${flag} || my_missing="${my_missing} ${flag}" |
| 192 |
done |
| 193 |
|
| 194 |
[[ -z "${my_missing}" ]] && return |
| 195 |
|
| 196 |
echo |
| 197 |
eerror "USE flag '${my_flag}' needs these additional flag(s) set:" |
| 198 |
eerror " ${my_missing}" |
| 199 |
eerror |
| 200 |
eerror "You can do this by enabling these flags in /etc/portage/package.use:" |
| 201 |
eerror " =${CATEGORY}/${PN}-${PVR} ${my_missing}" |
| 202 |
eerror |
| 203 |
eerror "You could disable this flag instead in /etc/portage/package.use:" |
| 204 |
eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}" |
| 205 |
echo |
| 206 |
die "Need missing USE flags" |
| 207 |
} |
| 208 |
|
| 209 |
# @FUNCTION: confutils_use_depend_any |
| 210 |
# @USAGE: <enabled flag> <needed flag> [more needed flags ...] |
| 211 |
# @DESCRIPTION: |
| 212 |
# Use this function to automatically complain to the user if a USE flag depends |
| 213 |
# on another USE flag that hasn't been enabled |
| 214 |
confutils_use_depend_any() { |
| 215 |
use $1 || return |
| 216 |
|
| 217 |
local my_flag="$1" && shift |
| 218 |
local my_found= |
| 219 |
local my_missing= |
| 220 |
|
| 221 |
for flag in "$@"; do |
| 222 |
if use ${flag}; then |
| 223 |
my_found="${my_found} ${flag}" |
| 224 |
else |
| 225 |
my_missing="${my_missing} ${flag}" |
| 226 |
fi |
| 227 |
done |
| 228 |
|
| 229 |
[[ -n "${my_found}" ]] && return |
| 230 |
|
| 231 |
echo |
| 232 |
eerror "USE flag '${my_flag}' needs one or more of these additional flag(s) set:" |
| 233 |
eerror " ${my_missing}" |
| 234 |
eerror |
| 235 |
eerror "You can do this by enabling one of these flags in /etc/portage/package.use:" |
| 236 |
eerror " =${CATEGORY}/${PN}-${PVR} ${my_missing}" |
| 237 |
eerror |
| 238 |
eerror "You could disable this flag instead in /etc/portage/package.use:" |
| 239 |
eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}" |
| 240 |
echo |
| 241 |
die "Need missing USE flag(s)" |
| 242 |
} |
| 243 |
|
| 244 |
# @FUNCTION: confutils_use_depend_built_with_all |
| 245 |
# @USAGE: <enabled flag> <foreign> <needed flag> [more needed flags ...] |
| 246 |
# @DESCRIPTION: |
| 247 |
# Use this function to automatically complain to the user if a USE flag depends |
| 248 |
# on a USE flag in another package that hasn't been enabled |
| 249 |
confutils_use_depend_built_with_all() { |
| 250 |
use $1 || return |
| 251 |
|
| 252 |
local my_flag="$1" && shift |
| 253 |
local foreign=$1 && shift |
| 254 |
local required_flags="$@" |
| 255 |
|
| 256 |
built_with_use ${foreign} ${required_flags} && return |
| 257 |
|
| 258 |
echo |
| 259 |
eerror "USE flag '${my_flag}' needs the following USE flags in ${foreign}:" |
| 260 |
eerror " ${required_flags}" |
| 261 |
eerror |
| 262 |
eerror "You can do this by enabling these flags in /etc/portage/package.use:" |
| 263 |
eerror " ${foreign} ${required_flags}" |
| 264 |
eerror |
| 265 |
eerror "You could disable this flag instead in /etc/portage/package.use:" |
| 266 |
eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}" |
| 267 |
echo |
| 268 |
die "Missing USE flags in ${foreign}" |
| 269 |
} |
| 270 |
|
| 271 |
# @FUNCTION: confutils_use_depend_built_with_any |
| 272 |
# @USAGE: <enabled flag> <foreign> <needed flag> [more needed flags ...] |
| 273 |
# @DESCRIPTION: |
| 274 |
# Use this function to automatically complain to the user if a USE flag depends |
| 275 |
# on a USE flag in another package that hasn't been enabled |
| 276 |
confutils_use_depend_built_with_any() { |
| 277 |
use $1 || return |
| 278 |
|
| 279 |
local my_flag="$1" && shift |
| 280 |
local foreign=$1 && shift |
| 281 |
local required_flags="$@" |
| 282 |
local success=0 |
| 283 |
|
| 284 |
for flag in ${required_flags}; do |
| 285 |
built_with_use ${foreign} ${flag} && success=1 |
| 286 |
done |
| 287 |
|
| 288 |
[[ ${success} -eq 1 ]] && return |
| 289 |
|
| 290 |
echo |
| 291 |
eerror "USE flag '${my_flag}' needs one or more of the following USE flags in ${foreign}:" |
| 292 |
eerror " ${required_flags}" |
| 293 |
eerror |
| 294 |
eerror "You can do this by enabling these flags in /etc/portage/package.use:" |
| 295 |
eerror " ${foreign} ${required_flags}" |
| 296 |
eerror |
| 297 |
eerror "You could disable this flag instead in /etc/portage/package.use:" |
| 298 |
eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}" |
| 299 |
echo |
| 300 |
die "Missing USE flags in ${foreign}" |
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
# internal function constructs the configure values for optional shared module |
| 305 |
# support and extra arguments |
| 306 |
_confutils_shared_suffix() { |
| 307 |
local my_shared= |
| 308 |
|
| 309 |
if [[ "$1" == "1" ]]; then |
| 310 |
if [[ -n "${shared}" ]]; then |
| 311 |
my_shared="${shared}" |
| 312 |
if [[ -n "$2" ]]; then |
| 313 |
my_shared="${my_shared},$2" |
| 314 |
fi |
| 315 |
elif [[ -n "$2" ]]; then |
| 316 |
my_shared="=$2" |
| 317 |
fi |
| 318 |
else |
| 319 |
if [[ -n "$2" ]]; then |
| 320 |
my_shared="=$2" |
| 321 |
fi |
| 322 |
fi |
| 323 |
|
| 324 |
echo "${my_shared}" |
| 325 |
} |
| 326 |
|
| 327 |
# @FUNCTION: enable_extension_disable |
| 328 |
# @USAGE: <extension> <flag> [msg] |
| 329 |
# @DESCRIPTION: |
| 330 |
# Use this function to disable an extension that is enabled by default. This is |
| 331 |
# provided for those rare configure scripts that don't support a --enable for |
| 332 |
# the corresponding --disable. |
| 333 |
enable_extension_disable() { |
| 334 |
local my_msg=${3:-$1} |
| 335 |
|
| 336 |
if use "$2" ; then |
| 337 |
einfo " Enabling ${my_msg}" |
| 338 |
else |
| 339 |
my_conf="${my_conf} --disable-$1" |
| 340 |
einfo " Disabling ${my_msg}" |
| 341 |
fi |
| 342 |
} |
| 343 |
|
| 344 |
# @FUNCTION: enable_extension_enable |
| 345 |
# @USAGE: <extension> <flag> [shared] [extra conf] [msg] |
| 346 |
# @DESCRIPTION: |
| 347 |
# This function is like use_enable(), except that it knows about enabling |
| 348 |
# modules as shared libraries, and it supports passing additional data with the |
| 349 |
# switch. |
| 350 |
enable_extension_enable() { |
| 351 |
local my_shared=$(_confutils_shared_suffix $3 $4) |
| 352 |
local my_msg=${5:-$1} |
| 353 |
|
| 354 |
if use $2; then |
| 355 |
my_conf="${my_conf} --enable-${1}${my_shared}" |
| 356 |
einfo " Enabling ${my_msg}" |
| 357 |
else |
| 358 |
my_conf="${my_conf} --disable-$1" |
| 359 |
einfo " Disabling ${my_msg}" |
| 360 |
fi |
| 361 |
} |
| 362 |
|
| 363 |
# @FUNCTION: enable_extension_enableonly |
| 364 |
# @USAGE: <extension> <flag> [shared] [extra conf] [msg] |
| 365 |
# @DESCRIPTION: |
| 366 |
# This function is like use_enable(), except that it knows about enabling |
| 367 |
# modules as shared libraries, and it supports passing additional data with the |
| 368 |
# switch. This function is provided for those rare configure scripts that support |
| 369 |
# --enable but not the corresponding --disable. |
| 370 |
enable_extension_enableonly() { |
| 371 |
local my_shared=$(_confutils_shared_suffix $3 $4) |
| 372 |
local my_msg=${5:-$1} |
| 373 |
|
| 374 |
if use $2 ; then |
| 375 |
my_conf="${my_conf} --enable-${1}${my_shared}" |
| 376 |
einfo " Enabling ${my_msg}" |
| 377 |
else |
| 378 |
# note: we deliberately do *not* use a --disable switch here |
| 379 |
einfo " Disabling ${my_msg}" |
| 380 |
fi |
| 381 |
} |
| 382 |
|
| 383 |
# @FUNCTION: enable_extension_without |
| 384 |
# @USAGE: <extension> <flag> [msg] |
| 385 |
# @DESCRIPTION: |
| 386 |
# Use this function to disable an extension that is enabled by default. This |
| 387 |
# function is provided for those rare configure scripts that support --without |
| 388 |
# but not the corresponding --with |
| 389 |
enable_extension_without() { |
| 390 |
local my_msg=${3:-$1} |
| 391 |
|
| 392 |
if use "$2"; then |
| 393 |
einfo " Enabling ${my_msg}" |
| 394 |
else |
| 395 |
my_conf="${my_conf} --without-$1" |
| 396 |
einfo " Disabling ${my_msg}" |
| 397 |
fi |
| 398 |
} |
| 399 |
|
| 400 |
# @FUNCTION: enable_extension_with |
| 401 |
# @USAGE: <extension> <flag> [shared] [extra conf] [msg] |
| 402 |
# @DESCRIPTION: |
| 403 |
# This function is like use_with(), except that it knows about enabling modules |
| 404 |
# as shared libraries, and it supports passing additional data with the switch. |
| 405 |
enable_extension_with() { |
| 406 |
local my_shared=$(_confutils_shared_suffix $3 $4) |
| 407 |
local my_msg=${5:-$1} |
| 408 |
|
| 409 |
if use $2; then |
| 410 |
my_conf="${my_conf} --with-${1}${my_shared}" |
| 411 |
einfo " Enabling ${my_msg}" |
| 412 |
else |
| 413 |
my_conf="${my_conf} --without-$1" |
| 414 |
einfo " Disabling ${my_msg}" |
| 415 |
fi |
| 416 |
} |
| 417 |
|
| 418 |
# @FUNCTION: enable_extension_withonly |
| 419 |
# @USAGE: <extension> <flag> [shared] [extra conf] [msg] |
| 420 |
# @DESCRIPTION: |
| 421 |
# This function is like use_with(), except that it knows about enabling modules |
| 422 |
# as shared libraries, and it supports passing additional data with the switch. |
| 423 |
# This function is provided for those rare configure scripts that support --enable |
| 424 |
# but not the corresponding --disable. |
| 425 |
enable_extension_withonly() { |
| 426 |
local my_shared=$(_confutils_shared_suffix $3 $4) |
| 427 |
local my_msg=${5:-$1} |
| 428 |
|
| 429 |
if use $2; then |
| 430 |
my_conf="${my_conf} --with-${1}${my_shared}" |
| 431 |
einfo " Enabling ${my_msg}" |
| 432 |
else |
| 433 |
# note: we deliberately do *not* use a --without switch here |
| 434 |
einfo " Disabling ${my_msg}" |
| 435 |
fi |
| 436 |
} |
| 437 |
|
| 438 |
# @FUNCTION: enable_extension_enable_built_with |
| 439 |
# @USAGE: <foreign> <flag> <extension> [shared] [extra conf] [msg] |
| 440 |
# @DESCRIPTION: |
| 441 |
# This function is like enable_extension_enable(), except that it |
| 442 |
# enables/disables modules based on a USE flag in a foreign package. |
| 443 |
enable_extension_enable_built_with() { |
| 444 |
local my_shared=$(_confutils_shared_suffix $4 $5) |
| 445 |
local my_msg=${6:-$3} |
| 446 |
|
| 447 |
if built_with_use $1 $2; then |
| 448 |
my_conf="${my_conf} --enable-${3}${my_shared}" |
| 449 |
einfo " Enabling ${my_msg}" |
| 450 |
else |
| 451 |
my_conf="${my_conf} --disable-$3" |
| 452 |
einfo " Disabling ${my_msg}" |
| 453 |
fi |
| 454 |
} |
| 455 |
|
| 456 |
# @FUNCTION: enable_extension_with_built_with () |
| 457 |
# @USAGE: <foreign> <flag> <extension> [shared] [extra conf] [msg] |
| 458 |
# @DESCRIPTION: |
| 459 |
# This function is like enable_extension_with(), except that it |
| 460 |
# enables/disables modules based on a USE flag in a foreign package. |
| 461 |
enable_extension_with_built_with() { |
| 462 |
# legacy workaround |
| 463 |
if [[ "$4" != "0" && "$4" != "1" ]]; then |
| 464 |
enable_extension_with_built_with "$1" "$2" "$3" 0 "$4" "$5" |
| 465 |
return |
| 466 |
fi |
| 467 |
|
| 468 |
local my_shared=$(_confutils_shared_suffix $4 $5) |
| 469 |
local my_msg=${6:-$3} |
| 470 |
|
| 471 |
if built_with_use $1 $2; then |
| 472 |
my_conf="${my_conf} --with-${3}${my_shared}" |
| 473 |
einfo " Enabling ${my_msg}" |
| 474 |
else |
| 475 |
my_conf="${my_conf} --disable-$3" |
| 476 |
einfo " Disabling ${my_msg}" |
| 477 |
fi |
| 478 |
} |