1 # Copyright 1999-2011 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: apache-module.eclass
6 # apache-devs@gentoo.org
7 # @BLURB: Provides a common set of functions for apache modules
9 # This eclass handles apache modules in a sane way.
11 # To make use of this eclass simply call one of the need/want_apache functions
12 # described in depend.apache.eclass. Make sure you use the need/want_apache call
13 # after you have defined DEPEND and RDEPEND. Also note that you can not rely on
14 # the automatic RDEPEND=DEPEND that portage does if you use this eclass.
16 # See Bug 107127 for more information.
20 # Here is a simple example of an ebuild for mod_foo:
23 # APACHE2_MOD_CONF="42_mod_foo"
24 # APACHE2_MOD_DEFINE="FOO"
28 # A more complicated example for a module with non-standard locations:
31 # APXS2_S="${S}/apache22/src"
32 # APACHE2_MOD_FILE="${APXS2_S}/${PN}.so"
33 # APACHE2_MOD_CONF="42_${PN}"
34 # APACHE2_MOD_DEFINE="FOO"
35 # DOCFILES="docs/*.html"
39 # A basic module configuration which just loads the module into apache:
43 # LoadModule foo_module modules/mod_foo.so
49 # ==============================================================================
51 # ==============================================================================
55 # Path to temporary build directory. (Defaults to `${S}/src' if it exists,
58 # @VARIABLE: APXS2_ARGS
60 # Arguments to pass to the apxs tool. (Defaults to `-c ${PN}.c')
62 # @VARIABLE: APACHE2_EXECFILES
64 # List of files that will be installed into ${APACHE_MODULE_DIR} beside
65 # ${APACHE2_MOD_FILE}. In addition, this function also sets the executable
66 # permission on those files.
68 # @VARIABLE: APACHE2_MOD_CONF
70 # Module configuration file installed by src_install (minus the .conf suffix and
71 # relative to ${FILESDIR}).
73 # @VARIABLE: APACHE2_MOD_DEFINE
75 # Name of define (e.g. FOO) to use in conditional loading of the installed
76 # module/its config file, multiple defines should be space separated.
78 # @VARIABLE: APACHE2_MOD_FILE
80 # Name of the module that src_install installs minus the .so suffix. (Defaults
81 # to `${APXS2_S}/.libs/${PN}.so')
83 # @VARIABLE: APACHE2_VHOST_CONF
85 # Virtual host configuration file installed by src_install (minus the .conf
86 # suffix and relative to ${FILESDIR}).
90 # If the exported src_install() is being used, and ${DOCFILES} is non-zero, some
91 # sed-fu is applied to split out html documentation (if any) from normal
92 # documentation, and dodoc'd or dohtml'd.
94 # ==============================================================================
96 # ==============================================================================
98 # Internal function to construct the default ${APXS2_S} path if required.
100 debug-print-function $FUNCNAME $*
102 local CD_DIR="${APXS2_S}"
104 if [[ -z "${CD_DIR}" ]] ; then
105 if [[ -d "${S}/src" ]] ; then
112 debug-print $FUNCNAME "CD_DIR=${CD_DIR}"
116 # Internal function to construct the default ${APACHE2_MOD_FILE} if required.
118 debug-print-function $FUNCNAME $*
120 local MOD_FILE="${APACHE2_MOD_FILE:-$(apache_cd_dir)/.libs/${PN}.so}"
122 debug-print $FUNCNAME "MOD_FILE=${MOD_FILE}"
126 # Internal function for picking out html files from ${DOCFILES}. It takes an
127 # optional first argument `html'; if the first argument is equals `html', only
128 # html files are returned, otherwise normal (non-html) docs are returned.
130 debug-print-function $FUNCNAME $*
134 if [[ -n "${DOCFILES}" ]] ; then
135 if [[ "x$1" == "xhtml" ]] ; then
136 DOCS="`echo ${DOCFILES} | sed -e 's/ /\n/g' | sed -e '/^[^ ]*.html$/ !d'`"
138 DOCS="`echo ${DOCFILES} | sed 's, *[^ ]*\+.html, ,g'`"
142 debug-print $FUNCNAME "DOCS=${DOCS}"
146 # ==============================================================================
148 # ==============================================================================
150 # @FUNCTION: apache-module_src_compile
152 # The default action is to call ${APXS} with the value of ${APXS2_ARGS}. If a
153 # module requires a different build setup than this, use ${APXS} in your own
154 # src_compile routine.
155 apache-module_src_compile() {
156 debug-print-function $FUNCNAME $*
158 local CD_DIR=$(apache_cd_dir)
159 cd "${CD_DIR}" || die "cd ${CD_DIR} failed"
161 APXS2_ARGS="${APXS2_ARGS:--c ${PN}.c}"
162 ${APXS} ${APXS2_ARGS} || die "${APXS} ${APXS2_ARGS} failed"
165 # @FUNCTION: apache-module_src_install
167 # This installs the files into apache's directories. The module is installed
168 # from a directory chosen as above (apache_cd_dir). In addition, this function
169 # can also set the executable permission on files listed in
170 # ${APACHE2_EXECFILES}. The configuration file name is listed in
171 # ${APACHE2_MOD_CONF} without the .conf extensions, so if you configuration is
172 # 55_mod_foo.conf, APACHE2_MOD_CONF would be 55_mod_foo. ${DOCFILES} contains
173 # the list of files you want filed as documentation.
174 apache-module_src_install() {
175 debug-print-function $FUNCNAME $*
177 local CD_DIR=$(apache_cd_dir)
178 pushd "${CD_DIR}" >/dev/null || die "cd ${CD_DIR} failed"
180 local MOD_FILE=$(apache_mod_file)
182 exeinto "${APACHE_MODULESDIR}"
183 doexe ${MOD_FILE} || die "internal ebuild error: '${MOD_FILE}' not found"
184 [[ -n "${APACHE2_EXECFILES}" ]] && doexe ${APACHE2_EXECFILES}
186 if [[ -n "${APACHE2_MOD_CONF}" ]] ; then
187 insinto "${APACHE_MODULES_CONFDIR}"
188 set -- ${APACHE2_MOD_CONF}
189 newins "${FILESDIR}/${1}.conf" "$(basename ${2:-$1}).conf" \
190 || die "internal ebuild error: '${FILESDIR}/${1}.conf' not found"
193 if [[ -n "${APACHE2_VHOST_CONF}" ]] ; then
194 insinto "${APACHE_VHOSTS_CONFDIR}"
195 set -- ${APACHE2_VHOST_CONF}
196 newins "${FILESDIR}/${1}.conf" "$(basename ${2:-$1}).conf " \
197 || die "internal ebuild error: '${FILESDIR}/${1}.conf' not found"
202 if [[ -n "${DOCFILES}" ]] ; then
203 local OTHER_DOCS=$(apache_doc_magic)
204 local HTML_DOCS=$(apache_doc_magic html)
206 [[ -n "${OTHER_DOCS}" ]] && dodoc ${OTHER_DOCS}
207 [[ -n "${HTML_DOCS}" ]] && dohtml ${HTML_DOCS}
213 # @FUNCTION: apache-module_pkg_postinst
215 # This prints out information about the installed module and how to enable it.
216 apache-module_pkg_postinst() {
217 debug-print-function $FUNCNAME $*
219 if [[ -n "${APACHE2_MOD_DEFINE}" ]] ; then
220 local my_opts="-D ${APACHE2_MOD_DEFINE// / -D }"
223 einfo "To enable ${PN}, you need to edit your /etc/conf.d/apache2 file and"
224 einfo "add '${my_opts}' to APACHE2_OPTS."
228 if [[ -n "${APACHE2_MOD_CONF}" ]] ; then
229 set -- ${APACHE2_MOD_CONF}
231 einfo "Configuration file installed as"
232 einfo " ${APACHE_MODULES_CONFDIR}/$(basename ${2:-$1}).conf"
233 einfo "You may want to edit it before turning the module on in /etc/conf.d/apache2"
238 EXPORT_FUNCTIONS src_compile src_install pkg_postinst