about summary refs log tree commit diff
path: root/pkgs/applications/graphics/deskew/default.nix
blob: f43a26f692a34d39c45c923d2070ef3ab80ebb6b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{ lib, stdenv, fetchFromGitHub, libtiff, fpc }:

stdenv.mkDerivation rec {

  pname = "deskew";
  version = "1.30";

  src = fetchFromGitHub {
    owner = "galfar";
    repo = pname;
    rev = "v${version}";
    hash = "sha256-xghVOEMkQ/mXpOzJqMaT3SII7xneMNoFqRlqjtzmDnA=";
  };

  nativeBuildInputs = [ fpc ];
  buildInputs = [ libtiff ];

  buildPhase = ''
    runHook preBuild
    patchShebangs ./Scripts

    # Deskew insists on using dlopen to load libtiff, we insist it links against it.
    sed -i -e 's/{$DEFINE DYNAMIC_DLL_LOADING}//' Imaging/LibTiff/LibTiffDynLib.pas
    sed -i -e 's/if LibTiffDynLib\.LoadTiffLibrary then//' Imaging/LibTiff/ImagingTiffLib.pas
    # Make sure libtiff is in the RPATH, so that Nix can find and track the runtime dependency
    export NIX_LDFLAGS="$NIX_LDFLAGS -rpath ${lib.getLib libtiff}/lib"
    pushd Scripts && ./compile.sh && popd
    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall
    install -Dt $out/bin Bin/deskew
    runHook postInstall
  '';

  meta = with lib; {
    description = "A command line tool for deskewing scanned text documents";
    homepage = "https://galfar.vevb.net/deskew";
    license = with licenses; [ mit mpl11 ];
    maintainers = with maintainers; [ryantm];
    platforms = platforms.all;
    mainProgram = "deskew";
  };

}