mail-client/thunderbird: bump to v68.8.1
[gentoo.git] / eclass / apache-module.eclass
1 # Copyright 1999-2011 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: apache-module.eclass
5 # @MAINTAINER:
6 # apache-devs@gentoo.org
7 # @BLURB: Provides a common set of functions for apache modules
8 # @DESCRIPTION:
9 # This eclass handles apache modules in a sane way.
10 #
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.
15 #
16 # See Bug 107127 for more information.
17 #
18 # @EXAMPLE:
19 #
20 # Here is a simple example of an ebuild for mod_foo:
21 #
22 # @CODE
23 # APACHE2_MOD_CONF="42_mod_foo"
24 # APACHE2_MOD_DEFINE="FOO"
25 # need_apache2
26 # @CODE
27 #
28 # A more complicated example for a module with non-standard locations:
29 #
30 # @CODE
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"
36 # need_apache2_2
37 # @CODE
38 #
39 # A basic module configuration which just loads the module into apache:
40 #
41 # @CODE
42 # <IfDefine FOO>
43 # LoadModule foo_module modules/mod_foo.so
44 # </IfDefine>
45 # @CODE
46
47 inherit depend.apache
48
49 # ==============================================================================
50 # PUBLIC VARIABLES
51 # ==============================================================================
52
53 # @VARIABLE: APXS2_S
54 # @DESCRIPTION:
55 # Path to temporary build directory. (Defaults to `${S}/src' if it exists,
56 # `${S}' otherwise)
57
58 # @VARIABLE: APXS2_ARGS
59 # @DESCRIPTION:
60 # Arguments to pass to the apxs tool. (Defaults to `-c ${PN}.c')
61
62 # @VARIABLE: APACHE2_EXECFILES
63 # @DESCRIPTION:
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.
67
68 # @VARIABLE: APACHE2_MOD_CONF
69 # @DESCRIPTION:
70 # Module configuration file installed by src_install (minus the .conf suffix and
71 # relative to ${FILESDIR}).
72
73 # @VARIABLE: APACHE2_MOD_DEFINE
74 # @DESCRIPTION:
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.
77
78 # @VARIABLE: APACHE2_MOD_FILE
79 # @DESCRIPTION:
80 # Name of the module that src_install installs minus the .so suffix. (Defaults
81 # to `${APXS2_S}/.libs/${PN}.so')
82
83 # @VARIABLE: APACHE2_VHOST_CONF
84 # @DESCRIPTION:
85 # Virtual host configuration file installed by src_install (minus the .conf
86 # suffix and relative to ${FILESDIR}).
87
88 # @VARIABLE: DOCFILES
89 # @DESCRIPTION:
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.
93
94 # ==============================================================================
95 # INTERNAL FUNCTIONS
96 # ==============================================================================
97
98 # Internal function to construct the default ${APXS2_S} path if required.
99 apache_cd_dir() {
100         debug-print-function $FUNCNAME $*
101
102         local CD_DIR="${APXS2_S}"
103
104         if [[ -z "${CD_DIR}" ]] ; then
105                 if [[ -d "${S}/src" ]] ; then
106                         CD_DIR="${S}/src"
107                 else
108                         CD_DIR="${S}"
109                 fi
110         fi
111
112         debug-print $FUNCNAME "CD_DIR=${CD_DIR}"
113         echo "${CD_DIR}"
114 }
115
116 # Internal function to construct the default ${APACHE2_MOD_FILE} if required.
117 apache_mod_file() {
118         debug-print-function $FUNCNAME $*
119
120         local MOD_FILE="${APACHE2_MOD_FILE:-$(apache_cd_dir)/.libs/${PN}.so}"
121
122         debug-print $FUNCNAME "MOD_FILE=${MOD_FILE}"
123         echo "${MOD_FILE}"
124 }
125
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.
129 apache_doc_magic() {
130         debug-print-function $FUNCNAME $*
131
132         local DOCS=
133
134         if [[ -n "${DOCFILES}" ]] ; then
135                 if [[ "x$1" == "xhtml" ]] ; then
136                         DOCS="`echo ${DOCFILES} | sed -e 's/ /\n/g' | sed -e '/^[^ ]*.html$/ !d'`"
137                 else
138                         DOCS="`echo ${DOCFILES} | sed 's, *[^ ]*\+.html, ,g'`"
139                 fi
140         fi
141
142         debug-print $FUNCNAME "DOCS=${DOCS}"
143         echo "${DOCS}"
144 }
145
146 # ==============================================================================
147 # EXPORTED FUNCTIONS
148 # ==============================================================================
149
150 # @FUNCTION: apache-module_src_compile
151 # @DESCRIPTION:
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 $*
157
158         local CD_DIR=$(apache_cd_dir)
159         cd "${CD_DIR}" || die "cd ${CD_DIR} failed"
160
161         APXS2_ARGS="${APXS2_ARGS:--c ${PN}.c}"
162         ${APXS} ${APXS2_ARGS} || die "${APXS} ${APXS2_ARGS} failed"
163 }
164
165 # @FUNCTION: apache-module_src_install
166 # @DESCRIPTION:
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 $*
176
177         local CD_DIR=$(apache_cd_dir)
178         pushd "${CD_DIR}" >/dev/null || die "cd ${CD_DIR} failed"
179
180         local MOD_FILE=$(apache_mod_file)
181
182         exeinto "${APACHE_MODULESDIR}"
183         doexe ${MOD_FILE} || die "internal ebuild error: '${MOD_FILE}' not found"
184         [[ -n "${APACHE2_EXECFILES}" ]] && doexe ${APACHE2_EXECFILES}
185
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"
191         fi
192
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"
198         fi
199
200         cd "${S}"
201
202         if [[ -n "${DOCFILES}" ]] ; then
203                 local OTHER_DOCS=$(apache_doc_magic)
204                 local HTML_DOCS=$(apache_doc_magic html)
205
206                 [[ -n "${OTHER_DOCS}" ]] && dodoc ${OTHER_DOCS}
207                 [[ -n "${HTML_DOCS}" ]] && dohtml ${HTML_DOCS}
208         fi
209
210         popd >/dev/null
211 }
212
213 # @FUNCTION: apache-module_pkg_postinst
214 # @DESCRIPTION:
215 # This prints out information about the installed module and how to enable it.
216 apache-module_pkg_postinst() {
217         debug-print-function $FUNCNAME $*
218
219         if [[ -n "${APACHE2_MOD_DEFINE}" ]] ; then
220                 local my_opts="-D ${APACHE2_MOD_DEFINE// / -D }"
221
222                 einfo
223                 einfo "To enable ${PN}, you need to edit your /etc/conf.d/apache2 file and"
224                 einfo "add '${my_opts}' to APACHE2_OPTS."
225                 einfo
226         fi
227
228         if [[ -n "${APACHE2_MOD_CONF}" ]] ; then
229                 set -- ${APACHE2_MOD_CONF}
230                 einfo
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"
234                 einfo
235         fi
236 }
237
238 EXPORT_FUNCTIONS src_compile src_install pkg_postinst