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

# source: BLFS 11.3 updated to BLFS SVN r890
TARBALL=cups-$PKGVER-source.tar.gz
MD5SUM=b8ca6027eaeeed6171178cc526879ff5
SRC_URL=https://github.com/OpenPrinting/cups/releases/download/v$PKGVER/$TARBALL
BUNDLE=

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

### default pkg_download

### prepare
pkg_prepare() {
	pkg_prepare_default &&
	cd tmp/cups* &&
	# patch
	true
}

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 \
            --disable-avahi \
            --enable-libusb --enable-relro \
            --with-pkgconfpath=/usr/$LIBDIR/pkgconfig \
            &&
#           --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

}
