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

Contents of /eclass/apache-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download)
Wed Nov 28 13:04:12 2007 UTC (6 years, 8 months ago) by hollow
Branch: MAIN
Add apache-2 eclass

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

  ViewVC Help
Powered by ViewVC 1.1.20