depend.apache.eclass: Add missing function want_apache2_4
[gentoo.git] / eclass / depend.apache.eclass
1 # Copyright 1999-2012 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: depend.apache.eclass
6 # @MAINTAINER:
7 # apache-devs@gentoo.org
8 # @BLURB: Functions to allow ebuilds to depend on apache
9 # @DESCRIPTION:
10 # This eclass handles depending on apache in a sane way and provides information
11 # about where certain binaries and configuration files are located.
12 #
13 # To make use of this eclass simply call one of the need/want_apache functions
14 # described below. Make sure you use the need/want_apache call after you have
15 # defined DEPEND and RDEPEND. Also note that you can not rely on the automatic
16 # RDEPEND=DEPEND that portage does if you use this eclass.
17 #
18 # See Bug 107127 for more information.
19 #
20 # @EXAMPLE:
21 #
22 # Here is an example of an ebuild depending on apache:
23 #
24 # @CODE
25 # DEPEND="virtual/Perl-CGI"
26 # RDEPEND="${DEPEND}"
27 # need_apache2
28 # @CODE
29 #
30 # Another example which demonstrates non-standard IUSE options for optional
31 # apache support:
32 #
33 # @CODE
34 # DEPEND="server? ( virtual/Perl-CGI )"
35 # RDEPEND="${DEPEND}"
36 # want_apache2 server
37 #
38 # pkg_setup() {
39 #       depend.apache_pkg_setup server
40 # }
41 # @CODE
42
43 case ${EAPI:-0} in
44         0|2|3|4|5)
45                 inherit multilib
46                 ;;
47         6)
48                 ;;
49         *)
50                 die "EAPI=${EAPI} is not supported by depend.apache.eclass"
51                 ;;
52 esac
53
54 # ==============================================================================
55 # INTERNAL VARIABLES
56 # ==============================================================================
57
58 # @ECLASS-VARIABLE: APACHE_VERSION
59 # @DESCRIPTION:
60 # Stores the version of apache we are going to be ebuilding.
61 # This variable is set by the want/need_apache functions.
62
63 # @ECLASS-VARIABLE: APXS
64 # @DESCRIPTION:
65 # Path to the apxs tool.
66 # This variable is set by the want/need_apache functions.
67
68 # @ECLASS-VARIABLE: APACHE_BIN
69 # @DESCRIPTION:
70 # Path to the apache binary.
71 # This variable is set by the want/need_apache functions.
72
73 # @ECLASS-VARIABLE: APACHE_CTL
74 # @DESCRIPTION:
75 # Path to the apachectl tool.
76 # This variable is set by the want/need_apache functions.
77
78 # @ECLASS-VARIABLE: APACHE_BASEDIR
79 # @DESCRIPTION:
80 # Path to the server root directory.
81 # This variable is set by the want/need_apache functions (EAPI=0 through 5)
82 # or depend.apache_pkg_setup (EAPI=6 and later).
83
84 # @ECLASS-VARIABLE: APACHE_CONFDIR
85 # @DESCRIPTION:
86 # Path to the configuration file directory.
87 # This variable is set by the want/need_apache functions.
88
89 # @ECLASS-VARIABLE: APACHE_MODULES_CONFDIR
90 # @DESCRIPTION:
91 # Path where module configuration files are kept.
92 # This variable is set by the want/need_apache functions.
93
94 # @ECLASS-VARIABLE: APACHE_VHOSTS_CONFDIR
95 # @DESCRIPTION:
96 # Path where virtual host configuration files are kept.
97 # This variable is set by the want/need_apache functions.
98
99 # @ECLASS-VARIABLE: APACHE_MODULESDIR
100 # @DESCRIPTION:
101 # Path where we install modules.
102 # This variable is set by the want/need_apache functions (EAPI=0 through 5)
103 # or depend.apache_pkg_setup (EAPI=6 and later).
104
105 # @ECLASS-VARIABLE: APACHE_DEPEND
106 # @DESCRIPTION:
107 # Dependencies for Apache
108 APACHE_DEPEND="www-servers/apache"
109
110 # @ECLASS-VARIABLE: APACHE2_DEPEND
111 # @DESCRIPTION:
112 # Dependencies for Apache 2.x
113 APACHE2_DEPEND="=www-servers/apache-2*"
114
115 # @ECLASS-VARIABLE: APACHE2_2_DEPEND
116 # @DESCRIPTION:
117 # Dependencies for Apache 2.2.x
118 APACHE2_2_DEPEND="=www-servers/apache-2.2*"
119
120 # @ECLASS-VARIABLE: APACHE2_4_DEPEND
121 # @DESCRIPTION:
122 # Dependencies for Apache 2.4.x
123 APACHE2_4_DEPEND="=www-servers/apache-2.4*"
124
125
126 # ==============================================================================
127 # INTERNAL FUNCTIONS
128 # ==============================================================================
129
130 _init_apache2() {
131         debug-print-function $FUNCNAME $*
132
133         # WARNING: Do not use these variables with anything that is put
134         # into the dependency cache (DEPEND/RDEPEND/etc)
135         APACHE_VERSION="2"
136         APXS="/usr/sbin/apxs2"
137         APACHE_BIN="/usr/sbin/apache2"
138         APACHE_CTL="/usr/sbin/apache2ctl"
139         APACHE_INCLUDEDIR="/usr/include/apache2"
140         APACHE_CONFDIR="/etc/apache2"
141         APACHE_MODULES_CONFDIR="${APACHE_CONFDIR}/modules.d"
142         APACHE_VHOSTS_CONFDIR="${APACHE_CONFDIR}/vhosts.d"
143
144         case ${EAPI:-0} in
145                 0|2|3|4|5)
146                         _init_apache2_late
147                         ;;
148         esac
149 }
150
151 _init_apache2_late() {
152         APACHE_BASEDIR="/usr/$(get_libdir)/apache2"
153         APACHE_MODULESDIR="${APACHE_BASEDIR}/modules"
154 }
155
156 _init_no_apache() {
157         debug-print-function $FUNCNAME $*
158         APACHE_VERSION="0"
159 }
160
161 # ==============================================================================
162 # PUBLIC FUNCTIONS
163 # ==============================================================================
164
165 # @FUNCTION: depend.apache_pkg_setup
166 # @USAGE: [myiuse]
167 # @DESCRIPTION:
168 # An ebuild calls this in pkg_setup() to initialize variables for optional
169 # apache-2.x support. If the myiuse parameter is not given it defaults to
170 # apache2.
171 depend.apache_pkg_setup() {
172         debug-print-function $FUNCNAME $*
173
174         if [[ "${EBUILD_PHASE}" != "setup" ]]; then
175                 die "$FUNCNAME() should be called in pkg_setup()"
176         fi
177
178         local myiuse=${1:-apache2}
179         if has ${myiuse} ${IUSE}; then
180                 if use ${myiuse}; then
181                         case ${EAPI:-0} in
182                                 0|2|3|4|5)
183                                         _init_apache2
184                                         ;;
185                                 *)
186                                         _init_apache2
187                                         _init_apache2_late
188                                         ;;
189                         esac
190                 else
191                         _init_no_apache
192                 fi
193         fi
194 }
195
196 # @FUNCTION: want_apache
197 # @USAGE: [myiuse]
198 # @DESCRIPTION:
199 # An ebuild calls this to get the dependency information for optional apache
200 # support. If the myiuse parameter is not given it defaults to apache2.
201 # An ebuild should additionally call depend.apache_pkg_setup() in pkg_setup()
202 # with the same myiuse parameter.
203 want_apache() {
204         debug-print-function $FUNCNAME $*
205         want_apache2 "$@"
206 }
207
208 # @FUNCTION: want_apache2
209 # @USAGE: [myiuse]
210 # @DESCRIPTION:
211 # An ebuild calls this to get the dependency information for optional apache-2.x
212 # support. If the myiuse parameter is not given it defaults to apache2.
213 # An ebuild should additionally call depend.apache_pkg_setup() in pkg_setup()
214 # with the same myiuse parameter.
215 want_apache2() {
216         debug-print-function $FUNCNAME $*
217
218         local myiuse=${1:-apache2}
219         IUSE="${IUSE} ${myiuse}"
220         DEPEND="${DEPEND} ${myiuse}? ( ${APACHE2_DEPEND} )"
221         RDEPEND="${RDEPEND} ${myiuse}? ( ${APACHE2_DEPEND} )"
222 }
223
224 # @FUNCTION: want_apache2_2
225 # @USAGE: [myiuse]
226 # @DESCRIPTION:
227 # An ebuild calls this to get the dependency information for optional
228 # apache-2.2.x support. If the myiuse parameter is not given it defaults to
229 # apache2.
230 # An ebuild should additionally call depend.apache_pkg_setup() in pkg_setup()
231 # with the same myiuse parameter.
232 want_apache2_2() {
233         debug-print-function $FUNCNAME $*
234
235         local myiuse=${1:-apache2}
236         IUSE="${IUSE} ${myiuse}"
237         DEPEND="${DEPEND} ${myiuse}? ( ${APACHE2_2_DEPEND} )"
238         RDEPEND="${RDEPEND} ${myiuse}? ( ${APACHE2_2_DEPEND} )"
239 }
240
241 # @FUNCTION: want_apache2_4
242 # @USAGE: [myiuse]
243 # @DESCRIPTION:
244 # An ebuild calls this to get the dependency information for optional
245 # apache-2.4.x support. If the myiuse parameter is not given it defaults to
246 # apache2.
247 # An ebuild should additionally call depend.apache_pkg_setup() in pkg_setup()
248 # with the same myiuse parameter.
249 want_apache2_4() {
250         debug-print-function $FUNCNAME $*
251
252         local myiuse=${1:-apache2}
253         IUSE="${IUSE} ${myiuse}"
254         DEPEND="${DEPEND} ${myiuse}? ( ${APACHE2_4_DEPEND} )"
255         RDEPEND="${RDEPEND} ${myiuse}? ( ${APACHE2_4_DEPEND} )"
256 }
257
258 # @FUNCTION: need_apache
259 # @DESCRIPTION:
260 # An ebuild calls this to get the dependency information for apache.
261 need_apache() {
262         debug-print-function $FUNCNAME $*
263         need_apache2
264 }
265
266 # @FUNCTION: need_apache2
267 # @DESCRIPTION:
268 # An ebuild calls this to get the dependency information for apache-2.x.
269 need_apache2() {
270         debug-print-function $FUNCNAME $*
271
272         DEPEND="${DEPEND} ${APACHE2_DEPEND}"
273         RDEPEND="${RDEPEND} ${APACHE2_DEPEND}"
274         _init_apache2
275 }
276
277 # @FUNCTION: need_apache2_2
278 # @DESCRIPTION:
279 # An ebuild calls this to get the dependency information for apache-2.2.x.
280 need_apache2_2() {
281         debug-print-function $FUNCNAME $*
282
283         DEPEND="${DEPEND} ${APACHE2_2_DEPEND}"
284         RDEPEND="${RDEPEND} ${APACHE2_2_DEPEND}"
285         _init_apache2
286 }
287
288 # @FUNCTION: need_apache2_4
289 # @DESCRIPTION:
290 # An ebuild calls this to get the dependency information for apache-2.4.x.
291 need_apache2_4() {
292         debug-print-function $FUNCNAME $*
293
294         DEPEND="${DEPEND} ${APACHE2_4_DEPEND}"
295         RDEPEND="${RDEPEND} ${APACHE2_4_DEPEND}"
296         _init_apache2
297 }
298
299 # @FUNCTION: has_apache
300 # @DESCRIPTION:
301 # An ebuild calls this to get runtime variables for an indirect apache
302 # dependency without USE-flag, in which case want_apache does not work.
303 # DO NOT call this function in global scope.
304 has_apache() {
305         debug-print-function $FUNCNAME $*
306
307         if has_version '>=www-servers/apache-2'; then
308                 _init_apache2
309         else
310                 _init_no_apache
311         fi
312 }
313
314 # @FUNCTION: has_apache_threads
315 # @USAGE: [myflag]
316 # @DESCRIPTION:
317 # An ebuild calls this to make sure thread-safety is enabled if apache has been
318 # built with a threaded MPM. If the myflag parameter is not given it defaults to
319 # threads.
320 has_apache_threads() {
321         debug-print-function $FUNCNAME $*
322
323         case ${EAPI:-0} in
324                 0|1)
325                         die "depend.apache.eclass: has_apache_threads is not supported for EAPI=${EAPI:-0}"
326                         ;;
327         esac
328
329         if ! has_version 'www-servers/apache[threads]'; then
330                 return
331         fi
332
333         local myflag="${1:-threads}"
334
335         if ! use ${myflag}; then
336                 echo
337                 eerror "You need to enable USE flag '${myflag}' to build a thread-safe version"
338                 eerror "of ${CATEGORY}/${PN} for use with www-servers/apache"
339                 die "Need missing USE flag '${myflag}'"
340         fi
341 }
342
343 # @FUNCTION: has_apache_threads_in
344 # @USAGE: <myforeign> [myflag]
345 # @DESCRIPTION:
346 # An ebuild calls this to make sure thread-safety is enabled in a foreign
347 # package if apache has been built with a threaded MPM. If the myflag parameter
348 # is not given it defaults to threads.
349 has_apache_threads_in() {
350         debug-print-function $FUNCNAME $*
351
352         case ${EAPI:-0} in
353                 0|1)
354                         die "depend.apache.eclass: has_apache_threads_in is not supported for EAPI=${EAPI:-0}"
355                         ;;
356         esac
357
358         if ! has_version 'www-servers/apache[threads]'; then
359                 return
360         fi
361
362         local myforeign="$1"
363         local myflag="${2:-threads}"
364
365         if ! has_version "${myforeign}[${myflag}]"; then
366                 echo
367                 eerror "You need to enable USE flag '${myflag}' in ${myforeign} to"
368                 eerror "build a thread-safe version of ${CATEGORY}/${PN} for use"
369                 eerror "with www-servers/apache"
370                 die "Need missing USE flag '${myflag}' in ${myforeign}"
371         fi
372 }
373
374 EXPORT_FUNCTIONS pkg_setup