/[gentoo-x86]/eclass/apache-module.eclass
Gentoo

Diff of /eclass/apache-module.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.7 Revision 1.25
1# Copyright 2004 Gentoo Foundation 1# Copyright 1999-2011 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License, v2 or later 2# Distributed under the terms of the GNU General Public License v2
3# Author Michael Tindal <urilith@gentoo.org>
4# $Header: /var/cvsroot/gentoo-x86/eclass/apache-module.eclass,v 1.7 2005/06/01 22:54:45 urilith Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/apache-module.eclass,v 1.25 2011/12/27 17:55:12 fauli Exp $
5ECLASS=apache-module 4
6INHERITED="$INHERITED $ECLASS" 5# @ECLASS: apache-module.eclass
6# @MAINTAINER:
7# apache-devs@gentoo.org
8# @BLURB: Provides a common set of functions for apache modules
9# @DESCRIPTION:
10# This eclass handles apache modules in a sane way.
11#
12# To make use of this eclass simply call one of the need/want_apache functions
13# described in depend.apache.eclass. Make sure you use the need/want_apache call
14# after you have defined DEPEND and RDEPEND. Also note that you can not rely on
15# the automatic 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 a simple example of an ebuild for mod_foo:
22#
23# @CODE
24# APACHE2_MOD_CONF="42_mod_foo"
25# APACHE2_MOD_DEFINE="FOO"
26# need_apache2
27# @CODE
28#
29# A more complicated example for a module with non-standard locations:
30#
31# @CODE
32# APXS2_S="${S}/apache22/src"
33# APACHE2_MOD_FILE="${APXS2_S}/${PN}.so"
34# APACHE2_MOD_CONF="42_${PN}"
35# APACHE2_MOD_DEFINE="FOO"
36# DOCFILES="docs/*.html"
37# need_apache2_2
38# @CODE
39#
40# A basic module configuration which just loads the module into apache:
41#
42# @CODE
43# <IfDefine FOO>
44# LoadModule foo_module modules/mod_foo.so
45# </IfDefine>
46# @CODE
7 47
8inherit depend.apache 48inherit depend.apache
9 49
10# This eclass provides a common set of functions for Apache modules. 50# ==============================================================================
51# PUBLIC VARIABLES
52# ==============================================================================
11 53
12###### 54# @VARIABLE: APXS2_S
13## Common ebuild variables 55# @DESCRIPTION:
14###### 56# Path to temporary build directory. (Defaults to `${S}/src' if it exists,
57# `${S}' otherwise)
15 58
16#### 59# @VARIABLE: APXS2_ARGS
17## APXS1_S, APXS2_S 60# @DESCRIPTION:
18## 61# Arguments to pass to the apxs tool. (Defaults to `-c ${PN}.c')
19## Paths to temporary build directories
20####
21APXS1_S=""
22APXS2_S=""
23 62
24#### 63# @VARIABLE: APACHE2_EXECFILES
25## APXS1_ARGS, APXS2_ARGS 64# @DESCRIPTION:
26## 65# List of files that will be installed into ${APACHE_MODULE_DIR} beside
27## Arguments to pass to the apxs tool 66# ${APACHE2_MOD_FILE}. In addition, this function also sets the executable
28#### 67# permission on those files.
29APXS1_ARGS=""
30APXS2_ARGS=""
31 68
32#### 69# @VARIABLE: APACHE2_MOD_CONF
33## APACHE1_MOD_FILE, APACHE2_MOD_FILE 70# @DESCRIPTION:
34## 71# Module configuration file installed by src_install (minus the .conf suffix and
35## Name of the module that src_install installs (only, minus the .so) 72# relative to ${FILESDIR}).
36####
37APACHE1_MOD_FILE=""
38APACHE2_MOD_FILE=""
39 73
40#### 74# @VARIABLE: APACHE2_MOD_DEFINE
41## APACHE1_MOD_CONF, APACHE2_MOD_CONF 75# @DESCRIPTION:
42##
43## Configuration file installed by src_install
44####
45APACHE1_MOD_CONF=""
46APACHE2_MOD_CONF=""
47
48####
49## APACHE1_MOD_DEFINE, APACHE2_MOD_DEFINE
50##
51## Name of define (eg FOO) to use in conditional loading of the installed 76# Name of define (e.g. FOO) to use in conditional loading of the installed
52## module/it's config file 77# module/its config file, multiple defines should be space separated.
53####
54APACHE1_MOD_DEFINE=""
55APACHE2_MOD_DEFINE=""
56 78
57#### 79# @VARIABLE: APACHE2_MOD_FILE
58## DOCFILES 80# @DESCRIPTION:
59## 81# Name of the module that src_install installs minus the .so suffix. (Defaults
82# to `${APXS2_S}/.libs/${PN}.so')
83
84# @VARIABLE: APACHE2_VHOST_CONF
85# @DESCRIPTION:
86# Virtual host configuration file installed by src_install (minus the .conf
87# suffix and relative to ${FILESDIR}).
88
89# @VARIABLE: DOCFILES
90# @DESCRIPTION:
60## If the exported src_install() is being used, and ${DOCFILES} is non-zero, 91# If the exported src_install() is being used, and ${DOCFILES} is non-zero, some
61## some sed-fu is applied to split out html documentation (if any) from normal 92# sed-fu is applied to split out html documentation (if any) from normal
62## documentation, and dodoc'd or dohtml'd 93# documentation, and dodoc'd or dohtml'd.
63####
64DOCFILES=""
65 94
66###### 95# ==============================================================================
67## Utility functions 96# INTERNAL FUNCTIONS
68###### 97# ==============================================================================
69 98
70#### 99# Internal function to construct the default ${APXS2_S} path if required.
71## apache_cd_dir
72##
73## Return the path to our temporary build dir
74####
75apache_cd_dir() { 100apache_cd_dir() {
76 debug-print-function apache_cd_dir 101 debug-print-function $FUNCNAME $*
77 102
78 if [ "${APACHE_VERSION}" == "1" ]; then 103 local CD_DIR="${APXS2_S}"
79 [ -n "${APXS1_S}" ] && CD_DIR="${APXS1_S}"
80 else
81 [ -n "${APXS2_S}" ] && CD_DIR="${APXS2_S}"
82 fi
83 104
84 # XXX - is this really needed? can't we just return ${S}?
85 if [ -z "${CD_DIR}" ]; then 105 if [[ -z "${CD_DIR}" ]] ; then
86 if [ -d ${S}/src ] ; then 106 if [[ -d "${S}/src" ]] ; then
87 CD_DIR="${S}/src" 107 CD_DIR="${S}/src"
88 else 108 else
89 CD_DIR="${S}" 109 CD_DIR="${S}"
90 fi 110 fi
91 fi 111 fi
92 112
93 debug-print apache_cd_dir: "CD_DIR=${CD_DIR}" 113 debug-print $FUNCNAME "CD_DIR=${CD_DIR}"
94 echo ${CD_DIR} 114 echo "${CD_DIR}"
95} 115}
96 116
97#### 117# Internal function to construct the default ${APACHE2_MOD_FILE} if required.
98## apache_mod_file
99##
100## Return the path to the module file
101####
102apache_mod_file() { 118apache_mod_file() {
103 debug-print-function apache_mod_file 119 debug-print-function $FUNCNAME $*
104 120
105 if [ "${APACHE_VERSION}" == "1" ]; then 121 local MOD_FILE="${APACHE2_MOD_FILE:-$(apache_cd_dir)/.libs/${PN}.so}"
106 [ -n "${APACHE1_MOD_FILE}" ] && MOD_FILE="${APACHE1_MOD_FILE}"
107 [ -z "${MOD_FILE}" ] && MOD_FILE="$(apache_cd_dir)/${PN}.so"
108 else
109 [ -n "${APACHE2_MOD_FILE}" ] && MOD_FILE="${APACHE2_MOD_FILE}"
110 [ -z "${MOD_FILE}" ] && MOD_FILE="$(apache_cd_dir)/.libs/${PN}.so"
111 fi
112 122
113 debug-print apache_mod_file: MOD_FILE=${MOD_FILE} 123 debug-print $FUNCNAME "MOD_FILE=${MOD_FILE}"
114 echo ${MOD_FILE} 124 echo "${MOD_FILE}"
115} 125}
116 126
117####
118## apache_doc_magic
119##
120## Some magic for picking out html files from ${DOCFILES}. It takes 127# Internal function for picking out html files from ${DOCFILES}. It takes an
121## an optional first argument `html'; if the first argument is equals 128# optional first argument `html'; if the first argument is equals `html', only
122## `html', only html files are returned, otherwise normal (non-html) 129# html files are returned, otherwise normal (non-html) docs are returned.
123## docs are returned.
124####
125apache_doc_magic() { 130apache_doc_magic() {
126 debug-print-function apache_doc_magic $* 131 debug-print-function $FUNCNAME $*
127 132
133 local DOCS=
134
128 if [ -n "${DOCFILES}" ]; then 135 if [[ -n "${DOCFILES}" ]] ; then
129 if [ "x$1" == "xhtml" ]; then 136 if [[ "x$1" == "xhtml" ]] ; then
130 DOCS="`echo ${DOCFILES} | sed -e 's/ /\n/g' | sed -e '/^[^ ]*.html$/ !d'`" 137 DOCS="`echo ${DOCFILES} | sed -e 's/ /\n/g' | sed -e '/^[^ ]*.html$/ !d'`"
131 else 138 else
132 DOCS="`echo ${DOCFILES} | sed 's, *[^ ]*\+.html, ,g'`" 139 DOCS="`echo ${DOCFILES} | sed 's, *[^ ]*\+.html, ,g'`"
133 fi 140 fi
141 fi
134 142
135 debug-print apache_doc_magic: DOCS=${DOCS} 143 debug-print $FUNCNAME "DOCS=${DOCS}"
136 echo ${DOCS} 144 echo "${DOCS}"
137 fi
138} 145}
139 146
140###### 147# ==============================================================================
141## Apache 1.x ebuild functions 148# EXPORTED FUNCTIONS
142###### 149# ==============================================================================
143 150
144#### 151# @FUNCTION: apache-module_src_compile
145## apache1_src_compile 152# @DESCRIPTION:
146## The default action is to call ${APXS11} with the value of 153# The default action is to call ${APXS} with the value of ${APXS2_ARGS}. If a
147## ${APXS1_ARGS}. If a module requires a different build setup 154# module requires a different build setup than this, use ${APXS} in your own
148## than this, use ${APXS1} in your own src_compile routine. 155# src_compile routine.
149####
150apache1_src_compile() { 156apache-module_src_compile() {
151 debug-print-function apache1_src_compile 157 debug-print-function $FUNCNAME $*
152 158
153 CD_DIR=$(apache_cd_dir) 159 local CD_DIR=$(apache_cd_dir)
154 cd ${CD_DIR} || die "cd ${CD_DIR} failed" 160 cd "${CD_DIR}" || die "cd ${CD_DIR} failed"
161
155 APXS1_ARGS="${APXS1_ARGS:--c ${PN}.c}" 162 APXS2_ARGS="${APXS2_ARGS:--c ${PN}.c}"
156 ${APXS1} ${APXS1_ARGS} || die "${APXS1} ${APXS1_ARGS} failed" 163 ${APXS} ${APXS2_ARGS} || die "${APXS} ${APXS2_ARGS} failed"
157} 164}
158 165
159#### 166# @FUNCTION: apache-module_src_install
160## apache1_src_install 167# @DESCRIPTION:
161##
162## This installs the files into apache's directories. The module is installed 168# This installs the files into apache's directories. The module is installed
163## from a directory chosen as above (APXS2_S or ${S}/src). In addition, 169# from a directory chosen as above (apache_cd_dir). In addition, this function
164## this function can also set the executable permission on files listed in EXECFILES. 170# can also set the executable permission on files listed in
165## The configuration file name is listed in APACHE1_MOD_CONF without the .conf extensions, 171# ${APACHE2_EXECFILES}. The configuration file name is listed in
166## so if you configuration is 55_mod_foo.conf, APACHE1_MOD_CONF would be 55_mod_foo. 172# ${APACHE2_MOD_CONF} without the .conf extensions, so if you configuration is
167## DOCFILES contains the list of files you want filed as documentation. The name of the 173# 55_mod_foo.conf, APACHE2_MOD_CONF would be 55_mod_foo. ${DOCFILES} contains
168## module can also be specified using the APACHE1_MOD_FILE or defaults to 174# the list of files you want filed as documentation.
169## .libs/${PN}.so.
170####
171apache1_src_install() { 175apache-module_src_install() {
172 debug-print-function apache1_src_install 176 debug-print-function $FUNCNAME $*
173 177
174 CD_DIR=$(apache_cd_dir) 178 local CD_DIR=$(apache_cd_dir)
175 cd ${CD_DIR} || die "cd ${CD_DIR} failed" 179 cd "${CD_DIR}" || die "cd ${CD_DIR} failed"
176 180
177 MOD_FILE=$(apache_mod_file) 181 local MOD_FILE=$(apache_mod_file)
178 182
179 exeinto ${APACHE1_MODULESDIR} 183 exeinto "${APACHE_MODULESDIR}"
180 doexe ${MOD_FILE} || die "internal ebuild error: '${MOD_FILE}' not found" 184 doexe ${MOD_FILE} || die "internal ebuild error: '${MOD_FILE}' not found"
181 [ -n "${APACHE1_EXECFILES}" ] && doexe ${APACHE1_EXECFILES} 185 [[ -n "${APACHE2_EXECFILES}" ]] && doexe ${APACHE2_EXECFILES}
182 186
183 if [ -n "${APACHE1_MOD_CONF}" ] ; then 187 if [[ -n "${APACHE2_MOD_CONF}" ]] ; then
184 insinto ${APACHE1_MODULES_CONFDIR} 188 insinto "${APACHE_MODULES_CONFDIR}"
185 doins ${FILESDIR}/${APACHE1_MOD_CONF}.conf || die "internal ebuild error: '${FILESDIR}/${APACHE1_MOD_CONF}.conf' not found." 189 set -- ${APACHE2_MOD_CONF}
190 newins "${FILESDIR}/${1}.conf" "$(basename ${2:-$1}).conf" \
191 || die "internal ebuild error: '${FILESDIR}/${1}.conf' not found"
186 fi 192 fi
187 193
194 if [[ -n "${APACHE2_VHOST_CONF}" ]] ; then
195 insinto "${APACHE_VHOSTS_CONFDIR}"
196 set -- ${APACHE2_VHOST_CONF}
197 newins "${FILESDIR}/${1}.conf" "$(basename ${2:-$1}).conf " \
198 || die "internal ebuild error: '${FILESDIR}/${1}.conf' not found"
199 fi
200
188 cd ${S} 201 cd "${S}"
189 202
190 if [ -n "${DOCFILES}" ] ; then 203 if [[ -n "${DOCFILES}" ]] ; then
191 OTHER_DOCS=$(apache_doc_magic) 204 local OTHER_DOCS=$(apache_doc_magic)
192 HTML_DOCS=$(apache_doc_magic html) 205 local HTML_DOCS=$(apache_doc_magic html)
193 206
194 [ -n "${OTHER_DOCS}" ] && dodoc ${OTHER_DOCS} 207 [[ -n "${OTHER_DOCS}" ]] && dodoc ${OTHER_DOCS}
195 [ -n "${HTML_DOCS}" ] && dohtml ${HTML_DOCS} 208 [[ -n "${HTML_DOCS}" ]] && dohtml ${HTML_DOCS}
196 fi 209 fi
197} 210}
198 211
199#### 212# @FUNCTION: apache-module_pkg_postinst
200## apache1_pkg_postinst 213# @DESCRIPTION:
201## 214# This prints out information about the installed module and how to enable it.
202## Prints the standard config message, unless APACHE1_NO_CONFIG is set to yes.
203####
204apache1_pkg_postinst() { 215apache-module_pkg_postinst() {
205 debug-print-function apache1_pkg_postinst 216 debug-print-function $FUNCNAME $*
206 217
207 if [ -n "${APACHE1_MOD_DEFINE}" ]; then 218 if [[ -n "${APACHE2_MOD_DEFINE}" ]] ; then
219 local my_opts="-D ${APACHE2_MOD_DEFINE// / -D }"
220
208 einfo 221 einfo
209 einfo "To enable ${PN}, you need to edit your /etc/conf.d/apache file and" 222 einfo "To enable ${PN}, you need to edit your /etc/conf.d/apache2 file and"
210 einfo "add '-D ${APACHE1_MOD_DEFINE}' to APACHE_OPTS." 223 einfo "add '${my_opts}' to APACHE2_OPTS."
211 einfo 224 einfo
212 fi 225 fi
226
213 if [ -n "${APACHE1_MOD_CONF}" ] ; then 227 if [[ -n "${APACHE2_MOD_CONF}" ]] ; then
228 set -- ${APACHE2_MOD_CONF}
214 einfo 229 einfo
215 einfo "Configuration file installed as" 230 einfo "Configuration file installed as"
216 einfo " ${APACHE1_MODULES_CONFDIR}/$(basename ${APACHE1_MOD_CONF}).conf" 231 einfo " ${APACHE_MODULES_CONFDIR}/$(basename ${2:-$1}).conf"
217 einfo "You may want to edit it before turning the module on in /etc/conf.d/apache"
218 einfo
219 fi
220}
221
222######
223## Apache 2.x ebuild functions
224######
225
226####
227## apache2_pkg_setup
228##
229## Checks to see if APACHE2_MT_UNSAFE is set to anything other than "no". If it is, then
230## we check what the MPM style used by Apache is, if it isnt prefork, we let the user
231## know they need prefork, and then exit the build.
232####
233apache2_pkg_setup() {
234 debug-print-function apache2_pkg_setup
235
236 if [ -n "${APACHE2_SAFE_MPMS}" ]; then
237
238 for mpm in ${APACHE2_SAFE_MPMS}; do
239 MPM_USE="mpm-${mpm}"
240 if built_with_use apache ${MPM_USE}; then
241 INSTALLED_MPM_SAFE="yes"
242 fi
243 done
244
245 if [ -z "${INSTALLED_MPM_SAFE}" ] ; then
246 eerror "The module you are trying to install (${PN})"
247 eerror "will only work with one of the following MPMs:"
248 eerror " ${APACHE2_SAFE_MPMS}"
249 eerror "You do not currently have any of these MPMs installed."
250 eerror "Please re-install apache with the correct mpm-* USE flag set."
251 die "No safe MPM installed."
252 fi
253
254 fi
255
256}
257
258####
259## apache2_src_compile
260##
261## The default action is to call ${APXS2} with the value of
262## ${APXS2_ARGS}. If a module requires a different build setup
263## than this, use ${APXS2} in your own src_compile routine.
264####
265apache2_src_compile() {
266 debug-print-function apache2_src_compile
267
268 CD_DIR=$(apache_cd_dir)
269 cd ${CD_DIR} || die "cd ${CD_DIR} failed"
270 APXS2_ARGS="${APXS2_ARGS:--c ${PN}.c}"
271 ${APXS2} ${APXS2_ARGS} || die "${APXS2} ${APXS2_ARGS} failed"
272}
273
274####
275## apache2_src_install
276##
277## This installs the files into apache's directories. The module is installed
278## from a directory chosen as above (APXS2_S or ${S}/src). In addition,
279## this function can also set the executable permission on files listed in EXECFILES.
280## The configuration file name is listed in CONFFILE without the .conf extensions,
281## so if you configuration is 55_mod_foo.conf, CONFFILE would be 55_mod_foo.
282## DOCFILES contains the list of files you want filed as documentation.
283####
284apache2_src_install() {
285 debug-print-function apache2_src_install
286
287 CD_DIR=$(apache_cd_dir)
288 cd ${CD_DIR} || die "cd ${CD_DIR} failed"
289
290 MOD_FILE=$(apache_mod_file)
291
292 exeinto ${APACHE2_MODULESDIR}
293 doexe ${MOD_FILE} || die "internal ebuild error: '${MOD_FILE}' not found"
294 [ -n "${APACHE2_EXECFILES}" ] && doexe ${APACHE2_EXECFILES}
295
296 if [ -n "${APACHE2_MOD_CONF}" ] ; then
297 insinto ${APACHE2_MODULES_CONFDIR}
298 doins ${FILESDIR}/${APACHE2_MOD_CONF}.conf || die "internal ebuild error: '${FILESDIR}/${APACHE2_MOD_CONF}.conf' not found."
299 fi
300
301 if [ -n "${APACHE2_VHOSTFILE}" ]; then
302 insinto ${APACHE2_MODULES_VHOSTDIR}
303 doins ${FILESDIR}/${APACHE2_VHOSTFILE}.conf
304 fi
305
306 cd ${S}
307
308 if [ -n "${DOCFILES}" ] ; then
309 OTHER_DOCS=$(apache_doc_magic)
310 HTML_DOCS=$(apache_doc_magic html)
311
312 [ -n "${OTHER_DOCS}" ] && dodoc ${OTHER_DOCS}
313 [ -n "${HTML_DOCS}" ] && dohtml ${HTML_DOCS}
314 fi
315}
316
317apache2_pkg_postinst() {
318 debug-print-function apache2_pkg_postinst
319
320 if [ -n "${APACHE2_MOD_DEFINE}" ]; then
321 einfo
322 einfo "To enable ${PN}, you need to edit your /etc/conf.d/apache2 file and"
323 einfo "add '-D ${APACHE2_MOD_DEFINE}' to APACHE2_OPTS."
324 einfo
325 fi
326 if [ -n "${APACHE2_MOD_CONF}" ] ; then
327 einfo
328 einfo "Configuration file installed as"
329 einfo " ${APACHE2_MODULES_CONFDIR}/$(basename ${APACHE2_MOD_CONF}).conf"
330 einfo "You may want to edit it before turning the module on in /etc/conf.d/apache2" 232 einfo "You may want to edit it before turning the module on in /etc/conf.d/apache2"
331 einfo 233 einfo
332 fi 234 fi
333
334 if [ -n "${APACHE2_SAFE_MPMS}" ]; then
335
336 INSTALLED_MPM="$(apxs2 -q MPM_NAME)"
337
338 if ! hasq ${INSTALLED_MPM} ${APACHE2_SAFE_MPMS} ; then
339 INSTALLED_MPM_UNSAFE="${INSTALLED_MPM_UNSAFE} ${mpm}"
340 else
341 INSTALLED_MPM_SAFE="${INSTALLED_MPM_SAFE} ${mpm}"
342 fi
343
344 if [ -n "${INSTALLED_MPM_UNSAFE}" ] ; then
345 ewarn "You have one or more MPMs installed that will not work with"
346 ewarn "this module (${PN}). Please make sure that you only enable"
347 ewarn "this module if you are using one of the following MPMs:"
348 ewarn " ${INSTALLED_MPM_SAFE}"
349 fi
350
351 fi
352
353
354} 235}
355 236
356######
357## Apache dual (1.x or 2.x) ebuild functions
358##
359## This is where the magic happens. We provide dummy routines of all of the functions
360## provided by all of the specifics. We use APACHE_ECLASS_VER_* to see which versions
361## to call. If a function is provided by a given section (ie pkg_postinst in Apache 2.x)
362## the exported routine simply does nothing.
363######
364
365apache-module_pkg_setup() {
366 debug-print-function apache-module_pkg_setup
367
368 if [ ${APACHE_VERSION} -eq '2' ]; then
369 apache2_pkg_setup
370 fi
371}
372
373apache-module_src_compile() {
374 debug-print-function apache-module_src_compile
375
376 if [ ${APACHE_VERSION} -eq '1' ]; then
377 apache1_src_compile
378 else
379 apache2_src_compile
380 fi
381}
382
383apache-module_src_install() {
384 debug-print-function apache-module_src_install
385
386 if [ ${APACHE_VERSION} -eq '1' ]; then
387 apache1_src_install
388 else
389 apache2_src_install
390 fi
391}
392
393apache-module_pkg_postinst() {
394 debug-print-function apache-module_pkg_postinst
395
396 if [ ${APACHE_VERSION} -eq '1' ]; then
397 apache1_pkg_postinst
398 else
399 apache2_pkg_postinst
400 fi
401}
402
403EXPORT_FUNCTIONS pkg_setup src_compile src_install pkg_postinst 237EXPORT_FUNCTIONS src_compile src_install pkg_postinst
404
405# vim:ts=4

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.25

  ViewVC Help
Powered by ViewVC 1.1.20