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

Contents of /eclass/apache-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations) (download)
Sun Mar 23 00:14:13 2008 UTC (6 years, 5 months ago) by hollow
Branch: MAIN
Changes since 1.8: +11 -16 lines
fix documentation; use confutils eclass

1 # Copyright 1999-2007 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/apache-2.eclass,v 1.8 2008/02/02 10:10:36 hollow Exp $
4
5 # @ECLASS: apache-2
6 # @MAINTAINER: apache-devs@gentoo.org
7 # @BLURB: Provides a common set of functions for >=apache-2.2* ebuilds
8 # @DESCRIPTION:
9 # This eclass handles common apache ebuild functions in a sane way and providing
10 # information about where certain interfaces are located such as LoadModule
11 # generation and inter-module dependency checking.
12
13 inherit autotools confutils eutils flag-o-matic multilib
14
15 # ==============================================================================
16 # INTERNAL VARIABLES
17 # ==============================================================================
18
19 # @ECLASS-VARIABLE: GENTOO_PATCHNAME
20 # @DESCRIPTION:
21 # This internal variable contains the prefix for the patch tarball
22 GENTOO_PATCHNAME="gentoo-${PF}"
23
24 # @ECLASS-VARIABLE: GENTOO_PATCHDIR
25 # @DESCRIPTION:
26 # This internal variable contains the working directory where patches and config
27 # files are located
28 GENTOO_PATCHDIR="${WORKDIR}/${GENTOO_PATCHNAME}"
29
30 # @VARIABLE: GENTOO_DEVELOPER
31 # @DESCRIPTION:
32 # This variable needs to be set in the ebuild and contains the name of the
33 # gentoo developer who created the patch tarball
34
35 # @VARIABLE: GENTOO_PATCHSTAMP
36 # @DESCRIPTION:
37 # This variable needs to be set in the ebuild and contains the date the patch
38 # tarball was created at in YYYYMMDD format
39
40 SRC_URI="mirror://apache/httpd/httpd-${PV}.tar.bz2
41 http://dev.gentoo.org/~${GENTOO_DEVELOPER}/dist/apache/${GENTOO_PATCHNAME}-${GENTOO_PATCHSTAMP}.tar.bz2"
42
43 # @VARIABLE: IUSE_MPMS_FORK
44 # @DESCRIPTION:
45 # This variable needs to be set in the ebuild and contains a list of forking
46 # (i.e. non-threaded) MPMS
47
48 # @VARIABLE: IUSE_MPMS_THREAD
49 # @DESCRIPTION:
50 # This variable needs to be set in the ebuild and contains a list of threaded
51 # MPMS
52
53 # @VARIABLE: IUSE_MODULES
54 # @DESCRIPTION:
55 # This variable needs to be set in the ebuild and contains a list of available
56 # built-in modules
57
58 IUSE_MPMS="${IUSE_MPMS_FORK} ${IUSE_MPMS_THREAD}"
59 IUSE="${IUSE} debug doc ldap selinux ssl static suexec threads"
60
61 for module in ${IUSE_MODULES} ; do
62 IUSE="${IUSE} apache2_modules_${module}"
63 done
64
65 for mpm in ${IUSE_MPMS} ; do
66 IUSE="${IUSE} apache2_mpms_${mpm}"
67 done
68
69 DEPEND="dev-lang/perl
70 =dev-libs/apr-1*
71 =dev-libs/apr-util-1*
72 dev-libs/libpcre
73 ldap? ( =net-nds/openldap-2* )
74 selinux? ( sec-policy/selinux-apache )
75 ssl? ( >=dev-libs/openssl-0.9.8f )
76 !=www-servers/apache-1*"
77 RDEPEND="${DEPEND}"
78 PDEPEND="~app-admin/apache-tools-${PV}"
79
80 S="${WORKDIR}/httpd-${PV}"
81
82 # ==============================================================================
83 # INTERNAL FUNCTIONS
84 # ==============================================================================
85
86 # @ECLASS-VARIABLE: MY_MPM
87 # @DESCRIPTION:
88 # This internal variable contains the selected MPM after a call to setup_mpm()
89
90 # @FUNCTION: setup_mpm
91 # @DESCRIPTION:
92 # This internal function makes sure that only one of APACHE2_MPMS was selected
93 # or a default based on USE=threads is selected if APACHE2_MPMS is empty
94 setup_mpm() {
95 MY_MPM=""
96 for x in ${IUSE_MPMS} ; do
97 if use apache2_mpms_${x} ; then
98 if [[ -z "${MY_MPM}" ]] ; then
99 MY_MPM=${x}
100 elog
101 elog "Selected MPM: ${MY_MPM}"
102 elog
103 else
104 eerror "You have selected more then one mpm USE-flag."
105 eerror "Only one MPM is supported."
106 die "more then one mpm was specified"
107 fi
108 fi
109 done
110
111 if [[ -z "${MY_MPM}" ]] ; then
112 if use threads ; then
113 MY_MPM=worker
114 elog
115 elog "Selected default threaded MPM: ${MY_MPM}"
116 elog
117 else
118 MY_MPM=prefork
119 elog
120 elog "Selected default MPM: ${MY_MPM}"
121 elog
122 fi
123 fi
124
125 if has ${MY_MPM} ${IUSE_MPMS_THREAD} && ! use threads ; then
126 eerror "You have selected a threaded MPM but USE=threads is disabled"
127 die "invalid use flag combination"
128 fi
129
130 if has ${MY_MPM} ${IUSE_MPMS_FORK} && use threads ; then
131 eerror "You have selected a non-threaded MPM but USE=threads is enabled"
132 die "invalid use flag combination"
133 fi
134 }
135
136 # @VARIABLE: MODULE_CRITICAL
137 # @DESCRIPTION:
138 # This variable needs to be set in the ebuild and contains a space-separated
139 # list of modules critical for the default apache. A user may still
140 # disable these modules for custom minimal installation at their own risk.
141
142 # @FUNCTION: check_module_critical
143 # @DESCRIPTION:
144 # This internal function warns the user about modules critical for the default
145 # apache configuration.
146 check_module_critical() {
147 local unsupported=0
148
149 for m in ${MODULE_CRITICAL} ; do
150 if ! has ${m} ${MY_MODS} ; then
151 ewarn "Module '${m}' is required in the default apache configuration."
152 unsupported=1
153 fi
154 done
155
156 if [[ ${unsupported} -ne 0 ]] ; then
157 ewarn
158 ewarn "You have disabled one or more required modules"
159 ewarn "for the default apache configuration."
160 ewarn "Although this is not an error, please be"
161 ewarn "aware that this setup is UNSUPPORTED."
162 ewarn
163 ebeep 10
164 fi
165 }
166
167 # @VARIABLE: MODULE_DEPENDS
168 # @DESCRIPTION:
169 # This variable needs to be set in the ebuild and contains a space-separated
170 # list of dependency tokens each with a module and the module it depends on
171 # separated by a colon
172
173 # @FUNCTION: check_module_depends
174 # @DESCRIPTION:
175 # This internal function makes sure that all inter-module dependencies are
176 # satisfied with the current module selection
177 check_module_depends() {
178 local err=0
179
180 for m in ${MY_MODS} ; do
181 for dep in ${MODULE_DEPENDS} ; do
182 if [[ "${m}" == "${dep%:*}" ]] ; then
183 if ! use apache2_modules_${dep#*:} ; then
184 eerror "Module '${m}' depends on '${dep#*:}'"
185 err=1
186 fi
187 fi
188 done
189 done
190
191 if [[ ${err} -ne 0 ]] ; then
192 die "invalid use flag combination"
193 fi
194 }
195
196 # @ECLASS-VARIABLE: MY_CONF
197 # @DESCRIPTION:
198 # This internal variable contains the econf options for the current module
199 # selection after a call to setup_modules()
200
201 # @ECLASS-VARIABLE: MY_MODS
202 # @DESCRIPTION:
203 # This internal variable contains a sorted, space separated list of currently
204 # selected modules after a call to setup_modules()
205
206 # @FUNCTION: setup_modules
207 # @DESCRIPTION:
208 # This internal function selects all built-in modules based on USE flags and
209 # APACHE2_MODULES USE_EXPAND flags
210 setup_modules() {
211 local mod_type=
212
213 if use static ; then
214 mod_type="static"
215 else
216 mod_type="shared"
217 fi
218
219 MY_CONF="--enable-so=static"
220
221 if use ldap ; then
222 confutils_use_depend_built_with_all ldap dev-libs/apr-util ldap
223 MY_CONF="${MY_CONF} --enable-authnz_ldap=${mod_type} --enable-ldap=${mod_type}"
224 MY_MODS="${MY_MODS} ldap authnz_ldap"
225 else
226 MY_CONF="${MY_CONF} --disable-authnz_ldap --disable-ldap"
227 fi
228
229 if use ssl ; then
230 MY_CONF="${MY_CONF} --with-ssl=/usr --enable-ssl=${mod_type}"
231 MY_MODS="${MY_MODS} ssl"
232 else
233 MY_CONF="${MY_CONF} --without-ssl --disable-ssl"
234 fi
235
236 if use threads || has ${MY_MPM} ${IUSE_MPMS_THREAD} ; then
237 MY_CONF="${MY_CONF} --enable-cgid=${mod_type}"
238 MY_MODS="${MY_MODS} cgid"
239 else
240 MY_CONF="${MY_CONF} --enable-cgi=${mod_type}"
241 MY_MODS="${MY_MODS} cgi"
242 fi
243
244 if use suexec ; then
245 elog "You can manipulate several configure options of suexec"
246 elog "through the following environment variables:"
247 elog
248 elog " SUEXEC_SAFEPATH: Default PATH for suexec (default: /usr/local/bin:/usr/bin:/bin)"
249 elog " SUEXEC_LOGFILE: Path to the suexec logfile (default: /var/log/apache2/suexec_log)"
250 elog " SUEXEC_CALLER: Name of the user Apache is running as (default: apache)"
251 elog " SUEXEC_DOCROOT: Directory in which suexec will run scripts (default: /var/www)"
252 elog " SUEXEC_MINUID: Minimum UID, which is allowed to run scripts via suexec (default: 1000)"
253 elog " SUEXEC_MINGID: Minimum GID, which is allowed to run scripts via suexec (default: 100)"
254 elog " SUEXEC_USERDIR: User subdirectories (like /home/user/html) (default: public_html)"
255 elog " SUEXEC_UMASK: Umask for the suexec process (default: 077)"
256 elog
257
258 MY_CONF="${MY_CONF} --with-suexec-safepath=${SUEXEC_SAFEPATH:-/usr/local/bin:/usr/bin:/bin}"
259 MY_CONF="${MY_CONF} --with-suexec-logfile=${SUEXEC_LOGFILE:-/var/log/apache2/suexec_log}"
260 MY_CONF="${MY_CONF} --with-suexec-bin=/usr/sbin/suexec"
261 MY_CONF="${MY_CONF} --with-suexec-userdir=${SUEXEC_USERDIR:-public_html}"
262 MY_CONF="${MY_CONF} --with-suexec-caller=${SUEXEC_CALLER:-apache}"
263 MY_CONF="${MY_CONF} --with-suexec-docroot=${SUEXEC_DOCROOT:-/var/www}"
264 MY_CONF="${MY_CONF} --with-suexec-uidmin=${SUEXEC_MINUID:-1000}"
265 MY_CONF="${MY_CONF} --with-suexec-gidmin=${SUEXEC_MINGID:-100}"
266 MY_CONF="${MY_CONF} --with-suexec-umask=${SUEXEC_UMASK:-077}"
267 MY_CONF="${MY_CONF} --enable-suexec=${mod_type}"
268 MY_MODS="${MY_MODS} suexec"
269 else
270 MY_CONF="${MY_CONF} --disable-suexec"
271 fi
272
273 for x in ${IUSE_MODULES} ; do
274 if use apache2_modules_${x} ; then
275 MY_CONF="${MY_CONF} --enable-${x}=${mod_type}"
276 MY_MODS="${MY_MODS} ${x}"
277 else
278 MY_CONF="${MY_CONF} --disable-${x}"
279 fi
280 done
281
282 # sort and uniquify MY_MODS
283 MY_MODS=$(echo ${MY_MODS} | tr ' ' '\n' | sort -u)
284 check_module_depends
285 check_module_critical
286 }
287
288 # @VARIABLE: MODULE_DEFINES
289 # @DESCRIPTION:
290 # This variable needs to be set in the ebuild and contains a space-separated
291 # list of tokens each mapping a module to a runtime define which can be
292 # specified in APACHE2_OPTS in /etc/conf.d/apache2 to enable this particular
293 # module.
294
295 # @FUNCTION: generate_load_module
296 # @DESCRIPTION:
297 # This internal function generates the LoadModule lines for httpd.conf based on
298 # the current module selection and MODULE_DEFINES
299 generate_load_module() {
300 local endit=0 mod_lines= mod_dir="${D}/usr/$(get_libdir)/apache2/modules"
301
302 if use static; then
303 sed -i -e "/%%LOAD_MODULE%%/d" \
304 "${GENTOO_PATCHDIR}"/conf/httpd.conf
305 return
306 fi
307
308 for m in ${MY_MODS} ; do
309 if [[ -e "${mod_dir}/mod_${m}.so" ]] ; then
310 for def in ${MODULE_DEFINES} ; do
311 if [[ "${m}" == "${def%:*}" ]] ; then
312 mod_lines="${mod_lines}\n<IfDefine ${def#*:}>"
313 endit=1
314 fi
315 done
316
317 mod_lines="${mod_lines}\nLoadModule ${m}_module modules/mod_${m}.so"
318
319 if [[ ${endit} -ne 0 ]] ; then
320 mod_lines="${mod_lines}\n</IfDefine>"
321 endit=0
322 fi
323 fi
324 done
325
326 sed -i -e "s:%%LOAD_MODULE%%:${mod_lines}:" \
327 "${GENTOO_PATCHDIR}"/conf/httpd.conf
328 }
329
330 # @FUNCTION: check_upgrade
331 # @DESCRIPTION:
332 # This internal function checks if the previous configuration file for built-in
333 # modules exists in ROOT and prevents upgrade in this case. Users are supposed
334 # to convert this file to the new APACHE2_MODULES USE_EXPAND variable and remove
335 # it afterwards.
336 check_upgrade() {
337 if [[ -e "${ROOT}"etc/apache2/apache2-builtin-mods ]]; then
338 eerror "The previous configuration file for built-in modules"
339 eerror "(${ROOT}etc/apache2/apache2-builtin-mods) exists on your"
340 eerror "system."
341 eerror
342 eerror "Please read http://www.gentoo.org/doc/en/apache-upgrading.xml"
343 eerror "for detailed information how to convert this file to the new"
344 eerror "APACHE2_MODULES USE_EXPAND variable."
345 eerror
346 die "upgrade not possible with existing ${ROOT}etc/apache2/apache2-builtin-mods"
347 fi
348 }
349
350 # ==============================================================================
351 # EXPORTED FUNCTIONS
352 # ==============================================================================
353
354 # @FUNCTION: apache-2_pkg_setup
355 # @DESCRIPTION:
356 # This function selects built-in modules, the MPM and other configure options,
357 # creates the apache user and group and informs about CONFIG_SYSVIPC being
358 # needed (we don't depend on kernel sources and therefore cannot check).
359 apache-2_pkg_setup() {
360 check_upgrade
361
362 setup_mpm
363 setup_modules
364
365 if use debug; then
366 MY_CONF="${MY_CONF} --enable-maintainer-mode --enable-exception-hook"
367 fi
368
369 # setup apache user and group
370 enewgroup apache 81
371 enewuser apache 81 -1 /var/www apache
372
373 elog "Please note that you need SysV IPC support in your kernel."
374 elog "Make sure CONFIG_SYSVIPC=y is set."
375 elog
376 }
377
378 # @FUNCTION: apache-2_src_unpack
379 # @DESCRIPTION:
380 # This function applies patches, configures a custom file-system layout and
381 # rebuilds the configure scripts.
382 apache-2_src_unpack() {
383 unpack ${A}
384 cd "${S}"
385
386 # Use correct multilib libdir in gentoo patches
387 sed -i -e "s:/usr/lib:/usr/$(get_libdir):g" \
388 "${GENTOO_PATCHDIR}"/{conf/httpd.conf,init/*,patches/config.layout} \
389 || die "libdir sed failed"
390
391 epatch "${GENTOO_PATCHDIR}"/patches/*.patch
392
393 # setup the filesystem layout config
394 cat "${GENTOO_PATCHDIR}"/patches/config.layout >> "${S}"/config.layout || \
395 die "Failed preparing config.layout!"
396 sed -i -e "s:version:${PF}:g" "${S}"/config.layout
397
398 # apache2.8 instead of httpd.8 (bug #194828)
399 mv docs/man/{httpd,apache2}.8
400 sed -i -e 's/httpd\.8/apache2.8/g' Makefile.in
401
402 # patched-in MPMs need the build environment rebuilt
403 sed -i -e '/sinclude/d' configure.in
404 AT_GNUCONF_UPDATE=yes AT_M4DIR=build eautoreconf
405 }
406
407 # @FUNCTION: apache-2_src_compile
408 # @DESCRIPTION:
409 # This function adds compiler flags and runs econf and emake based on MY_MPM and
410 # MY_CONF
411 apache-2_src_compile() {
412 # Instead of filtering --as-needed (bug #128505), append --no-as-needed
413 # Thanks to Harald van Dijk
414 append-ldflags -Wl,--no-as-needed
415
416 # peruser MPM debugging with -X is nearly impossible
417 if has peruser ${IUSE_MPMS} && use apache2_mpms_peruser ; then
418 use debug && append-flags -DMPM_PERUSER_DEBUG
419 fi
420
421 # econf overwrites the stuff from config.layout, so we have to put them into
422 # our myconf line too
423 econf \
424 --includedir=/usr/include/apache2 \
425 --libexecdir=/usr/$(get_libdir)/apache2/modules \
426 --datadir=/var/www/localhost \
427 --sysconfdir=/etc/apache2 \
428 --localstatedir=/var \
429 --with-mpm=${MY_MPM} \
430 --with-perl=/usr/bin/perl \
431 --with-apr=/usr \
432 --with-apr-util=/usr \
433 --with-pcre=/usr \
434 --with-z=/usr \
435 --with-port=80 \
436 --with-program-name=apache2 \
437 --enable-layout=Gentoo \
438 ${MY_CONF} || die "econf failed!"
439
440 sed -i -e 's:apache2\.conf:httpd.conf:' include/ap_config_auto.h
441
442 emake || die "emake failed"
443 }
444
445 # @FUNCTION: apache-2_src_install
446 # @DESCRIPTION:
447 # This function runs emake install and generates, installs and adapts the gentoo
448 # specific configuration files found in the tarball
449 apache-2_src_install() {
450 make DESTDIR="${D}" install || die "make install failed"
451
452 # install our configuration files
453 keepdir /etc/apache2/vhosts.d
454 keepdir /etc/apache2/modules.d
455
456 generate_load_module
457 insinto /etc/apache2
458 doins -r "${GENTOO_PATCHDIR}"/conf/*
459 doins docs/conf/magic
460
461 insinto /etc/logrotate.d
462 newins "${GENTOO_PATCHDIR}"/scripts/apache2-logrotate apache2
463
464 # generate a sane default APACHE2_OPTS
465 APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D LANGUAGE"
466 use doc && APACHE2_OPTS="${APACHE2_OPTS} -D MANUAL"
467 use ssl && APACHE2_OPTS="${APACHE2_OPTS} -D SSL -D SSL_DEFAULT_VHOST"
468 use suexec && APACHE2_OPTS="${APACHE2_OPTS} -D SUEXEC"
469
470 sed -i -e "s:APACHE2_OPTS=\".*\":APACHE2_OPTS=\"${APACHE2_OPTS}\":" \
471 "${GENTOO_PATCHDIR}"/init/apache2.confd || die "sed failed"
472
473 newconfd "${GENTOO_PATCHDIR}"/init/apache2.confd apache2
474 newinitd "${GENTOO_PATCHDIR}"/init/apache2.initd apache2
475
476 # link apache2ctl to the init script
477 dosym /etc/init.d/apache2 /usr/sbin/apache2ctl
478
479 # provide legacy symlink for apxs, bug 177697
480 dosym /usr/sbin/apxs /usr/sbin/apxs2
481
482 # install some thirdparty scripts
483 exeinto /usr/sbin
484 use ssl && doexe "${GENTOO_PATCHDIR}"/scripts/gentestcrt.sh
485
486 # install some documentation
487 dodoc ABOUT_APACHE CHANGES LAYOUT README README.platforms VERSIONING
488 dodoc "${GENTOO_PATCHDIR}"/docs/*
489
490 # drop in a convenient link to the manual
491 if use doc ; then
492 sed -i -e "s:VERSION:${PVR}:" "${D}/etc/apache2/modules.d/00_apache_manual.conf"
493 else
494 rm -f "${D}/etc/apache2/modules.d/00_apache_manual.conf"
495 rm -Rf "${D}/usr/share/doc/${PF}/manual"
496 fi
497
498 # the default webroot gets stored in /usr/share/doc
499 ebegin "Installing default webroot to /usr/share/doc/${PF}"
500 mv -f "${D}/var/www/localhost" "${D}/usr/share/doc/${PF}/webroot"
501 eend $?
502 keepdir /var/www/localhost/htdocs
503
504 # set some sane permissions for suexec
505 if use suexec ; then
506 fowners 0:apache /usr/sbin/suexec
507 fperms 4710 /usr/sbin/suexec
508 # provide legacy symlink for suexec, bug 177697
509 dosym /usr/sbin/suexec /usr/sbin/suexec2
510 fi
511
512 # empty dirs
513 for i in /var/lib/dav /var/log/apache2 /var/cache/apache2 ; do
514 keepdir ${i}
515 fowners apache:apache ${i}
516 fperms 0755 ${i}
517 done
518
519 # we need /etc/apache2/ssl if USE=ssl
520 use ssl && keepdir /etc/apache2/ssl
521 }
522
523 # @FUNCTION: apache-2_pkg_postinst
524 # @DESCRIPTION:
525 # This function creates test certificates if SSL is enabled and installs the
526 # default webroot if /var/www/localhost does not exist. We do this here because
527 # the default webroot is a copy of the files that exist elsewhere and we don't
528 # want them to be managed/removed by portage when apache is upgraded.
529 apache-2_pkg_postinst() {
530 if use ssl && [[ ! -e "${ROOT}/etc/apache2/ssl/server.crt" ]] ; then
531 cd "${ROOT}"/etc/apache2/ssl
532 einfo
533 einfo "Generating self-signed test certificate in ${ROOT}etc/apache2/ssl ..."
534 yes "" 2>/dev/null | \
535 "${ROOT}"/usr/sbin/gentestcrt.sh >/dev/null 2>&1 || \
536 die "gentestcrt.sh failed"
537 einfo
538 fi
539
540 if [[ -e "${ROOT}/var/www/localhost" ]] ; then
541 elog "The default webroot has not been installed into"
542 elog "${ROOT}var/www/localhost because the directory already exists"
543 elog "and we do not want to overwrite any files you have put there."
544 elog
545 elog "If you would like to install the latest webroot, please run"
546 elog "emerge --config =${PF}"
547 elog
548 else
549 einfo "Installing default webroot to ${ROOT}var/www/localhost"
550 mkdir -p "${ROOT}"/var/www/localhost
551 cp -R "${ROOT}"/usr/share/doc/${PF}/webroot/* "${ROOT}"/var/www/localhost
552 chown -R apache:0 "${ROOT}"/var/www/localhost
553 fi
554 }
555
556 # @FUNCTION: apache-2_pkg_config
557 # @DESCRIPTION:
558 # This function installs -- and removes a previously existing -- default webroot
559 # to /var/www/localhost
560 apache-2_pkg_config() {
561 einfo "Installing default webroot to ${ROOT}var/www/localhost"
562 mkdir "${ROOT}"var{,/www{,/localhost}}
563 cp -R "${ROOT}"usr/share/doc/${PF}/webroot/* "${ROOT}"var/www/localhost/
564 }
565
566 EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_install pkg_postinst pkg_config

  ViewVC Help
Powered by ViewVC 1.1.20