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