# SliTaz package receipt.

PACKAGE="cups"
VERSION="1.4.6"
CATEGORY="system-tools"
SHORT_DESC="Common UNIX Printing System."
MAINTAINER="erjo@slitaz.org"
DEPENDS="libssl slitaz-base-files gnutls dbus jpeg libpng tiff zlib \
libcomerr libkrb5 gcc-lib-base libusb-compat libtasn1 poppler-apps"
BUILD_DEPENDS="openssl-dev php-dev poppler-apps"
TARBALL="$PACKAGE-$VERSION-source.tar.bz2"
WEB_SITE="http://www.cups.org/"
WGET_URL="ftp://ftp.easysw.com/pub/cups/$VERSION/$TARBALL"
TAGS="printer printing"

# Rules to configure and make the package.
compile_rules()
{
	cd $src
	./configure \
		--prefix=/usr \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--mandir=/usr/share/man \
		--enable-static \
		--disable-ldap \
		--disable-pam \
		--disable-gssapi \
		--disable-acl \
		--disable-slp \
		--enable-dbus \
		--with-dbusdir=/etc/dbus-1 \
		--with-cups-user=nobody \
		--with-cups-group=nogroup \
		--with-languages="de es fr" \
		--with-pdftops=pdftops \
		$CONFIGURE_ARGS &&
	make &&
	make BUILDROOT=$PWD/_pkg install

}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/etc $fs/usr/lib $fs/usr/share/pixmaps

	cp -a $_pkg/etc/cups $fs/etc
	cp -a $_pkg/etc/dbus* $fs/etc
	cp -a $_pkg/usr/bin $fs/usr
	cp -a $_pkg/usr/sbin $fs/usr
	cp -a $_pkg/usr/lib/*.so* $fs/usr/lib
	cp -a $_pkg/usr/lib/cups $fs/usr/lib
	cp -a $_pkg/usr/share/cups $fs/usr/share
	cp -a $_pkg/usr/share/icons/hicolor/32x32/apps/cups.png $fs/usr/share/pixmaps
	cp -a $_pkg/var $fs

	# We need the doc for CSS, images and help in the web interface.
	cp -a $_pkg/usr/share/doc $fs/usr/share

	# tazwok does not strip files other than .so in usr/lib

	for dir in $fs/usr/lib/cups
	do
		if [ -d "$dir" ]; then
			find $dir -type f -exec strip -s '{}' 2>/dev/null \;
		fi
	done

	# Daemon script
	cp -a $stuff/etc $fs
}

# Start cups daemon and edit daemons.conf.
post_install()
{
	local root
	root=$1
	if [ -z "$root" ]; then
		/etc/init.d/cupsd start || continue
	fi
	if ! grep -q ^CUPSD_OPTIONS $root/etc/daemons.conf; then
		echo '# Cups printing daemon options.' >> $root/etc/daemons.conf
		echo 'CUPSD_OPTIONS=""' >> $root/etc/daemons.conf
		echo '' >> $root/etc/daemons.conf
	fi
}

# Stop cups daemon before rm.
pre_remove()
{
	/etc/init.d/cupsd stop
}

# Overlap busybox
pre_install()
{
	rm -f $1/usr/bin/lpr
}

post_remove()
{
	ln -s /bin/busybox /usr/bin/lpr
}