libqalculate: Make it easier to change gnuplot hardcoding (#412773)

This commit is contained in:
Doron Behar
2025-06-12 14:23:51 +03:00
committed by GitHub
+18 -15
View File
@@ -14,7 +14,15 @@
libxml2,
mpfr,
icu,
# Upstream's `plot` UX is not ideal - it doesn't write a good message
# suggesting the user to install this optional dependency when they write
# `plot(..)`. Not to mention support for non-x dependent `gnuplot_qt`
# executable. Hence we hardcode a path to a gnuplot binary by default, and
# changing this is possible via putting an empty string as a `gnuplotBinary`
# - to let `libqalculate` pick it from $PATH during runtime. See also:
# https://github.com/Qalculate/libqalculate/issues/796
gnuplot,
gnuplotBinary ? lib.getExe gnuplot,
}:
stdenv.mkDerivation (finalAttrs: {
@@ -24,7 +32,7 @@ stdenv.mkDerivation (finalAttrs: {
src = fetchFromGitHub {
owner = "qalculate";
repo = "libqalculate";
rev = "v${finalAttrs.version}";
tag = "v${finalAttrs.version}";
hash = "sha256-sjVvsgDQbKXU+N7JrA36zezDfAGcDbyQ0fn1zMThYXQ=";
};
@@ -61,16 +69,11 @@ stdenv.mkDerivation (finalAttrs: {
intltoolize -f
'';
patchPhase =
''
substituteInPlace libqalculate/Calculator-plot.cc \
--replace 'commandline = "gnuplot"' 'commandline = "${gnuplot}/bin/gnuplot"' \
--replace '"gnuplot - ' '"${gnuplot}/bin/gnuplot - '
''
+ lib.optionalString stdenv.cc.isClang ''
substituteInPlace src/qalc.cc \
--replace 'printf(_("aborted"))' 'printf("%s", _("aborted"))'
'';
postPatch = lib.optionalString (gnuplotBinary != "") ''
substituteInPlace libqalculate/Calculator-plot.cc \
--replace-fail 'commandline = "gnuplot"' 'commandline = "${gnuplotBinary}"' \
--replace-fail '"gnuplot - ' '"${gnuplotBinary} - '
'';
preBuild = ''
pushd docs/reference
@@ -78,15 +81,15 @@ stdenv.mkDerivation (finalAttrs: {
popd
'';
meta = with lib; {
meta = {
description = "Advanced calculator library";
homepage = "http://qalculate.github.io";
license = licenses.gpl2Plus;
maintainers = with maintainers; [
license = lib.licenses.gpl2Plus;
maintainers = with lib.maintainers; [
doronbehar
pentane
];
mainProgram = "qalc";
platforms = platforms.all;
platforms = lib.platforms.all;
};
})