2020-04-28 04:29:39 +01:00
|
|
|
{ stdenv, fetchurl, callPackage, patchelf, makeWrapper, coreutils, libusb-compat-0_1 }:
|
2016-04-30 02:45:21 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
myPatchElf = file: with stdenv.lib; ''
|
|
|
|
patchelf --set-interpreter \
|
|
|
|
${stdenv.glibc}/lib/ld-linux${optionalString stdenv.is64bit "-x86-64"}.so.2 \
|
|
|
|
${file}
|
|
|
|
'';
|
|
|
|
|
|
|
|
udevRules = callPackage ./udev_rules_type1.nix {};
|
|
|
|
|
2016-05-04 11:08:35 +01:00
|
|
|
in stdenv.mkDerivation rec {
|
2020-03-04 21:47:31 +00:00
|
|
|
name = "brscan4-0.4.8-1";
|
2021-01-01 13:46:40 +00:00
|
|
|
src =
|
2018-08-20 20:11:29 +01:00
|
|
|
if stdenv.hostPlatform.system == "i686-linux" then
|
2017-03-03 03:03:16 +00:00
|
|
|
fetchurl {
|
|
|
|
url = "http://download.brother.com/welcome/dlf006646/${name}.i386.deb";
|
2020-03-04 21:47:31 +00:00
|
|
|
sha256 = "15hrf1gpm36lniqi6yf47dvdqjinm644xb752c6rcv8n06wb79ag";
|
2017-03-03 03:03:16 +00:00
|
|
|
}
|
2018-08-20 20:11:29 +01:00
|
|
|
else if stdenv.hostPlatform.system == "x86_64-linux" then
|
2017-03-03 03:03:16 +00:00
|
|
|
fetchurl {
|
2018-06-28 19:43:35 +01:00
|
|
|
url = "https://download.brother.com/welcome/dlf006645/${name}.amd64.deb";
|
2020-03-04 21:47:31 +00:00
|
|
|
sha256 = "0pyprjl0capg403yp6pp07gd6msx9kn7bzjcdswdbn28fyxrk5l4";
|
2017-03-03 03:03:16 +00:00
|
|
|
}
|
2018-08-20 20:11:29 +01:00
|
|
|
else throw "${name} is not supported on ${stdenv.hostPlatform.system} (only i686-linux and x86_64 linux are supported)";
|
2016-04-30 02:45:21 +01:00
|
|
|
|
|
|
|
unpackPhase = ''
|
|
|
|
ar x $src
|
|
|
|
tar xfvz data.tar.gz
|
|
|
|
'';
|
|
|
|
|
|
|
|
nativeBuildInputs = [ makeWrapper patchelf coreutils udevRules ];
|
2020-04-28 04:29:39 +01:00
|
|
|
buildInputs = [ libusb-compat-0_1 ];
|
2016-05-04 11:08:35 +01:00
|
|
|
dontBuild = true;
|
2016-04-30 02:45:21 +01:00
|
|
|
|
|
|
|
patchPhase = ''
|
|
|
|
${myPatchElf "opt/brother/scanner/brscan4/brsaneconfig4"}
|
|
|
|
|
2020-04-28 04:29:39 +01:00
|
|
|
RPATH=${libusb-compat-0_1.out}/lib
|
2016-04-30 02:45:21 +01:00
|
|
|
for a in usr/lib64/sane/*.so*; do
|
|
|
|
if ! test -L $a; then
|
|
|
|
patchelf --set-rpath $RPATH $a
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
2017-03-03 03:03:16 +00:00
|
|
|
installPhase = with stdenv.lib; ''
|
2016-04-30 02:45:21 +01:00
|
|
|
PATH_TO_BRSCAN4="opt/brother/scanner/brscan4"
|
|
|
|
mkdir -p $out/$PATH_TO_BRSCAN4
|
|
|
|
cp -rp $PATH_TO_BRSCAN4/* $out/$PATH_TO_BRSCAN4
|
|
|
|
mkdir -p $out/lib/sane
|
2017-03-03 03:03:16 +00:00
|
|
|
cp -rp usr/lib${optionalString stdenv.is64bit "64"}/sane/* $out/lib/sane
|
2016-04-30 02:45:21 +01:00
|
|
|
|
|
|
|
# Symbolic links were absolute. Fix them so that they point to $out.
|
|
|
|
pushd "$out/lib/sane" > /dev/null
|
|
|
|
for a in *.so*; do
|
|
|
|
if test -L $a; then
|
|
|
|
fixedTargetFileName="$(basename $(readlink $a))"
|
|
|
|
unlink "$a"
|
|
|
|
ln -s -T "$fixedTargetFileName" "$a"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
popd > /dev/null
|
|
|
|
|
|
|
|
# Generate an LD_PRELOAD wrapper to redirect execvp(), open() and open64()
|
|
|
|
# calls to `/opt/brother/scanner/brscan4`.
|
|
|
|
preload=$out/libexec/brother/scanner/brscan4/libpreload.so
|
|
|
|
mkdir -p $(dirname $preload)
|
|
|
|
gcc -shared ${./preload.c} -o $preload -ldl -DOUT=\"$out\" -fPIC
|
|
|
|
|
|
|
|
makeWrapper \
|
|
|
|
"$out/$PATH_TO_BRSCAN4/brsaneconfig4" \
|
|
|
|
"$out/bin/brsaneconfig4" \
|
|
|
|
--set LD_PRELOAD $preload
|
|
|
|
|
|
|
|
mkdir -p $out/etc/sane.d
|
|
|
|
echo "brother4" > $out/etc/sane.d/dll.conf
|
|
|
|
|
|
|
|
mkdir -p $out/etc/udev/rules.d
|
|
|
|
cp -p ${udevRules}/etc/udev/rules.d/*.rules \
|
|
|
|
$out/etc/udev/rules.d
|
|
|
|
'';
|
|
|
|
|
|
|
|
dontStrip = true;
|
|
|
|
dontPatchELF = true;
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
description = "Brother brscan4 sane backend driver";
|
2020-04-01 02:11:51 +01:00
|
|
|
homepage = "http://www.brother.com";
|
2016-04-30 02:45:21 +01:00
|
|
|
platforms = stdenv.lib.platforms.linux;
|
|
|
|
license = stdenv.lib.licenses.unfree;
|
|
|
|
maintainers = with stdenv.lib.maintainers; [ jraygauthier ];
|
|
|
|
};
|
|
|
|
}
|