# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# @ECLASS: apache-2.eclass
# @MAINTAINER:
# apache-bugs@gentoo.org
# @AUTHOR:
# polynomial-c@gentoo.org
# @SUPPORTED_EAPIS: 7
# @BLURB: Provides a common set of functions for apache-2.x ebuilds
# @DESCRIPTION:
# This eclass handles apache-2.x ebuild functions such as LoadModule generation
# and inter-module dependency checking.
LUA_COMPAT=( lua5-{1..4} )
inherit autotools flag-o-matic lua-single multilib ssl-cert toolchain-funcs
[[ ${CATEGORY}/${PN} != www-servers/apache ]] \
&& die "Do not use this eclass with anything else than www-servers/apache ebuilds!"
case ${EAPI} in
7) ;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac
# settings which are version specific go in here:
case $(ver_cut 1-2) in
2.4)
DEFAULT_MPM_THREADED="event" #509922
;;
*)
die "Unknown MAJOR.MINOR apache version."
;;
esac
# ==============================================================================
# INTERNAL VARIABLES
# ==============================================================================
# @ECLASS_VARIABLE: GENTOO_PATCHNAME
# @DESCRIPTION:
# This internal variable contains the prefix for the patch tarball.
# Defaults to the full name and version (including revision) of the package.
# If you want to override this in an ebuild, use:
# ORIG_PR="(revision of Gentoo stuff you want)"
# GENTOO_PATCHNAME="gentoo-${PN}-${PV}${ORIG_PR:+-${ORIG_PR}}"
[[ -n "${GENTOO_PATCHNAME}" ]] || GENTOO_PATCHNAME="gentoo-${PF}"
# @ECLASS_VARIABLE: GENTOO_PATCHDIR
# @DESCRIPTION:
# This internal variable contains the working directory where patches and config
# files are located.
# Defaults to the patchset name appended to the working directory.
[[ -n "${GENTOO_PATCHDIR}" ]] || GENTOO_PATCHDIR="${WORKDIR}/${GENTOO_PATCHNAME}"
# @VARIABLE: GENTOO_DEVELOPER
# @DESCRIPTION:
# This variable needs to be set in the ebuild and contains the name of the
# gentoo developer who created the patch tarball
# @VARIABLE: GENTOO_PATCHSTAMP
# @DESCRIPTION:
# This variable needs to be set in the ebuild and contains the date the patch
# tarball was created at in YYYYMMDD format
# @VARIABLE: GENTOO_PATCH_A
# @DESCRIPTION:
# This variable should contain the entire filename of patch tarball.
# Defaults to the name of the patchset, with a datestamp.
[[ -n "${GENTOO_PATCH_A}" ]] || GENTOO_PATCH_A="${GENTOO_PATCHNAME}-${GENTOO_PATCHSTAMP}.tar.bz2"
SRC_URI="mirror://apache/httpd/httpd-${PV}.tar.bz2
https://dev.gentoo.org/~${GENTOO_DEVELOPER}/dist/apache/${GENTOO_PATCH_A}"
# @VARIABLE: IUSE_MPMS_FORK
# @DESCRIPTION:
# This variable needs to be set in the ebuild and contains a list of forking
# (i.e. non-threaded) MPMs
# @VARIABLE: IUSE_MPMS_THREAD
# @DESCRIPTION:
# This variable needs to be set in the ebuild and contains a list of threaded
# MPMs
# @VARIABLE: IUSE_MODULES
# @DESCRIPTION:
# This variable needs to be set in the ebuild and contains a list of available
# built-in modules
IUSE_MPMS="${IUSE_MPMS_FORK} ${IUSE_MPMS_THREAD}"
IUSE="${IUSE} debug doc gdbm ldap selinux ssl static suexec +suexec-caps suexec-syslog threads"
for module in ${IUSE_MODULES} ; do
case ${module} in
# Enable http2 by default (bug #563452)
http2)
IUSE+=" +apache2_modules_${module}"
;;
systemd)
IUSE+=" systemd"
;;
*)
IUSE+=" apache2_modules_${module}"
;;
esac
done
_apache2_set_mpms() {
local mpm
local ompm
for mpm in ${IUSE_MPMS} ; do
IUSE="${IUSE} apache2_mpms_${mpm}"
REQUIRED_USE+=" apache2_mpms_${mpm}? ("
for ompm in ${IUSE_MPMS} ; do
if [[ "${mpm}" != "${ompm}" ]] ; then
REQUIRED_USE+=" !apache2_mpms_${ompm}"
fi
done
if has ${mpm} ${IUSE_MPMS_FORK} ; then
REQUIRED_USE+=" !threads"
else
REQUIRED_USE+=" threads"
fi
REQUIRED_USE+=" )"
done
REQUIRED_USE+=" apache2_mpms_prefork? ( !apache2_modules_http2 )"
}
_apache2_set_mpms
unset -f _apache2_set_mpms
NGHTTP2_VERSION=1.2.1
if ver_test ${PV} -ge 2.4.55 ; then
NGHTTP2_VERSION=1.50.0
fi
# Dependencies
RDEPEND="
acct-group/apache
acct-user/apache
dev-lang/perl
>=dev-libs/apr-1.5.1:=
=dev-libs/apr-util-1*:=[gdbm=,ldap?]
dev-libs/libpcre2
virtual/libcrypt:=
apache2_modules_brotli? ( >=app-arch/brotli-0.6.0:= )
apache2_modules_deflate? ( sys-libs/zlib )
apache2_modules_http2? (
>=net-libs/nghttp2-${NGHTTP2_VERSION}:=
kernel_linux? ( sys-apps/util-linux )
)
apache2_modules_lua? ( ${LUA_DEPS} )
apache2_modules_md? ( >=dev-libs/jansson-2.10:= )
apache2_modules_mime? ( app-misc/mime-types )
apache2_modules_proxy_http2? (
>=net-libs/nghttp2-${NGHTTP2_VERSION}:=
kernel_linux? ( sys-apps/util-linux )
)
apache2_modules_session_crypto? (
dev-libs/apr-util[openssl]
)
apache2_modules_tls? ( >=net-libs/rustls-ffi-0.9.2:= )
gdbm? ( sys-libs/gdbm:= )
ldap? ( net-nds/openldap:= )
selinux? ( sec-policy/selinux-apache )
ssl? (
>=dev-libs/openssl-1.0.2:=
kernel_linux? ( sys-apps/util-linux )
)
systemd? ( sys-apps/systemd )
"
DEPEND="${RDEPEND}"
BDEPEND="
virtual/pkgconfig
suexec? ( suexec-caps? ( sys-libs/libcap ) )
"
PDEPEND="~app-admin/apache-tools-${PV}"
REQUIRED_USE+="
apache2_modules_http2? ( ssl )
apache2_modules_lua? ( ${LUA_REQUIRED_USE} )
apache2_modules_md? ( ssl )
"
S="${WORKDIR}/httpd-${PV}"
# @VARIABLE: MODULE_DEPENDS
# @DESCRIPTION:
# This variable needs to be set in the ebuild and contains a space-separated
# list of dependency tokens each with a module and the module it depends on
# separated by a colon
# now extend REQUIRED_USE to reflect the module dependencies to portage
_apache2_set_module_depends() {
local dep
for dep in ${MODULE_DEPENDS} ; do
REQUIRED_USE+=" apache2_modules_${dep%:*}? ( apache2_modules_${dep#*:} )"
done
}
_apache2_set_module_depends
unset -f _apache2_set_module_depends
# ==============================================================================
# INTERNAL FUNCTIONS
# ==============================================================================
# @ECLASS_VARIABLE: MY_MPM
# @DESCRIPTION:
# This internal variable contains the selected MPM after a call to setup_mpm()
# @FUNCTION: setup_mpm
# @DESCRIPTION:
# This internal function makes sure that only one of APACHE2_MPMS was selected
# or a default based on USE=threads is selected if APACHE2_MPMS is empty
setup_mpm() {
MY_MPM=""
for x in ${IUSE_MPMS} ; do
if use apache2_mpms_${x} ; then
# there can at most be one MPM selected because of REQUIRED_USE constraints
MY_MPM=${x}
elog
elog "Selected MPM: ${MY_MPM}"
elog
break
fi
done
if [[ -z "${MY_MPM}" ]] ; then
if use threads ; then
MY_MPM=${DEFAULT_MPM_THREADED}
elog
elog "Selected default threaded MPM: ${MY_MPM}"
elog
else
MY_MPM=prefork
elog
elog "Selected default MPM: ${MY_MPM}"
elog
fi
fi
}
# @VARIABLE: MODULE_CRITICAL
# @DESCRIPTION:
# This variable needs to be set in the ebuild and contains a space-separated
# list of modules critical for the default apache. A user may still
# disable these modules for custom minimal installation at their own risk.
# @FUNCTION: check_module_critical
# @DESCRIPTION:
# This internal function warns the user about modules critical for the default
# apache configuration.
check_module_critical() {
local unsupported=0
for m in ${MODULE_CRITICAL} ; do
if ! has ${m} ${MY_MODS[@]} ; then
ewarn "Module '${m}' is required in the default apache configuration."
unsupported=1
fi
done
if [[ ${unsupported} -ne 0 ]] ; then
ewarn
ewarn "You have disabled one or more required modules"
ewarn "for the default apache configuration."
ewarn "Although this is not an error, please be"
ewarn "aware that this setup is UNSUPPORTED."
ewarn
fi
}
# @ECLASS_VARIABLE: MY_CONF
# @DESCRIPTION:
# This internal variable contains the econf options for the current module
# selection after a call to setup_modules()
# @ECLASS_VARIABLE: MY_MODS
# @DESCRIPTION:
# This internal variable contains a sorted, space separated list of currently
# selected modules after a call to setup_modules()
# @FUNCTION: setup_modules
# @DESCRIPTION:
# This internal function selects all built-in modules based on USE flags and
# APACHE2_MODULES USE_EXPAND flags
setup_modules() {
local mod_type= x=
if use static ; then
mod_type="static"
else
mod_type="shared"
fi
MY_CONF=( --enable-so=static --disable-static )
MY_MODS=()
if use ldap ; then
MY_CONF+=(
--enable-authnz_ldap=${mod_type}
--enable-ldap=${mod_type}
)
MY_MODS+=( ldap authnz_ldap )
else
MY_CONF+=( --disable-authnz_ldap --disable-ldap )
fi
if use ssl ; then
MY_CONF+=( --with-ssl --enable-ssl=${mod_type} )
MY_MODS+=( ssl )
else
MY_CONF+=( --without-ssl --disable-ssl )
fi
if use suexec ; then
elog "You can manipulate several configure options of suexec"
elog "through the following environment variables:"
elog
elog " SUEXEC_SAFEPATH: Default PATH for suexec (default: '${EPREFIX}/usr/local/bin:${EPREFIX}/usr/bin:${EPREFIX}/bin')"
if ! use suexec-syslog ; then
elog " SUEXEC_LOGFILE: Path to the suexec logfile (default: '${EPREFIX}/var/log/apache2/suexec_log')"
fi
elog " SUEXEC_CALLER: Name of the user Apache is running as (default: apache)"
elog " SUEXEC_DOCROOT: Directory in which suexec will run scripts (default: '${EPREFIX}/var/www')"
elog " SUEXEC_MINUID: Minimum UID, which is allowed to run scripts via suexec (default: 1000)"
elog " SUEXEC_MINGID: Minimum GID, which is allowed to run scripts via suexec (default: 100)"
elog " SUEXEC_USERDIR: User subdirectories (like /home/user/html) (default: public_html)"
elog " SUEXEC_UMASK: Umask for the suexec process (default: 077)"
elog
MY_CONF+=( --with-suexec-safepath="${SUEXEC_SAFEPATH:-${EPREFIX}/usr/local/bin:${EPREFIX}/usr/bin:${EPREFIX}/bin}" )
MY_CONF+=( $(use_with !suexec-syslog suexec-logfile "${SUEXEC_LOGFILE:-${EPREFIX}/var/log/apache2/suexec_log}") )
MY_CONF+=( $(use_with suexec-syslog) )
if use suexec-syslog && use suexec-caps ; then
MY_CONF+=( --enable-suexec-capabilities )
fi
MY_CONF+=( --with-suexec-bin="${EPREFIX}/usr/sbin/suexec" )
MY_CONF+=( --with-suexec-userdir=${SUEXEC_USERDIR:-public_html} )
MY_CONF+=( --with-suexec-caller=${SUEXEC_CALLER:-apache} )
MY_CONF+=( --with-suexec-docroot="${SUEXEC_DOCROOT:-${EPREFIX}/var/www}" )
MY_CONF+=( --with-suexec-uidmin=${SUEXEC_MINUID:-1000} )
MY_CONF+=( --with-suexec-gidmin=${SUEXEC_MINGID:-100} )
MY_CONF+=( --with-suexec-umask=${SUEXEC_UMASK:-077} )
MY_CONF+=( --enable-suexec=${mod_type} )
MY_MODS+=( suexec )
else
MY_CONF+=( --disable-suexec )
fi
if use systemd ; then
MY_CONF+=( --enable-systemd=${mod_type} )
MY_MODS+=( systemd )
fi
for x in ${IUSE_MODULES/ systemd} ; do
if use apache2_modules_${x} ; then
MY_CONF+=( --enable-${x}=${mod_type} )
MY_MODS+=( ${x} )
else
MY_CONF+=( --disable-${x} )
fi
done
# sort and uniquify MY_MODS
MY_MODS=( $(echo ${MY_MODS[@]} | tr ' ' '\n' | sort -u) )
check_module_critical
}
# @VARIABLE: MODULE_DEFINES
# @DESCRIPTION:
# This variable needs to be set in the ebuild and contains a space-separated
# list of tokens each mapping a module to a runtime define which can be
# specified in APACHE2_OPTS in /etc/conf.d/apache2 to enable this particular
# module.
# @FUNCTION: generate_load_module
# @DESCRIPTION:
# This internal function generates the LoadModule lines for httpd.conf based on
# the current module selection and MODULE_DEFINES
generate_load_module() {
local def= endit=0 m= mod_lines= mod_dir="${ED}/usr/$(get_libdir)/apache2/modules"
if use static; then
sed -i -e "/%%LOAD_MODULE%%/d" \
"${GENTOO_PATCHDIR}"/conf/httpd.conf
return
fi
for m in ${MY_MODS[@]} ; do
if [[ -e "${mod_dir}/mod_${m}.so" ]] ; then
for def in ${MODULE_DEFINES} ; do
if [[ "${m}" == "${def%:*}" ]] ; then
mod_lines="${mod_lines}\n