# Template file for 'brother-brscan5'
pkgname=brother-brscan5
version=1.6.2
revision=1
archs="i686 x86_64"
depends="sane libusb-compat"
short_desc="SANE scanner driver for brscan5-compatible printers"
maintainer="Alexandru Barbur <alex@ctrlc.name>"
license="custom:EULA"
homepage="https://support.brother.com/"
repository="nonfree"
nopie=yes
conf_files="/opt/brother/scanner/brscan5/brscan5.ini
 /opt/brother/scanner/brscan5/brsanenetdevice.cfg
 /opt/brother/scanner/brscan5/models/*.ini"

_sane_library="libsane-brother5.so.1.0.7"
_pkg_libraries="libLxBsScanCoreApi.so.3.2.6
 libLxBsNetDevAccs.so.1.0.0
 libLxBsDeviceAccs.so.1.0.0
 libLxBsUsbDevAccs.so.1.0.0"

if [ "$XBPS_TARGET_MACHINE" = "x86_64" ]; then
	_rpmpkgid="0.x86_64"
	distfiles="https://download.brother.com/welcome/dlf104036/brscan5-${version}-${_rpmpkgid}.rpm"
	checksum="a14b991dafd0279cc92c981154901178825174b8ac2123868037b3614b8f905e"
	_rpmlibdir="usr/lib64"
else
	_rpmpkgid="0.i386"
	distfiles="https://download.brother.com/welcome/dlf104035/brscan5-${version}-${_rpmpkgid}.rpm"
	checksum="0fb59e0eb74f6c46568e314f6c6d5c8da22acdeb9b637519fdb922663be889c7"
	_rpmlibdir="usr/lib"
fi

do_install() {
	vinstall opt/brother/scanner/brscan5/${_sane_library} 755 usr/lib/sane
	ln -sf /usr/lib/sane/${_sane_library} ${DESTDIR}/usr/lib/sane/$(echo ${_sane_library} | sed -e 's/\.[0-9]\.[0-9]$//')
	ln -sf /usr/lib/sane/${_sane_library} ${DESTDIR}/usr/lib/sane/$(echo ${_sane_library} | sed -e 's/\.[0-9]\.[0-9]\.[0-9]$//')

	for library in $_pkg_libraries; do
		vinstall opt/brother/scanner/brscan5/${library} 755 usr/lib
		ln -sf /usr/lib/${library} ${DESTDIR}/usr/lib/$(echo ${library} | sed -e 's/\.[0-9]\.[0-9]$//')
		ln -sf /usr/lib/${library} ${DESTDIR}/usr/lib/$(echo ${library} | sed -e 's/\.[0-9]\.[0-9]\.[0-9]$//')
	done

	pushd opt/brother/scanner/brscan5/udev-rules
	sed '/SYSFS/d' NN-brother-mfp-brscan5-1.0.2-2.rules > 40-brother-mfp-brscan5-1.0.2-2.rules
	vinstall 40-brother-mfp-brscan5-1.0.2-2.rules 644 usr/lib/udev/rules.d
	popd

	# note: configuration file locations are hard-coded in libsane-brother5.so
	vinstall opt/brother/scanner/brscan5/brsaneconfig5 755 opt/brother/scanner/brscan5
	vinstall opt/brother/scanner/brscan5/brscan5.ini 644 opt/brother/scanner/brscan5
	vinstall opt/brother/scanner/brscan5/brsanenetdevice.cfg 644 opt/brother/scanner/brscan5
	vinstall opt/brother/scanner/brscan5/brscan_cnetconfig 755 opt/brother/scanner/brscan5
	vinstall opt/brother/scanner/brscan5/brscan_gnetconfig 755 opt/brother/scanner/brscan5

	vmkdir etc/opt/brother/scanner/brscan5 755
	ln -sf /opt/brother/scanner/brscan5/brscan5.ini ${DESTDIR}/etc/opt/brother/scanner/brscan5/brscan5.ini
	ln -sf /opt/brother/scanner/brscan5/brsanenetdevice.cfg ${DESTDIR}/etc/opt/brother/scanner/brscan5/brsanenetdevice.cfg
	ln -sf /opt/brother/scanner/brscan5/models ${DESTDIR}/etc/opt/brother/scanner/brscan5/models

	vmkdir opt/brother/scanner/brscan5 755
	vcopy opt/brother/scanner/brscan5/models opt/brother/scanner/brscan5

	vlicense opt/brother/scanner/brscan5/doc/LICENSE_ENG.txt
	vlicense opt/brother/scanner/brscan5/doc/LICENSE_JPN.txt
	vlicense opt/brother/scanner/brscan5/doc/readme.txt # Independent JPEG blurb.

	vbin opt/brother/scanner/brscan5/brsaneconfig5
}

post_install() {
	vdoc "${FILESDIR}/README.voidlinux"
}
