koreader: migrate leptonica dep away from the sources hack

i hope that by using the makefile vars i can eventually get rid of the
"stamp" nonsense.
This commit is contained in:
Colin 2024-03-22 17:16:19 +00:00
parent e11dd0ecb0
commit 8ff34d8518
2 changed files with 37 additions and 15 deletions

View File

@ -89,6 +89,21 @@ let
hash = "sha256-/51pOGSAoaS0gOKlqNKruwaKY5qylzCpeNUrWyzYTpA=";
};
leptonica-src-ko = fetchFromGitHub {
# k2pdf needs leptonica src, because it actually patches it and builds it itself:
# - `cp -f $(LEPTONICA_MOD)/dewarp2.c $(LEPTONICA_DIR)/src/dewarp2.c`
# - i.e. cp -f /build/koreader/base/thirdparty/libk2pdfopt/build/aarch64-unknown-linux-gnu/libk2pdfopt-prefix/src/libk2pdfopt/leptonica_mod/dewarp2.c ...
# k2pdf uses an old leptonica -- like 2015-2017-ish (1.74.1).
# seems it can be at least partially updated, by replacing `numaGetMedianVariation` with `numaGetMedianDevFromMedian` (drop-in replacement)
# and replacing references to `liblept.so` with `libleptonica.so`,
# but eventually this requires patching the tesseract Makefiles. could get intense, idk.
owner = "DanBloomberg";
repo = "leptonica";
name = "leptonica"; # where to unpack this in `srcs`
rev = "1.74.1";
hash = "sha256-SDXKam768xvZZvTbXe3sssvZyeLEEiY97Vrzx8hoc6g=";
};
nanosvg-headers-ko = symlinkJoin {
# koreader's heavily-patched mupdf is dependent on a koreader-specific `stb_image_write` extension to nanosvg.
# nanosvg is used as a header-only library, so just patch that extension straight into the src.
@ -257,6 +272,7 @@ let
JPEG_LIB_LINK_FLAG="-L ${lib.getLib libjpeg_turbo}/lib -l:libjpeg.so" \
JPEG_DIR="${lib.getDev libjpeg_turbo}" \
TURBOJPEG_LIB="${lib.getLib libjpeg_turbo}/lib/libturbojpeg.so" \
LEPTONICA_DIR="$NIX_BUILD_TOP/leptonica" \
LIBICONV="${lib.getLib libiconvReal}/lib/libiconv.so" \
LIBICONV_DIR="${lib.getDev libiconvReal}" \
LIBUNIBREAK_LIB="${lib.getLib libunibreak}/lib/libunibreak.so" \
@ -346,7 +362,10 @@ in
stdenv.mkDerivation rec {
pname = "koreader-from-src";
inherit version;
srcs = [ src ] ++ (lib.mapAttrsToList
srcs = [
src
leptonica-src-ko
] ++ (lib.mapAttrsToList
(name: src: fetchgit (
{
inherit name;
@ -397,6 +416,9 @@ stdenv.mkDerivation rec {
substituteInPlace base/Makefile.third \
--replace-fail ' -rm ' ' # -rm'
# make some sources writable (only the `sourceRoot` is writable by default)
chmod -R u+w "$NIX_BUILD_TOP/leptonica"
# lots of places in Makefile.third (incorrectly) assume lib paths are relative to CURDIR,
# so link /nix into CURDIR to allow them to work anyway
ln -s /nix base/nix
@ -456,7 +478,7 @@ stdenv.mkDerivation rec {
)}
# outDir should match OUTPUT_DIR in koreader-base
outDir="/build/koreader/base/build/${stdenv.hostPlatform.config}"
outDir="$NIX_BUILD_TOP/koreader/base/build/${stdenv.hostPlatform.config}"
mkdir -p "$outDir"
${symlinkThirdpartyBins "$outDir"}

View File

@ -125,19 +125,19 @@ in
source.hash = "sha256-/yYpagekWlfTrXu/1DNTmBmdd3IkCDjRtslRv13mtCg=";
# package: not in nixpkgs
};
leptonica = {
source.url = "https://github.com/DanBloomberg/leptonica.git";
source.rev = "1.74.1";
source.hash = "sha256-SDXKam768xvZZvTbXe3sssvZyeLEEiY97Vrzx8hoc6g=";
# k2pdf needs leptonica src, because it actually patches it and builds it itself
# `cp -f $(LEPTONICA_MOD)/dewarp2.c $(LEPTONICA_DIR)/src/dewarp2.c`
# i.e. cp -f /build/koreader/base/thirdparty/libk2pdfopt/build/aarch64-unknown-linux-gnu/libk2pdfopt-prefix/src/libk2pdfopt/leptonica_mod/dewarp2.c ...
# k2pdf uses an old leptonica -- like 2015-2017-ish.
# seems it can be at least partially updated, by replacing `numaGetMedianVariation` with `numaGetMedianDevFromMedian` (drop-in replacement)
# and replacing references to `liblept.so` with `libleptonica.so`,
# but eventually this requires patching the tesseract Makefiles. could get intense, idk.
# package = leptonica;
};
# leptonica = {
# source.url = "https://github.com/DanBloomberg/leptonica.git";
# source.rev = "1.74.1";
# source.hash = "sha256-SDXKam768xvZZvTbXe3sssvZyeLEEiY97Vrzx8hoc6g=";
# # k2pdf needs leptonica src, because it actually patches it and builds it itself
# # `cp -f $(LEPTONICA_MOD)/dewarp2.c $(LEPTONICA_DIR)/src/dewarp2.c`
# # i.e. cp -f /build/koreader/base/thirdparty/libk2pdfopt/build/aarch64-unknown-linux-gnu/libk2pdfopt-prefix/src/libk2pdfopt/leptonica_mod/dewarp2.c ...
# # k2pdf uses an old leptonica -- like 2015-2017-ish.
# # seems it can be at least partially updated, by replacing `numaGetMedianVariation` with `numaGetMedianDevFromMedian` (drop-in replacement)
# # and replacing references to `liblept.so` with `libleptonica.so`,
# # but eventually this requires patching the tesseract Makefiles. could get intense, idk.
# # package = leptonica;
# };
# libjpeg-turbo = {
# source.url = "https://github.com/libjpeg-turbo/libjpeg-turbo.git";
# source.rev = "3.0.1";