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

Contents of /eclass/apache-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download)
Mon Dec 31 23:46:24 2007 UTC (6 years, 6 months ago) by hollow
Branch: MAIN
Changes since 1.4: +2 -2 lines
fix #202722

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.4 2007/12/20 15:53:19 zmedico 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 depend.apache eutils flag-o-matic multilib autotools
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 # @ECLASS-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 # @ECLASS-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 YYMMDD 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 # @ECLASS-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 # @ECLASS-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 # @ECLASS-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 )
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 # @ECLASS-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 # @ECLASS-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 if ! built_with_use 'dev-libs/apr-util' ldap ; then
223 eerror "dev-libs/apr-util is missing LDAP support. For apache to have"
224 eerror "ldap support, apr-util must be built with the ldap USE-flag"
225 eerror "enabled."
226 die "ldap USE-flag enabled while not supported in apr-util"
227 fi
228 MY_CONF="${MY_CONF} --enable-authnz_ldap=${mod_type} --enable-ldap=${mod_type}"
229 MY_MODS="${MY_MODS} ldap authnz_ldap"
230 else
231 MY_CONF="${MY_CONF} --disable-authnz_ldap --disable-ldap"
232 fi
233
234 if use ssl ; then
235 MY_CONF="${MY_CONF} --with-ssl=/usr --enable-ssl=${mod_type}"
236 MY_MODS="${MY_MODS} ssl"
237 else
238 MY_CONF="${MY_CONF} --without-ssl --disable-ssl"
239 fi
240
241 if use threads || has ${MY_MPM} ${IUSE_MPMS_THREAD} ; then
242 MY_CONF="${MY_CONF} --enable-cgid=${mod_type}"
243 MY_MODS="${MY_MODS} cgid"
244 else
245 MY_CONF="${MY_CONF} --enable-cgi=${mod_type}"
246 MY_MODS="${MY_MODS} cgi"
247 fi
248
249 if use suexec ; then
250 elog "You can manipulate several configure options of suexec"
251 elog "through the following environment variables:"
252 elog
253 elog " SUEXEC_SAFEPATH: Default PATH for suexec (default: /usr/local/bin:/usr/bin:/bin)"
254 elog " SUEXEC_LOGFILE: Path to the suexec logfile (default: /var/log/apache2/suexec_log)"
255 elog " SUEXEC_CALLER: Name of the user Apache is running as (default: apache)"
256 elog " SUEXEC_DOCROOT: Directory in which suexec will run scripts (default: /var/www)"
257 elog " SUEXEC_MINUID: Minimum UID, which is allowed to run scripts via suexec (default: 1000)"
258 elog " SUEXEC_MINGID: Minimum GID, which is allowed to run scripts via suexec (default: 100)"
259 elog " SUEXEC_USERDIR: User subdirectories (like /home/user/html) (default: public_html)"
260 elog " SUEXEC_UMASK: Umask for the suexec process (default: 077)"
261 elog
262
263 MY_CONF="${MY_CONF} --with-suexec-safepath=${SUEXEC_SAFEPATH:-/usr/local/bin:/usr/bin:/bin}"
264 MY_CONF="${MY_CONF} --with-suexec-logfile=${SUEXEC_LOGFILE:-/var/log/apache2/suexec_log}"
265 MY_CONF="${MY_CONF} --with-suexec-bin=/usr/sbin/suexec"
266 MY_CONF="${MY_CONF} --with-suexec-userdir=${SUEXEC_USERDIR:-public_html}"
267 MY_CONF="${MY_CONF} --with-suexec-caller=${SUEXEC_CALLER:-apache}"
268 MY_CONF="${MY_CONF} --with-suexec-docroot=${SUEXEC_DOCROOT:-/var/www}"
269 MY_CONF="${MY_CONF} --with-suexec-uidmin=${SUEXEC_MINUID:-1000}"
270 MY_CONF="${MY_CONF} --with-suexec-gidmin=${SUEXEC_MINGID:-100}"
271 MY_CONF="${MY_CONF} --with-suexec-umask=${SUEXEC_UMASK:-077}"
272 MY_CONF="${MY_CONF} --enable-suexec=${mod_type}"
273 MY_MODS="${MY_MODS} suexec"
274 else
275 MY_CONF="${MY_CONF} --disable-suexec"
276 fi
277
278 for x in ${IUSE_MODULES} ; do
279 if use apache2_modules_${x} ; then
280 MY_CONF="${MY_CONF} --enable-${x}=${mod_type}"
281 MY_MODS="${MY_MODS} ${x}"
282 else
283 MY_CONF="${MY_CONF} --disable-${x}"
284 fi
285 done
286
287 # sort and uniquify MY_MODS
288 MY_MODS=$(echo ${MY_MODS} | tr ' ' '\n' | sort -u)
289 check_module_depends
290 check_module_critical
291 }
292
293 # @ECLASS-VARIABLE: MODULE_DEFINES
294 # @DESCRIPTION:
295 # This variable needs to be set in the ebuild and contains a space-separated
296 # list of tokens each mapping a module to a runtime define which can be
297 # specified in APACHE2_OPTS in /etc/conf.d/apache2 to enable this particular
298 # module.
299
300 # @FUNCTION: generate_load_module
301 # @DESCRIPTION:
302 # This internal function generates the LoadModule lines for httpd.conf based on
303 # the current module selection and MODULE_DEFINES
304 generate_load_module() {
305 local endit=0 mod_lines= mod_dir="${D}${APACHE2_MODULESDIR}"
306
307 if use static; then
308 sed -i -e "/%%LOAD_MODULE%%/d" \
309 "${GENTOO_PATCHDIR}"/conf/httpd.conf
310 return
311 fi
312
313 for m in ${MY_MODS} ; do
314 if [[ -e "${mod_dir}/mod_${m}.so" ]] ; then
315 for def in ${MODULE_DEFINES} ; do
316 if [[ "${m}" == "${def%:*}" ]] ; then
317 mod_lines="${mod_lines}\n<IfDefine ${def#*:}>"
318 endit=1
319 fi
320 done
321
322 mod_lines="${mod_lines}\nLoadModule ${m}_module modules/mod_${m}.so"
323
324 if [[ ${endit} -ne 0 ]] ; then
325 mod_lines="${mod_lines}\n</IfDefine>"
326 endit=0
327 fi
328 fi
329 done
330
331 sed -i -e "s:%%LOAD_MODULE%%:${mod_lines}:" \
332 "${GENTOO_PATCHDIR}"/conf/httpd.conf
333 }
334
335 # @FUNCTION: check_upgrade
336 # @DESCRIPTION:
337 # This internal function checks if the previous configuration file for built-in
338 # modules exists in ROOT and prevents upgrade in this case. Users are supposed
339 # to convert this file to the new APACHE2_MODULES USE_EXPAND variable and remove
340 # it afterwards.
341 check_upgrade() {
342 if [[ -e "${ROOT}"etc/apache2/apache2-builtin-mods ]]; then
343 eerror "The previous configuration file for built-in modules"
344 eerror "(${ROOT}etc/apache2/apache2-builtin-mods) exists on your"
345 eerror "system."
346 eerror
347 eerror "Please read http://www.gentoo.org/doc/en/apache-upgrading.xml"
348 eerror "for detailed information how to convert this file to the new"
349 eerror "APACHE2_MODULES USE_EXPAND variable."
350 eerror
351 die "upgrade not possible with existing ${ROOT}etc/apache2/apache2-builtin-mods"
352 fi
353 }
354
355 # ==============================================================================
356 # EXPORTED FUNCTIONS
357 # ==============================================================================
358
359 # @FUNCTION: apache-2_pkg_setup
360 # @DESCRIPTION:
361 # This function selects built-in modules, the MPM and other configure options,
362 # creates the apache user and group and informs about CONFIG_SYSVIPC being
363 # needed (we don't depend on kernel sources and therefore cannot check).
364 apache-2_pkg_setup() {
365 check_upgrade
366
367 setup_mpm
368 setup_modules
369
370 if use debug; then
371 MY_CONF="${MY_CONF} --enable-maintainer-mode --enable-exception-hook"
372 fi
373
374 # setup apache user and group
375 enewgroup apache 81
376 enewuser apache 81 -1 /var/www apache
377
378 elog "Please note that you need SysV IPC support in your kernel."
379 elog "Make sure CONFIG_SYSVIPC=y is set."
380 elog
381 }
382
383 # @FUNCTION: apache-2_src_unpack
384 # @DESCRIPTION:
385 # This function applies patches, configures a custom file-system layout and
386 # rebuilds the configure scripts.
387 apache-2_src_unpack() {
388 unpack ${A}
389 cd "${S}"
390
391 # Use correct multilib libdir in gentoo patches
392 sed -i -e "s:/usr/lib:/usr/$(get_libdir):g" \
393 "${GENTOO_PATCHDIR}"/{conf/httpd.conf,init/*,patches/config.layout} \
394 || die "libdir sed failed"
395
396 epatch "${GENTOO_PATCHDIR}"/patches/*.patch
397
398 # setup the filesystem layout config
399 cat "${GENTOO_PATCHDIR}"/patches/config.layout >> "${S}"/config.layout || \
400 die "Failed preparing config.layout!"
401 sed -i -e "s:version:${PF}:g" "${S}"/config.layout
402
403 # apache2.8 instead of httpd.8 (bug #194828)
404 mv docs/man/{httpd,apache2}.8
405 sed -i -e 's/httpd\.8/apache2.8/g' Makefile.in
406
407 # patched-in MPMs need the build environment rebuilt
408 sed -i -e '/sinclude/d' configure.in
409 AT_GNUCONF_UPDATE=yes AT_M4DIR=build eautoreconf
410 }
411
412 # @FUNCTION: apache-2_src_compile
413 # @DESCRIPTION:
414 # This function adds compiler flags and runs econf and emake based on MY_MPM and
415 # MY_CONF
416 apache-2_src_compile() {
417 # Instead of filtering --as-needed (bug #128505), append --no-as-needed
418 # Thanks to Harald van Dijk
419 append-ldflags -Wl,--no-as-needed
420
421 # peruser MPM debugging with -X is nearly impossible
422 if has peruser ${IUSE_MPMS} && use apache2_mpms_peruser ; then
423 use debug && append-flags -DMPM_PERUSER_DEBUG
424 fi
425
426 # econf overwrites the stuff from config.layout, so we have to put them into
427 # our myconf line too
428 econf \
429 --includedir=/usr/include/apache2 \
430 --libexecdir=/usr/$(get_libdir)/apache2/modules \
431 --datadir=/var/www/localhost \
432 --sysconfdir=/etc/apache2 \
433 --localstatedir=/var \
434 --with-mpm=${MY_MPM} \
435 --with-perl=/usr/bin/perl \
436 --with-apr=/usr \
437 --with-apr-util=/usr \
438 --with-pcre=/usr \
439 --with-z=/usr \
440 --with-port=80 \
441 --with-program-name=apache2 \
442 --enable-layout=Gentoo \
443 ${MY_CONF} || die "econf failed!"
444
445 sed -i -e 's:apache2\.conf:httpd.conf:' include/ap_config_auto.h
446
447 emake || die "emake failed"
448 }
449
450 # @FUNCTION: apache-2_src_install
451 # @DESCRIPTION:
452 # This function runs emake install and generates, install and adapts the gentoo
453 # specific configuration files found in the tarball
454 apache-2_src_install() {
455 make DESTDIR="${D}" install || die "make install failed"
456
457 # install our configuration files
458 keepdir /etc/apache2/vhosts.d
459 keepdir /etc/apache2/modules.d
460
461 generate_load_module
462 insinto /etc/apache2
463 doins -r "${GENTOO_PATCHDIR}"/conf/*
464 doins docs/conf/magic
465
466 insinto /etc/logrotate.d
467 newins "${GENTOO_PATCHDIR}"/scripts/apache2-logrotate apache2
468
469 # generate a sane default APACHE2_OPTS
470 APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D LANGUAGE"
471 use doc && APACHE2_OPTS="${APACHE2_OPTS} -D MANUAL"
472 use ssl && APACHE2_OPTS="${APACHE2_OPTS} -D SSL -D SSL_DEFAULT_VHOST"
473 use suexec && APACHE2_OPTS="${APACHE2_OPTS} -D SUEXEC"
474
475 sed -i -e "s:APACHE2_OPTS=\".*\":APACHE2_OPTS=\"${APACHE2_OPTS}\":" \
476 "${GENTOO_PATCHDIR}"/init/apache2.confd || die "sed failed"
477
478 newconfd "${GENTOO_PATCHDIR}"/init/apache2.confd apache2
479 newinitd "${GENTOO_PATCHDIR}"/init/apache2.initd apache2
480
481 # link apache2ctl to the init script
482 dosym /etc/init.d/apache2 /usr/sbin/apache2ctl
483
484 # provide symlinks for all the stuff we no longer rename, bug 177697
485 for i in suexec apxs; do
486 dosym /usr/sbin/${i} /usr/sbin/${i}2
487 done
488
489 # install some thirdparty scripts
490 exeinto /usr/sbin
491 use ssl && doexe "${GENTOO_PATCHDIR}"/scripts/gentestcrt.sh
492
493 # install some documentation
494 dodoc ABOUT_APACHE CHANGES LAYOUT README README.platforms VERSIONING
495 dodoc "${GENTOO_PATCHDIR}"/docs/*
496
497 # drop in a convenient link to the manual
498 if use doc ; then
499 sed -i -e "s:VERSION:${PVR}:" "${D}/etc/apache2/modules.d/00_apache_manual.conf"
500 else
501 rm -f "${D}/etc/apache2/modules.d/00_apache_manual.conf"
502 rm -Rf "${D}/usr/share/doc/${PF}/manual"
503 fi
504
505 # the default webroot gets stored in /usr/share/doc
506 ebegin "Installing default webroot to /usr/share/doc/${PF}"
507 mv -f "${D}/var/www/localhost" "${D}/usr/share/doc/${PF}/webroot"
508 eend $?
509 keepdir /var/www/localhost/htdocs
510
511 # set some sane permissions for suexec
512 if use suexec ; then
513 fowners 0:apache /usr/sbin/suexec
514 fperms 4710 /usr/sbin/suexec
515 fi
516
517 # empty dirs
518 for i in /var/lib/dav /var/log/apache2 /var/cache/apache2 ; do
519 keepdir ${i}
520 fowners apache:apache ${i}
521 fperms 0755 ${i}
522 done
523
524 # we need /etc/apache2/ssl if USE=ssl
525 use ssl && keepdir /etc/apache2/ssl
526 }
527
528 # @FUNCTION: apache-2_pkg_postinst
529 # @DESCRIPTION:
530 # This function creates test certificates if SSL is enabled and installs the
531 # default webroot if /var/www/localhost does not exist. We do this here because
532 # the default webroot is a copy of the files that exist elsewhere and we don't
533 # want them to be managed/removed by portage when apache is upgraded.
534 apache-2_pkg_postinst() {
535 if use ssl && [[ ! -e "${ROOT}/etc/apache2/ssl/server.crt" ]] ; then
536 cd "${ROOT}"/etc/apache2/ssl
537 einfo
538 einfo "Generating self-signed test certificate in ${ROOT}etc/apache2/ssl ..."
539 yes "" 2>/dev/null | \
540 "${ROOT}"/usr/sbin/gentestcrt.sh >/dev/null 2>&1 || \
541 die "gentestcrt.sh failed"
542 einfo
543 fi
544
545 if [[ -e "${ROOT}/var/www/localhost" ]] ; then
546 elog "The default webroot has not been installed into"
547 elog "${ROOT}var/www/localhost because the directory already exists"
548 elog "and we do not want to overwrite any files you have put there."
549 elog
550 elog "If you would like to install the latest webroot, please run"
551 elog "emerge --config =${PF}"
552 elog
553 else
554 einfo "Installing default webroot to ${ROOT}var/www/localhost"
555 mkdir -p "${ROOT}"/var/www/localhost
556 cp -R "${ROOT}"/usr/share/doc/${PF}/webroot/* "${ROOT}"/var/www/localhost
557 chown -R apache:0 "${ROOT}"/var/www/localhost
558 fi
559 }
560
561 # @FUNCTION: apache-2_pkg_config
562 # @DESCRIPTION:
563 # This function installs -- and removes a previously existing -- default webroot
564 # to /var/www/localhost
565 apache-2_pkg_config() {
566 einfo "Installing default webroot to ${ROOT}var/www/localhost"
567 mkdir "${ROOT}"var{,/www{,/localhost}}
568 cp -R "${ROOT}"usr/share/doc/${PF}/webroot/* "${ROOT}"var/www/localhost/
569 }
570
571 EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_install pkg_postinst pkg_config

  ViewVC Help
Powered by ViewVC 1.1.20