# Template file for 'cups'
pkgname=cups
version=2.4.2
revision=3
build_style=gnu-configure
make_install_args="BUILDROOT=${DESTDIR}"
hostmakedepends="gnutls-devel pkg-config
 $(vopt_if avahi avahi-libs-devel)"
makedepends="acl-devel gnutls-devel libpaper-devel libusb-devel pam-devel
 zlib-devel $(vopt_if avahi avahi-libs-devel) $(vopt_if gssapi mit-krb5-devel)"
depends="xdg-utils"
short_desc="Common Unix Printing System"
maintainer="Orphaned <orphan@voidlinux.org>"
license="Apache-2.0"
homepage="https://github.com/OpenPrinting/cups"
distfiles="https://github.com/OpenPrinting/cups/releases/download/v${version}/cups-${version}-source.tar.gz"
checksum=f03ccb40b087d1e30940a40e0141dcbba263f39974c20eb9f2521066c9c6c908

conf_files="/etc/pam.d/cups /etc/cups/*.conf /etc/xinetd.d/cups-lpd"
make_dirs="
 /usr/lib/cups/driver 0755 root root
 /var/log/cups 0750 root root
 /var/cache/cups/rss 0750 cups lp
 /var/spool/cups 0755 cups lp
 /etc/cups/ssl 0700 cups lp"
make_check=ci-skip # testsuite does not run as root

build_options="avahi gssapi"
build_options_default="avahi"

system_accounts="cups"
system_groups=lpadmin
cups_pgroup=lp
cups_homedir=/var/spool/cups

do_configure() {
	./configure ${configure_args} --sbindir=/usr/bin --libdir=/usr/lib \
		--enable-acl --with-logdir=/var/log/cups \
		--docdir=/usr/share/cups/doc --with-rundir=/run/cups \
		--with-cups-user=cups --with-cups-group=lp \
		--with-system-groups="lpadmin sys root" --enable-relro \
		--enable-libpaper --with-menudir=/usr/share/applications \
		--with-xinetd=/etc/xinetd.d --with-optim="${CFLAGS}" \
		--with-rcdir=no \
		$(vopt_if avahi '--with-dnssd=avahi') $(vopt_enable gssapi)
}

post_install() {
	# install some more configuration files that will get filled by cupsd
	for f in printers classes client subscriptions; do
		touch ${DESTDIR}/etc/cups/${f}.conf
	done

	# remove unnecessary PageLogFormat entry
	vsed -i -e 's:PageLogFormat:#PageLogFormat:' ${DESTDIR}/etc/cups/cupsd.conf*

	# fix .desktop file
	vsed -i 's|^Exec=htmlview http://localhost:631/|Exec=xdg-open http://localhost:631/|g' \
		${DESTDIR}/usr/share/applications/cups.desktop

	vinstall ${FILESDIR}/cups.pam 644 etc/pam.d cups
	vinstall ${FILESDIR}/client.conf 644 etc/cups client.conf

	vsv cupsd
}

libcups_package() {
	short_desc+=" - client runtime shared libraries"
	conf_files="/etc/cups/client.conf"
	pkg_install() {
		vmove "usr/lib/*.so.*"
		vmove etc/cups/client.conf
		vmove usr/share/man/man5/client.conf.5
	}
}

cups-devel_package() {
	depends="libcups>=${version}_${revision} openssl-devel avahi-libs-devel"
	short_desc+=" - development files"
	pkg_install() {
		vmove usr/lib/pkgconfig
		vmove usr/include
		vmove usr/bin/cups-config
		vmove "usr/lib/*.so"
	}
}
