# Template file for 'brother-brscan4'
pkgname=brother-brscan4
version=0.4.9
revision=1
archs="i686 x86_64"
depends="sane"
short_desc="SANE scanner driver for brscan4-compatible printers"
maintainer="Martijn van Buul <martijn.van.buul@gmail.com>"
license="custom:EULA"
homepage="https://support.brother.com/"
repository="nonfree"
nopie=yes
_mylibrary="libsane-brother4.so.1.0.7"
conf_files="/etc/opt/brother/scanner/brscan4/Brsane4.ini
 /etc/opt/brother/scanner/brscan4/brsanenetdevice4.cfg
 /etc/opt/brother/scanner/brscan4/models4/*.ini"

# The license was removed by Brother - we vendor it.
# distfiles="http://www.brother.com/agreement/English_sane/agree.html>LICENSE.html"
# checksum="3434bca1936d6a5fd6afd810cde7e1876dd4d1496722b09af180278480f464f2"

if [ "$XBPS_TARGET_MACHINE" = "x86_64" ]; then
	_rpmpkgid="1.x86_64"
	distfiles="https://download.brother.com/welcome/dlf006648/brscan4-${version}-${_rpmpkgid}.rpm"
	checksum="0d0af0f3f299a94d32b275f4714c72407ee679dd9e27eac050d6728cd728ac89"
	_rpmlibdir="usr/lib64"
else
	_rpmpkgid="1.i386"
	distfiles="https://download.brother.com/welcome/dlf006647/brscan4-${version}-${_rpmpkgid}.rpm"
	checksum="73bcbcc661a05000375266369fc6e22a980cc956ac7f92926ff42516f92845f8"
	_rpmlibdir="usr/lib"
fi

do_install() {
	# binary package makes a fine mess of things, and installs stuff in very
	# unwieldly locations. Some of this cannot be avoided.

	# deb package installs 64-bit libraries in /usr/lib64; fix this
	vinstall ./${_rpmlibdir}/sane/${_mylibrary} 755 usr/lib/sane
	ln -sf /usr/lib/sane/${_mylibrary} ${DESTDIR}/usr/lib/sane/$(echo ${_mylibrary} | sed -e 's/\.[0-9]\.[0-9]$//')
	ln -sf /usr/lib/sane/${_mylibrary} ${DESTDIR}/usr/lib/sane/$(echo ${_mylibrary} | sed -e 's/\.[0-9]\.[0-9]\.[0-9]$//')

	# The binary library has hard-coded paths to
	#
	# /etc/opt/brother/scanner/brscan4
	#
	# This is very unfortunate, but cannot be avoided without the source to
	# recompile the binary - which is not available.
	#
	# The deb package then goes ahead and installs symlinks to the actual
	# files in /opt/brother/scanner/brscan4. Limit the mess by actually
	# installing these files to /etc/opt/brother/scanner/brscan4 so there
	# are no configuration files in /opt

	vmkdir etc/opt/brother/scanner/brscan4 755
	vinstall opt/brother/scanner/brscan4/Brsane4.ini 644 etc/opt/brother/scanner/brscan4
	vinstall opt/brother/scanner/brscan4/brsanenetdevice4.cfg 644 etc/opt/brother/scanner/brscan4
	vcopy opt/brother/scanner/brscan4/models4 etc/opt/brother/scanner/brscan4

	# Install the licenses.
	vlicense ${FILESDIR}/agree.html LICENSE.html
	vlicense opt/brother/scanner/brscan4/doc/brscan4/readme.txt # Independent JPEG blurb.

	# config helper - installed by the deb package as a symlink.
	vbin opt/brother/scanner/brscan4/brsaneconfig4

	# The only file in the deb package that has *not* been installed is a
	# setup script to modify the SANE configuration. This will be performed
	# by INSTALL and REMOVE instead.
	vdoc "${FILESDIR}/README.voidlinux"
}
