]> Creatis software - CreaPhase.git/blob - octave_packages/m/miscellaneous/mkoctfile.m
update packages
[CreaPhase.git] / octave_packages / m / miscellaneous / mkoctfile.m
1 ## Copyright (C) 2006-2012 Keith Goodman
2 ##
3 ## This file is part of Octave.
4 ##
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.
9 ##
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.
14 ##
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/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Command} {} mkoctfile [-options] file @dots{}
21 ## @deftypefnx {Function File} {[@var{output}, @var{status} =} mkoctfile (@dots{})
22 ##
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
26 ## application.
27 ##
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.
32 ##
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:
35 ##
36 ## @table @samp
37 ## @item -I DIR
38 ## Add the include directory DIR to compile commands.
39 ##
40 ## @item -D DEF
41 ## Add the definition DEF to the compiler call.
42 ##
43 ## @item -l LIB
44 ## Add the library LIB to the link command.
45 ##
46 ## @item -L DIR
47 ## Add the library directory DIR to the link command.
48 ##
49 ## @item -M
50 ## @itemx --depend
51 ## Generate dependency files (.d) for C and C++ source files.
52 ##
53 ## @item -R DIR
54 ## Add the run-time path to the link command.
55 ##
56 ## @item -Wl,@dots{}
57 ## Pass flags though the linker like "-Wl,-rpath=@dots{}".
58 ## The quotes are needed since commas are interpreted as command
59 ## separators.
60 ##
61 ## @item -W@dots{}
62 ## Pass flags though the compiler like "-Wa,OPTION".
63 ##
64 ## @item -c
65 ## Compile but do not link.
66 ##
67 ## @item -g
68 ## Enable debugging options for compilers.
69 ##
70 ## @item -o FILE
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.
75 ##
76 ## @item -p VAR
77 ## @itemx --print VAR
78 ## Print the configuration variable VAR@.  Recognized variables are:
79 ##
80 ## @example
81 ##    ALL_CFLAGS                FFTW3F_LIBS
82 ##    ALL_CXXFLAGS              FLIBS
83 ##    ALL_FFLAGS                FPICFLAG
84 ##    ALL_LDFLAGS               INCFLAGS
85 ##    BLAS_LIBS                 LAPACK_LIBS
86 ##    CC                        LDFLAGS
87 ##    CFLAGS                    LD_CXX
88 ##    CPICFLAG                  LD_STATIC_FLAG
89 ##    CPPFLAGS                  LFLAGS
90 ##    CXX                       LIBCRUFT
91 ##    CXXFLAGS                  LIBOCTAVE
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
98 ##    F77                       READLINE_LIBS
99 ##    F77_INTEGER_8_FLAG        SED
100 ##    FFLAGS                    XTRA_CFLAGS
101 ##    FFTW3_LDFLAGS             XTRA_CXXFLAGS
102 ##    FFTW3_LIBS
103 ##    FFTW3F_LDFLAGS
104 ##
105 ## @end example
106 ##
107 ## @item --link-stand-alone
108 ## Link a stand-alone executable file.
109 ##
110 ## @item --mex
111 ## Assume we are creating a MEX file.  Set the default output extension
112 ## to ".mex".
113 ##
114 ## @item -s
115 ## @itemx --strip
116 ## Strip the output file.
117 ##
118 ## @item -v
119 ## @itemx --verbose
120 ## Echo commands as they are executed.
121 ##
122 ## @item file
123 ## The file to compile or link.  Recognized file types are
124 ##
125 ## @example
126 ## @group
127 ##    .c    C source
128 ##    .cc   C++ source
129 ##    .C    C++ source
130 ##    .cpp  C++ source
131 ##    .f    Fortran source (fixed form)
132 ##    .F    Fortran source (fixed form)
133 ##    .f90  Fortran source (free form)
134 ##    .F90  Fortran source (free form)
135 ##    .o    object file
136 ##    .a    library file
137 ## @end group
138 ## @end example
139 ##
140 ## @end table
141 ## @end deftypefn
142
143 function [output, status] = mkoctfile (varargin)
144
145   bindir = octave_config_info ("bindir");
146
147   shell_script = fullfile (bindir, "mkoctfile");
148
149   cmd = cstrcat ("\"", shell_script, "\"");
150   for i = 1:nargin
151     cmd = cstrcat (cmd, " \"", varargin{i}, "\"");
152   endfor
153
154   [sys, out] = system (cmd);
155
156   if (nargout > 0)
157     [output, status] = deal (out, sys);
158   else
159     printf ("%s", out);
160   endif
161
162   if (sys == 127)
163     warning ("unable to find mkoctfile in expected location: `%s'",
164              shell_script);
165
166     warning ("mkoctfile exited with failure status");
167   endif
168
169 endfunction