# Template file for 'cups'
pkgname=cups
version=1.6.1
revision=2
patch_args="-Np1"
depends="libcups>=${version}_${revision} cups-filters bc"
makedepends="automake perl pkg-config acl-devel jpeg-devel libpng-devel>=1.5.10 tiff-devel
openssl-devel pam-devel mit-krb5-devel poppler-devel libusb-devel avahi-libs-devel
systemd-devel gnutls-devel poppler-utils"
short_desc="Common Unix Printing System"
maintainer="Juan RP <xtraeme@gmail.com>"
homepage="http://www.cups.org/"
license="GPL-2"
distfiles="ftp://ftp.easysw.com/pub/cups/${version}/cups-${version}-source.tar.bz2"
checksum=5842ab1144e653160fe667ee78b932ee036b054c0c2d20533d19e309149a7790
long_desc="
 The Common UNIX Printing System (or CUPS(tm)) is a printing system and general
 replacement for lpd and the like. It supports the Internet Printing Protocol
 (IPP), and has its own filtering driver model for handling various document types."

make_dirs="
/var/cache/cups/rss 	0750 root lp
/var/run/cups/certs 	0750 root lp
/var/log/cups 		0750 root root
/var/spool/cups 	0755 root lp
/etc/cups/ssl 		0700 root lp"

subpackages="libcups cups-devel"
systemd_services="cups.socket on"
gtk_iconcache_dirs="/usr/share/icons/hicolor"

conf_files="
/etc/cups/cupsd.conf
/etc/cups/snmp.conf
/etc/cups/printers.conf
/etc/cups/classes.conf
/etc/cups/subscriptions.conf
/etc/dbus-1/system.d/cups.conf
/etc/logrotate.d/cups
/etc/pam.d/cups"

pre_configure() {
	aclocal -I config-scripts
	autoconf -I config-scripts
}

do_configure() {
	./configure ${CONFIGURE_SHARED_ARGS} --libdir=/usr/lib \
		--enable-acl --enable-dbus --enable-raw-printing \
		--enable-threads --with-logdir=/var/log/cups \
		--with-docdir=/usr/share/cups/doc \
		--with-cups-user=daemon --with-cups-group=lp \
		--enable-avahi --enable-pam --enable-ssl=yes --enable-gnutls \
		--with-systemdsystemunitdir=/usr/lib/systemd/system \
		--with-menudir=/usr/share/applications \
		--with-optim="${CFLAGS}"
}

do_build() {
	make ${makejobs}
}

do_install() {
	make BUILDROOT=${DESTDIR} install
	# Remove sysvinit scripts.
	rm -rf ${DESTDIR}/etc/rc.d
	rm -rf ${DESTDIR}/etc/init.d

	# compress some driver files, adopted from Fedora
	find ${DESTDIR}/usr/share/cups/model -name "*.ppd"|xargs gzip -n9f
	# 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
		chgrp lp ${DESTDIR}/etc/cups/${f}.conf
	done

	echo "# see 'man client.conf'" >> ${DESTDIR}/etc/cups/client.conf
	echo "ServerName /var/run/cups/cups.sock" >> ${DESTDIR}/etc/cups/client.conf
	echo "# alternative: ServerName hostname-or-ip-address[:port] of a remote server" >> \
		${DESTDIR}/etc/cups/client.conf
	# fix .desktop file
	sed -i 's|^Exec=htmlview http://localhost:631/|Exec=xdg-open http://localhost:631/|g' \
		${DESTDIR}/usr/share/applications/cups.desktop
	# Install pam and logrotate files.
	vinstall ${FILESDIR}/cups.pam 644 etc/pam.d cups
	vinstall ${FILESDIR}/cups.logrotate 644 etc/logrotate.d cups

	# Remove files provided by cups-filters.
	rm -f ${DESTDIR}/usr/share/cups/banners/*
	rm -f ${DESTDIR}/usr/share/cups/data/testprint
	# comment out all conversion rules which use any of the removed filters
	perl -p -i -e 's:^(.*\s+bannertops\s*)$:#\1:' \
		${DESTDIR}/usr/share/cups/mime/mime.convs
}
