1{ lib, stdenv, fetchFromGitHub
2, freetype, harfbuzz, jbig2dec, libjpeg, libX11, mupdf_1_17, ncurses, openjpeg
3, openssl
4
5, imageSupport ? true, imlib2 ? null }:
6
7let
8 package = if imageSupport
9 then "jfbview"
10 else "jfbpdf";
11 binaries = if imageSupport
12 then [ "jfbview" "jpdfcat" "jpdfgrep" ] # all require imlib2
13 else [ "jfbpdf" ]; # does not
14in
15
16stdenv.mkDerivation rec {
17 pname = package;
18 version = "0.5.7";
19
20 src = fetchFromGitHub {
21 repo = "JFBView";
22 owner = "jichu4n";
23 rev = version;
24 sha256 = "0ppns49hnmp04zdjw6wc28v0yvz31rkzvd5ylcj7arikx20llpxf";
25 };
26
27 postPatch = ''
28 substituteInPlace main.cpp \
29 --replace "<stropts.h>" "<sys/ioctl.h>"
30 '';
31
32 hardeningDisable = [ "format" ];
33
34 buildInputs = [
35 freetype harfbuzz jbig2dec libjpeg libX11 mupdf_1_17 ncurses openjpeg
36 openssl
37 ] ++ lib.optionals imageSupport [
38 imlib2
39 ];
40
41 configurePhase = ''
42 # Hack. Probing (`ldconfig -p`) fails with ‘cannot execute binary file’.
43 # Overriding `OPENJP2 =` later works, but makes build output misleading:
44 substituteInPlace Makefile --replace "ldconfig -p" "echo libopenjp2"
45
46 make config.mk
47 '';
48
49 buildFlags = binaries;
50 enableParallelBuilding = true;
51
52 installPhase = ''
53 mkdir -p $out/bin
54 install ${toString binaries} $out/bin
55 '';
56
57 meta = with lib; {
58 description = "PDF and image viewer for the Linux framebuffer";
59 longDescription = ''
60 A very fast PDF and image viewer for the Linux framebuffer with some
61 advanced and unique features, including:
62 - Reads PDFs (MuPDF) and common image formats (Imlib2)
63 - Supports arbitrary zoom (10% - 1000%) and rotation
64 - Table of Contents (TOC) viewer for PDF documents
65 - Multi-threaded rendering on multi-core machines
66 - Asynchronous background rendering of the next page
67 - Customizable multi-threaded caching
68 '';
69 homepage = "https://seasonofcode.com/pages/jfbview.html";
70 license = licenses.asl20;
71 platforms = platforms.linux;
72 };
73}