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

Contents of /eclass/apache-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (show annotations) (download)
Sun Mar 23 10:28:45 2008 UTC (6 years, 9 months ago) by hollow
Branch: MAIN
Changes since 1.9: +4 -3 lines
fix documentation syntax

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

  ViewVC Help
Powered by ViewVC 1.1.20