summaryrefslogtreecommitdiff
blob: 1e6c56baae2430e6cb81264f2f99604e542f1ca7 (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
# Copyright 1999-2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/confutils.eclass,v 1.21 2008/02/20 13:07:50 hollow Exp $

# @ECLASS: confutils.eclass
# @MAINTAINER:
# Benedikt Böhm <hollow@gentoo.org>
# @BLURB: utility functions to help with configuring a package
# @DESCRIPTION:
# The confutils eclass contains functions to handle use flag dependencies and
# extended --with-*/--enable-* magic.
#
# Based on the PHP5 eclass by Stuart Herbert <stuart@stuartherbert.com>

inherit eutils

DESCRIPTION="Based on the ${ECLASS} eclass"

# @VARIABLE: EBUILD_SUPPORTS_SHAREDEXT
# @DESCRIPTION:
# Set this variable to 1 if your ebuild supports shared extensions. You need to
# call confutils_init() in pkg_setup() if you use this variable.
if [[ ${EBUILD_SUPPORTS_SHAREDEXT} == 1 ]]; then
	IUSE="sharedext"
fi

# @FUNCTION: confutils_init
# @USAGE: [value]
# @DESCRIPTION:
# Call this function from your pkg_setup() function to initialize this eclass
# if EBUILD_SUPPORTS_SHAREDEXT is enabled. If no value is given `shared' is used
# by default.
confutils_init() {
	if [[ ${EBUILD_SUPPORTS_SHAREDEXT} == 1 ]] && use sharedext; then
		shared="=${1:-shared}"
	else
		shared=
	fi
}

# @FUNCTION: confutils_require_any
# @USAGE: <flag> [more flags ...]
# @DESCRIPTION:
# Use this function to ensure one or more of the specified USE flags have been
# enabled
confutils_require_any() {
	local required_flags="$@"
	local success=0

	for flag in ${required_flags}; do
		use ${flag} && success=1
	done

	[[ ${success} -eq 1 ]] && return

	echo
	eerror "You *must* 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}"
	echo
	die "Missing USE flags"
}

# @FUNCTION: confutils_require_built_with_all
# @USAGE: <foreign> <flag> [more flags ...]
# @DESCRIPTION:
# Use this function to ensure all of the specified USE flags have been enabled
# in the specified foreign package
confutils_require_built_with_all() {
	local foreign=$1 && shift
	local required_flags="$@"

	built_with_use ${foreign} ${required_flags} && return

	echo
	eerror "You *must* enable all of the following USE flags in ${foreign}:"
	eerror "  ${required_flags}"
	eerror
	eerror "You can do this by enabling these flags in /etc/portage/package.use:"
	eerror "    ${foreign} ${required_flags}"
	echo
	die "Missing USE flags in ${foreign}"
}

# @FUNCTION: confutils_require_built_with_any
# @USAGE: <foreign> <flag> [more flags ...]
# @DESCRIPTION:
# Use this function to ensure one or more of the specified USE flags have been
# enabled in the specified foreign package
confutils_require_built_with_any() {
	local foreign=$1 && shift
	local required_flags="$@"
	local success=0

	for flag in ${required_flags}; do
		built_with_use ${foreign} ${flag} && success=1
	done

	[[ ${success} -eq 1 ]] && return

	echo
	eerror "You *must* enable one or more of the following USE flags in ${foreign}:"
	eerror "  ${required_flags}"
	eerror
	eerror "You can do this by enabling these flags in /etc/portage/package.use:"
	eerror "    ${foreign} ${required_flags}"
	echo
	die "Missing USE flags in ${foreign}"
}

# @FUNCTION: confutils_use_conflict
# @USAGE: <enabled flag> <conflicting flag> [more conflicting flags ...]
# @DESCRIPTION:
# Use this function to automatically complain to the user if conflicting USE
# flags have been enabled
confutils_use_conflict() {
	use $1 || return

	local my_flag="$1" && shift
	local my_present=
	local my_remove=

	for flag in "$@"; do
		if use ${flag}; then
			my_present="${my_present} ${flag}"
			my_remove="${my_remove} -${flag}"
		fi
	done

	[[ -z "${my_present}" ]] && return

	echo
	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
	eerror "You could disable this flag instead in /etc/portage/package.use:"
	eerror "    =${CATEGORY}/${PN}-${PVR} -${my_flag}"
	echo
	die "Conflicting USE flags"
}

# @FUNCTION: confutils_use_depend_all
# @USAGE: <enabled flag> <needed flag> [more needed flags ...]
# @DESCRIPTION:
# Use this function to automatically complain to the user if a USE flag depends
# on another USE flag that hasn't been enabled
confutils_use_depend_all() {
	use $1 || return

	local my_flag="$1" && shift
	local my_missing=

	for flag in "$@"; do
		use ${flag} || my_missing="${my_missing} ${flag}"
	done

	[[ -z "${my_missing}" ]] && return

	echo
	eerror "USE flag '${my_flag}' needs these additional flag(s) set:"
	eerror "  ${my_missing}"
	eerror
	eerror "You can do this by enabling these flags in /etc/portage/package.use:"
	eerror "    =${CATEGORY}/${PN}-${PVR} ${my_missing}"
	eerror
	eerror "You could disable this flag instead in /etc/portage/package.use:"
	eerror "    =${CATEGORY}/${PN}-${PVR} -${my_flag}"
	echo
	die "Need missing USE flags"
}

# @FUNCTION: confutils_use_depend_any
# @USAGE: <enabled flag> <needed flag> [more needed flags ...]
# @DESCRIPTION:
# Use this function to automatically complain to the user if a USE flag depends
# on another USE flag that hasn't been enabled
confutils_use_depend_any() {
	use $1 || return

	local my_flag="$1" && shift
	local my_found=
	local my_missing=

	for flag in "$@"; do
		if use ${flag}; then
			my_found="${my_found} ${flag}"
		else
			my_missing="${my_missing} ${flag}"
		fi
	done

	[[ -n "${my_found}" ]] && return

	echo
	eerror "USE flag '${my_flag}' needs one or more of these additional flag(s) set:"
	eerror "  ${my_missing}"
	eerror
	eerror "You can do this by enabling one of these flags in /etc/portage/package.use:"
	eerror "    =${CATEGORY}/${PN}-${PVR} ${my_missing}"
	eerror
	eerror "You could disable this flag instead in /etc/portage/package.use:"
	eerror "    =${CATEGORY}/${PN}-${PVR} -${my_flag}"
	echo
	die "Need missing USE flag(s)"
}

# @FUNCTION: confutils_use_depend_built_with_all
# @USAGE: <enabled flag> <foreign> <needed flag> [more needed flags ...]
# @DESCRIPTION:
# Use this function to automatically complain to the user if a USE flag depends
# on a USE flag in another package that hasn't been enabled
confutils_use_depend_built_with_all() {
	use $1 || return

	local my_flag="$1" && shift
	local foreign=$1 && shift
	local required_flags="$@"

	built_with_use ${foreign} ${required_flags} && return

	echo
	eerror "USE flag '${my_flag}' needs the following USE flags in ${foreign}:"
	eerror "  ${required_flags}"
	eerror
	eerror "You can do this by enabling these flags in /etc/portage/package.use:"
	eerror "    ${foreign} ${required_flags}"
	eerror
	eerror "You could disable this flag instead in /etc/portage/package.use:"
	eerror "    =${CATEGORY}/${PN}-${PVR} -${my_flag}"
	echo
	die "Missing USE flags in ${foreign}"
}

# @FUNCTION: confutils_use_depend_built_with_any
# @USAGE: <enabled flag> <foreign> <needed flag> [more needed flags ...]
# @DESCRIPTION:
# Use this function to automatically complain to the user if a USE flag depends
# on a USE flag in another package that hasn't been enabled
confutils_use_depend_built_with_any() {
	use $1 || return

	local my_flag="$1" && shift
	local foreign=$1 && shift
	local required_flags="$@"
	local success=0

	for flag in ${required_flags}; do
		built_with_use ${foreign} ${flag} && success=1
	done

	[[ ${success} -eq 1 ]] && return

	echo
	eerror "USE flag '${my_flag}' needs one or more of the following USE flags in ${foreign}:"
	eerror "  ${required_flags}"
	eerror
	eerror "You can do this by enabling these flags in /etc/portage/package.use:"
	eerror "    ${foreign} ${required_flags}"
	eerror
	eerror "You could disable this flag instead in /etc/portage/package.use:"
	eerror "    =${CATEGORY}/${PN}-${PVR} -${my_flag}"
	echo
	die "Missing USE flags in ${foreign}"
}


# internal function constructs the configure values for optional shared module
# support and extra arguments
_confutils_shared_suffix() {
	local my_shared=

	if [[ "$1" == "1" ]]; then
		if [[ -n "${shared}" ]]; then
			my_shared="${shared}"
			if [[ -n "$2" ]]; then
				my_shared="${my_shared},$2"
			fi
		elif [[ -n "$2" ]]; then
			my_shared="=$2"
		fi
	else
		if [[ -n "$2" ]]; then
			my_shared="=$2"
		fi
	fi

	echo "${my_shared}"
}

# @FUNCTION: enable_extension_disable
# @USAGE: <extension> <flag> [msg]
# @DESCRIPTION:
# 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.
enable_extension_disable() {
	local my_msg=${3:-$1}

	if use "$2" ; then
		einfo "  Enabling ${my_msg}"
	else
		my_conf="${my_conf} --disable-$1"
		einfo "  Disabling ${my_msg}"
	fi
}

# @FUNCTION: enable_extension_enable
# @USAGE: <extension> <flag> [shared] [extra conf] [msg]
# @DESCRIPTION:
# 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.
enable_extension_enable() {
	local my_shared=$(_confutils_shared_suffix $3 $4)
	local my_msg=${5:-$1}

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

# @FUNCTION: enable_extension_enableonly
# @USAGE: <extension> <flag> [shared] [extra conf] [msg]
# @DESCRIPTION:
# 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.  This function is provided for those rare configure scripts that support
# --enable but not the corresponding --disable.
enable_extension_enableonly() {
	local my_shared=$(_confutils_shared_suffix $3 $4)
	local my_msg=${5:-$1}

	if use $2 ; then
		my_conf="${my_conf} --enable-${1}${my_shared}"
		einfo "  Enabling ${my_msg}"
	else
		# note: we deliberately do *not* use a --disable switch here
		einfo "  Disabling ${my_msg}"
	fi
}

# @FUNCTION: enable_extension_without
# @USAGE: <extension> <flag> [msg]
# @DESCRIPTION:
# 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
enable_extension_without() {
	local my_msg=${3:-$1}

	if use "$2"; then
		einfo "  Enabling ${my_msg}"
	else
		my_conf="${my_conf} --without-$1"
		einfo "  Disabling ${my_msg}"
	fi
}

# @FUNCTION: enable_extension_with
# @USAGE: <extension> <flag> [shared] [extra conf] [msg]
# @DESCRIPTION:
# This function is like use_with(), except that it knows about enabling modules
# as shared libraries, and it supports passing additional data with the switch.
enable_extension_with() {
	local my_shared=$(_confutils_shared_suffix $3 $4)
	local my_msg=${5:-$1}

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

# @FUNCTION: enable_extension_withonly
# @USAGE: <extension> <flag> [shared] [extra conf] [msg]
# @DESCRIPTION:
# This function is like use_with(), except that it knows about enabling modules
# as shared libraries, and it supports passing additional data with the switch.
# This function is provided for those rare configure scripts that support --enable
# but not the corresponding --disable.
enable_extension_withonly() {
	local my_shared=$(_confutils_shared_suffix $3 $4)
	local my_msg=${5:-$1}

	if use $2; then
		my_conf="${my_conf} --with-${1}${my_shared}"
		einfo "  Enabling ${my_msg}"
	else
		# note: we deliberately do *not* use a --without switch here
		einfo "  Disabling ${my_msg}"
	fi
}

# @FUNCTION: enable_extension_enable_built_with
# @USAGE: <foreign> <flag> <extension> [shared] [extra conf] [msg]
# @DESCRIPTION:
# This function is like enable_extension_enable(), except that it
# enables/disables modules based on a USE flag in a foreign package.
enable_extension_enable_built_with() {
	local my_shared=$(_confutils_shared_suffix $4 $5)
	local my_msg=${6:-$3}

	if built_with_use $1 $2; then
		my_conf="${my_conf} --enable-${3}${my_shared}"
		einfo "  Enabling ${my_msg}"
	else
		my_conf="${my_conf} --disable-$3"
		einfo "  Disabling ${my_msg}"
	fi
}

# @FUNCTION: enable_extension_with_built_with ()
# @USAGE: <foreign> <flag> <extension> [shared] [extra conf] [msg]
# @DESCRIPTION:
# This function is like enable_extension_with(), except that it
# enables/disables modules based on a USE flag in a foreign package.
enable_extension_with_built_with() {
	# legacy workaround
	if [[ "$4" != "0" && "$4" != "1" ]]; then
		enable_extension_with_built_with "$1" "$2" "$3" 0 "$4" "$5"
		return
	fi

	local my_shared=$(_confutils_shared_suffix $4 $5)
	local my_msg=${6:-$3}

	if built_with_use $1 $2; then
		my_conf="${my_conf} --with-${3}${my_shared}"
		einfo "  Enabling ${my_msg}"
	else
		my_conf="${my_conf} --disable-$3"
		einfo "  Disabling ${my_msg}"
	fi
}