24 #if defined (HAVE_CONFIG_H) 40 # include <sys/types.h> 41 # include <sys/wait.h> 44 # ifndef OCTAVE_UNUSED 45 # define OCTAVE_UNUSED 52 static std::map<std::string, std::string>
vars;
54 #if ! defined (OCTAVE_VERSION) 55 # define OCTAVE_VERSION %OCTAVE_CONF_VERSION% 58 #if ! defined (OCTAVE_PREFIX) 59 # define OCTAVE_PREFIX %OCTAVE_CONF_PREFIX% 62 #if ! defined (OCTAVE_EXEC_PREFIX) 63 # define OCTAVE_EXEC_PREFIX %OCTAVE_CONF_EXEC_PREFIX% 79 return WIFEXITED (status);
85 return WEXITSTATUS (status);
93 std::ostringstream buf;
97 int c = std::fgetc (fp);
99 if (
c ==
'\n' ||
c == EOF)
102 buf << static_cast<char> (
c);
111 const char *
val = getenv (
name);
122 if (
s.find (
' ') != std::string::npos &&
s[0] !=
'"')
123 return '"' +
s +
'"';
138 vars[
"OCTINCLUDEDIR"]
152 #if defined (OCTAVE_USE_WINDOWS_API) 162 if (
vars[
"INCLUDEDIR"] !=
"/usr/include")
167 if (
vars[
"LIBDIR"] !=
"/usr/lib")
192 vars[
"XTRA_CFLAGS"] =
get_variable (
"XTRA_CFLAGS", %OCTAVE_CONF_XTRA_CFLAGS%);
195 %OCTAVE_CONF_XTRA_CXXFLAGS%);
202 %OCTAVE_CONF_DEPEND_FLAGS%);
204 vars[
"DEPEND_EXTRA_SED_PATTERN"]
206 %OCTAVE_CONF_DEPEND_EXTRA_SED_PATTERN%);
211 %OCTAVE_CONF_MKOCTFILE_DL_LDFLAGS%);
214 %OCTAVE_CONF_RDYNAMIC_FLAG%);
216 vars[
"LIBOCTAVE"] =
"-loctave";
218 vars[
"LIBOCTINTERP"] =
"-loctinterp";
220 vars[
"READLINE_LIBS"] =
"-lreadline";
222 vars[
"LAPACK_LIBS"] =
get_variable (
"LAPACK_LIBS", %OCTAVE_CONF_LAPACK_LIBS%);
227 %OCTAVE_CONF_FFTW3_LDFLAGS%);
232 %OCTAVE_CONF_FFTW3F_LDFLAGS%);
234 vars[
"FFTW3F_LIBS"] =
get_variable (
"FFTW3F_LIBS", %OCTAVE_CONF_FFTW3F_LIBS%);
241 %OCTAVE_CONF_MKOCTFILE_OCTAVE_LINK_DEPS%);
244 %OCTAVE_CONF_OCTAVE_LINK_OPTS%);
247 %OCTAVE_CONF_MKOCTFILE_OCT_LINK_DEPS%);
250 %OCTAVE_CONF_OCT_LINK_OPTS%);
257 %OCTAVE_CONF_LD_STATIC_FLAG%);
262 %OCTAVE_CONF_F77_INTEGER_8_FLAG%);
263 vars[
"ALL_FFLAGS"] =
vars[
"FFLAGS"] +
' ' +
vars[
"F77_INTEGER8_FLAG"];
266 =
vars[
"INCFLAGS"] +
' ' +
vars[
"XTRA_CFLAGS"] +
' ' +
vars[
"CFLAGS"];
269 =
vars[
"INCFLAGS"] +
' ' +
vars[
"XTRA_CXXFLAGS"] +
' ' +
vars[
"CXXFLAGS"];
272 =
vars[
"LD_STATIC_FLAG"] +
' ' +
vars[
"CPICFLAG"] +
' ' +
vars[
"LDFLAGS"];
275 = (
vars[
"LIBOCTINTERP"] +
' ' +
vars[
"LIBOCTAVE"] +
' ' 276 +
vars[
"SPECIAL_MATH_LIB"]);
278 vars[
"FFTW_LIBS"] =
vars[
"FFTW3_LDFLAGS"] +
' ' +
vars[
"FFTW3_LIBS"] +
' ' 279 +
vars[
"FFTW3F_LDFLAGS"] +
' ' +
vars[
"FFTW3F_LIBS"];
292 " -h, -?, --help Print this message.\n" 294 " -IDIR Add -IDIR to compile commands.\n" 296 " -idirafter DIR Add -idirafter DIR to compile commands.\n" 298 " -DDEF Add -DDEF to compile commands.\n" 300 " -lLIB Add library LIB to link command.\n" 302 " -LDIR Add -LDIR to link command.\n" 304 " -M, --depend Generate dependency files (.d) for C and C++\n" 306 #if ! defined (OCTAVE_USE_WINDOWS_API) 308 " -pthread Add -pthread to link command.\n" 311 " -RDIR Add -RDIR to link command.\n" 313 " -Wl,... Pass flags though the linker like -Wl,-rpath=...\n" 315 " -W... Pass flags though the compiler like -Wa,OPTION.\n" 317 " -c, --compile Compile, but do not link.\n" 319 " -o FILE, --output FILE Output filename. Default extension is .oct\n" 320 " (or .mex if --mex is specified) unless linking\n" 321 " a stand-alone executable.\n" 323 " -g Enable debugging options for compilers.\n" 325 " -p VAR, --print VAR Print configuration variable VAR. Recognized\n" 328 " ALL_CFLAGS INCFLAGS\n" 329 " ALL_CXXFLAGS INCLUDEDIR\n" 330 " ALL_FFLAGS LAPACK_LIBS\n" 331 " ALL_LDFLAGS LD_CXX\n" 333 " BLAS_LIBS LD_STATIC_FLAG\n" 336 " CPICFLAG LIBOCTAVE\n" 337 " CPPFLAGS LIBOCTINTERP\n" 339 " CXXFLAGS OCTAVE_EXEC_HOME\n" 340 " CXXPICFLAG OCTAVE_HOME\n" 341 " DEPEND_EXTRA_SED_PATTERN OCTAVE_LIBS\n" 342 " DEPEND_FLAGS OCTAVE_LINK_DEPS\n" 343 " DL_LD OCTAVE_LINK_OPTS\n" 344 " DL_LDFLAGS OCTINCLUDEDIR\n" 346 " F77_INTEGER8_FLAG OCT_LINK_DEPS\n" 347 " FFLAGS OCT_LINK_OPTS\n" 348 " FFTW3F_LDFLAGS RANLIB\n" 349 " FFTW3F_LIBS RDYNAMIC_FLAG\n" 350 " FFTW3_LDFLAGS READLINE_LIBS\n" 352 " FFTW_LIBS SPECIAL_MATH_LIB\n" 353 " FLIBS XTRA_CFLAGS\n" 354 " FPICFLAG XTRA_CXXFLAGS\n" 356 " --link-stand-alone Link a stand-alone executable file.\n" 358 " --mex Assume we are creating a MEX file. Set the\n" 359 " default output extension to \".mex\".\n" 361 " -s, --strip Strip output file.\n" 363 " -n, --just-print, --dry-run\n" 364 " Print commands, but do not execute them.\n" 366 " -v, --verbose Echo commands as they are executed.\n" 368 " FILE Compile or link FILE. Recognized file types are:\n" 378 " .f Fortran source (fixed form)\n" 379 " .F Fortran source (fixed form)\n" 380 " .f90 Fortran source (free form)\n" 381 " .F90 Fortran source (free form)\n" 384 #if defined (_MSC_VER) 385 " .lib library file\n" 394 size_t pos =
s.rfind (
'.');
396 if (pos == std::string::npos)
403 size_t p1 =
retval.rfind (
'/'), p2 =
retval.rfind (
'\\');
405 pos = (p1 != std::string::npos && p2 != std::string::npos
406 ?
std::max (p1, p2) : (p2 != std::string::npos ? p2 : p1));
408 if (pos != std::string::npos)
418 return (
s.length () >= prefix.length () &&
s.find (prefix) == 0);
424 return (
s.length () >= suffix.length ()
425 &&
s.rfind (suffix) ==
s.length () - suffix.length ());
433 std::cout << cmd << std::endl;
438 std::cout << cmd << std::endl;
451 return (
s ==
"yes" ||
s ==
"true");
473 std::list<std::string> cfiles, ccfiles, f77files;
475 std::string objfiles, libfiles, octfile, outputfile;
476 std::string incflags, defs, ldflags, pass_on_options;
478 bool no_oct_file_strip_on_this_platform =
is_true (
"%NO_OCT_FILE_STRIP%");
480 bool link_stand_alone =
false;
482 bool printonly =
false;
493 cfiles.push_back (
file);
501 ccfiles.push_back (
file);
507 f77files.push_back (
file);
519 else if (
arg ==
"-d" ||
arg ==
"-debug" ||
arg ==
"--debug" 520 ||
arg ==
"-v" ||
arg ==
"-verbose" ||
arg ==
"--verbose")
523 if (
vars[
"CC"] ==
"cc-msvc")
525 if (
vars[
"CXX"] ==
"cc-msvc")
526 vars[
"CXX"] +=
" -d";
527 if (
vars[
"DL_LD"] ==
"cc-msvc")
528 vars[
"DL_LD"] +=
" -d";
530 else if (
arg ==
"-h" ||
arg ==
"-?" ||
arg ==
"-help" ||
arg ==
"--help")
540 else if (
arg ==
"-idirafter")
545 incflags += (
" -idirafter " +
arg);
548 std::cerr <<
"mkoctfile: include directory name missing" 555 else if (
arg ==
"-largeArrayDims" ||
arg ==
"-compatibleArrayDims")
557 std::cout <<
"warning: -largeArrayDims and -compatibleArrayDims are accepted for compatibility, but ignored" << std::endl;
562 ldflags += (
' ' +
arg);
564 #if ! defined (OCTAVE_USE_WINDOWS_API) 565 else if (
arg ==
"-pthread")
567 ldflags += (
' ' +
arg);
570 else if (
arg ==
"-M" ||
arg ==
"-depend" ||
arg ==
"--depend")
574 else if (
arg ==
"-o" ||
arg ==
"-output" ||
arg ==
"--output")
582 std::cerr <<
"mkoctfile: output filename missing" << std::endl;
584 else if (
arg ==
"-n" ||
arg ==
"--dry-run" ||
arg ==
"--just-print")
588 else if (
arg ==
"-p" ||
arg ==
"-print" ||
arg ==
"--print")
593 std::cout <<
vars[
arg] << std::endl;
597 std::cerr <<
"mkoctfile: --print requires argument" << std::endl;
599 else if (
arg ==
"-s" ||
arg ==
"-strip" ||
arg ==
"--strip")
601 if (no_oct_file_strip_on_this_platform)
602 std::cerr <<
"mkoctfile: stripping disabled on this platform" 607 else if (
arg ==
"-c" ||
arg ==
"-compile" ||
arg ==
"--compile")
611 else if (
arg ==
"-g")
613 vars[
"ALL_CFLAGS"] +=
" -g";
614 vars[
"ALL_CXXFLAGS"] +=
" -g";
615 vars[
"ALL_FFLAGS"] +=
" -g";
617 else if (
arg ==
"-link-stand-alone" ||
arg ==
"--link-stand-alone")
619 link_stand_alone =
true;
621 else if (
arg ==
"-mex" ||
arg ==
"--mex")
624 #if defined (_MSC_VER) 625 ldflags +=
" -Wl,-export:mexFunction";
631 pass_on_options += (
' ' +
arg);
635 pass_on_options += (
' ' +
arg);
640 pass_on_options += (
' ' +
arg);
648 pass_on_options += (
' ' +
arg);
655 std::cerr <<
"mkoctfile: unrecognized argument " <<
arg << std::endl;
659 if (!
file.empty () && octfile.empty ())
663 if (output_ext ==
".mex" 664 &&
vars[
"ALL_CFLAGS"].
find (
"-g") != std::string::npos)
666 defs +=
" -DMEX_DEBUG";
671 if (link_stand_alone)
673 if (! outputfile.empty ())
674 output_option =
"-o " + outputfile;
678 if (! outputfile.empty ())
680 octfile = outputfile;
681 size_t len = octfile.length ();
682 size_t len_ext = output_ext.length ();
683 if (octfile.substr (len-len_ext) != output_ext)
684 octfile += output_ext;
687 octfile =
basename (octfile,
true) + output_ext;
692 for (
const auto&
f : cfiles)
699 = (
vars[
"CC"] +
' ' +
vars[
"DEPEND_FLAGS"] +
' ' 700 +
vars[
"CPPFLAGS"] +
' ' +
vars[
"ALL_CFLAGS"] +
' ' 703 FILE *fd = popen (cmd.c_str (),
"r");
704 std::ofstream fo (dfile.c_str ());
709 if ((pos =
line.rfind (
".o:")) != std::string::npos)
711 size_t spos =
line.rfind (
'/', pos);
713 (spos == std::string::npos
714 ?
line.substr (0, pos+2)
715 :
line.substr (spos+1, pos-spos+1));
717 << dfile <<
line.substr (pos) << std::endl;
720 fo <<
line << std::endl;
726 for (
const auto&
f : ccfiles)
733 = (
vars[
"CXX"] +
' ' +
vars[
"DEPEND_FLAGS"] +
' ' 734 +
vars[
"CPPFLAGS"] +
' ' +
vars[
"ALL_CXXFLAGS"] +
' ' 737 FILE *fd = popen (cmd.c_str (),
"r");
738 std::ofstream fo (dfile.c_str ());
743 if ((pos =
line.rfind (
".o:")) != std::string::npos)
745 size_t spos =
line.rfind (
'/', pos);
747 (spos == std::string::npos
748 ?
line.substr (0, pos+2)
749 :
line.substr (spos+1, pos-spos+1));
751 << dfile <<
line.substr (pos+2) << std::endl;
754 fo <<
line << std::endl;
763 for (
const auto&
f : f77files)
770 if (! outputfile.empty ())
779 objfiles += (
' ' + o);
782 = (
vars[
"F77"] +
" -c " +
vars[
"FPICFLAG"] +
' ' 783 +
vars[
"ALL_FFLAGS"] +
' ' + incflags +
' ' + defs +
' ' 784 + pass_on_options +
' ' +
f +
" -o " + o);
793 std::cerr <<
"mkoctfile: no way to compile Fortran file " <<
f 799 for (
const auto&
f : cfiles)
804 if (! outputfile.empty ())
813 objfiles += (
' ' + o);
816 = (
vars[
"CC"] +
" -c " +
vars[
"CPPFLAGS"] +
' ' 817 +
vars[
"CPICFLAG"] +
' ' +
vars[
"ALL_CFLAGS"] +
' ' 818 + pass_on_options +
' ' + incflags +
' ' + defs +
' ' 828 std::cerr <<
"mkoctfile: no way to compile C file " <<
f 834 for (
const auto&
f : ccfiles)
839 if (! outputfile.empty ())
848 objfiles += (
' ' + o);
851 = (
vars[
"CXX"] +
" -c " +
vars[
"CPPFLAGS"] +
' ' 852 +
vars[
"CXXPICFLAG"] +
' ' +
vars[
"ALL_CXXFLAGS"] +
' ' 853 + pass_on_options +
' ' + incflags +
' ' + defs +
' ' 863 std::cerr <<
"mkoctfile: no way to compile C++ file " <<
f 869 if (
link && ! objfiles.empty ())
871 if (link_stand_alone)
876 = (
vars[
"LD_CXX"] +
' ' +
vars[
"CPPFLAGS"] +
' ' 877 +
vars[
"ALL_CXXFLAGS"] +
' ' +
vars[
"RDYNAMIC_FLAG"] +
' ' 878 +
vars[
"ALL_LDFLAGS"] +
' ' + pass_on_options +
' ' 879 + output_option +
' ' + objfiles +
' ' + libfiles +
' ' 880 + ldflags +
' ' +
vars[
"LFLAGS"] +
" -loctinterp -loctave " 881 +
vars[
"OCTAVE_LINK_OPTS"] +
' ' +
vars[
"OCTAVE_LINK_DEPS"]);
891 <<
"mkoctfile: no way to link stand-alone executable file" 899 = (
vars[
"DL_LD"] +
' ' +
vars[
"ALL_CXXFLAGS"] +
' ' 900 +
vars[
"DL_LDFLAGS"] +
' ' + pass_on_options
901 +
" -o " + octfile +
' ' + objfiles +
' ' + libfiles +
' ' 902 + ldflags +
' ' +
vars[
"LFLAGS"] +
" -loctinterp -loctave " 903 +
vars[
"OCT_LINK_OPTS"] +
' ' +
vars[
"OCT_LINK_DEPS"]);
static void set_octave_home(void)
For example cd octave end example noindent changes the current working directory to file
static std::string prepend_octave_exec_home(const std::string &s)
static std::string Voctave_exec_home
static std::string usage_msg
bool octave_wifexited_wrapper(int status)
static std::string help_msg
int unlink(const std::string &name)
identity matrix If supplied two scalar respectively For allows like xample val
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE * f
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 of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the system(carriage-return linefeed on Windows). The default when no mode is specified is binary. Additionally
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)
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 of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
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
nd deftypefn *std::string name
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.
static std::string Voctave_home
bool is_true(const std::string &s)
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)
static OCTAVE_UNUSED std::string prepend_octave_home(const std::string &s)
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)