2017-09-09 06:09:03 +01:00
|
|
|
{ stdenv, fetchzip, fetchurl, fetchpatch, cmake, pkgconfig
|
2019-06-16 20:59:06 +01:00
|
|
|
, zlib, libpng
|
2017-09-09 06:09:03 +01:00
|
|
|
, enableGSL ? true, gsl
|
|
|
|
, enableGhostScript ? true, ghostscript
|
2017-10-03 19:04:56 +01:00
|
|
|
, enableMuPDF ? true, mupdf
|
2017-09-09 06:09:03 +01:00
|
|
|
, enableJPEG2K ? true, jasper
|
|
|
|
, enableDJVU ? true, djvulibre
|
|
|
|
, enableGOCR ? false, gocr # Disabled by default due to crashes
|
2018-12-30 04:13:53 +00:00
|
|
|
, enableTesseract ? true, leptonica, tesseract4
|
2017-09-09 06:09:03 +01:00
|
|
|
}:
|
|
|
|
|
|
|
|
with stdenv.lib;
|
|
|
|
|
|
|
|
stdenv.mkDerivation rec {
|
2019-08-15 13:41:18 +01:00
|
|
|
pname = "k2pdfopt";
|
2018-12-30 04:13:53 +00:00
|
|
|
version = "2.51a";
|
2017-09-09 06:09:03 +01:00
|
|
|
|
2018-12-30 04:13:53 +00:00
|
|
|
src = (fetchzip {
|
|
|
|
url = "http://www.willus.com/k2pdfopt/src/k2pdfopt_v2.51_src.zip";
|
|
|
|
sha256 = "133l7xkvi67s6sfk8cfh7rmavbsf7ib5fyksk1ci6b6sch3z2sw9";
|
|
|
|
});
|
|
|
|
|
|
|
|
# Note: the v2.51a zip contains only files to be replaced in the v2.50 zip.
|
|
|
|
v251a_src = (fetchzip {
|
|
|
|
url = "http://www.willus.com/k2pdfopt/src/k2pdfopt_v2.51a_src.zip";
|
|
|
|
sha256 = "0vvwblii7kgdwfxw8dzk6jbmz4dv94d7rkv18i60y8wkayj6yhl6";
|
|
|
|
});
|
|
|
|
|
|
|
|
postUnpack = ''
|
|
|
|
cp -r ${v251a_src}/* $sourceRoot
|
|
|
|
'';
|
2014-10-19 08:55:06 +01:00
|
|
|
|
2017-09-09 06:09:03 +01:00
|
|
|
patches = [ ./k2pdfopt.patch ];
|
|
|
|
|
|
|
|
nativeBuildInputs = [ cmake pkgconfig ];
|
|
|
|
|
|
|
|
buildInputs =
|
|
|
|
let
|
2019-09-13 20:53:03 +01:00
|
|
|
# The patches below were constructed by taking the files from k2pdfopt in
|
|
|
|
# the {mupdf,leptonica,tesseract}_mod/ directories, replacing the
|
|
|
|
# corresponding files in the respective source trees, resolving any errors
|
|
|
|
# with more recent versions of these depencencies, and running diff.
|
2017-09-09 06:09:03 +01:00
|
|
|
mupdf_modded = mupdf.overrideAttrs (attrs: {
|
2019-09-13 20:53:03 +01:00
|
|
|
patches = attrs.patches ++ [ ./mupdf.patch ]; # Last verified with mupdf 1.14.0
|
2017-09-09 06:09:03 +01:00
|
|
|
});
|
|
|
|
leptonica_modded = leptonica.overrideAttrs (attrs: {
|
2019-09-13 20:53:03 +01:00
|
|
|
patches = [ ./leptonica.patch ]; # Last verified with leptonica 1.78.0
|
2017-09-09 06:09:03 +01:00
|
|
|
});
|
2018-12-30 04:13:53 +00:00
|
|
|
tesseract_modded = tesseract4.override {
|
|
|
|
tesseractBase = tesseract4.tesseractBase.overrideAttrs (_: {
|
2019-09-13 20:53:03 +01:00
|
|
|
patches = [ ./tesseract.patch ]; # Last verified with tesseract 1.4
|
2018-12-18 18:02:13 +00:00
|
|
|
});
|
|
|
|
};
|
2017-09-09 06:09:03 +01:00
|
|
|
in
|
|
|
|
[ zlib libpng ] ++
|
|
|
|
optional enableGSL gsl ++
|
|
|
|
optional enableGhostScript ghostscript ++
|
2017-10-03 19:04:56 +01:00
|
|
|
optional enableMuPDF mupdf_modded ++
|
|
|
|
optional enableJPEG2K jasper ++
|
2017-09-09 06:09:03 +01:00
|
|
|
optional enableDJVU djvulibre ++
|
|
|
|
optional enableGOCR gocr ++
|
|
|
|
optionals enableTesseract [ leptonica_modded tesseract_modded ];
|
|
|
|
|
|
|
|
dontUseCmakeBuildDir = true;
|
|
|
|
|
|
|
|
cmakeFlags = [ "-DCMAKE_C_FLAGS=-I${src}/include_mod" ];
|
|
|
|
|
2019-01-04 19:33:50 +00:00
|
|
|
NIX_LDFLAGS = [
|
|
|
|
"-lpthread"
|
|
|
|
];
|
|
|
|
|
2017-09-09 06:09:03 +01:00
|
|
|
installPhase = ''
|
|
|
|
install -D -m 755 k2pdfopt $out/bin/k2pdfopt
|
2014-10-19 08:55:06 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
meta = with stdenv.lib; {
|
2014-11-11 13:20:43 +00:00
|
|
|
description = "Optimizes PDF/DJVU files for mobile e-readers (e.g. the Kindle) and smartphones";
|
2014-10-19 08:55:06 +01:00
|
|
|
homepage = http://www.willus.com/k2pdfopt;
|
|
|
|
license = licenses.gpl3;
|
|
|
|
platforms = platforms.linux;
|
2017-09-09 06:09:03 +01:00
|
|
|
maintainers = with maintainers; [ bosu danielfullmer ];
|
2014-10-19 08:55:06 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|