1{ lib, stdenv, fetchurl, makeWrapper, pkg-config, texinfo
2, cairo, gd, libcerf, pango, readline, zlib
3, withTeXLive ? false, texlive
4, withLua ? false, lua
5, withCaca ? false, libcaca
6, libX11 ? null
7, libXt ? null
8, libXpm ? null
9, libXaw ? null
10, aquaterm ? false
11, withWxGTK ? false, wxGTK ? null
12, fontconfig ? null
13, gnused ? null
14, coreutils ? null
15, withQt ? false, mkDerivation, qttools, qtbase, qtsvg
16}:
17
18assert libX11 != null -> (fontconfig != null && gnused != null && coreutils != null);
19let
20 withX = libX11 != null && !aquaterm && !stdenv.isDarwin;
21in
22(if withQt then mkDerivation else stdenv.mkDerivation) rec {
23 pname = "gnuplot";
24 version = "5.4.2";
25
26 src = fetchurl {
27 url = "mirror://sourceforge/gnuplot/${pname}-${version}.tar.gz";
28 sha256 = "sha256-5Xx14TGBM5UdMqg7zcSv8X/tKHIsTnHyMFz8KuHK57o=";
29 };
30
31 nativeBuildInputs = [ makeWrapper pkg-config texinfo ] ++ lib.optional withQt qttools;
32
33 buildInputs =
34 [ cairo gd libcerf pango readline zlib ]
35 ++ lib.optional withTeXLive (texlive.combine { inherit (texlive) scheme-small; })
36 ++ lib.optional withLua lua
37 ++ lib.optional withCaca libcaca
38 ++ lib.optionals withX [ libX11 libXpm libXt libXaw ]
39 ++ lib.optionals withQt [ qtbase qtsvg ]
40 ++ lib.optional withWxGTK wxGTK;
41
42 postPatch = ''
43 # lrelease is in qttools, not in qtbase.
44 sed -i configure -e 's|''${QT5LOC}/lrelease|lrelease|'
45 '';
46
47 configureFlags = [
48 (if withX then "--with-x" else "--without-x")
49 (if withQt then "--with-qt=qt5" else "--without-qt")
50 (if aquaterm then "--with-aquaterm" else "--without-aquaterm")
51 ] ++ lib.optional withCaca "--with-caca";
52
53 CXXFLAGS = lib.optionalString (stdenv.isDarwin && withQt) "-std=c++11";
54
55 postInstall = lib.optionalString withX ''
56 wrapProgram $out/bin/gnuplot \
57 --prefix PATH : '${gnused}/bin' \
58 --prefix PATH : '${coreutils}/bin' \
59 --prefix PATH : '${fontconfig.bin}/bin' \
60 --run '. ${./set-gdfontpath-from-fontconfig.sh}'
61 '';
62
63 enableParallelBuilding = true;
64
65 meta = with lib; {
66 homepage = "http://www.gnuplot.info/";
67 description = "A portable command-line driven graphing utility for many platforms";
68 platforms = platforms.linux ++ platforms.darwin;
69 license = {
70 # Essentially a BSD license with one modifaction:
71 # Permission to modify the software is granted, but not the right to
72 # distribute the complete modified source code. Modifications are to
73 # be distributed as patches to the released version. Permission to
74 # distribute binaries produced by compiling modified sources is granted,
75 # provided you: ...
76 url = "https://sourceforge.net/p/gnuplot/gnuplot-main/ci/master/tree/Copyright";
77 };
78 maintainers = with maintainers; [ lovek323 ];
79 };
80}