1{ lib, stdenv, fetchurl, makeWrapper, pkgconfig, texinfo
2, cairo, gd, libcerf, pango, readline, zlib
3, withTeXLive ? false, texlive
4, withLua ? false, lua
5, libX11 ? null
6, libXt ? null
7, libXpm ? null
8, libXaw ? null
9, aquaterm ? false
10, withWxGTK ? false, wxGTK ? null
11, fontconfig ? null
12, gnused ? null
13, coreutils ? null
14, withQt ? false, mkDerivation, qttools, qtbase, qtsvg
15}:
16
17assert libX11 != null -> (fontconfig != null && gnused != null && coreutils != null);
18let
19 withX = libX11 != null && !aquaterm && !stdenv.isDarwin;
20in
21(if withQt then mkDerivation else stdenv.mkDerivation) rec {
22 pname = "gnuplot";
23 version = "5.4.0";
24
25 src = fetchurl {
26 url = "mirror://sourceforge/gnuplot/${pname}-${version}.tar.gz";
27 sha256 = "0iwwliq5a6qcawbpxk4d7l17fpkq9xxcz05kwblx37rr7bq84h7b";
28 };
29
30 nativeBuildInputs = [ makeWrapper pkgconfig texinfo ] ++ lib.optional withQt qttools;
31
32 buildInputs =
33 [ cairo gd libcerf pango readline zlib ]
34 ++ lib.optional withTeXLive (texlive.combine { inherit (texlive) scheme-small; })
35 ++ lib.optional withLua lua
36 ++ lib.optionals withX [ libX11 libXpm libXt libXaw ]
37 ++ lib.optionals withQt [ qtbase qtsvg ]
38 ++ lib.optional withWxGTK wxGTK;
39
40 postPatch = ''
41 # lrelease is in qttools, not in qtbase.
42 sed -i configure -e 's|''${QT5LOC}/lrelease|lrelease|'
43 '';
44
45 configureFlags = [
46 (if withX then "--with-x" else "--without-x")
47 (if withQt then "--with-qt=qt5" else "--without-qt")
48 (if aquaterm then "--with-aquaterm" else "--without-aquaterm")
49 ];
50
51 CXXFLAGS = lib.optionalString (stdenv.isDarwin && withQt) "-std=c++11";
52
53 postInstall = lib.optionalString withX ''
54 wrapProgram $out/bin/gnuplot \
55 --prefix PATH : '${gnused}/bin' \
56 --prefix PATH : '${coreutils}/bin' \
57 --prefix PATH : '${fontconfig.bin}/bin' \
58 --run '. ${./set-gdfontpath-from-fontconfig.sh}'
59 '' + lib.optionalString (stdenv.isDarwin && withQt) ''
60 wrapQtApp $out/bin/gnuplot
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}