1{
2 lib,
3 stdenv,
4 fetchurl,
5 makeWrapper,
6 pkg-config,
7 texinfo,
8 cairo,
9 gd,
10 libcerf,
11 pango,
12 readline,
13 zlib,
14 withTeXLive ? false,
15 texliveSmall,
16 withLua ? false,
17 lua,
18 withCaca ? false,
19 libcaca,
20 libX11 ? null,
21 libXt ? null,
22 libXpm ? null,
23 libXaw ? null,
24 aquaterm ? false,
25 withWxGTK ? false,
26 wxGTK32,
27 fontconfig ? null,
28 gnused ? null,
29 coreutils ? null,
30 withQt ? false,
31 mkDerivation,
32 qttools,
33 qtbase,
34 qtsvg,
35}:
36
37assert libX11 != null -> (fontconfig != null && gnused != null && coreutils != null);
38let
39 withX = libX11 != null && !aquaterm && !stdenv.hostPlatform.isDarwin;
40in
41(if withQt then mkDerivation else stdenv.mkDerivation) rec {
42 pname = "gnuplot";
43 version = "6.0.2";
44
45 src = fetchurl {
46 url = "mirror://sourceforge/gnuplot/${pname}-${version}.tar.gz";
47 sha256 = "sha256-9oo7C7t7u7Q3ZJZ0EG2UUiwAvy8oXM4MGcMYCx7n5zg=";
48 };
49
50 nativeBuildInputs = [
51 makeWrapper
52 pkg-config
53 texinfo
54 ] ++ lib.optional withQt qttools;
55
56 buildInputs =
57 [
58 cairo
59 gd
60 libcerf
61 pango
62 readline
63 zlib
64 ]
65 ++ lib.optional withTeXLive texliveSmall
66 ++ lib.optional withLua lua
67 ++ lib.optional withCaca libcaca
68 ++ lib.optionals withX [
69 libX11
70 libXpm
71 libXt
72 libXaw
73 ]
74 ++ lib.optionals withQt [
75 qtbase
76 qtsvg
77 ]
78 ++ lib.optional withWxGTK wxGTK32;
79
80 postPatch = ''
81 # lrelease is in qttools, not in qtbase.
82 sed -i configure -e 's|''${QT5LOC}/lrelease|lrelease|'
83 '';
84
85 configureFlags =
86 [
87 (if withX then "--with-x" else "--without-x")
88 (if withQt then "--with-qt=qt5" else "--without-qt")
89 (if aquaterm then "--with-aquaterm" else "--without-aquaterm")
90 ]
91 ++ lib.optional withCaca "--with-caca"
92 ++ lib.optional withTeXLive "--with-texdir=${placeholder "out"}/share/texmf/tex/latex/gnuplot";
93
94 CXXFLAGS = lib.optionalString (stdenv.hostPlatform.isDarwin && withQt) "-std=c++11";
95
96 # we'll wrap things ourselves
97 dontWrapGApps = true;
98 dontWrapQtApps = true;
99
100 # binary wrappers don't support --run
101 postInstall = lib.optionalString withX ''
102 wrapProgramShell $out/bin/gnuplot \
103 --prefix PATH : '${
104 lib.makeBinPath [
105 gnused
106 coreutils
107 fontconfig.bin
108 ]
109 }' \
110 "''${gappsWrapperArgs[@]}" \
111 "''${qtWrapperArgs[@]}" \
112 --run '. ${./set-gdfontpath-from-fontconfig.sh}'
113 '';
114
115 # When cross-compiling, don't build docs and demos.
116 # Inspiration taken from https://sourceforge.net/p/gnuplot/gnuplot-main/merge-requests/10/
117 makeFlags = lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
118 "-C src"
119 ];
120
121 enableParallelBuilding = true;
122
123 meta = with lib; {
124 homepage = "http://www.gnuplot.info/";
125 description = "Portable command-line driven graphing utility for many platforms";
126 platforms = platforms.linux ++ platforms.darwin;
127 license = {
128 # Essentially a BSD license with one modification:
129 # Permission to modify the software is granted, but not the right to
130 # distribute the complete modified source code. Modifications are to
131 # be distributed as patches to the released version. Permission to
132 # distribute binaries produced by compiling modified sources is granted,
133 # provided you: ...
134 url = "https://sourceforge.net/p/gnuplot/gnuplot-main/ci/master/tree/Copyright";
135 };
136 maintainers = with maintainers; [ lovek323 ];
137 mainProgram = "gnuplot";
138 };
139}