x11-terms/xfce4-terminal: amd64 stable wrt bug #712350
[gentoo.git] / eclass / apache-2.eclass
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: apache-2.eclass
5 # @MAINTAINER:
6 # polynomial-c@gentoo.org
7 # @SUPPORTED_EAPIS: 5 6 7
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 flag-o-matic multilib ssl-cert user toolchain-funcs eapi7-ver
14
15 [[ ${CATEGORY}/${PN} != www-servers/apache ]] \
16         && die "Do not use this eclass with anything else than www-servers/apache ebuilds!"
17
18 case ${EAPI:-0} in
19         0|1|2|3|4)
20                 die "This eclass is banned for EAPI<5"
21         ;;
22 esac
23
24 # settings which are version specific go in here:
25 case $(ver_cut 1-2) in
26         2.4)
27                 DEFAULT_MPM_THREADED="event" #509922
28                 CDEPEND=">=dev-libs/apr-1.5.1:=
29                         !www-apache/mod_macro" #492578 #477702
30         ;;
31         2.2)
32                 DEFAULT_MPM_THREADED="worker"
33                 CDEPEND=">=dev-libs/apr-1.4.5:=" #368651
34         ;;
35         *)
36                 die "Unknown MAJOR.MINOR apache version."
37         ;;
38 esac
39
40 # ==============================================================================
41 # INTERNAL VARIABLES
42 # ==============================================================================
43
44 # @ECLASS-VARIABLE: GENTOO_PATCHNAME
45 # @DESCRIPTION:
46 # This internal variable contains the prefix for the patch tarball.
47 # Defaults to the full name and version (including revision) of the package.
48 # If you want to override this in an ebuild, use:
49 # ORIG_PR="(revision of Gentoo stuff you want)"
50 # GENTOO_PATCHNAME="gentoo-${PN}-${PV}${ORIG_PR:+-${ORIG_PR}}"
51 [[ -n "${GENTOO_PATCHNAME}" ]] || GENTOO_PATCHNAME="gentoo-${PF}"
52
53 # @ECLASS-VARIABLE: GENTOO_PATCHDIR
54 # @DESCRIPTION:
55 # This internal variable contains the working directory where patches and config
56 # files are located.
57 # Defaults to the patchset name appended to the working directory.
58 [[ -n "${GENTOO_PATCHDIR}" ]] || GENTOO_PATCHDIR="${WORKDIR}/${GENTOO_PATCHNAME}"
59
60 # @VARIABLE: GENTOO_DEVELOPER
61 # @DESCRIPTION:
62 # This variable needs to be set in the ebuild and contains the name of the
63 # gentoo developer who created the patch tarball
64
65 # @VARIABLE: GENTOO_PATCHSTAMP
66 # @DESCRIPTION:
67 # This variable needs to be set in the ebuild and contains the date the patch
68 # tarball was created at in YYYYMMDD format
69
70 # @VARIABLE: GENTOO_PATCH_A
71 # @DESCRIPTION:
72 # This variable should contain the entire filename of patch tarball.
73 # Defaults to the name of the patchset, with a datestamp.
74 [[ -n "${GENTOO_PATCH_A}" ]] || GENTOO_PATCH_A="${GENTOO_PATCHNAME}-${GENTOO_PATCHSTAMP}.tar.bz2"
75
76 SRC_URI="mirror://apache/httpd/httpd-${PV}.tar.bz2
77         https://dev.gentoo.org/~${GENTOO_DEVELOPER}/dist/apache/${GENTOO_PATCH_A}"
78
79 # @VARIABLE: IUSE_MPMS_FORK
80 # @DESCRIPTION:
81 # This variable needs to be set in the ebuild and contains a list of forking
82 # (i.e.  non-threaded) MPMs
83
84 # @VARIABLE: IUSE_MPMS_THREAD
85 # @DESCRIPTION:
86 # This variable needs to be set in the ebuild and contains a list of threaded
87 # MPMs
88
89 # @VARIABLE: IUSE_MODULES
90 # @DESCRIPTION:
91 # This variable needs to be set in the ebuild and contains a list of available
92 # built-in modules
93
94 IUSE_MPMS="${IUSE_MPMS_FORK} ${IUSE_MPMS_THREAD}"
95 IUSE="${IUSE} debug doc gdbm ldap libressl selinux ssl static suexec threads"
96
97 for module in ${IUSE_MODULES} ; do
98         IUSE="${IUSE} apache2_modules_${module}"
99 done
100
101 _apache2_set_mpms() {
102         local mpm
103         local ompm
104
105         for mpm in ${IUSE_MPMS} ; do
106                 IUSE="${IUSE} apache2_mpms_${mpm}"
107
108                 REQUIRED_USE+=" apache2_mpms_${mpm}? ("
109                 for ompm in ${IUSE_MPMS} ; do
110                         if [[ "${mpm}" != "${ompm}" ]] ; then
111                                 REQUIRED_USE+=" !apache2_mpms_${ompm}"
112                         fi
113                 done
114
115                 if has ${mpm} ${IUSE_MPMS_FORK} ; then
116                         REQUIRED_USE+=" !threads"
117                 else
118                         REQUIRED_USE+=" threads"
119                 fi
120                 REQUIRED_USE+=" )"
121         done
122
123         if [[ "$(ver_cut 1-2)" != 2.2 ]] ; then
124                 REQUIRED_USE+=" apache2_mpms_prefork? ( !apache2_modules_http2 )"
125         fi
126 }
127 _apache2_set_mpms
128 unset -f _apache2_set_mpms
129
130 DEPEND="${CDEPEND}
131         dev-lang/perl
132         =dev-libs/apr-util-1*:=[gdbm=,ldap?]
133         dev-libs/libpcre
134         apache2_modules_deflate? ( sys-libs/zlib )
135         apache2_modules_mime? ( app-misc/mime-types )
136         gdbm? ( sys-libs/gdbm:= )
137         ldap? ( =net-nds/openldap-2* )
138         ssl? (
139                 !libressl? ( >=dev-libs/openssl-1.0.2:0= )
140                 libressl? ( dev-libs/libressl:0= )
141         )
142         !=www-servers/apache-1*"
143 RDEPEND+=" ${DEPEND}
144         selinux? ( sec-policy/selinux-apache )"
145 PDEPEND="~app-admin/apache-tools-${PV}"
146
147 S="${WORKDIR}/httpd-${PV}"
148
149 # @VARIABLE: MODULE_DEPENDS
150 # @DESCRIPTION:
151 # This variable needs to be set in the ebuild and contains a space-separated
152 # list of dependency tokens each with a module and the module it depends on
153 # separated by a colon
154
155 # now extend REQUIRED_USE to reflect the module dependencies to portage
156 _apache2_set_module_depends() {
157         local dep
158
159         for dep in ${MODULE_DEPENDS} ; do
160                 REQUIRED_USE+=" apache2_modules_${dep%:*}? ( apache2_modules_${dep#*:} )"
161         done
162 }
163 _apache2_set_module_depends
164 unset -f _apache2_set_module_depends
165
166 # ==============================================================================
167 # INTERNAL FUNCTIONS
168 # ==============================================================================
169
170 # @ECLASS-VARIABLE: MY_MPM
171 # @DESCRIPTION:
172 # This internal variable contains the selected MPM after a call to setup_mpm()
173
174 # @FUNCTION: setup_mpm
175 # @DESCRIPTION:
176 # This internal function makes sure that only one of APACHE2_MPMS was selected
177 # or a default based on USE=threads is selected if APACHE2_MPMS is empty
178 setup_mpm() {
179         MY_MPM=""
180         for x in ${IUSE_MPMS} ; do
181                 if use apache2_mpms_${x} ; then
182                         # there can at most be one MPM selected because of REQUIRED_USE constraints
183                         MY_MPM=${x}
184                         elog
185                         elog "Selected MPM: ${MY_MPM}"
186                         elog
187                         break
188                 fi
189         done
190
191         if [[ -z "${MY_MPM}" ]] ; then
192                 if use threads ; then
193                         MY_MPM=${DEFAULT_MPM_THREADED}
194                         elog
195                         elog "Selected default threaded MPM: ${MY_MPM}"
196                         elog
197                 else
198                         MY_MPM=prefork
199                         elog
200                         elog "Selected default MPM: ${MY_MPM}"
201                         elog
202                 fi
203         fi
204 }
205
206 # @VARIABLE: MODULE_CRITICAL
207 # @DESCRIPTION:
208 # This variable needs to be set in the ebuild and contains a space-separated
209 # list of modules critical for the default apache. A user may still
210 # disable these modules for custom minimal installation at their own risk.
211
212 # @FUNCTION: check_module_critical
213 # @DESCRIPTION:
214 # This internal function warns the user about modules critical for the default
215 # apache configuration.
216 check_module_critical() {
217         local unsupported=0
218
219         for m in ${MODULE_CRITICAL} ; do
220                 if ! has ${m} ${MY_MODS[@]} ; then
221                         ewarn "Module '${m}' is required in the default apache configuration."
222                         unsupported=1
223                 fi
224         done
225
226         if [[ ${unsupported} -ne 0 ]] ; then
227                 ewarn
228                 ewarn "You have disabled one or more required modules"
229                 ewarn "for the default apache configuration."
230                 ewarn "Although this is not an error, please be"
231                 ewarn "aware that this setup is UNSUPPORTED."
232                 ewarn
233         fi
234 }
235
236 # @ECLASS-VARIABLE: MY_CONF
237 # @DESCRIPTION:
238 # This internal variable contains the econf options for the current module
239 # selection after a call to setup_modules()
240
241 # @ECLASS-VARIABLE: MY_MODS
242 # @DESCRIPTION:
243 # This internal variable contains a sorted, space separated list of currently
244 # selected modules after a call to setup_modules()
245
246 # @FUNCTION: setup_modules
247 # @DESCRIPTION:
248 # This internal function selects all built-in modules based on USE flags and
249 # APACHE2_MODULES USE_EXPAND flags
250 setup_modules() {
251         local mod_type=
252
253         if use static ; then
254                 mod_type="static"
255         else
256                 mod_type="shared"
257         fi
258
259         MY_CONF=( --enable-so=static )
260         MY_MODS=()
261
262         if use ldap ; then
263                 MY_CONF+=( --enable-authnz_ldap=${mod_type} --enable-ldap=${mod_type} )
264                 MY_MODS+=( ldap authnz_ldap )
265         else
266                 MY_CONF+=( --disable-authnz_ldap --disable-ldap )
267         fi
268
269         if use ssl ; then
270                 MY_CONF+=( --with-ssl --enable-ssl=${mod_type} )
271                 MY_MODS+=( ssl )
272         else
273                 MY_CONF+=( --without-ssl --disable-ssl )
274         fi
275
276         if use suexec ; then
277                 elog "You can manipulate several configure options of suexec"
278                 elog "through the following environment variables:"
279                 elog
280                 elog " SUEXEC_SAFEPATH: Default PATH for suexec (default: '${EPREFIX}/usr/local/bin:${EPREFIX}/usr/bin:${EPREFIX}/bin')"
281                 if { ver_test ${PV} -ge 2.4.34 && ! use suexec-syslog ; } || ver_test ${PV} -lt 2.4.34 ; then
282                         elog "  SUEXEC_LOGFILE: Path to the suexec logfile (default: '${EPREFIX}/var/log/apache2/suexec_log')"
283                 fi
284                 elog "   SUEXEC_CALLER: Name of the user Apache is running as (default: apache)"
285                 elog "  SUEXEC_DOCROOT: Directory in which suexec will run scripts (default: '${EPREFIX}/var/www')"
286                 elog "   SUEXEC_MINUID: Minimum UID, which is allowed to run scripts via suexec (default: 1000)"
287                 elog "   SUEXEC_MINGID: Minimum GID, which is allowed to run scripts via suexec (default: 100)"
288                 elog "  SUEXEC_USERDIR: User subdirectories (like /home/user/html) (default: public_html)"
289                 elog "    SUEXEC_UMASK: Umask for the suexec process (default: 077)"
290                 elog
291
292                 MY_CONF+=( --with-suexec-safepath="${SUEXEC_SAFEPATH:-${EPREFIX}/usr/local/bin:${EPREFIX}/usr/bin:${EPREFIX}/bin}" )
293                 if ver_test ${PV} -ge 2.4.34 ; then
294                         MY_CONF+=( $(use_with !suexec-syslog suexec-logfile "${SUEXEC_LOGFILE:-${EPREFIX}/var/log/apache2/suexec_log}") )
295                         MY_CONF+=( $(use_with suexec-syslog) )
296                         if use suexec-syslog && use suexec-caps ; then
297                                 MY_CONF+=( --enable-suexec-capabilities )
298                         fi
299                 else
300                         MY_CONF+=( --with-suexec-logfile="${SUEXEC_LOGFILE:-${EPREFIX}/var/log/apache2/suexec_log}" )
301                 fi
302                 MY_CONF+=( --with-suexec-bin="${EPREFIX}/usr/sbin/suexec" )
303                 MY_CONF+=( --with-suexec-userdir=${SUEXEC_USERDIR:-public_html} )
304                 MY_CONF+=( --with-suexec-caller=${SUEXEC_CALLER:-apache} )
305                 MY_CONF+=( --with-suexec-docroot="${SUEXEC_DOCROOT:-${EPREFIX}/var/www}" )
306                 MY_CONF+=( --with-suexec-uidmin=${SUEXEC_MINUID:-1000} )
307                 MY_CONF+=( --with-suexec-gidmin=${SUEXEC_MINGID:-100} )
308                 MY_CONF+=( --with-suexec-umask=${SUEXEC_UMASK:-077} )
309                 MY_CONF+=( --enable-suexec=${mod_type} )
310                 MY_MODS+=( suexec )
311         else
312                 MY_CONF+=( --disable-suexec )
313         fi
314
315         for x in ${IUSE_MODULES} ; do
316                 if use apache2_modules_${x} ; then
317                         MY_CONF+=( --enable-${x}=${mod_type} )
318                         MY_MODS+=( ${x} )
319                 else
320                         MY_CONF+=( --disable-${x} )
321                 fi
322         done
323
324         # sort and uniquify MY_MODS
325         MY_MODS=( $(echo ${MY_MODS[@]} | tr ' ' '\n' | sort -u) )
326         check_module_critical
327 }
328
329 # @VARIABLE: MODULE_DEFINES
330 # @DESCRIPTION:
331 # This variable needs to be set in the ebuild and contains a space-separated
332 # list of tokens each mapping a module to a runtime define which can be
333 # specified in APACHE2_OPTS in /etc/conf.d/apache2 to enable this particular
334 # module.
335
336 # @FUNCTION: generate_load_module
337 # @DESCRIPTION:
338 # This internal function generates the LoadModule lines for httpd.conf based on
339 # the current module selection and MODULE_DEFINES
340 generate_load_module() {
341         local endit=0 mod_lines= mod_dir="${ED%/}/usr/$(get_libdir)/apache2/modules"
342
343         if use static; then
344                 sed -i -e "/%%LOAD_MODULE%%/d" \
345                         "${GENTOO_PATCHDIR}"/conf/httpd.conf
346                 return
347         fi
348
349         for m in ${MY_MODS[@]} ; do
350                 if [[ -e "${mod_dir}/mod_${m}.so" ]] ; then
351                         for def in ${MODULE_DEFINES} ; do
352                                 if [[ "${m}" == "${def%:*}" ]] ; then
353                                         mod_lines="${mod_lines}\n<IfDefine ${def#*:}>"
354                                         endit=1
355                                 fi
356                         done
357
358                         mod_lines="${mod_lines}\nLoadModule ${m}_module modules/mod_${m}.so"
359
360                         if [[ ${endit} -ne 0 ]] ; then
361                                 mod_lines="${mod_lines}\n</IfDefine>"
362                                 endit=0
363                         fi
364                 fi
365         done
366
367         sed -i -e "s:%%LOAD_MODULE%%:${mod_lines}:" \
368                 "${GENTOO_PATCHDIR}"/conf/httpd.conf
369 }
370
371 # @FUNCTION: check_upgrade
372 # @DESCRIPTION:
373 # This internal function checks if the previous configuration file for built-in
374 # modules exists in ROOT and prevents upgrade in this case. Users are supposed
375 # to convert this file to the new APACHE2_MODULES USE_EXPAND variable and remove
376 # it afterwards.
377 check_upgrade() {
378         if [[ -e "${EROOT}"etc/apache2/apache2-builtin-mods ]]; then
379                 eerror "The previous configuration file for built-in modules"
380                 eerror "(${EROOT}etc/apache2/apache2-builtin-mods) exists on your"
381                 eerror "system."
382                 eerror
383                 eerror "Please read https://wiki.gentoo.org/wiki/Project:Apache/Upgrading"
384                 eerror "for detailed information how to convert this file to the new"
385                 eerror "APACHE2_MODULES USE_EXPAND variable."
386                 eerror
387                 die "upgrade not possible with existing ${ROOT}etc/apache2/apache2-builtin-mods"
388         fi
389 }
390
391 # ==============================================================================
392 # EXPORTED FUNCTIONS
393 # ==============================================================================
394
395 # @FUNCTION: apache-2_pkg_setup
396 # @DESCRIPTION:
397 # This function selects built-in modules, the MPM and other configure options,
398 # creates the apache user and group and informs about CONFIG_SYSVIPC being
399 # needed (we don't depend on kernel sources and therefore cannot check).
400 apache-2_pkg_setup() {
401         check_upgrade
402
403         # setup apache user and group
404         enewgroup apache 81
405         enewuser apache 81 -1 /var/www apache
406
407         setup_mpm
408         setup_modules
409
410         if use debug; then
411                 MY_CONF+=( --enable-exception-hook )
412         fi
413
414         elog "Please note that you need SysV IPC support in your kernel."
415         elog "Make sure CONFIG_SYSVIPC=y is set."
416         elog
417
418         if use userland_BSD; then
419                 elog "On BSD systems you need to add the following line to /boot/loader.conf:"
420                 elog "  accf_http_load=\"YES\""
421                 if use ssl ; then
422                         elog "  accf_data_load=\"YES\""
423                 fi
424                 elog
425         fi
426 }
427
428 # @FUNCTION: apache-2_src_prepare
429 # @DESCRIPTION:
430 # This function applies patches, configures a custom file-system layout and
431 # rebuilds the configure scripts.
432 apache-2_src_prepare() {
433         #fix prefix in conf files etc (bug #433736)
434         use !prefix || sed -e "s@/\(usr\|var\|etc\|run\)/@${EPREFIX}&@g" \
435                 -i "${GENTOO_PATCHDIR}"/conf/httpd.conf "${GENTOO_PATCHDIR}"/scripts/* \
436                 "${GENTOO_PATCHDIR}"/docs/*.example "${GENTOO_PATCHDIR}"/patches/*.layout \
437                 "${GENTOO_PATCHDIR}"/init/* "${GENTOO_PATCHDIR}"/conf/vhosts.d/* \
438                 "${GENTOO_PATCHDIR}"/conf/modules.d/* || die
439
440         # 03_all_gentoo-apache-tools.patch injects -Wl,-z,now, which is not a good
441         # idea for everyone
442         case ${CHOST} in
443                 *-linux-gnu|*-solaris*|*-freebsd*)
444                         # do nothing, these use GNU binutils
445                         :
446                 ;;
447                 *-darwin*)
448                         sed -i -e 's/-Wl,-z,now/-Wl,-bind_at_load/g' \
449                                 "${GENTOO_PATCHDIR}"/patches/03_all_gentoo_apache-tools.patch
450                 ;;
451                 *)
452                         # patch it out to be like upstream
453                         sed -i -e 's/-Wl,-z,now//g' \
454                                 "${GENTOO_PATCHDIR}"/patches/03_all_gentoo_apache-tools.patch
455                 ;;
456         esac
457
458         # Use correct multilib libdir in gentoo patches
459         sed -i -e "s:/usr/lib:/usr/$(get_libdir):g" \
460                 "${GENTOO_PATCHDIR}"/{conf/httpd.conf,init/*,patches/config.layout} \
461                 || die "libdir sed failed"
462
463         if [[ "${EAPI}" -ge 6 ]] ; then
464                 default
465                 eapply "${GENTOO_PATCHDIR}"/patches/*.patch
466         else
467                 epatch "${GENTOO_PATCHDIR}"/patches/*.patch
468         fi
469
470         if [[ ${EAPI} = 5 ]] ; then
471                 # Handle patches from ebuild's PATCHES array if one is given
472                 if [[ -n "${PATCHES}" ]] ; then
473                         local patchestype=$(declare -p PATCHES 2>&-)
474                         if [[ "${patchestype}" != "declare -a PATCHES="* ]] ; then
475                                 die "Declaring PATCHES as a variable is forbidden. Please use an array instead."
476                         fi
477                         epatch "${PATCHES[@]}"
478                 fi
479
480                 # Handle user patches
481                 epatch_user
482         fi
483
484         # Don't rename configure.in _before_ any possible user patches!
485         if [[ -f "configure.in" ]] ; then
486                 mv configure.{in,ac} || die
487         fi
488
489         # setup the filesystem layout config
490         cat "${GENTOO_PATCHDIR}"/patches/config.layout >> "${S}"/config.layout || \
491                 die "Failed preparing config.layout!"
492         sed -i -e "s:version:${PF}:g" "${S}"/config.layout
493
494         # apache2.8 instead of httpd.8 (bug #194828)
495         mv docs/man/{httpd,apache2}.8
496         sed -i -e 's/httpd\.8/apache2.8/g' Makefile.in
497
498         # patched-in MPMs need the build environment rebuilt
499         sed -i -e '/sinclude/d' configure.ac
500         AT_M4DIR=build eautoreconf
501
502         # ${T} must be not group-writable, else grsec TPE will block it
503         chmod g-w "${T}"
504
505         # This package really should upgrade to using pcre's .pc file.
506         cat <<-\EOF >"${T}"/pcre-config
507         #!/bin/bash
508         flags=()
509         for flag; do
510                 if [[ ${flag} == "--version" ]]; then
511                         flags+=( --modversion )
512                 else
513                         flags+=( "${flag}" )
514                 fi
515         done
516         exec ${PKG_CONFIG} libpcre "${flags[@]}"
517         EOF
518         chmod a+x "${T}"/pcre-config
519 }
520
521 # @FUNCTION: apache-2_src_configure
522 # @DESCRIPTION:
523 # This function adds compiler flags and runs econf and emake based on MY_MPM and
524 # MY_CONF
525 apache-2_src_configure() {
526         tc-export PKG_CONFIG
527
528         # Sanity check in case people have bad mounts/TPE settings. #500928
529         if ! "${T}"/pcre-config --help >/dev/null ; then
530                 eerror "Could not execute ${T}/pcre-config; do you have bad mount"
531                 eerror "permissions in ${T} or have TPE turned on in your kernel?"
532                 die "check your runtime settings #500928"
533         fi
534
535         # Instead of filtering --as-needed (bug #128505), append --no-as-needed
536         # Thanks to Harald van Dijk
537         append-ldflags $(no-as-needed)
538
539         # peruser MPM debugging with -X is nearly impossible
540         if has peruser ${IUSE_MPMS} && use apache2_mpms_peruser ; then
541                 use debug && append-flags -DMPM_PERUSER_DEBUG
542         fi
543
544         # econf overwrites the stuff from config.layout, so we have to put them into
545         # our myconf line too
546         MY_CONF+=(
547                 --includedir="${EPREFIX}"/usr/include/apache2
548                 --libexecdir="${EPREFIX}"/usr/$(get_libdir)/apache2/modules
549                 --datadir="${EPREFIX}"/var/www/localhost
550                 --sysconfdir="${EPREFIX}"/etc/apache2
551                 --localstatedir="${EPREFIX}"/var
552                 --with-mpm=${MY_MPM}
553                 --with-apr="${SYSROOT}${EPREFIX}"/usr
554                 --with-apr-util="${SYSROOT}${EPREFIX}"/usr
555                 --with-pcre="${T}"/pcre-config
556                 --with-z="${EPREFIX}"/usr
557                 --with-port=80
558                 --with-program-name=apache2
559                 --enable-layout=Gentoo
560         )
561         ac_cv_path_PKGCONFIG=${PKG_CONFIG} \
562         econf "${MY_CONF[@]}"
563
564         sed -i -e 's:apache2\.conf:httpd.conf:' include/ap_config_auto.h || die
565 }
566
567 # @FUNCTION: apache-2_src_install
568 # @DESCRIPTION:
569 # This function runs `emake install' and generates, installs and adapts the gentoo
570 # specific configuration files found in the tarball
571 apache-2_src_install() {
572         emake DESTDIR="${D}" MKINSTALLDIRS="mkdir -p" install
573
574         # install our configuration files
575         keepdir /etc/apache2/vhosts.d
576         keepdir /etc/apache2/modules.d
577
578         generate_load_module
579         insinto /etc/apache2
580         doins -r "${GENTOO_PATCHDIR}"/conf/*
581         use apache2_modules_mime_magic && doins docs/conf/magic
582
583         insinto /etc/logrotate.d
584         newins "${GENTOO_PATCHDIR}"/scripts/apache2-logrotate apache2
585
586         # generate a sane default APACHE2_OPTS
587         APACHE2_OPTS="-D DEFAULT_VHOST -D INFO"
588         use doc && APACHE2_OPTS+=" -D MANUAL"
589         use ssl && APACHE2_OPTS+=" -D SSL -D SSL_DEFAULT_VHOST"
590         use suexec && APACHE2_OPTS+=" -D SUEXEC"
591         if has negotiation ${APACHE2_MODULES} && use apache2_modules_negotiation; then
592                 APACHE2_OPTS+=" -D LANGUAGE"
593         fi
594
595         sed -i -e "s:APACHE2_OPTS=\".*\":APACHE2_OPTS=\"${APACHE2_OPTS}\":" \
596                 "${GENTOO_PATCHDIR}"/init/apache2.confd || die
597
598         newconfd "${GENTOO_PATCHDIR}"/init/apache2.confd apache2
599         newinitd "${GENTOO_PATCHDIR}"/init/apache2.initd apache2
600
601         # install apache2ctl wrapper for our init script if available
602         if test -e "${GENTOO_PATCHDIR}"/scripts/apache2ctl; then
603                 exeinto /usr/sbin
604                 doexe "${GENTOO_PATCHDIR}"/scripts/apache2ctl
605         else
606                 dosym /etc/init.d/apache2 /usr/sbin/apache2ctl
607         fi
608
609         # provide legacy symlink for apxs, bug 177697
610         dosym apxs /usr/sbin/apxs2
611
612         # install some documentation
613         dodoc ABOUT_APACHE CHANGES LAYOUT README README.platforms VERSIONING
614         dodoc "${GENTOO_PATCHDIR}"/docs/*
615
616         # drop in a convenient link to the manual
617         if use doc ; then
618                 sed -i -e "s:VERSION:${PVR}:" "${ED%/}/etc/apache2/modules.d/00_apache_manual.conf"
619                 docompress -x /usr/share/doc/${PF}/manual # 503640
620         else
621                 rm -f "${ED%/}/etc/apache2/modules.d/00_apache_manual.conf"
622                 rm -Rf "${ED%/}/usr/share/doc/${PF}/manual"
623         fi
624
625         # the default icons and error pages get stored in
626         # /usr/share/apache2/{error,icons}
627         dodir /usr/share/apache2
628         mv -f "${ED%/}/var/www/localhost/error" "${ED%/}/usr/share/apache2/error"
629         mv -f "${ED%/}/var/www/localhost/icons" "${ED%/}/usr/share/apache2/icons"
630         rm -rf "${ED%/}/var/www/localhost/"
631         eend $?
632
633         # set some sane permissions for suexec
634         if use suexec ; then
635                 local needs_adjustment="$(ver_test ${PV} -ge 2.4.34 && { { ! use suexec-syslog || ! use suexec-caps ; } && echo true || echo false ; } || echo true)"
636                 if ${needs_adjustment} ; then
637                         fowners 0:${SUEXEC_CALLER:-apache} /usr/sbin/suexec
638                         fperms 4710 /usr/sbin/suexec
639                         # provide legacy symlink for suexec, bug 177697
640                         dosym /usr/sbin/suexec /usr/sbin/suexec2
641                 fi
642         fi
643
644         # empty dirs
645         for i in /var/lib/dav /var/log/apache2 /var/cache/apache2 ; do
646                 keepdir ${i}
647                 fowners apache:apache ${i}
648                 fperms 0750 ${i}
649         done
650 }
651
652 # @FUNCTION: apache-2_pkg_postinst
653 # @DESCRIPTION:
654 # This function creates test certificates if SSL is enabled and installs the
655 # default index.html to /var/www/localhost if it does not exist. We do this here
656 # because the default webroot is a copy of the files that exist elsewhere and we
657 # don't want them to be managed/removed by portage when apache is upgraded.
658 apache-2_pkg_postinst() {
659         if use ssl && [[ ! -e "${EROOT}/etc/ssl/apache2/server.pem" ]]; then
660                 SSL_ORGANIZATION="${SSL_ORGANIZATION:-Apache HTTP Server}"
661                 install_cert /etc/ssl/apache2/server
662                 ewarn
663                 ewarn "The location of SSL certificates has changed. If you are"
664                 ewarn "upgrading from ${CATEGORY}/${PN}-2.2.13 or earlier (or remerged"
665                 ewarn "*any* apache version), you might want to move your old"
666                 ewarn "certificates from /etc/apache2/ssl/ to /etc/ssl/apache2/ and"
667                 ewarn "update your config files."
668                 ewarn
669         fi
670
671         if [[ ! -e "${EROOT}/var/www/localhost" ]] ; then
672                 mkdir -p "${EROOT}/var/www/localhost/htdocs"
673                 echo "<html><body><h1>It works!</h1></body></html>" > "${EROOT}/var/www/localhost/htdocs/index.html"
674         fi
675
676         echo
677         elog "Attention: cgi and cgid modules are now handled via APACHE2_MODULES flags"
678         elog "in make.conf. Make sure to enable those in order to compile them."
679         elog "In general, you should use 'cgid' with threaded MPMs and 'cgi' otherwise."
680         echo
681
682 }
683
684 EXPORT_FUNCTIONS pkg_setup src_prepare src_configure src_install pkg_postinst