### this file is sourced not run
PKGVER=2.2.7
PKGBUILD=1
PKGARCH=i686

# source: post BLFS 8.2 2018-06-01
TARBALL=cups-$PKGVER-source.tar.gz
MD5SUM=ac703bcde223dab6d205a5fff193f716
SRC_URL=https://github.com/apple/cups/releases/download/v${PKGVER}/$TARBALL
BUNDLE=

SLACKREQ='libgnutls cups-filters dbus32 libusb32 avahi32'
SLACKDESC="cups-avahi32: cups-avahi32 $PKGVER (CUPS - Common Unix Printing System)  
cups-avahi32:  
cups-avahi32: The Common Unix Printing System (CUPS) is a print spooler and associated 
cups-avahi32: utilities. It is based on the \"Internet Printing Protocol\" and provides 
cups-avahi32: printing services to most PostScript and raster printers.  
cups-avahi32: 
cups-avahi32: This version of CUPS is compiled with support for Bonjour/Zeroconf/mdns
cups-avahi32: and requires avahi package to be installed. If you don't want 
cups-avahi32: zeroconf support, use cups-std32.
cups-avahi32: 
cups-avahi32: This contains 32-bit version of the library.
"
SLACKSUG=xdg-utils
SLACKCON=cups-std

### default pkg_download

### prepare
pkg_prepare() {
	pkg_prepare_default &&
	cd tmp/cups* &&
	patch -Np1 -i ../pkg/pam-less-build-fix.patch
}

pkg_package() {
	rm -rf etc bin sbin usr/bin usr/sbin usr/include usr/share var
	mkdir -p usr/bin
	mv tmp/*-32 usr/bin
}

### build
pkg_build() {
	# note: NO CONFFLAGS here!!! Edit !!!

	# create users (must be the same as the one we will use in the running system)
	echo lp::111: >> /etc/group
	echo lpadmin::112: >> /etc/group
	echo lp:x:9:111:lp:/var/spool/cups:/bin/false >> /etc/passwd
	#return 1
	
	cd /tmp/cups* &&
	#sed -i -e '/CUPS_SERVERBIN/ s|/lib/|/lib64/|' \
	#config-scripts/cups-directories.m4 && # lib64 patch

	# BLFS 8.2: only if we don't use xdg-utils ... but we do.
	#sed -i 's#@CUPS_HTMLVIEW@#firefox#' desktop/cups.desktop.in

	# BLFS 8.2: fix permissions and don't compress manpages
	sed -i 's:444:644:' Makedefs.in                                     &&
	sed -i '/MAN.EXT/s:.gz::' configure config-scripts/cups-manpages.m4 &&
	
	# re-generate configure
	aclocal -I config-scripts &&
	autoconf -I config-scripts &&
	./configure --libdir=/usr/$LIBDIR \
            --with-rcdir=/tmp/cupsinit \
            --with-docdir=/usr/share/cups/doc-$PKGVER \
            --with-system-groups=lpadmin \
            --disable-dnssd \
            --enable-avahi \
            --enable-libusb --enable-relro &&
#           --disable-libusb # they say in cups after 1.7.3 both usblp and libusb works
#           --disable-dbus # if disabled, remote printing with cups-browsed will not work.

	make $MAKEFLAGS &&
	make $MAKEINSTALLFLAGS install &&
	
	ln -sfv ../cups/doc-$PKGVER /usr/share/doc/cups-$PKGVER &&
	echo "ServerName /var/run/cups/cups.sock" > /etc/cups/client.conf &&
	rm -rf /usr/share/cups/banners &&
	rm -rf /usr/share/cups/data/testprint &&
	rm /etc/passwd /etc/group &&
	pkg_build_slackdesc &&
	
	# multilib
	mv -v /usr/bin/cups-config /tmp/cups-config-32

}
