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

Contents of /eclass/apache-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (show annotations) (download)
Fri Aug 29 13:22:21 2008 UTC (5 years, 11 months ago) by hollow
Branch: MAIN
Changes since 1.11: +7 -2 lines
remove unsupported --with-perl; add message for BSD users

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.11 2008/03/23 13:03:53 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.x ebuilds
9 # @DESCRIPTION:
10 # This eclass handles apache-2.x ebuild functions such as LoadModule generation
11 # 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 apache user and group
363 enewgroup apache 81
364 enewuser apache 81 -1 /var/www apache
365
366 setup_mpm
367 setup_modules
368
369 if use debug; then
370 MY_CONF="${MY_CONF} --enable-maintainer-mode --enable-exception-hook"
371 fi
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 if use userland_BSD; then
378 elog "On BSD systems you need to add the following line to /boot/loader.conf:"
379 elog " accf_http_load=\"YES\""
380 elog
381 fi
382 }
383
384 # @FUNCTION: apache-2_src_unpack
385 # @DESCRIPTION:
386 # This function applies patches, configures a custom file-system layout and
387 # rebuilds the configure scripts.
388 apache-2_src_unpack() {
389 unpack ${A}
390 cd "${S}"
391
392 # Use correct multilib libdir in gentoo patches
393 sed -i -e "s:/usr/lib:/usr/$(get_libdir):g" \
394 "${GENTOO_PATCHDIR}"/{conf/httpd.conf,init/*,patches/config.layout} \
395 || die "libdir sed failed"
396
397 epatch "${GENTOO_PATCHDIR}"/patches/*.patch
398
399 # setup the filesystem layout config
400 cat "${GENTOO_PATCHDIR}"/patches/config.layout >> "${S}"/config.layout || \
401 die "Failed preparing config.layout!"
402 sed -i -e "s:version:${PF}:g" "${S}"/config.layout
403
404 # apache2.8 instead of httpd.8 (bug #194828)
405 mv docs/man/{httpd,apache2}.8
406 sed -i -e 's/httpd\.8/apache2.8/g' Makefile.in
407
408 # patched-in MPMs need the build environment rebuilt
409 sed -i -e '/sinclude/d' configure.in
410 AT_GNUCONF_UPDATE=yes AT_M4DIR=build eautoreconf
411 }
412
413 # @FUNCTION: apache-2_src_compile
414 # @DESCRIPTION:
415 # This function adds compiler flags and runs econf and emake based on MY_MPM and
416 # MY_CONF
417 apache-2_src_compile() {
418 # Instead of filtering --as-needed (bug #128505), append --no-as-needed
419 # Thanks to Harald van Dijk
420 append-ldflags -Wl,--no-as-needed
421
422 # peruser MPM debugging with -X is nearly impossible
423 if has peruser ${IUSE_MPMS} && use apache2_mpms_peruser ; then
424 use debug && append-flags -DMPM_PERUSER_DEBUG
425 fi
426
427 # econf overwrites the stuff from config.layout, so we have to put them into
428 # our myconf line too
429 econf \
430 --includedir=/usr/include/apache2 \
431 --libexecdir=/usr/$(get_libdir)/apache2/modules \
432 --datadir=/var/www/localhost \
433 --sysconfdir=/etc/apache2 \
434 --localstatedir=/var \
435 --with-mpm=${MY_MPM} \
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, installs 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 legacy symlink for apxs, bug 177697
485 dosym /usr/sbin/apxs /usr/sbin/apxs2
486
487 # install some thirdparty scripts
488 exeinto /usr/sbin
489 use ssl && doexe "${GENTOO_PATCHDIR}"/scripts/gentestcrt.sh
490
491 # install some documentation
492 dodoc ABOUT_APACHE CHANGES LAYOUT README README.platforms VERSIONING
493 dodoc "${GENTOO_PATCHDIR}"/docs/*
494
495 # drop in a convenient link to the manual
496 if use doc ; then
497 sed -i -e "s:VERSION:${PVR}:" "${D}/etc/apache2/modules.d/00_apache_manual.conf"
498 else
499 rm -f "${D}/etc/apache2/modules.d/00_apache_manual.conf"
500 rm -Rf "${D}/usr/share/doc/${PF}/manual"
501 fi
502
503 # the default webroot gets stored in /usr/share/${PF}/webroot
504 ebegin "Installing default webroot to /usr/share/${PF}/webroot"
505 dodir /usr/share/${PF}
506 mv -f "${D}/var/www/localhost" "${D}/usr/share/${PF}/webroot"
507 eend $?
508
509 # set some sane permissions for suexec
510 if use suexec ; then
511 fowners 0:apache /usr/sbin/suexec
512 fperms 4710 /usr/sbin/suexec
513 # provide legacy symlink for suexec, bug 177697
514 dosym /usr/sbin/suexec /usr/sbin/suexec2
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 to /var/www/localhost if it does not exist. We do this here
532 # because the default webroot is a copy of the files that exist elsewhere and we
533 # don't want them to be managed/removed by portage when apache is upgraded.
534 apache-2_pkg_postinst() {
535 einfo
536
537 if use ssl && [[ ! -e "${ROOT}/etc/apache2/ssl/server.crt" ]] ; then
538 cd "${ROOT}"/etc/apache2/ssl
539 einfo "Generating self-signed test certificate in ${ROOT}etc/apache2/ssl ..."
540 yes "" 2>/dev/null | \
541 "${ROOT}"/usr/sbin/gentestcrt.sh >/dev/null 2>&1 || \
542 die "gentestcrt.sh failed"
543 einfo
544 fi
545
546 if [[ -e "${ROOT}/var/www/localhost" ]] ; then
547 elog "The default webroot has not been installed into"
548 elog "${ROOT}var/www/localhost because the directory already exists"
549 elog "and we do not want to overwrite any files you have put there."
550 elog
551 elog "If you would like to install the latest webroot, please run"
552 elog "emerge --config =${PF}"
553 elog
554 else
555 einfo "Installing default webroot to ${ROOT}var/www/localhost"
556 mkdir -p "${ROOT}"/var/www/localhost
557 cp -R "${ROOT}"/usr/share/${PF}/webroot/* "${ROOT}"/var/www/localhost/
558 einfo
559 fi
560 }
561
562 # @FUNCTION: apache-2_pkg_config
563 # @DESCRIPTION:
564 # This function installs -- and overwrites -- the default webroot to
565 # /var/www/localhost
566 apache-2_pkg_config() {
567 einfo "Installing default webroot to ${ROOT}var/www/localhost"
568 mkdir -p "${ROOT}"/var/www/localhost
569 cp -R "${ROOT}"/usr/share/${PF}/webroot/* "${ROOT}"/var/www/localhost/
570 }
571
572 EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_install pkg_postinst pkg_config

  ViewVC Help
Powered by ViewVC 1.1.20