summaryrefslogtreecommitdiff
blob: 46bf93461bc03716cca4d7dc49196067ba1b9517 (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
# Copyright 1999-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# @ECLASS: depend.apache.eclass
# @MAINTAINER:
# apache-devs@gentoo.org
# @SUPPORTED_EAPIS: 0 2 3 4 5 6 7
# @BLURB: Functions to allow ebuilds to depend on apache
# @DESCRIPTION:
# This eclass handles depending on apache in a sane way and provides information
# about where certain binaries and configuration files are located.
#
# To make use of this eclass simply call one of the need/want_apache functions
# described below. Make sure you use the need/want_apache call after you have
# defined DEPEND and RDEPEND. Also note that you can not rely on the automatic
# RDEPEND=DEPEND that portage does if you use this eclass.
#
# See Bug 107127 for more information.
#
# @EXAMPLE:
#
# Here is an example of an ebuild depending on apache:
#
# @CODE
# DEPEND="virtual/Perl-CGI"
# RDEPEND="${DEPEND}"
# need_apache2
# @CODE
#
# Another example which demonstrates non-standard IUSE options for optional
# apache support:
#
# @CODE
# DEPEND="server? ( virtual/Perl-CGI )"
# RDEPEND="${DEPEND}"
# want_apache2 server
#
# pkg_setup() {
# 	depend.apache_pkg_setup server
# }
# @CODE

case ${EAPI:-0} in
	0|2|3|4|5)
		inherit multilib
		;;
	6|7)
		;;
	*)
		die "EAPI=${EAPI} is not supported by depend.apache.eclass"
		;;
esac

# ==============================================================================
# INTERNAL VARIABLES
# ==============================================================================

# @ECLASS-VARIABLE: APACHE_VERSION
# @DESCRIPTION:
# Stores the version of apache we are going to be ebuilding.
# This variable is set by the want/need_apache functions.

# @ECLASS-VARIABLE: APXS
# @DESCRIPTION:
# Path to the apxs tool.
# This variable is set by the want/need_apache functions.

# @ECLASS-VARIABLE: APACHE_BIN
# @DESCRIPTION:
# Path to the apache binary.
# This variable is set by the want/need_apache functions.

# @ECLASS-VARIABLE: APACHE_CTL
# @DESCRIPTION:
# Path to the apachectl tool.
# This variable is set by the want/need_apache functions.

# @ECLASS-VARIABLE: APACHE_BASEDIR
# @DESCRIPTION:
# Path to the server root directory.
# This variable is set by the want/need_apache functions (EAPI=0 through 5)
# or depend.apache_pkg_setup (EAPI=6 and later).

# @ECLASS-VARIABLE: APACHE_CONFDIR
# @DESCRIPTION:
# Path to the configuration file directory.
# This variable is set by the want/need_apache functions.

# @ECLASS-VARIABLE: APACHE_MODULES_CONFDIR
# @DESCRIPTION:
# Path where module configuration files are kept.
# This variable is set by the want/need_apache functions.

# @ECLASS-VARIABLE: APACHE_VHOSTS_CONFDIR
# @DESCRIPTION:
# Path where virtual host configuration files are kept.
# This variable is set by the want/need_apache functions.

# @ECLASS-VARIABLE: APACHE_MODULESDIR
# @DESCRIPTION:
# Path where we install modules.
# This variable is set by the want/need_apache functions (EAPI=0 through 5)
# or depend.apache_pkg_setup (EAPI=6 and later).

# @ECLASS-VARIABLE: APACHE_DEPEND
# @DESCRIPTION:
# Dependencies for Apache
APACHE_DEPEND="www-servers/apache"

# @ECLASS-VARIABLE: APACHE2_DEPEND
# @DESCRIPTION:
# Dependencies for Apache 2.x
APACHE2_DEPEND="=www-servers/apache-2*"

# @ECLASS-VARIABLE: APACHE2_2_DEPEND
# @DESCRIPTION:
# Dependencies for Apache 2.2.x
APACHE2_2_DEPEND="=www-servers/apache-2.2*"

# @ECLASS-VARIABLE: APACHE2_4_DEPEND
# @DESCRIPTION:
# Dependencies for Apache 2.4.x
APACHE2_4_DEPEND="=www-servers/apache-2.4*"


# ==============================================================================
# INTERNAL FUNCTIONS
# ==============================================================================

# @FUNCTION: _init_apache2
# @INTERNAL
# @DESCRIPTION:
# Please document me

_init_apache2() {
	debug-print-function $FUNCNAME $*

	# WARNING: Do not use these variables with anything that is put
	# into the dependency cache (DEPEND/RDEPEND/etc)
	APACHE_VERSION="2"
	APXS="/usr/bin/apxs"
	APACHE_BIN="/usr/sbin/apache2"
	APACHE_CTL="/usr/sbin/apache2ctl"
	APACHE_INCLUDEDIR="/usr/include/apache2"
	APACHE_CONFDIR="/etc/apache2"
	APACHE_MODULES_CONFDIR="${APACHE_CONFDIR}/modules.d"
	APACHE_VHOSTS_CONFDIR="${APACHE_CONFDIR}/vhosts.d"

	case ${EAPI:-0} in
		0|2|3|4|5)
			_init_apache2_late
			;;
	esac
}

# @FUNCTION: _init_apache2_late
# @INTERNAL
# @DESCRIPTION:
# Please document me

_init_apache2_late() {
	APACHE_BASEDIR="/usr/$(get_libdir)/apache2"
	APACHE_MODULESDIR="${APACHE_BASEDIR}/modules"
}

# @FUNCTION: _init_no_apache
# @INTERNAL
# @DESCRIPTION:
# Please document me

_init_no_apache() {
	debug-print-function $FUNCNAME $*
	APACHE_VERSION="0"
}

# ==============================================================================
# PUBLIC FUNCTIONS
# ==============================================================================

# @FUNCTION: depend.apache_pkg_setup
# @USAGE: [myiuse]
# @DESCRIPTION:
# An ebuild calls this in pkg_setup() to initialize variables for optional
# apache-2.x support. If the myiuse parameter is not given it defaults to
# apache2.
depend.apache_pkg_setup() {
	debug-print-function $FUNCNAME $*

	if [[ "${EBUILD_PHASE}" != "setup" ]]; then
		die "$FUNCNAME() should be called in pkg_setup()"
	fi

	local myiuse=${1:-apache2}

	case ${EAPI:-0} in
		0|2|3|4|5)
			if has ${myiuse} ${IUSE}; then
				if use ${myiuse}; then
					_init_apache2
				else
					_init_no_apache
				fi
			fi
			;;
		*)
			if in_iuse ${myiuse}; then
				if use ${myiuse}; then
					_init_apache2
					_init_apache2_late
				else
					_init_no_apache
				fi
			fi
			;;
	esac
}

# @FUNCTION: want_apache
# @USAGE: [myiuse]
# @DESCRIPTION:
# An ebuild calls this to get the dependency information for optional apache
# support. If the myiuse parameter is not given it defaults to apache2.
# An ebuild should additionally call depend.apache_pkg_setup() in pkg_setup()
# with the same myiuse parameter.
want_apache() {
	debug-print-function $FUNCNAME $*
	want_apache2 "$@"
}

# @FUNCTION: want_apache2
# @USAGE: [myiuse]
# @DESCRIPTION:
# An ebuild calls this to get the dependency information for optional apache-2.x
# support. If the myiuse parameter is not given it defaults to apache2.
# An ebuild should additionally call depend.apache_pkg_setup() in pkg_setup()
# with the same myiuse parameter.
want_apache2() {
	debug-print-function $FUNCNAME $*

	local myiuse=${1:-apache2}
	IUSE="${IUSE} ${myiuse}"
	DEPEND="${DEPEND} ${myiuse}? ( ${APACHE2_DEPEND} )"
	RDEPEND="${RDEPEND} ${myiuse}? ( ${APACHE2_DEPEND} )"
}

# @FUNCTION: want_apache2_2
# @USAGE: [myiuse]
# @DESCRIPTION:
# An ebuild calls this to get the dependency information for optional
# apache-2.2.x support. If the myiuse parameter is not given it defaults to
# apache2.
# An ebuild should additionally call depend.apache_pkg_setup() in pkg_setup()
# with the same myiuse parameter.
want_apache2_2() {
	debug-print-function $FUNCNAME $*

	local myiuse=${1:-apache2}
	IUSE="${IUSE} ${myiuse}"
	DEPEND="${DEPEND} ${myiuse}? ( ${APACHE2_2_DEPEND} )"
	RDEPEND="${RDEPEND} ${myiuse}? ( ${APACHE2_2_DEPEND} )"
}

# @FUNCTION: want_apache2_4
# @USAGE: [myiuse]
# @DESCRIPTION:
# An ebuild calls this to get the dependency information for optional
# apache-2.4.x support. If the myiuse parameter is not given it defaults to
# apache2.
# An ebuild should additionally call depend.apache_pkg_setup() in pkg_setup()
# with the same myiuse parameter.
want_apache2_4() {
	debug-print-function $FUNCNAME $*

	local myiuse=${1:-apache2}
	IUSE="${IUSE} ${myiuse}"
	DEPEND="${DEPEND} ${myiuse}? ( ${APACHE2_4_DEPEND} )"
	RDEPEND="${RDEPEND} ${myiuse}? ( ${APACHE2_4_DEPEND} )"
}

# @FUNCTION: need_apache
# @DESCRIPTION:
# An ebuild calls this to get the dependency information for apache.
need_apache() {
	debug-print-function $FUNCNAME $*
	need_apache2
}

# @FUNCTION: need_apache2
# @DESCRIPTION:
# An ebuild calls this to get the dependency information for apache-2.x.
need_apache2() {
	debug-print-function $FUNCNAME $*

	DEPEND="${DEPEND} ${APACHE2_DEPEND}"
	RDEPEND="${RDEPEND} ${APACHE2_DEPEND}"
	_init_apache2
}

# @FUNCTION: need_apache2_2
# @DESCRIPTION:
# An ebuild calls this to get the dependency information for apache-2.2.x.
need_apache2_2() {
	debug-print-function $FUNCNAME $*

	DEPEND="${DEPEND} ${APACHE2_2_DEPEND}"
	RDEPEND="${RDEPEND} ${APACHE2_2_DEPEND}"
	_init_apache2
}

# @FUNCTION: need_apache2_4
# @DESCRIPTION:
# An ebuild calls this to get the dependency information for apache-2.4.x.
need_apache2_4() {
        debug-print-function $FUNCNAME $*

        DEPEND="${DEPEND} ${APACHE2_4_DEPEND}"
        RDEPEND="${RDEPEND} ${APACHE2_4_DEPEND}"
        _init_apache2
}

# @FUNCTION: has_apache
# @DESCRIPTION:
# An ebuild calls this to get runtime variables for an indirect apache
# dependency without USE-flag, in which case want_apache does not work.
# DO NOT call this function in global scope.
has_apache() {
	debug-print-function $FUNCNAME $*

	if has_version '>=www-servers/apache-2'; then
		_init_apache2
	else
		_init_no_apache
	fi
}

# @FUNCTION: has_apache_threads
# @USAGE: [myflag]
# @DESCRIPTION:
# An ebuild calls this to make sure thread-safety is enabled if apache has been
# built with a threaded MPM. If the myflag parameter is not given it defaults to
# threads.
has_apache_threads() {
	debug-print-function $FUNCNAME $*

	case ${EAPI:-0} in
		0|1)
			die "depend.apache.eclass: has_apache_threads is not supported for EAPI=${EAPI:-0}"
			;;
	esac

	if ! has_version 'www-servers/apache[threads]'; then
		return
	fi

	local myflag="${1:-threads}"

	if ! use ${myflag}; then
		echo
		eerror "You need to enable USE flag '${myflag}' to build a thread-safe version"
		eerror "of ${CATEGORY}/${PN} for use with www-servers/apache"
		die "Need missing USE flag '${myflag}'"
	fi
}

# @FUNCTION: has_apache_threads_in
# @USAGE: <myforeign> [myflag]
# @DESCRIPTION:
# An ebuild calls this to make sure thread-safety is enabled in a foreign
# package if apache has been built with a threaded MPM. If the myflag parameter
# is not given it defaults to threads.
has_apache_threads_in() {
	debug-print-function $FUNCNAME $*

	case ${EAPI:-0} in
		0|1)
			die "depend.apache.eclass: has_apache_threads_in is not supported for EAPI=${EAPI:-0}"
			;;
	esac

	if ! has_version 'www-servers/apache[threads]'; then
		return
	fi

	local myforeign="$1"
	local myflag="${2:-threads}"

	if ! has_version "${myforeign}[${myflag}]"; then
		echo
		eerror "You need to enable USE flag '${myflag}' in ${myforeign} to"
		eerror "build a thread-safe version of ${CATEGORY}/${PN} for use"
		eerror "with www-servers/apache"
		die "Need missing USE flag '${myflag}' in ${myforeign}"
	fi
}

EXPORT_FUNCTIONS pkg_setup