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.3";
44
45 src = fetchurl {
46 url = "mirror://sourceforge/gnuplot/${pname}-${version}.tar.gz";
47 sha256 = "sha256-7FLjr4xAg9RTgVKz8T20f20pkpo/bs7FNlyDTnfyUas=";
48 };
49
50 nativeBuildInputs = [
51 makeWrapper
52 pkg-config
53 texinfo
54 ]
55 ++ lib.optional withQt qttools;
56
57 buildInputs = [
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 (if withX then "--with-x" else "--without-x")
87 (if withQt then "--with-qt=qt5" else "--without-qt")
88 (if aquaterm then "--with-aquaterm" else "--without-aquaterm")
89 ]
90 ++ lib.optional withCaca "--with-caca"
91 ++ lib.optional withTeXLive "--with-texdir=${placeholder "out"}/share/texmf/tex/latex/gnuplot";
92
93 CXXFLAGS = lib.optionalString (stdenv.hostPlatform.isDarwin && withQt) "-std=c++11";
94
95 # we'll wrap things ourselves
96 dontWrapGApps = true;
97 dontWrapQtApps = true;
98
99 # binary wrappers don't support --run
100 postInstall = lib.optionalString withX ''
101 wrapProgramShell $out/bin/gnuplot \
102 --prefix PATH : '${
103 lib.makeBinPath [
104 gnused
105 coreutils
106 fontconfig.bin
107 ]
108 }' \
109 "''${gappsWrapperArgs[@]}" \
110 "''${qtWrapperArgs[@]}" \
111 --run '. ${./set-gdfontpath-from-fontconfig.sh}'
112 '';
113
114 # When cross-compiling, don't build docs and demos.
115 # Inspiration taken from https://sourceforge.net/p/gnuplot/gnuplot-main/merge-requests/10/
116 makeFlags = lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
117 "-C src"
118 ];
119
120 enableParallelBuilding = true;
121
122 meta = with lib; {
123 homepage = "http://www.gnuplot.info/";
124 description = "Portable command-line driven graphing utility for many platforms";
125 platforms = platforms.linux ++ platforms.darwin;
126 license = {
127 # Essentially a BSD license with one modification:
128 # Permission to modify the software is granted, but not the right to
129 # distribute the complete modified source code. Modifications are to
130 # be distributed as patches to the released version. Permission to
131 # distribute binaries produced by compiling modified sources is granted,
132 # provided you: ...
133 url = "https://sourceforge.net/p/gnuplot/gnuplot-main/ci/master/tree/Copyright";
134 };
135 maintainers = with maintainers; [ lovek323 ];
136 mainProgram = "gnuplot";
137 };
138}