1 # Copyright 1999-2011 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: apache-module.eclass
7 # apache-devs@gentoo.org
8 # @BLURB: Provides a common set of functions for apache modules
10 # This eclass handles apache modules in a sane way.
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.
17 # See Bug 107127 for more information.
21 # Here is a simple example of an ebuild for mod_foo:
24 # APACHE2_MOD_CONF="42_mod_foo"
25 # APACHE2_MOD_DEFINE="FOO"
29 # A more complicated example for a module with non-standard locations:
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"
40 # A basic module configuration which just loads the module into apache:
44 # LoadModule foo_module modules/mod_foo.so
50 # ==============================================================================
52 # ==============================================================================
56 # Path to temporary build directory. (Defaults to `${S}/src' if it exists,
59 # @VARIABLE: APXS2_ARGS
61 # Arguments to pass to the apxs tool. (Defaults to `-c ${PN}.c')
63 # @VARIABLE: APACHE2_EXECFILES
65 # List of files that will be installed into ${APACHE_MODULE_DIR} beside
66 # ${APACHE2_MOD_FILE}. In addition, this function also sets the executable
67 # permission on those files.
69 # @VARIABLE: APACHE2_MOD_CONF
71 # Module configuration file installed by src_install (minus the .conf suffix and
72 # relative to ${FILESDIR}).
74 # @VARIABLE: APACHE2_MOD_DEFINE
76 # Name of define (e.g. FOO) to use in conditional loading of the installed
77 # module/its config file, multiple defines should be space separated.
79 # @VARIABLE: APACHE2_MOD_FILE
81 # Name of the module that src_install installs minus the .so suffix. (Defaults
82 # to `${APXS2_S}/.libs/${PN}.so')
84 # @VARIABLE: APACHE2_VHOST_CONF
86 # Virtual host configuration file installed by src_install (minus the .conf
87 # suffix and relative to ${FILESDIR}).
91 # If the exported src_install() is being used, and ${DOCFILES} is non-zero, some
92 # sed-fu is applied to split out html documentation (if any) from normal
93 # documentation, and dodoc'd or dohtml'd.
95 # ==============================================================================
97 # ==============================================================================
99 # Internal function to construct the default ${APXS2_S} path if required.
101 debug-print-function $FUNCNAME $*
103 local CD_DIR="${APXS2_S}"
105 if [[ -z "${CD_DIR}" ]] ; then
106 if [[ -d "${S}/src" ]] ; then
113 debug-print $FUNCNAME "CD_DIR=${CD_DIR}"
117 # Internal function to construct the default ${APACHE2_MOD_FILE} if required.
119 debug-print-function $FUNCNAME $*
121 local MOD_FILE="${APACHE2_MOD_FILE:-$(apache_cd_dir)/.libs/${PN}.so}"
123 debug-print $FUNCNAME "MOD_FILE=${MOD_FILE}"
127 # Internal function for picking out html files from ${DOCFILES}. It takes an
128 # optional first argument `html'; if the first argument is equals `html', only
129 # html files are returned, otherwise normal (non-html) docs are returned.
131 debug-print-function $FUNCNAME $*
135 if [[ -n "${DOCFILES}" ]] ; then
136 if [[ "x$1" == "xhtml" ]] ; then
137 DOCS="`echo ${DOCFILES} | sed -e 's/ /\n/g' | sed -e '/^[^ ]*.html$/ !d'`"
139 DOCS="`echo ${DOCFILES} | sed 's, *[^ ]*\+.html, ,g'`"
143 debug-print $FUNCNAME "DOCS=${DOCS}"
147 # ==============================================================================
149 # ==============================================================================
151 # @FUNCTION: apache-module_src_compile
153 # The default action is to call ${APXS} with the value of ${APXS2_ARGS}. If a
154 # module requires a different build setup than this, use ${APXS} in your own
155 # src_compile routine.
156 apache-module_src_compile() {
157 debug-print-function $FUNCNAME $*
159 local CD_DIR=$(apache_cd_dir)
160 cd "${CD_DIR}" || die "cd ${CD_DIR} failed"
162 APXS2_ARGS="${APXS2_ARGS:--c ${PN}.c}"
163 ${APXS} ${APXS2_ARGS} || die "${APXS} ${APXS2_ARGS} failed"
166 # @FUNCTION: apache-module_src_install
168 # This installs the files into apache's directories. The module is installed
169 # from a directory chosen as above (apache_cd_dir). In addition, this function
170 # can also set the executable permission on files listed in
171 # ${APACHE2_EXECFILES}. The configuration file name is listed in
172 # ${APACHE2_MOD_CONF} without the .conf extensions, so if you configuration is
173 # 55_mod_foo.conf, APACHE2_MOD_CONF would be 55_mod_foo. ${DOCFILES} contains
174 # the list of files you want filed as documentation.
175 apache-module_src_install() {
176 debug-print-function $FUNCNAME $*
178 local CD_DIR=$(apache_cd_dir)
179 pushd "${CD_DIR}" >/dev/null || die "cd ${CD_DIR} failed"
181 local MOD_FILE=$(apache_mod_file)
183 exeinto "${APACHE_MODULESDIR}"
184 doexe ${MOD_FILE} || die "internal ebuild error: '${MOD_FILE}' not found"
185 [[ -n "${APACHE2_EXECFILES}" ]] && doexe ${APACHE2_EXECFILES}
187 if [[ -n "${APACHE2_MOD_CONF}" ]] ; then
188 insinto "${APACHE_MODULES_CONFDIR}"
189 set -- ${APACHE2_MOD_CONF}
190 newins "${FILESDIR}/${1}.conf" "$(basename ${2:-$1}).conf" \
191 || die "internal ebuild error: '${FILESDIR}/${1}.conf' not found"
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"
203 if [[ -n "${DOCFILES}" ]] ; then
204 local OTHER_DOCS=$(apache_doc_magic)
205 local HTML_DOCS=$(apache_doc_magic html)
207 [[ -n "${OTHER_DOCS}" ]] && dodoc ${OTHER_DOCS}
208 [[ -n "${HTML_DOCS}" ]] && dohtml ${HTML_DOCS}
214 # @FUNCTION: apache-module_pkg_postinst
216 # This prints out information about the installed module and how to enable it.
217 apache-module_pkg_postinst() {
218 debug-print-function $FUNCNAME $*
220 if [[ -n "${APACHE2_MOD_DEFINE}" ]] ; then
221 local my_opts="-D ${APACHE2_MOD_DEFINE// / -D }"
224 einfo "To enable ${PN}, you need to edit your /etc/conf.d/apache2 file and"
225 einfo "add '${my_opts}' to APACHE2_OPTS."
229 if [[ -n "${APACHE2_MOD_CONF}" ]] ; then
230 set -- ${APACHE2_MOD_CONF}
232 einfo "Configuration file installed as"
233 einfo " ${APACHE_MODULES_CONFDIR}/$(basename ${2:-$1}).conf"
234 einfo "You may want to edit it before turning the module on in /etc/conf.d/apache2"
239 EXPORT_FUNCTIONS src_compile src_install pkg_postinst