24 #if defined (HAVE_CONFIG_H)
39 # include <sys/types.h>
40 # include <sys/wait.h>
47 static std::map<std::string, std::string>
vars;
49 #if ! defined (OCTAVE_VERSION)
50 # define OCTAVE_VERSION %OCTAVE_CONF_VERSION%
53 #if ! defined (OCTAVE_PREFIX)
54 # define OCTAVE_PREFIX %OCTAVE_CONF_PREFIX%
70 return WIFEXITED (status);
76 return WEXITSTATUS (status);
84 static std::vector<char> buf (100);
91 if (c ==
'\n' || c == EOF)
93 if (buf.size () <= idx)
94 buf.resize (buf.size () + 100);
106 const char *
val = getenv (name);
116 if (s.find (
' ') != std::string::npos && s[0] !=
'"')
117 return "\"" + s +
"\"";
130 std::string DEFAULT_OCTINCLUDEDIR = %OCTAVE_CONF_OCTINCLUDEDIR%;
131 std::string DEFAULT_INCLUDEDIR = %OCTAVE_CONF_INCLUDEDIR%;
133 std::string DEFAULT_OCTLIBDIR = %OCTAVE_CONF_OCTLIBDIR%;
140 vars[
"OCTINCLUDEDIR"] =
get_variable (
"OCTINCLUDEDIR", DEFAULT_OCTINCLUDEDIR);
141 vars[
"INCLUDEDIR"] =
get_variable (
"INCLUDEDIR", DEFAULT_INCLUDEDIR);
142 vars[
"LIBDIR"] =
get_variable (
"LIBDIR", DEFAULT_LIBDIR);
143 vars[
"OCTLIBDIR"] =
get_variable (
"OCTLIBDIR", DEFAULT_OCTLIBDIR);
145 #if defined (OCTAVE_USE_WINDOWS_API)
147 =
"-I" +
quote_path (vars[
"OCTINCLUDEDIR"] +
"\\..")
151 =
"-I" +
quote_path (vars[
"OCTINCLUDEDIR"] +
"/..")
154 if (vars[
"INCLUDEDIR"] !=
"/usr/include")
155 DEFAULT_INCFLAGS +=
" -I" +
quote_path (vars[
"INCLUDEDIR"]);
158 if (vars[
"LIBDIR"] !=
"/usr/lib")
159 DEFAULT_LFLAGS +=
" -L" +
quote_path (vars[
"LIBDIR"]);
161 vars[
"CPPFLAGS"] =
get_variable (
"CPPFLAGS", %OCTAVE_CONF_CPPFLAGS%);
162 vars[
"INCFLAGS"] =
get_variable (
"INCFLAGS", DEFAULT_INCFLAGS);
163 vars[
"F77"] =
get_variable (
"F77", %OCTAVE_CONF_MKOCTFILE_F77%);
164 vars[
"FFLAGS"] =
get_variable (
"FFLAGS", %OCTAVE_CONF_FFLAGS%);
165 vars[
"FPICFLAG"] =
get_variable (
"FPICFLAG", %OCTAVE_CONF_FPICFLAG%);
166 vars[
"CC"] =
get_variable (
"CC", %OCTAVE_CONF_MKOCTFILE_CC%);
167 vars[
"CFLAGS"] =
get_variable (
"CFLAGS", %OCTAVE_CONF_CFLAGS%);
168 vars[
"CPICFLAG"] =
get_variable (
"CPICFLAG", %OCTAVE_CONF_CPICFLAG%);
169 vars[
"CXX"] =
get_variable (
"CXX", %OCTAVE_CONF_MKOCTFILE_CXX%);
170 vars[
"CXXFLAGS"] =
get_variable (
"CXXFLAGS", %OCTAVE_CONF_CXXFLAGS%);
171 vars[
"CXXPICFLAG"] =
get_variable (
"CXXPICFLAG", %OCTAVE_CONF_CXXPICFLAG%);
172 vars[
"XTRA_CFLAGS"] =
get_variable (
"XTRA_CFLAGS", %OCTAVE_CONF_XTRA_CFLAGS%);
174 %OCTAVE_CONF_XTRA_CXXFLAGS%);
176 vars[
"AR"] =
get_variable (
"AR", %OCTAVE_CONF_MKOCTFILE_AR%);
177 vars[
"RANLIB"] =
get_variable (
"RANLIB", %OCTAVE_CONF_MKOCTFILE_RANLIB%);
180 %OCTAVE_CONF_DEPEND_FLAGS%);
181 vars[
"DEPEND_EXTRA_SED_PATTERN"] =
get_variable (
"DEPEND_EXTRA_SED_PATTERN",
182 %OCTAVE_CONF_DEPEND_EXTRA_SED_PATTERN%);
184 vars[
"DL_LD"] =
get_variable (
"DL_LD", %OCTAVE_CONF_MKOCTFILE_DL_LD%);
186 %OCTAVE_CONF_MKOCTFILE_DL_LDFLAGS%);
189 %OCTAVE_CONF_RDYNAMIC_FLAG%);
190 vars[
"LIBOCTAVE"] =
"-loctave";
191 vars[
"LIBOCTINTERP"] =
"-loctinterp";
192 vars[
"READLINE_LIBS"] =
"-lreadline";
193 vars[
"LAPACK_LIBS"] =
get_variable (
"LAPACK_LIBS", %OCTAVE_CONF_LAPACK_LIBS%);
194 vars[
"BLAS_LIBS"] =
get_variable (
"BLAS_LIBS", %OCTAVE_CONF_BLAS_LIBS%);
196 %OCTAVE_CONF_FFTW3_LDFLAGS%);
197 vars[
"FFTW3_LIBS"] =
get_variable (
"FFTW3_LIBS", %OCTAVE_CONF_FFTW3_LIBS%);
198 vars[
"FFTW3F_LDFLAGS"] =
get_variable (
"FFTW3F_LDFLAGS",
199 %OCTAVE_CONF_FFTW3F_LDFLAGS%);
200 vars[
"FFTW3F_LIBS"] =
get_variable (
"FFTW3F_LIBS", %OCTAVE_CONF_FFTW3F_LIBS%);
201 vars[
"LIBS"] =
get_variable (
"LIBS", %OCTAVE_CONF_LIBS%);
202 vars[
"FLIBS"] =
get_variable (
"FLIBS", %OCTAVE_CONF_FLIBS%);
203 vars[
"OCTAVE_LINK_DEPS"] =
get_variable (
"OCTAVE_LINK_DEPS",
204 %OCTAVE_CONF_OCTAVE_LINK_DEPS%);
205 vars[
"OCTAVE_LINK_OPTS"] =
get_variable (
"OCTAVE_LINK_OPTS",
206 %OCTAVE_CONF_OCTAVE_LINK_OPTS%);
208 %OCTAVE_CONF_OCT_LINK_DEPS%);
210 %OCTAVE_CONF_OCT_LINK_OPTS%);
211 vars[
"LD_CXX"] =
get_variable (
"LD_CXX", %OCTAVE_CONF_MKOCTFILE_LD_CXX%);
212 vars[
"LDFLAGS"] =
get_variable (
"LDFLAGS", %OCTAVE_CONF_LDFLAGS%);
213 vars[
"LD_STATIC_FLAG"] =
get_variable (
"LD_STATIC_FLAG",
214 %OCTAVE_CONF_LD_STATIC_FLAG%);
215 vars[
"LFLAGS"] =
get_variable (
"LFLAGS", DEFAULT_LFLAGS);
216 vars[
"F77_INTEGER8_FLAG"] =
get_variable (
"F77_INTEGER8_FLAG",
217 %OCTAVE_CONF_F77_INTEGER_8_FLAG%);
219 vars[
"ALL_FFLAGS"] = vars[
"FFLAGS"] +
" " + vars[
"F77_INTEGER8_FLAG"];
221 vars[
"ALL_CFLAGS"] = vars[
"INCFLAGS"] +
" " + vars[
"XTRA_CFLAGS"] +
" "
224 vars[
"ALL_CXXFLAGS"] = vars[
"INCFLAGS"] +
" " + vars[
"XTRA_CXXFLAGS"] +
" "
227 vars[
"ALL_LDFLAGS"] = vars[
"LD_STATIC_FLAG"] +
" " + vars[
"CPICFLAG"] +
" "
230 vars[
"OCTAVE_LIBS"] = vars[
"LIBOCTINTERP"] +
" " + vars[
"LIBOCTAVE"] +
" "
231 + vars[
"SPECIAL_MATH_LIB"];
233 vars[
"FFTW_LIBS"] = vars[
"FFTW3_LDFLAGS"] +
" " + vars[
"FFTW3_LIBS"] +
" "
234 + vars[
"FFTW3F_LDFLAGS"] +
" " + vars[
"FFTW3F_LIBS"];
244 " -h, -?, --help Print this message.\n"
246 " -IDIR Add -IDIR to compile commands.\n"
248 " -idirafter DIR Add -idirafter DIR to compile commands.\n"
250 " -DDEF Add -DDEF to compile commands.\n"
252 " -lLIB Add library LIB to link command.\n"
254 " -LDIR Add -LDIR to link command.\n"
256 " -M, --depend Generate dependency files (.d) for C and C++\n"
258 #if ! defined (OCTAVE_USE_WINDOWS_API)
260 " -pthread Add -pthread to link command.\n"
263 " -RDIR Add -RDIR to link command.\n"
265 " -Wl,... Pass flags though the linker like -Wl,-rpath=...\n"
267 " -W... Pass flags though the compiler like -Wa,OPTION.\n"
269 " -c, --compile Compile, but do not link.\n"
271 " -o FILE, --output FILE Output filename. Default extension is .oct\n"
272 " (or .mex if --mex is specified) unless linking\n"
273 " a stand-alone executable.\n"
275 " -g Enable debugging options for compilers.\n"
277 " -p VAR, --print VAR Print configuration variable VAR. Recognized\n"
280 " ALL_CFLAGS INCFLAGS\n"
281 " ALL_CXXFLAGS INCLUDEDIR\n"
282 " ALL_FFLAGS LAPACK_LIBS\n"
283 " ALL_LDFLAGS LD_CXX\n"
285 " BLAS_LIBS LD_STATIC_FLAG\n"
288 " CPICFLAG LIBOCTAVE\n"
289 " CPPFLAGS LIBOCTINTERP\n"
291 " CXXFLAGS OCTAVE_HOME\n"
292 " CXXPICFLAG OCTAVE_LIBS\n"
293 " DEPEND_EXTRA_SED_PATTERN OCTAVE_LINK_DEPS\n"
294 " DEPEND_FLAGS OCTAVE_LINK_OPTS\n"
295 " DL_LD OCTAVE_PREFIX\n"
296 " DL_LDFLAGS OCTINCLUDEDIR\n"
298 " F77_INTEGER8_FLAG OCT_LINK_DEPS\n"
299 " FFLAGS OCT_LINK_OPTS\n"
300 " FFTW3F_LDFLAGS RANLIB\n"
301 " FFTW3F_LIBS RDYNAMIC_FLAG\n"
302 " FFTW3_LDFLAGS READLINE_LIBS\n"
304 " FFTW_LIBS SPECIAL_MATH_LIB\n"
305 " FLIBS XTRA_CFLAGS\n"
306 " FPICFLAG XTRA_CXXFLAGS\n"
308 " --link-stand-alone Link a stand-alone executable file.\n"
310 " --mex Assume we are creating a MEX file. Set the\n"
311 " default output extension to \".mex\".\n"
313 " -s, --strip Strip output file.\n"
315 " -n, --just-print, --dry-run\n"
316 " Print commands, but do not execute them.\n"
318 " -v, --verbose Echo commands as they are executed.\n"
320 " FILE Compile or link FILE. Recognized file types are:\n"
330 " .f Fortran source (fixed form)\n"
331 " .F Fortran source (fixed form)\n"
332 " .f90 Fortran source (free form)\n"
333 " .F90 Fortran source (free form)\n"
336 #if defined (_MSC_VER)
337 " .lib library file\n"
345 size_t pos = s.rfind (
'.');
347 if (pos == std::string::npos)
350 retval = s.substr (0, pos);
354 size_t p1 = retval.rfind (
'/'), p2 = retval.rfind (
'\\');
355 pos = (p1 != std::string::npos && p2 != std::string::npos
356 ?
std::max (p1, p2) : (p2 != std::string::npos ? p2 : p1));
357 if (pos != std::string::npos)
358 retval = retval.substr (++pos, std::string::npos);
367 return (s.length () >= prefix.length () && s.find (prefix) == 0);
373 return (s.length () >= suffix.length ()
374 && s.rfind (suffix) == s.length () - suffix.length ());
382 std::cout << cmd << std::endl;
387 std::cout << cmd << std::endl;
400 return (s ==
"yes" || s ==
"true");
409 std::list<std::string> cfiles, ccfiles, f77files;
421 bool no_oct_file_strip_on_this_platform =
is_true (
"%NO_OCT_FILE_STRIP%");
423 bool link_stand_alone =
false;
426 bool printonly =
false;
434 if (argc == 2 && (!
strcmp (argv[1],
"-v")
435 || !
strcmp (argv[1],
"-version")
436 || !
strcmp (argv[1],
"--version")))
449 cfiles.push_back (file);
457 ccfiles.push_back (file);
463 f77files.push_back (file);
475 else if (arg ==
"-d" || arg ==
"-debug" || arg ==
"--debug"
476 || arg ==
"-v" || arg ==
"-verbose" || arg ==
"--verbose")
479 if (vars[
"CC"] ==
"cc-msvc")
481 if (vars[
"CXX"] ==
"cc-msvc")
482 vars[
"CXX"] +=
" -d";
483 if (vars[
"DL_LD"] ==
"cc-msvc")
484 vars[
"DL_LD"] +=
" -d";
486 else if (arg ==
"-h" || arg ==
"-?" || arg ==
"-help" || arg ==
"--help")
496 else if (arg ==
"-idirafter")
501 incflags += (
" -idirafter " +
arg);
504 std::cerr <<
"mkoctfile: include directory name missing"
511 else if (arg ==
"-largeArrayDims" || arg ==
"-compatibleArrayDims")
513 std::cout <<
"warning: -largeArrayDims and -compatibleArrayDims are accepted for compatibility, but ignored" << std::endl;
518 ldflags += (
" " +
arg);
520 #if ! defined (OCTAVE_USE_WINDOWS_API)
521 else if (arg ==
"-pthread")
523 ldflags += (
" " +
arg);
526 else if (arg ==
"-M" || arg ==
"-depend" || arg ==
"--depend")
530 else if (arg ==
"-o" || arg ==
"-output" || arg ==
"--output")
538 std::cerr <<
"mkoctfile: output filename missing" << std::endl;
540 else if (arg ==
"-n" || arg ==
"--dry-run" || arg ==
"--just-print")
544 else if (arg ==
"-p" || arg ==
"-print" || arg ==
"--print")
549 std::cout << vars[
arg] << std::endl;
553 std::cerr <<
"mkoctfile: --print requires argument" << std::endl;
555 else if (arg ==
"-s" || arg ==
"-strip" || arg ==
"--strip")
557 if (no_oct_file_strip_on_this_platform)
558 std::cerr <<
"mkoctfile: stripping disabled on this platform"
563 else if (arg ==
"-c" || arg ==
"-compile" || arg ==
"--compile")
567 else if (arg ==
"-g")
569 vars[
"ALL_CFLAGS"] +=
" -g";
570 vars[
"ALL_CXXFLAGS"] +=
" -g";
571 vars[
"ALL_FFLAGS"] +=
" -g";
573 else if (arg ==
"-link-stand-alone" || arg ==
"--link-stand-alone")
575 link_stand_alone =
true;
577 else if (arg ==
"-mex" || arg ==
"--mex")
580 #if defined (_MSC_VER)
581 ldflags +=
" -Wl,-export:mexFunction";
587 pass_on_options += (
" " +
arg);
592 pass_on_options += (
" " +
arg);
596 std::cerr <<
"mkoctfile: unrecognized argument " << arg << std::endl;
600 if (! file.empty () && octfile.empty ())
604 if (output_ext ==
".mex"
605 && vars[
"ALL_CFLAGS"].
find (
"-g") != std::string::npos)
607 defs +=
" -DMEX_DEBUG";
610 if (link_stand_alone)
612 if (! outputfile.empty ())
613 output_option =
"-o " + outputfile;
617 if (! outputfile.empty ())
619 octfile = outputfile;
620 size_t len = octfile.length ();
621 size_t len_ext = output_ext.length ();
622 if (octfile.substr (len-len_ext) != output_ext)
623 octfile += output_ext;
626 octfile =
basename (octfile,
true) + output_ext;
629 std::list<std::string>::const_iterator it;
633 for (it = cfiles.begin (); it != cfiles.end (); ++it)
639 + vars[
"DEPEND_FLAGS"] +
" "
640 + vars[
"CPPFLAGS"] +
" "
641 + vars[
"ALL_CFLAGS"] +
" "
642 + incflags +
" " + defs +
" " +
quote_path (f);
644 FILE *fd = popen (cmd.c_str (),
"r");
645 std::ofstream fo (dfile.c_str ());
650 if ((pos =
line.rfind (
".o:")) != std::string::npos)
652 size_t spos =
line.rfind (
'/', pos);
654 (spos == std::string::npos
655 ?
line.substr (0, pos+2)
656 :
line.substr (spos+1, pos-spos+1));
657 fo <<
"pic/" << ofile <<
" " << ofile <<
" "
658 << dfile <<
line.substr (pos) << std::endl;
661 fo <<
line << std::endl;
667 for (it = ccfiles.begin (); it != ccfiles.end (); ++it)
673 + vars[
"DEPEND_FLAGS"] +
" "
674 + vars[
"CPPFLAGS"] +
" "
675 + vars[
"ALL_CXXFLAGS"] +
" "
676 + incflags +
" " + defs +
" " +
quote_path (f);
678 FILE *fd = popen (cmd.c_str (),
"r");
679 std::ofstream fo (dfile.c_str ());
684 if ((pos =
line.rfind (
".o:")) != std::string::npos)
686 size_t spos =
line.rfind (
'/', pos);
688 (spos == std::string::npos
689 ?
line.substr (0, pos+2)
690 :
line.substr (spos+1, pos-spos+1));
691 fo <<
"pic/" << ofile <<
" " << ofile <<
" "
692 << dfile <<
line.substr (pos+2) << std::endl;
695 fo <<
line << std::endl;
704 for (it = f77files.begin (); it != f77files.end () && !
result; ++it)
707 if (! vars[
"F77"].
empty ())
710 if (! outputfile.empty ())
719 objfiles += (
" " + o);
721 + vars[
"FPICFLAG"] +
" "
722 + vars[
"ALL_FFLAGS"] +
" "
723 + incflags +
" " + defs +
" " + pass_on_options
724 +
" " + f +
" -o " + o;
729 std::cerr <<
"mkoctfile: no way to compile Fortran file " << f
735 for (it = cfiles.begin (); it != cfiles.end () && !
result; ++it)
738 if (! vars[
"CC"].
empty ())
741 if (! outputfile.empty ())
750 objfiles += (
" " + o);
752 + vars[
"CPPFLAGS"] +
" "
753 + vars[
"CPICFLAG"] +
" " + vars[
"ALL_CFLAGS"] +
" "
754 + pass_on_options +
" "
755 + incflags +
" " + defs +
" "
761 std::cerr <<
"mkoctfile: no way to compile C file " << f
767 for (it = ccfiles.begin (); it != ccfiles.end () && !
result; ++it)
770 if (! vars[
"CXX"].
empty ())
773 if (! outputfile.empty ())
782 objfiles += (
" " + o);
784 + vars[
"CPPFLAGS"] +
" "
785 + vars[
"CXXPICFLAG"] +
" "
786 + vars[
"ALL_CXXFLAGS"] +
" "
787 + pass_on_options +
" "
788 + incflags +
" " + defs +
" "
794 std::cerr <<
"mkoctfile: no way to compile C++ file " << f
800 if (link && ! objfiles.empty () && !
result)
802 if (link_stand_alone)
804 if (! vars[
"LD_CXX"].
empty ())
807 + vars[
"CPPFLAGS"] +
" "
808 + vars[
"ALL_CXXFLAGS"] +
" "
809 + vars[
"RDYNAMIC_FLAG"] +
" "
810 + vars[
"ALL_LDFLAGS"] +
" "
811 + pass_on_options +
" " + output_option +
" "
812 + objfiles +
" " + libfiles +
" "
813 + ldflags +
" " + vars[
"LFLAGS"]
814 +
" -loctinterp -loctave "
815 +
" " + vars[
"OCTAVE_LINK_OPTS"]
816 +
" " + vars[
"OCTAVE_LINK_DEPS"];
822 <<
"mkoctfile: no way to link stand-alone executable file"
830 + vars[
"ALL_CXXFLAGS"] +
" "
831 + vars[
"DL_LDFLAGS"] +
" "
833 +
" -o " + octfile +
" "
834 + objfiles +
" " + libfiles +
" "
836 + vars[
"LFLAGS"] +
" -loctinterp -loctave "
837 + vars[
"OCT_LINK_OPTS"] +
" "
838 + vars[
"OCT_LINK_DEPS"];
static std::string get_octave_home(void)
For example cd octave end example noindent changes the current working directory to file
static std::string usage_msg
bool octave_wifexited_wrapper(int status)
static std::string help_msg
static std::string subst_octave_home(const std::string &s)
int unlink(const std::string &name)
identity matrix If supplied two scalar respectively For allows like xample val
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
static std::map< std::string, std::string > vars
static int run_command(const std::string &cmd, bool printonly=false)
bool starts_with(const std::string &s, const std::string &prefix)
static std::string basename(const std::string &s, bool strip_path=false)
bool ends_with(const std::string &s, const std::string &suffix)
int main(int argc, char **argv)
static void initialize(void)
static octave_idx_type link(octave_idx_type s, octave_idx_type t, octave_idx_type *pp)
static std::string version_msg
create a structure array and initialize its values The dimensions of each cell array of values must match Singleton cells and non cell values are repeated so that they fill the entire array If the cells are empty
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
int octave_unlink_wrapper(const char *nm)
bool strcmp(const T &str_a, const T &str_b)
True if strings are the same.
bool is_true(const std::string &s)
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
int octave_wexitstatus_wrapper(int status)
With real return the complex result
static octave_idx_type find(octave_idx_type i, octave_idx_type *pp)
charNDArray max(char d, const charNDArray &m)
std::ofstream ofile(filename.c_str(), std::ios::out|std::ios::binary)
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values text mode reading and writing automatically converts linefeeds to the appropriate line end character for the system(carriage-return linefeed on Windows, carriage-return on Macintosh).The default when no mode is specified is binary mode.Additionally
=val(i)}if ode{val(i)}occurs in table i
static std::string get_variable(const char *name, const std::string &defval)
static std::string get_line(FILE *fp)
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
static std::string quote_path(const std::string &s)