1 ## Copyright (C) 2006-2012 Keith Goodman
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Command} {} mkoctfile [-options] file @dots{}
21 ## @deftypefnx {Function File} {[@var{output}, @var{status} =} mkoctfile (@dots{})
23 ## The @code{mkoctfile} function compiles source code written in C,
24 ## C++, or Fortran. Depending on the options used with @code{mkoctfile}, the
25 ## compiled code can be called within Octave or can be used as a stand-alone
28 ## @code{mkoctfile} can be called from the shell prompt or from the Octave
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.
33 ## @code{mkoctfile} accepts the following options, all of which are optional
34 ## except for the file name of the code you wish to compile:
38 ## Add the include directory DIR to compile commands.
41 ## Add the definition DEF to the compiler call.
44 ## Add the library LIB to the link command.
47 ## Add the library directory DIR to the link command.
51 ## Generate dependency files (.d) for C and C++ source files.
54 ## Add the run-time path to the link command.
57 ## Pass flags though the linker like "-Wl,-rpath=@dots{}".
58 ## The quotes are needed since commas are interpreted as command
62 ## Pass flags though the compiler like "-Wa,OPTION".
65 ## Compile but do not link.
68 ## Enable debugging options for compilers.
71 ## @itemx --output FILE
72 ## Output file name. Default extension is .oct
73 ## (or .mex if @samp{--mex} is specified) unless linking
74 ## a stand-alone executable.
78 ## Print the configuration variable VAR@. Recognized variables are:
81 ## ALL_CFLAGS FFTW3F_LIBS
83 ## ALL_FFLAGS FPICFLAG
84 ## ALL_LDFLAGS INCFLAGS
85 ## BLAS_LIBS LAPACK_LIBS
88 ## CPICFLAG LD_STATIC_FLAG
92 ## CXXPICFLAG LIBOCTINTERP
93 ## DEPEND_EXTRA_SED_PATTERN LIBS
94 ## DEPEND_FLAGS OCTAVE_LIBS
95 ## DL_LD OCTAVE_LINK_DEPS
96 ## DL_LDFLAGS OCT_LINK_DEPS
97 ## EXEEXT RDYNAMIC_FLAG
99 ## F77_INTEGER_8_FLAG SED
100 ## FFLAGS XTRA_CFLAGS
101 ## FFTW3_LDFLAGS XTRA_CXXFLAGS
107 ## @item --link-stand-alone
108 ## Link a stand-alone executable file.
111 ## Assume we are creating a MEX file. Set the default output extension
116 ## Strip the output file.
120 ## Echo commands as they are executed.
123 ## The file to compile or link. Recognized file types are
131 ## .f Fortran source (fixed form)
132 ## .F Fortran source (fixed form)
133 ## .f90 Fortran source (free form)
134 ## .F90 Fortran source (free form)
143 function [output, status] = mkoctfile (varargin)
145 bindir = octave_config_info ("bindir");
147 shell_script = fullfile (bindir, "mkoctfile");
149 cmd = cstrcat ("\"", shell_script, "\"");
151 cmd = cstrcat (cmd, " \"", varargin{i}, "\"");
154 [sys, out] = system (cmd);
157 [output, status] = deal (out, sys);
163 warning ("unable to find mkoctfile in expected location: `%s'",
166 warning ("mkoctfile exited with failure status");