File: version.m

package info (click to toggle)
octave 9.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 144,300 kB
  • sloc: cpp: 332,784; ansic: 77,239; fortran: 20,963; objc: 9,396; sh: 8,213; yacc: 4,925; lex: 4,389; perl: 1,544; java: 1,366; awk: 1,259; makefile: 648; xml: 189
file content (142 lines) | stat: -rw-r--r-- 4,694 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
########################################################################
##
## Copyright (C) 1994-2024 The Octave Project Developers
##
## See the file COPYRIGHT.md in the top-level directory of this
## distribution or <https://octave.org/copyright/>.
##
## This file is part of Octave.
##
## Octave is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <https://www.gnu.org/licenses/>.
##
########################################################################

## -*- texinfo -*-
## @deftypefn  {} {@var{v} =} version ()
## @deftypefnx {} {[@var{v}, @var{d}] =} version ()
## @deftypefnx {} {@var{v} =} version (@var{feature})
## Get version information for Octave.
##
## If called without input argument, the first return value @var{v} gives the
## version number of Octave as a string.  The second return value @var{d} holds
## the release date as a string.
##
## The following options can be passed for @var{feature}:
##
## @table @asis
## @item @qcode{"-date"}
## for the release date of the running build,
##
## @item @qcode{"-description"}
## for a description of the release (always an empty string),
##
## @item @qcode{"-release"}
## for the name of the running build (always an empty string),
##
## @item @qcode{"-java"}
## for version information of the Java @nospell{VM},
##
## @item @qcode{"-fftw"}
## for version information for the linked @sc{fftw},
##
## @item @qcode{"-blas"}
## for version information for the linked @sc{blas},
##
## @item @qcode{"-lapack"}
## for version information for the linked @sc{lapack}.
##
## @item @qcode{"-hgid"}
## the mercurial ID of the sources used to build Octave.
## @end table
##
## The information returned for the @qcode{"-blas"} and @qcode{"-lapack"}
## options might be unreliable.  It might report which library was linked in
## when Octave was built instead of which library is currently used.
##
## The variant with no input and output argument is an alias for the function
## @w{@env{OCTAVE_VERSION}}@ provided for compatibility.
## @seealso{OCTAVE_VERSION, ver}
## @end deftypefn

function [v, d] = version (feature)

  if (nargin == 1 && (nargout > 1 || ! ischar (feature)))
    print_usage ();
  endif

  if (nargin == 0)
    v = OCTAVE_VERSION ();

    if (nargout > 1)
      d = __octave_config_info__ ("release_date");
    endif
  else
    switch (lower (feature))
      case "-date"
        v = __octave_config_info__ ("release_date");
      case "-description"
        v = "";
      case "-release"
        v = "";
      case "-java"
        try
          jversion = javaMethod ("getProperty", "java.lang.System", ...
                                 "java.runtime.version");
          jvendor = javaMethod ("getProperty", "java.lang.System", ...
                                "java.vendor");
          jname = javaMethod ("getProperty", "java.lang.System", ...
                              "java.vm.name");
          jjitmode = javaMethod ("getProperty", "java.lang.System", ...
                                 "java.vm.info");
          v = ["Java " jversion " with " jvendor " " jname " " jjitmode];
        catch err
          v = sprintf ("no usable Java Runtime Environment (%s) found:\n%s", ...
                       uname ().machine, err.message);
        end_try_catch
      case "-fftw"
        v = __octave_config_info__ ("fftw_version");
      case "-blas"
        v = __blas_version__ ();
      case "-lapack"
        v = __lapack_version__ ();
      case "-hgid"
        v = __octave_config_info__ ("hg_id");
      otherwise
        error ("version: invalid FEATURE");
    endswitch
  endif

endfunction


%!assert (ischar (version ()))

%!test
%! [v, d] = version ();
%! assert (v, OCTAVE_VERSION);
%! assert (d, __octave_config_info__ ("release_date"));

%!assert (version ("-date"), __octave_config_info__ ("release_date"))

%!assert (version ("-description"), "")
%!assert (version ("-release"), "")
%!assert (ischar (version ("-blas")))
%!assert (ischar (version ("-LAPACK")))

## Test input validation
%!error version ("-date", "-release")
%!error [v, d] = version ("-date")
%!error version (1)
%!error <invalid FEATURE> version ("-foobar")