# here goes apache2 specific macroses
# (although not all of them are required
# for building modules)
%apache2_branch			2
%apache2_name			apache%apache2_branch
%apache2_dname			httpd%apache2_branch

%apache2_version		%get_version %apache2_name-devel
%apache2_release		%get_release %apache2_name-devel

# Macros for libssl selected
%apache2_libssl_name		libssl
%apache2_libssl_soname		%(rpm -qR %apache2_libssl_name-devel | sed -rn '/^[[:space:]]*%apache2_libssl_name[0-9.]+[[:space:]]+[=<>]/s/^[[:space:]]*libssl([0-9.]+)[[:space:]]+[=<>].*$/\\1/p')
%apache2_libssl			%apache2_libssl_name%apache2_libssl_soname

# Macros for libapr{,util} selected
%apache2_libapr_name		libapr1
%apache2_libapr_evr		%get_SVR %apache2_libapr_name-devel
%apache2_libaprutil_name	libaprutil1
%apache2_libaprutil_evr		%get_SVR %apache2_libaprutil_name-devel

# Macros for SSL certs/keys
%apache2_ssldir			%(openssl-config --openssldir)
%apache2_sslcertsdir		%apache2_ssldir/certs
%apache2_sslkeysdir		%apache2_ssldir/private
%apache2_sslcertname		%apache2_dname
%apache2_sslcertext		cert
%apache2_sslcertificatefile	%apache2_sslcertsdir/%apache2_sslcertname.%apache2_sslcertext
%apache2_sslcertificatekeyfile	%apache2_sslkeysdir/%apache2_sslcertname.key
%apache2_sslrootcertfilename	ca-root.pem
%apache2_sslcertsh		%apache2_bindir/%apache2_dname-cert-sh
%apache2_sslcertshfunctions	%apache2_sslcertsh-functions

# Users and groups
%apache2_user			%apache2_name
%apache2_group			%apache2_name
%apache2_webmaster		%webserver_webmaster

# Use webserver-common macros
%apache2_datadir		%webserver_datadir
%apache2_htdocsdir		%webserver_htdocsdir
%apache2_htdocsaddondir		%webserver_htdocsaddondir
%apache2_manualaddonsdir	%webserver_manualaddonsdir
%apache2_cgibindir		%webserver_cgibindir
%apache2_iconsdir		%webserver_iconsdir
%apache2_iconssmalldir		%webserver_iconssmalldir
%apache2_vhostdir		%webserver_vhostdir
%apache2_webappsdir		%webserver_webappsdir
%apache2_uploadsdir		%webserver_uploadsdir

# Server specific datadirs
%apache2_serverdatadir		%webserver_datadir/%apache2_name
%apache2_manualdir		%apache2_serverdatadir/manual
%apache2_errordir		%apache2_serverdatadir/error

# Macros for support the old configurations
%apache2_compat_datadir		%apache2_serverdatadir
%apache2_compat_htdocsdir	%apache2_compat_datadir/html
%apache2_compat_manualaddonsdir	%apache2_compat_datadir/manual-addons
%apache2_compat_cgibindir	%apache2_compat_datadir/cgi-bin
%apache2_compat_iconsdir	%apache2_compat_datadir/icons
%apache2_compat_iconssmalldir	%apache2_compat_iconsdir/small
%apache2_compat_vhostdir	%apache2_vhostdir
%apache2_compat_webappsdir	%apache2_webappsdir
%apache2_compat_manualdir	%apache2_manualdir
%apache2_compat_errordir	%apache2_errordir

%apache2_bindir			%_bindir
%apache2_sbindir		%_sbindir
%apache2_mandir			%_mandir
%apache2_localstatedir		%_var
%apache2_logfiledir		%_logdir/%apache2_dname
%apache2_includedir		%_includedir/%apache2_name
%apache2_runtimedir		%_runtimedir/%apache2_dname
%apache2_proxycachedir		%_cachedir/%apache2_dname
%apache2_spooldir		%_spooldir/%apache2_name
%apache2_infodir		%_infodir
%apache2_libdir			%_libdir/%apache2_name
%apache2_installbuilddir	%apache2_libdir/build
%apache2_moduledir		%apache2_libdir/modules
%apache2_libexecdir		%apache2_moduledir
%apache2_logdir			%_logdir/%apache2_dname
%apache2_tmpdir			%_spooldir/%apache2_name
%apache2_lockdir		%_lockdir/%apache2_dname
%apache2_httpdlockfile		%_locksubsysdir/%apache2_dname
%apache2_docdir_prefix		%_docdir/%apache2_name

# Basedir
%apache2_basedir		%_sysconfdir/%apache2_dname

# Links in basedir
%apache2_modulelink		%apache2_basedir/modules
%apache2_loglink		%apache2_basedir/logs
%apache2_runtimelink		%apache2_basedir/run
%apache2_uploadslink		%apache2_basedir/uploads
%apache2_locklink		%apache2_basedir/lock

# Configs
%apache2_confdir_name		conf
%apache2_confdir		%apache2_basedir/%apache2_confdir_name
%apache2_conf			%apache2_confdir/%apache2_dname.conf

# Env config
%apache2_envconf		%_sysconfdir/sysconfig/%apache2_dname

# Pid file
%apache2_pidfile_name		httpd.pid
%apache2_pidfile		%apache2_runtimedir/%apache2_pidfile_name

# Debian`like conf
%apache2_mods_available		%apache2_confdir/mods-available
%apache2_mods_enabled		%apache2_confdir/mods-enabled
%apache2_mods_start		%apache2_confdir/mods-start.d
%apache2_ports_available	%apache2_confdir/ports-available
%apache2_ports_enabled		%apache2_confdir/ports-enabled
%apache2_ports_start		%apache2_confdir/ports-start.d
%apache2_sites_available	%apache2_confdir/sites-available
%apache2_sites_enabled		%apache2_confdir/sites-enabled
%apache2_sites_start		%apache2_confdir/sites-start.d
%apache2_extra_available	%apache2_confdir/extra-available
%apache2_extra_enabled		%apache2_confdir/extra-enabled
%apache2_extra_start		%apache2_confdir/extra-start.d
%apache2_confdir_inc		%apache2_confdir/include

# apachectl
%apache2_apachectl_name		apachectl%apache2_branch
%apache2_apachectl		%apache2_sbindir/%apache2_apachectl_name

# RPMFileTrigger
%apache2_rpmfiletriggerdir	%apache2_runtimedir/rpmfiletrigger
%apache2_rpmhttpdrestartfile	%apache2_rpmfiletriggerdir/%apache2_dname-restart
%apache2_rpmhttpdstartfile	%apache2_rpmfiletriggerdir/%apache2_dname-start
%apache2_rpma2chkconfigfile	%apache2_rpmfiletriggerdir/a2chkconfig
%apache2_rpmhtcachecleanrestartfile	%apache2_rpmfiletriggerdir/%apache2_htcacheclean_dname-restart

# htcacheclean
%apache2_htcacheclean_dname	htcacheclean2
%apache2_htcacheclean_cachepath	%apache2_proxycachedir/mod_cache_disk
%apache2_htcacheclean_lockdir	%_locksubsysdir
%apache2_htcacheclean_piddir	%apache2_runtimedir

# Old macros
%apache2_addonconfdir		%apache2_confdir/addon.d

# This tells apache-based packages what
# APR to require and use
%apache2_apr_buildreq		libaprutil1-devel
%apache2_apr_config		%_bindir/apr-1-config
%apache2_apu_config		%_bindir/apu-1-config

%apache2_exec_prefix		%prefix

# apxs
%apache2_apxs_name		apxs%apache2_branch
%apache2_apxs			%apache2_bindir/%apache2_apxs_name

%apache2_suexec_docroot		/home

# Standard %%post/%%postun scripts for packages extending apache configuration
# see also https://bugzilla.altlinux.org/show_bug.cgi?id=1735
%post_apache2conf	/sbin/service %apache2_dname condreload
%postun_apache2conf	/sbin/service %apache2_dname condreload

# create rpmfiletrigger scripts
%apache2_create_rpmfiletriggerdir() \
if [ ! -d %apache2_rpmfiletriggerdir ]; then \
	mkdir -p %apache2_rpmfiletriggerdir \
fi \
%nil

# triggerun scripts
%triggerun_apache2_rpmhttpdstartfile() \
if [ -e %apache2_httpdlockfile ]; then \
	%apache2_create_rpmfiletriggerdir \
	touch %apache2_rpmhttpdstartfile \
fi \
%nil

# httpd2 restart scripts
%post_apache2_rpmhttpdrestartfile() \
%apache2_create_rpmfiletriggerdir \
touch %apache2_rpmhttpdrestartfile \
%nil

# htcacheclean restart scripts
%post_apache2_rpmhtcachecleanrestartfile() \
%apache2_create_rpmfiletriggerdir \
touch %apache2_rpmhtcachecleanrestartfile \
%nil

# a2chkconfig using scripts
%post_apache2_rpma2chkconfigfile() \
%apache2_create_rpmfiletriggerdir \
touch %apache2_rpma2chkconfigfile \
%nil

# rename var in config file scripts
# use:
# %post_apache2_rpmrenamevarinconfig <file> <oldname> <newname>
%post_apache2_rpmrenamevarinconfig() \
if ! grep -qsm1 '^[[:space:]]*%3=' %1; then \
	if grep -qsm1 '^[[:space:]]*%2=' %1; then \
		echo 'Warning: The file %1' \
		echo '    variable %2 renamed to %3' \
		sed -ri 's/^([[:space:]]*)%2(=.*)$/#\\0\\n\\1%3\\2/' %1 \
	fi \
fi \
%nil
