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