1{
2 stdenv,
3 pkgs,
4 lib,
5 fetchurl,
6 gfortran,
7 ncurses,
8 perl,
9 flex,
10 testers,
11 texinfo,
12 qhull,
13 libsndfile,
14 portaudio,
15 libX11,
16 graphicsmagick,
17 pcre2,
18 pkg-config,
19 libGL,
20 libGLU,
21 fltk,
22 # Both are needed for discrete Fourier transform
23 fftw,
24 fftwSinglePrec,
25 zlib,
26 curl,
27 rapidjson,
28 blas,
29 lapack,
30 # These 3 should use the same lapack and blas as the above, see code prepending
31 qrupdate,
32 arpack,
33 suitesparse,
34 # If set to true, the above 5 deps are overridden to use the blas and lapack
35 # with 64 bit indexes support. If all are not compatible, the build will fail.
36 use64BitIdx ? false,
37 libwebp,
38 gl2ps,
39 ghostscript,
40 hdf5,
41 glpk,
42 gnuplot,
43 # - Include support for GNU readline:
44 enableReadline ? true,
45 readline,
46 # - Build Java interface:
47 enableJava ? true,
48 jdk,
49 python3,
50 sundials,
51 # - Packages required for building extra packages.
52 newScope,
53 callPackage,
54 makeSetupHook,
55 makeWrapper,
56 # - Build Octave Qt GUI:
57 enableQt ? false,
58 libsForQt5,
59 libiconv,
60}:
61
62let
63 # Not always evaluated
64 blas' =
65 if use64BitIdx then
66 blas.override {
67 isILP64 = true;
68 }
69 else
70 blas;
71 lapack' =
72 if use64BitIdx then
73 lapack.override {
74 isILP64 = true;
75 }
76 else
77 lapack;
78 qrupdate' = qrupdate.override {
79 # If use64BitIdx is false, this override doesn't evaluate to a new
80 # derivation, as blas and lapack are not overridden.
81 blas = blas';
82 lapack = lapack';
83 };
84 arpack' = arpack.override {
85 blas = blas';
86 lapack = lapack';
87 };
88 # We keep the option to not enable suitesparse support by putting it null
89 suitesparse' =
90 if suitesparse != null then
91 suitesparse.override {
92 blas = blas';
93 lapack = lapack';
94 }
95 else
96 null;
97 # To avoid confusion later in passthru
98 allPkgs = pkgs;
99in
100stdenv.mkDerivation (finalAttrs: {
101 version = "10.3.0";
102 pname = "octave";
103
104 src = fetchurl {
105 url = "mirror://gnu/octave/octave-${finalAttrs.version}.tar.gz";
106 sha256 = "sha256-L8s43AYuRA8eBsBpu8qEDtRtzI+YPkc+FVj8w4OE7ms=";
107 };
108
109 postPatch = ''
110 patchShebangs --build build-aux/*.pl
111 '';
112
113 buildInputs = [
114 readline
115 ncurses
116 flex
117 qhull
118 graphicsmagick
119 pcre2
120 fltk
121 zlib
122 curl
123 rapidjson
124 blas'
125 lapack'
126 libsndfile
127 fftw
128 fftwSinglePrec
129 portaudio
130 qrupdate'
131 arpack'
132 libwebp
133 gl2ps
134 ghostscript
135 hdf5
136 glpk
137 suitesparse'
138 sundials
139 gnuplot
140 python3
141 ]
142 ++ lib.optionals enableQt [
143 libsForQt5.qtbase
144 libsForQt5.qtsvg
145 libsForQt5.qscintilla
146 ]
147 ++ lib.optionals (enableJava) [
148 jdk
149 ]
150 ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
151 libGL
152 libGLU
153 libX11
154 ]
155 ++ lib.optionals stdenv.hostPlatform.isDarwin [
156 libiconv
157 ];
158 nativeBuildInputs = [
159 perl
160 pkg-config
161 gfortran
162 texinfo
163 ]
164 ++ lib.optionals enableQt [
165 libsForQt5.wrapQtAppsHook
166 libsForQt5.qtscript
167 libsForQt5.qttools
168 ];
169
170 doCheck = !stdenv.hostPlatform.isDarwin;
171
172 enableParallelBuilding = true;
173
174 # Fix linker error on Darwin (see https://trac.macports.org/ticket/61865)
175 NIX_LDFLAGS = lib.optionalString stdenv.hostPlatform.isDarwin "-lobjc";
176
177 # See https://savannah.gnu.org/bugs/?50339
178 F77_INTEGER_8_FLAG = lib.optionalString use64BitIdx "-fdefault-integer-8";
179
180 configureFlags = [
181 "--with-blas=blas"
182 "--with-lapack=lapack"
183 (if use64BitIdx then "--enable-64" else "--disable-64")
184 ]
185 ++ lib.optionals enableReadline [ "--enable-readline" ]
186 ++ lib.optionals stdenv.hostPlatform.isDarwin [ "--with-x=no" ]
187 ++ lib.optionals enableQt [ "--with-qt=5" ];
188
189 # Keep a copy of the octave tests detailed results in the output
190 # derivation, because someone may care
191 postInstall = ''
192 cp test/fntests.log $out/share/octave/octave-${finalAttrs.version}-fntests.log || true
193 '';
194
195 passthru = rec {
196 sitePath = "share/octave/${finalAttrs.version}/site";
197 octPkgsPath = "share/octave/octave_packages";
198 blas = blas';
199 lapack = lapack';
200 qrupdate = qrupdate';
201 arpack = arpack';
202 suitesparse = suitesparse';
203 octavePackages = import ../../../top-level/octave-packages.nix {
204 pkgs = allPkgs;
205 inherit
206 lib
207 stdenv
208 fetchurl
209 newScope
210 ;
211 octave = finalAttrs.finalPackage;
212 };
213 wrapOctave = callPackage ./wrap-octave.nix {
214 octave = finalAttrs.finalPackage;
215 inherit (allPkgs) makeSetupHook makeWrapper;
216 };
217 inherit fftw fftwSinglePrec;
218 inherit portaudio;
219 inherit jdk;
220 python = python3;
221 inherit enableQt enableReadline enableJava;
222 buildEnv = callPackage ./build-env.nix {
223 octave = finalAttrs.finalPackage;
224 inherit wrapOctave;
225 inherit (octavePackages) computeRequiredOctavePackages;
226 };
227 withPackages = import ./with-packages.nix { inherit buildEnv octavePackages; };
228 pkgs = octavePackages;
229 interpreter = "${finalAttrs.finalPackage}/bin/octave";
230 tests = {
231 wrapper = testers.testVersion {
232 package = finalAttrs.finalPackage.withPackages (ps: [ ps.doctest ]);
233 command = "octave --version";
234 };
235 };
236 };
237
238 meta = {
239 homepage = "https://www.gnu.org/software/octave/";
240 license = lib.licenses.gpl3Plus;
241 maintainers = with lib.maintainers; [
242 raskin
243 doronbehar
244 ];
245 description = "Scientific Programming Language";
246 };
247})