Mercurial > octave-nkf
comparison scripts/miscellaneous/mkoctfile.m @ 14121:6a59b271cd91 stable
mkoctfile.m: Return the output and exit status from the mkoctfile shell command
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Thu, 29 Dec 2011 09:53:33 -0500 |
parents | 4a86826dbb0e |
children | 72c96de7a403 |
comparison
equal
deleted
inserted
replaced
14120:0a051c406242 | 14121:6a59b271cd91 |
---|---|
16 ## along with Octave; see the file COPYING. If not, see | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | 17 ## <http://www.gnu.org/licenses/>. |
18 | 18 |
19 ## -*- texinfo -*- | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Command} {} mkoctfile [-options] file @dots{} | 20 ## @deftypefn {Command} {} mkoctfile [-options] file @dots{} |
21 ## @deftypefnx {Function File} {[@var{output}, @var{status} =} mkoctfile (@dots{}) | |
21 ## | 22 ## |
22 ## The @code{mkoctfile} function compiles source code written in C, | 23 ## The @code{mkoctfile} function compiles source code written in C, |
23 ## C++, or Fortran. Depending on the options used with @code{mkoctfile}, the | 24 ## C++, or Fortran. Depending on the options used with @code{mkoctfile}, the |
24 ## compiled code can be called within Octave or can be used as a stand-alone | 25 ## compiled code can be called within Octave or can be used as a stand-alone |
25 ## application. | 26 ## application. |
26 ## | 27 ## |
27 ## @code{mkoctfile} can be called from the shell prompt or from the Octave | 28 ## @code{mkoctfile} can be called from the shell prompt or from the Octave |
28 ## prompt. | 29 ## prompt. Calling it from the Octave prompt simply delegates the |
30 ## call to the shell prompt. The output is stored in the @var{output} | |
31 ## variable and the exit status in the @var{status} variable. | |
29 ## | 32 ## |
30 ## @code{mkoctfile} accepts the following options, all of which are optional | 33 ## @code{mkoctfile} accepts the following options, all of which are optional |
31 ## except for the file name of the code you wish to compile: | 34 ## except for the file name of the code you wish to compile: |
32 ## | 35 ## |
33 ## @table @samp | 36 ## @table @samp |
135 ## @end example | 138 ## @end example |
136 ## | 139 ## |
137 ## @end table | 140 ## @end table |
138 ## @end deftypefn | 141 ## @end deftypefn |
139 | 142 |
140 function mkoctfile (varargin) | 143 function [output, status] = mkoctfile (varargin) |
141 | 144 |
142 bindir = octave_config_info ("bindir"); | 145 bindir = octave_config_info ("bindir"); |
143 | 146 |
144 shell_script = fullfile (bindir, sprintf ("mkoctfile-%s", OCTAVE_VERSION)); | 147 shell_script = fullfile (bindir, sprintf ("mkoctfile-%s", OCTAVE_VERSION)); |
145 | 148 |
146 cmd = cstrcat ("\"", shell_script, "\""); | 149 cmd = cstrcat ("\"", shell_script, "\""); |
147 for i = 1:nargin | 150 for i = 1:nargin |
148 cmd = cstrcat (cmd, " \"", varargin{i}, "\""); | 151 cmd = cstrcat (cmd, " \"", varargin{i}, "\""); |
149 endfor | 152 endfor |
150 | 153 |
151 status = system (cmd); | 154 [sys, out] = system (cmd); |
152 | 155 |
153 if (status == 127) | 156 if (nargout > 0) |
157 [output, status] = deal (out, sys); | |
158 else | |
159 printf ("%s", out); | |
160 endif | |
161 | |
162 if (sys == 127) | |
154 warning ("unable to find mkoctfile in expected location: `%s'", | 163 warning ("unable to find mkoctfile in expected location: `%s'", |
155 shell_script); | 164 shell_script); |
156 | 165 |
157 warning ("mkoctfile exited with failure status"); | 166 warning ("mkoctfile exited with failure status"); |
158 endif | 167 endif |