uboot: (firmwareOdroidC2/C4) don't invoke patch tool, use patches = [] instead
https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/generic/setup.sh#L948 this can do it nicely. Signed-off-by: Anton Arapov <anton@deadbeef.mx>
This commit is contained in:
commit
56de2bcd43
30691 changed files with 3076956 additions and 0 deletions
95
pkgs/applications/graphics/sane/backends/brscan4/default.nix
Normal file
95
pkgs/applications/graphics/sane/backends/brscan4/default.nix
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
{ stdenv, lib, fetchurl, callPackage, patchelf, makeWrapper, libusb-compat-0_1 }:
|
||||
let
|
||||
myPatchElf = file: with lib; ''
|
||||
patchelf --set-interpreter \
|
||||
${stdenv.cc.libc}/lib/ld-linux${optionalString stdenv.is64bit "-x86-64"}.so.2 \
|
||||
${file}
|
||||
'';
|
||||
|
||||
udevRules = callPackage ./udev_rules_type1.nix { };
|
||||
|
||||
in
|
||||
stdenv.mkDerivation rec {
|
||||
pname = "brscan4";
|
||||
version = "0.4.10-1";
|
||||
src = {
|
||||
"i686-linux" = fetchurl {
|
||||
url = "http://download.brother.com/welcome/dlf006646/${pname}-${version}.i386.deb";
|
||||
sha256 = "sha256-ymIAg+rfSYP5uzsAM1hUYZacJ0PXmKEoljNtb0pgGMw=";
|
||||
};
|
||||
"x86_64-linux" = fetchurl {
|
||||
url = "https://download.brother.com/welcome/dlf006645/${pname}-${version}.amd64.deb";
|
||||
sha256 = "sha256-Gpr5456MCNpyam3g2qPo7S3aEZFMaUGR8bu7YmRY8xk=";
|
||||
};
|
||||
}."${stdenv.hostPlatform.system}";
|
||||
|
||||
unpackPhase = ''
|
||||
ar x $src
|
||||
tar xfvz data.tar.gz
|
||||
'';
|
||||
|
||||
nativeBuildInputs = [ makeWrapper patchelf udevRules ];
|
||||
buildInputs = [ libusb-compat-0_1 ];
|
||||
dontBuild = true;
|
||||
|
||||
postPatch = ''
|
||||
${myPatchElf "opt/brother/scanner/brscan4/brsaneconfig4"}
|
||||
|
||||
RPATH=${libusb-compat-0_1.out}/lib
|
||||
for a in usr/lib64/sane/*.so*; do
|
||||
if ! test -L $a; then
|
||||
patchelf --set-rpath $RPATH $a
|
||||
fi
|
||||
done
|
||||
'';
|
||||
|
||||
installPhase = with lib; ''
|
||||
runHook preInstall
|
||||
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
|
||||
cp -rp usr/lib${optionalString stdenv.is64bit "64"}/sane/* $out/lib/sane
|
||||
|
||||
# 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
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
dontStrip = true;
|
||||
dontPatchELF = true;
|
||||
|
||||
meta = {
|
||||
description = "Brother brscan4 sane backend driver";
|
||||
homepage = "http://www.brother.com";
|
||||
platforms = [ "i686-linux" "x86_64-linux" ];
|
||||
license = lib.licenses.unfree;
|
||||
maintainers = with lib.maintainers; [ jraygauthier ];
|
||||
};
|
||||
}
|
||||
170
pkgs/applications/graphics/sane/backends/brscan4/preload.c
Normal file
170
pkgs/applications/graphics/sane/backends/brscan4/preload.c
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
/* Brgen4 search for configuration under `/etc/opt/brother/scanner/brscan4`. This
|
||||
LD_PRELOAD library intercepts execvp(), open and open64 calls to redirect them to
|
||||
the corresponding location in $out. Also support specifying an alternate
|
||||
file name for `brsanenetdevice4.cfg` which otherwise is invariable
|
||||
created at `/etc/opt/brother/scanner/brscan4`*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <dlfcn.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
|
||||
char origDir [] = "/etc/opt/brother/scanner/brscan4";
|
||||
char realDir [] = OUT "/opt/brother/scanner/brscan4";
|
||||
|
||||
char devCfgFileNameEnvVar [] = "BRSANENETDEVICE4_CFG_FILENAME";
|
||||
char devCfgFileName [] = "/etc/opt/brother/scanner/brscan4//brsanenetdevice4.cfg";
|
||||
|
||||
const char * rewrite(const char * path, char * buf)
|
||||
{
|
||||
if (strncmp(path, devCfgFileName, sizeof(devCfgFileName)) == 0) {
|
||||
|
||||
const char* newCfgFileName = getenv(devCfgFileNameEnvVar);
|
||||
if (!newCfgFileName) return path;
|
||||
|
||||
if (snprintf(buf, PATH_MAX, "%s", newCfgFileName) >= PATH_MAX)
|
||||
abort();
|
||||
return buf;
|
||||
}
|
||||
|
||||
if (strncmp(path, origDir, sizeof(origDir) - 1) != 0) return path;
|
||||
if (snprintf(buf, PATH_MAX, "%s%s", realDir, path + sizeof(origDir) - 1) >= PATH_MAX)
|
||||
abort();
|
||||
return buf;
|
||||
}
|
||||
|
||||
const char* findAndReplaceFirstOccurence(const char* inStr, const char* subStr,
|
||||
const char* replaceStr,
|
||||
char* buf, unsigned maxBuf)
|
||||
{
|
||||
const char* foundStr = strstr(inStr, subStr);
|
||||
if (!foundStr)
|
||||
return inStr;
|
||||
|
||||
const unsigned inStrLen = strlen(inStr);
|
||||
const unsigned subStrLen = strlen(subStr);
|
||||
const unsigned replaceStrLen = strlen(replaceStr);
|
||||
|
||||
const unsigned precedingStrLen = foundStr - inStr;
|
||||
if (precedingStrLen + 1 > maxBuf)
|
||||
return NULL;
|
||||
|
||||
const unsigned followingStrPos = precedingStrLen + subStrLen;
|
||||
const unsigned followingStrLen = inStrLen - followingStrPos;
|
||||
|
||||
strncpy(buf, inStr, precedingStrLen);
|
||||
unsigned outLength = precedingStrLen;
|
||||
|
||||
if (outLength + replaceStrLen + 1 > maxBuf)
|
||||
return NULL;
|
||||
|
||||
strncpy(buf + outLength, replaceStr, replaceStrLen);
|
||||
outLength += replaceStrLen;
|
||||
|
||||
if (outLength + followingStrLen + 1 > maxBuf)
|
||||
return NULL;
|
||||
|
||||
strncpy(buf + outLength, inStr + followingStrPos, followingStrLen);
|
||||
outLength += followingStrLen;
|
||||
|
||||
buf[outLength] = '\0';
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
const char* rewriteSystemCall(const char* command, char* buf, unsigned maxBuf)
|
||||
{
|
||||
|
||||
const char* foundStr = strstr(command, devCfgFileName);
|
||||
if (!foundStr)
|
||||
return command;
|
||||
|
||||
const char* replaceStr = getenv(devCfgFileNameEnvVar);
|
||||
if (!replaceStr) return command;
|
||||
|
||||
const char* result =
|
||||
findAndReplaceFirstOccurence(command, devCfgFileName, replaceStr, buf, maxBuf);
|
||||
|
||||
if (!result)
|
||||
abort();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int execvp(const char * path, char * const argv[])
|
||||
{
|
||||
int (*_execvp) (const char *, char * const argv[]) = dlsym(RTLD_NEXT, "execvp");
|
||||
char buf[PATH_MAX];
|
||||
return _execvp(rewrite(path, buf), argv);
|
||||
}
|
||||
|
||||
|
||||
int open(const char *path, int flags, ...)
|
||||
{
|
||||
char buf[PATH_MAX];
|
||||
int (*_open) (const char *, int, mode_t) = dlsym(RTLD_NEXT, "open");
|
||||
mode_t mode = 0;
|
||||
if (flags & O_CREAT) {
|
||||
va_list ap;
|
||||
va_start(ap, flags);
|
||||
mode = va_arg(ap, mode_t);
|
||||
va_end(ap);
|
||||
}
|
||||
return _open(rewrite(path, buf), flags, mode);
|
||||
}
|
||||
|
||||
int open64(const char *path, int flags, ...)
|
||||
{
|
||||
char buf[PATH_MAX];
|
||||
int (*_open64) (const char *, int, mode_t) = dlsym(RTLD_NEXT, "open64");
|
||||
mode_t mode = 0;
|
||||
if (flags & O_CREAT) {
|
||||
va_list ap;
|
||||
va_start(ap, flags);
|
||||
mode = va_arg(ap, mode_t);
|
||||
va_end(ap);
|
||||
}
|
||||
return _open64(rewrite(path, buf), flags, mode);
|
||||
}
|
||||
|
||||
FILE* fopen(const char* path, const char* mode)
|
||||
{
|
||||
char buf[PATH_MAX];
|
||||
FILE* (*_fopen) (const char*, const char*) = dlsym(RTLD_NEXT, "fopen");
|
||||
|
||||
return _fopen(rewrite(path, buf), mode);
|
||||
}
|
||||
|
||||
FILE *fopen64(const char *path, const char *mode)
|
||||
{
|
||||
char buf[PATH_MAX];
|
||||
FILE* (*_fopen64) (const char*, const char*) = dlsym(RTLD_NEXT, "fopen64");
|
||||
|
||||
return _fopen64(rewrite(path, buf), mode);
|
||||
}
|
||||
|
||||
DIR* opendir(const char* path)
|
||||
{
|
||||
char buf[PATH_MAX];
|
||||
DIR* (*_opendir) (const char*) = dlsym(RTLD_NEXT, "opendir");
|
||||
|
||||
return _opendir(rewrite(path, buf));
|
||||
}
|
||||
|
||||
#define SYSTEM_CMD_MAX 512
|
||||
|
||||
int system(const char *command)
|
||||
{
|
||||
char buf[SYSTEM_CMD_MAX];
|
||||
int (*_system) (const char*) = dlsym(RTLD_NEXT, "system");
|
||||
|
||||
const char* newCommand = rewriteSystemCall(command, buf, SYSTEM_CMD_MAX);
|
||||
return _system(newCommand);
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
{ lib, stdenv, fetchurl, libsaneUDevRuleNumber ? "49" }:
|
||||
|
||||
stdenv.mkDerivation rec {
|
||||
pname = "brother-udev-rule-type1";
|
||||
version = "1.0.0-1";
|
||||
|
||||
src = fetchurl {
|
||||
url = "http://download.brother.com/welcome/dlf006654/brother-udev-rule-type1-${version}.all.deb";
|
||||
sha256 = "0i0x5jw135pli4jl9mgnr5n2rrdvml57nw84yq2999r4frza53xi";
|
||||
};
|
||||
|
||||
dontBuild = true;
|
||||
|
||||
unpackPhase = ''
|
||||
ar x $src
|
||||
tar xfvz data.tar.gz
|
||||
'';
|
||||
|
||||
/*
|
||||
Fix the following error:
|
||||
|
||||
~~~
|
||||
invalid rule 49-brother-libsane-type1.rules
|
||||
unknown key 'SYSFS{idVendor}'
|
||||
~~~
|
||||
|
||||
Apparently the udev rules syntax has change and the SYSFS key has to
|
||||
be changed to ATTR.
|
||||
|
||||
See:
|
||||
|
||||
- <http://ubuntuforums.org/showthread.php?t=1496878>
|
||||
- <http://www.planet-libre.org/index.php?post_id=10937>
|
||||
*/
|
||||
patchPhase = ''
|
||||
sed -i -e s/SYSFS/ATTR/g opt/brother/scanner/udev-rules/type1/*.rules
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/etc/udev/rules.d
|
||||
cp opt/brother/scanner/udev-rules/type1/NN-brother-mfp-type1.rules \
|
||||
$out/etc/udev/rules.d/${libsaneUDevRuleNumber}-brother-libsane-type1.rules
|
||||
chmod 644 $out/etc/udev/rules.d/${libsaneUDevRuleNumber}-brother-libsane-type1.rules
|
||||
'';
|
||||
|
||||
dontStrip = true;
|
||||
dontPatchELF = true;
|
||||
|
||||
meta = {
|
||||
description = "Brother type1 scanners udev rules";
|
||||
homepage = "http://www.brother.com";
|
||||
platforms = lib.platforms.linux;
|
||||
license = lib.licenses.unfree;
|
||||
maintainers = with lib.maintainers; [ jraygauthier ];
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue