GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
mkoctfile.in.cc
Go to the documentation of this file.
1 // %NO_EDIT_WARNING%
2 /*
3 
4 Copyright (C) 2008-2017 Michael Goffioul
5 
6 This file is part of Octave.
7 
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if defined (HAVE_CONFIG_H)
25 # include "config.h"
26 #endif
27 
28 #include <string>
29 #include <cstring>
30 #include <map>
31 #include <list>
32 #include <algorithm>
33 #include <iostream>
34 #include <fstream>
35 #include <vector>
36 #include <cstdlib>
37 
38 #if defined (CROSS)
39 # include <sys/types.h>
40 # include <sys/wait.h>
41 # include <unistd.h>
42 #else
43 # include "unistd-wrappers.h"
44 # include "wait-wrappers.h"
45 #endif
46 
47 static std::map<std::string, std::string> vars;
48 
49 #if ! defined (OCTAVE_VERSION)
50 # define OCTAVE_VERSION %OCTAVE_CONF_VERSION%
51 #endif
52 
53 #if ! defined (OCTAVE_PREFIX)
54 # define OCTAVE_PREFIX %OCTAVE_CONF_PREFIX%
55 #endif
56 
57 #include "shared-fcns.h"
58 
59 #if defined (CROSS)
60 
61 static int
62 octave_unlink_wrapper (const char *nm)
63 {
64  return unlink (nm);
65 }
66 
67 static bool
68 octave_wifexited_wrapper (int status)
69 {
70  return WIFEXITED (status);
71 }
72 
73 static int
74 octave_wexitstatus_wrapper (int status)
75 {
76  return WEXITSTATUS (status);
77 }
78 
79 #endif
80 
81 static std::string
82 get_line (FILE *fp)
83 {
84  static std::vector<char> buf (100);
85  unsigned int idx = 0;
86  int c;
87 
88  while (true)
89  {
90  c = std::fgetc (fp);
91  if (c == '\n' || c == EOF)
92  break;
93  if (buf.size () <= idx)
94  buf.resize (buf.size () + 100);
95  buf[idx++] = c;
96  }
97  if (idx == 0)
98  return std::string ("");
99  else
100  return std::string (&buf[0], idx);
101 }
102 
103 static std::string
104 get_variable (const char *name, const std::string& defval)
105 {
106  const char *val = getenv (name);
107  if (val && *val)
108  return std::string (val);
109  else
110  return defval;
111 }
112 
113 static std::string
115 {
116  if (s.find (' ') != std::string::npos && s[0] != '"')
117  return "\"" + s + "\"";
118  else
119  return s;
120 }
121 
122 static void
124 {
125  vars["OCTAVE_HOME"] = get_octave_home ();
126  vars["OCTAVE_PREFIX"] = OCTAVE_PREFIX;
127 
128  vars["SED"] = get_variable ("SED", %OCTAVE_CONF_SED%);
129 
130  std::string DEFAULT_OCTINCLUDEDIR = %OCTAVE_CONF_OCTINCLUDEDIR%;
131  std::string DEFAULT_INCLUDEDIR = %OCTAVE_CONF_INCLUDEDIR%;
132  std::string DEFAULT_LIBDIR = %OCTAVE_CONF_LIBDIR%;
133  std::string DEFAULT_OCTLIBDIR = %OCTAVE_CONF_OCTLIBDIR%;
134 
135  DEFAULT_OCTINCLUDEDIR = subst_octave_home (DEFAULT_OCTINCLUDEDIR);
136  DEFAULT_INCLUDEDIR = subst_octave_home (DEFAULT_INCLUDEDIR);
137  DEFAULT_LIBDIR = subst_octave_home (DEFAULT_LIBDIR);
138  DEFAULT_OCTLIBDIR = subst_octave_home (DEFAULT_OCTLIBDIR);
139 
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);
144 
145 #if defined (OCTAVE_USE_WINDOWS_API)
146  std::string DEFAULT_INCFLAGS
147  = "-I" + quote_path (vars["OCTINCLUDEDIR"] + "\\..")
148  + " -I" + quote_path (vars["OCTINCLUDEDIR"]);
149 #else
150  std::string DEFAULT_INCFLAGS
151  = "-I" + quote_path (vars["OCTINCLUDEDIR"] + "/..")
152  + " -I" + quote_path (vars["OCTINCLUDEDIR"]);
153 #endif
154  if (vars["INCLUDEDIR"] != "/usr/include")
155  DEFAULT_INCFLAGS += " -I" + quote_path (vars["INCLUDEDIR"]);
156 
157  std::string DEFAULT_LFLAGS = "-L" + quote_path (vars["OCTLIBDIR"]);
158  if (vars["LIBDIR"] != "/usr/lib")
159  DEFAULT_LFLAGS += " -L" + quote_path (vars["LIBDIR"]);
160 
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%);
173  vars["XTRA_CXXFLAGS"] = get_variable ("XTRA_CXXFLAGS",
174  %OCTAVE_CONF_XTRA_CXXFLAGS%);
175 
176  vars["AR"] = get_variable ("AR", %OCTAVE_CONF_MKOCTFILE_AR%);
177  vars["RANLIB"] = get_variable ("RANLIB", %OCTAVE_CONF_MKOCTFILE_RANLIB%);
178 
179  vars["DEPEND_FLAGS"] = get_variable ("DEPEND_FLAGS",
180  %OCTAVE_CONF_DEPEND_FLAGS%);
181  vars["DEPEND_EXTRA_SED_PATTERN"] = get_variable ("DEPEND_EXTRA_SED_PATTERN",
182  %OCTAVE_CONF_DEPEND_EXTRA_SED_PATTERN%);
183 
184  vars["DL_LD"] = get_variable ("DL_LD", %OCTAVE_CONF_MKOCTFILE_DL_LD%);
185  vars["DL_LDFLAGS"] = get_variable ("DL_LDFLAGS",
186  %OCTAVE_CONF_MKOCTFILE_DL_LDFLAGS%);
187 
188  vars["RDYNAMIC_FLAG"] = get_variable ("RDYNAMIC_FLAG",
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%);
195  vars["FFTW3_LDFLAGS"] = get_variable ("FFTW3_LDFLAGS",
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%);
207  vars["OCT_LINK_DEPS"] = get_variable ("OCT_LINK_DEPS",
208  %OCTAVE_CONF_OCT_LINK_DEPS%);
209  vars["OCT_LINK_OPTS"] = get_variable ("OCT_LINK_OPTS",
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%);
218 
219  vars["ALL_FFLAGS"] = vars["FFLAGS"] + " " + vars["F77_INTEGER8_FLAG"];
220 
221  vars["ALL_CFLAGS"] = vars["INCFLAGS"] + " " + vars["XTRA_CFLAGS"] + " "
222  + vars["CFLAGS"];
223 
224  vars["ALL_CXXFLAGS"] = vars["INCFLAGS"] + " " + vars["XTRA_CXXFLAGS"] + " "
225  + vars["CXXFLAGS"];
226 
227  vars["ALL_LDFLAGS"] = vars["LD_STATIC_FLAG"] + " " + vars["CPICFLAG"] + " "
228  + vars["LDFLAGS"];
229 
230  vars["OCTAVE_LIBS"] = vars["LIBOCTINTERP"] + " " + vars["LIBOCTAVE"] + " "
231  + vars["SPECIAL_MATH_LIB"];
232 
233  vars["FFTW_LIBS"] = vars["FFTW3_LDFLAGS"] + " " + vars["FFTW3_LIBS"] + " "
234  + vars["FFTW3F_LDFLAGS"] + " " + vars["FFTW3F_LIBS"];
235 }
236 
237 static std::string usage_msg = "usage: mkoctfile [options] file ...";
238 static std::string version_msg = "mkoctfile, version " OCTAVE_VERSION;
239 static bool debug = false;
241 "\n"
242 "Options:\n"
243 "\n"
244 " -h, -?, --help Print this message.\n"
245 "\n"
246 " -IDIR Add -IDIR to compile commands.\n"
247 "\n"
248 " -idirafter DIR Add -idirafter DIR to compile commands.\n"
249 "\n"
250 " -DDEF Add -DDEF to compile commands.\n"
251 "\n"
252 " -lLIB Add library LIB to link command.\n"
253 "\n"
254 " -LDIR Add -LDIR to link command.\n"
255 "\n"
256 " -M, --depend Generate dependency files (.d) for C and C++\n"
257 " source files.\n"
258 #if ! defined (OCTAVE_USE_WINDOWS_API)
259 "\n"
260 " -pthread Add -pthread to link command.\n"
261 #endif
262 "\n"
263 " -RDIR Add -RDIR to link command.\n"
264 "\n"
265 " -Wl,... Pass flags though the linker like -Wl,-rpath=...\n"
266 "\n"
267 " -W... Pass flags though the compiler like -Wa,OPTION.\n"
268 "\n"
269 " -c, --compile Compile, but do not link.\n"
270 "\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"
274 "\n"
275 " -g Enable debugging options for compilers.\n"
276 "\n"
277 " -p VAR, --print VAR Print configuration variable VAR. Recognized\n"
278 " variables are:\n"
279 "\n"
280 " ALL_CFLAGS INCFLAGS\n"
281 " ALL_CXXFLAGS INCLUDEDIR\n"
282 " ALL_FFLAGS LAPACK_LIBS\n"
283 " ALL_LDFLAGS LD_CXX\n"
284 " AR LDFLAGS\n"
285 " BLAS_LIBS LD_STATIC_FLAG\n"
286 " CC LFLAGS\n"
287 " CFLAGS LIBDIR\n"
288 " CPICFLAG LIBOCTAVE\n"
289 " CPPFLAGS LIBOCTINTERP\n"
290 " CXX LIBS\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"
297 " F77 OCTLIBDIR\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"
303 " FFTW3_LIBS SED\n"
304 " FFTW_LIBS SPECIAL_MATH_LIB\n"
305 " FLIBS XTRA_CFLAGS\n"
306 " FPICFLAG XTRA_CXXFLAGS\n"
307 "\n"
308 " --link-stand-alone Link a stand-alone executable file.\n"
309 "\n"
310 " --mex Assume we are creating a MEX file. Set the\n"
311 " default output extension to \".mex\".\n"
312 "\n"
313 " -s, --strip Strip output file.\n"
314 "\n"
315 " -n, --just-print, --dry-run\n"
316 " Print commands, but do not execute them.\n"
317 "\n"
318 " -v, --verbose Echo commands as they are executed.\n"
319 "\n"
320 " FILE Compile or link FILE. Recognized file types are:\n"
321 "\n"
322 " .c C source\n"
323 " .cc C++ source\n"
324 " .cp C++ source\n"
325 " .cpp C++ source\n"
326 " .CPP C++ source\n"
327 " .cxx C++ source\n"
328 " .c++ C++ source\n"
329 " .C C++ source\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"
334 " .o object file\n"
335 " .a library file\n"
336 #if defined (_MSC_VER)
337 " .lib library file\n"
338 #endif
339 "\n";
340 
341 static std::string
342 basename (const std::string& s, bool strip_path = false)
343 {
345  size_t pos = s.rfind ('.');
346 
347  if (pos == std::string::npos)
348  retval = s;
349  else
350  retval = s.substr (0, pos);
351 
352  if (strip_path)
353  {
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);
359  }
360 
361  return retval;
362 }
363 
364 inline bool
365 starts_with (const std::string& s, const std::string& prefix)
366 {
367  return (s.length () >= prefix.length () && s.find (prefix) == 0);
368 }
369 
370 inline bool
371 ends_with (const std::string& s, const std::string& suffix)
372 {
373  return (s.length () >= suffix.length ()
374  && s.rfind (suffix) == s.length () - suffix.length ());
375 }
376 
377 static int
378 run_command (const std::string& cmd, bool printonly = false)
379 {
380  if (printonly)
381  {
382  std::cout << cmd << std::endl;
383  return 0;
384  }
385 
386  if (debug)
387  std::cout << cmd << std::endl;
388 
389  int result = system (cmd.c_str ());
390 
391  if (octave_wifexited_wrapper (result))
392  result = octave_wexitstatus_wrapper (result);
393 
394  return result;
395 }
396 
397 bool
399 {
400  return (s == "yes" || s == "true");
401 }
402 
403 int
404 main (int argc, char **argv)
405 {
406  initialize ();
407 
408  std::string file, output_option;
409  std::list<std::string> cfiles, ccfiles, f77files;
410  int result = 0;
411 
412  std::string objfiles = "";
413  std::string libfiles = "";
414  std::string octfile = "";
415  std::string outputfile = "";
416  std::string incflags = "";
417  std::string defs = "";
418  std::string ldflags = "";
419  std::string pass_on_options = "";
420  bool strip = false;
421  bool no_oct_file_strip_on_this_platform = is_true ("%NO_OCT_FILE_STRIP%");
422  bool link = true;
423  bool link_stand_alone = false;
424  std::string output_ext = ".oct";
425  bool depend = false;
426  bool printonly = false;
427 
428  if (argc == 1)
429  {
430  std::cout << usage_msg << std::endl;
431  return 1;
432  }
433 
434  if (argc == 2 && (! strcmp (argv[1], "-v")
435  || ! strcmp (argv[1], "-version")
436  || ! strcmp (argv[1], "--version")))
437  {
438  std::cout << version_msg << std::endl;
439  return 0;
440  }
441 
442  for (int i = 1; i < argc; i++)
443  {
444  std::string arg = argv[i];
445 
446  if (ends_with (arg, ".c"))
447  {
448  file = arg;
449  cfiles.push_back (file);
450  }
451  else if (ends_with (arg, ".cc") || ends_with (arg, ".cp")
452  || ends_with (arg, ".cpp") || ends_with (arg, ".CPP")
453  || ends_with (arg, ".cxx") || ends_with (arg, ".c++")
454  || ends_with (arg, ".C"))
455  {
456  file = arg;
457  ccfiles.push_back (file);
458  }
459  else if (ends_with (arg, ".f") || ends_with (arg, ".F")
460  || ends_with (arg, "f90") || ends_with (arg, ".F90"))
461  {
462  file = arg;
463  f77files.push_back (file);
464  }
465  else if (ends_with (arg, ".o") || ends_with (arg, ".obj"))
466  {
467  file = arg;
468  objfiles += (" " + quote_path (arg));
469  }
470  else if (ends_with (arg, ".lib") || ends_with (arg, ".a"))
471  {
472  file = arg;
473  libfiles += (" " + quote_path (arg));
474  }
475  else if (arg == "-d" || arg == "-debug" || arg == "--debug"
476  || arg == "-v" || arg == "-verbose" || arg == "--verbose")
477  {
478  debug = true;
479  if (vars["CC"] == "cc-msvc")
480  vars["CC"] += " -d";
481  if (vars["CXX"] == "cc-msvc")
482  vars["CXX"] += " -d";
483  if (vars["DL_LD"] == "cc-msvc")
484  vars["DL_LD"] += " -d";
485  }
486  else if (arg == "-h" || arg == "-?" || arg == "-help" || arg == "--help")
487  {
488  std::cout << usage_msg << std::endl;
489  std::cout << help_msg << std::endl;
490  return 0;
491  }
492  else if (starts_with (arg, "-I"))
493  {
494  incflags += (" " + quote_path (arg));
495  }
496  else if (arg == "-idirafter")
497  {
498  if (i < argc-1)
499  {
500  arg = argv[++i];
501  incflags += (" -idirafter " + arg);
502  }
503  else
504  std::cerr << "mkoctfile: include directory name missing"
505  << std::endl;
506  }
507  else if (starts_with (arg, "-D"))
508  {
509  defs += (" " + arg);
510  }
511  else if (arg == "-largeArrayDims" || arg == "-compatibleArrayDims")
512  {
513  std::cout << "warning: -largeArrayDims and -compatibleArrayDims are accepted for compatibility, but ignored" << std::endl;
514  }
515  else if (starts_with (arg, "-Wl,") || starts_with (arg, "-l")
516  || starts_with (arg, "-L") || starts_with (arg, "-R"))
517  {
518  ldflags += (" " + arg);
519  }
520 #if ! defined (OCTAVE_USE_WINDOWS_API)
521  else if (arg == "-pthread")
522  {
523  ldflags += (" " + arg);
524  }
525 #endif
526  else if (arg == "-M" || arg == "-depend" || arg == "--depend")
527  {
528  depend = true;
529  }
530  else if (arg == "-o" || arg == "-output" || arg == "--output")
531  {
532  if (i < argc-1)
533  {
534  arg = argv[++i];
535  outputfile = arg;
536  }
537  else
538  std::cerr << "mkoctfile: output filename missing" << std::endl;
539  }
540  else if (arg == "-n" || arg == "--dry-run" || arg == "--just-print")
541  {
542  printonly = true;
543  }
544  else if (arg == "-p" || arg == "-print" || arg == "--print")
545  {
546  if (i < argc-1)
547  {
548  arg = argv[++i];
549  std::cout << vars[arg] << std::endl;
550  return 0;
551  }
552  else
553  std::cerr << "mkoctfile: --print requires argument" << std::endl;
554  }
555  else if (arg == "-s" || arg == "-strip" || arg == "--strip")
556  {
557  if (no_oct_file_strip_on_this_platform)
558  std::cerr << "mkoctfile: stripping disabled on this platform"
559  << std::endl;
560  else
561  strip = true;
562  }
563  else if (arg == "-c" || arg == "-compile" || arg == "--compile")
564  {
565  link = false;
566  }
567  else if (arg == "-g")
568  {
569  vars["ALL_CFLAGS"] += " -g";
570  vars["ALL_CXXFLAGS"] += " -g";
571  vars["ALL_FFLAGS"] += " -g";
572  }
573  else if (arg == "-link-stand-alone" || arg == "--link-stand-alone")
574  {
575  link_stand_alone = true;
576  }
577  else if (arg == "-mex" || arg == "--mex")
578  {
579  incflags += " -I.";
580 #if defined (_MSC_VER)
581  ldflags += " -Wl,-export:mexFunction";
582 #endif
583  output_ext = ".mex";
584  }
585  else if (starts_with (arg, "-W"))
586  {
587  pass_on_options += (" " + arg);
588  }
589  else if (starts_with (arg, "-"))
590  {
591  // Pass through any unrecognized options
592  pass_on_options += (" " + arg);
593  }
594  else
595  {
596  std::cerr << "mkoctfile: unrecognized argument " << arg << std::endl;
597  return 1;
598  }
599 
600  if (! file.empty () && octfile.empty ())
601  octfile = file;
602  }
603 
604  if (output_ext == ".mex"
605  && vars["ALL_CFLAGS"].find ("-g") != std::string::npos)
606  {
607  defs += " -DMEX_DEBUG";
608  }
609 
610  if (link_stand_alone)
611  {
612  if (! outputfile.empty ())
613  output_option = "-o " + outputfile;
614  }
615  else
616  {
617  if (! outputfile.empty ())
618  {
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;
624  }
625  else
626  octfile = basename (octfile, true) + output_ext;
627  }
628 
629  std::list<std::string>::const_iterator it;
630 
631  if (depend)
632  {
633  for (it = cfiles.begin (); it != cfiles.end (); ++it)
634  {
635  std::string f = *it, dfile = basename (f, true) + ".d", line;
636 
637  octave_unlink_wrapper (dfile.c_str ());
638  std::string cmd = vars["CC"] + " "
639  + vars["DEPEND_FLAGS"] + " "
640  + vars["CPPFLAGS"] + " "
641  + vars["ALL_CFLAGS"] + " "
642  + incflags + " " + defs + " " + quote_path (f);
643 
644  FILE *fd = popen (cmd.c_str (), "r");
645  std::ofstream fo (dfile.c_str ());
646  size_t pos;
647  while (! feof (fd))
648  {
649  line = get_line (fd);
650  if ((pos = line.rfind (".o:")) != std::string::npos)
651  {
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;
659  }
660  else
661  fo << line << std::endl;
662  }
663  pclose (fd);
664  fo.close ();
665  }
666 
667  for (it = ccfiles.begin (); it != ccfiles.end (); ++it)
668  {
669  std::string f = *it, dfile = basename (f, true) + ".d", line;
670 
671  octave_unlink_wrapper (dfile.c_str ());
672  std::string cmd = vars["CXX"] + " "
673  + vars["DEPEND_FLAGS"] + " "
674  + vars["CPPFLAGS"] + " "
675  + vars["ALL_CXXFLAGS"] + " "
676  + incflags + " " + defs + " " + quote_path (f);
677 
678  FILE *fd = popen (cmd.c_str (), "r");
679  std::ofstream fo (dfile.c_str ());
680  size_t pos;
681  while (! feof (fd))
682  {
683  line = get_line (fd);
684  if ((pos = line.rfind (".o:")) != std::string::npos)
685  {
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;
693  }
694  else
695  fo << line << std::endl;
696  }
697  pclose (fd);
698  fo.close ();
699  }
700 
701  return 0;
702  }
703 
704  for (it = f77files.begin (); it != f77files.end () && ! result; ++it)
705  {
706  std::string f = *it, b = basename (f, true);
707  if (! vars["F77"].empty ())
708  {
709  std::string o;
710  if (! outputfile.empty ())
711  {
712  if (link)
713  o = b + ".o";
714  else
715  o = outputfile;
716  }
717  else
718  o = b + ".o";
719  objfiles += (" " + o);
720  std::string cmd = vars["F77"] + " -c "
721  + vars["FPICFLAG"] + " "
722  + vars["ALL_FFLAGS"] + " "
723  + incflags + " " + defs + " " + pass_on_options
724  + " " + f + " -o " + o;
725  result = run_command (cmd, printonly);
726  }
727  else
728  {
729  std::cerr << "mkoctfile: no way to compile Fortran file " << f
730  << std::endl;
731  return 1;
732  }
733  }
734 
735  for (it = cfiles.begin (); it != cfiles.end () && ! result; ++it)
736  {
737  std::string f = *it;
738  if (! vars["CC"].empty ())
739  {
740  std::string b = basename (f, true), o;
741  if (! outputfile.empty ())
742  {
743  if (link)
744  o = b + ".o";
745  else
746  o = outputfile;
747  }
748  else
749  o = b + ".o";
750  objfiles += (" " + o);
751  std::string cmd = vars["CC"] + " -c "
752  + vars["CPPFLAGS"] + " "
753  + vars["CPICFLAG"] + " " + vars["ALL_CFLAGS"] + " "
754  + pass_on_options + " "
755  + incflags + " " + defs + " "
756  + quote_path (f) + " -o " + quote_path (o);
757  result = run_command (cmd, printonly);
758  }
759  else
760  {
761  std::cerr << "mkoctfile: no way to compile C file " << f
762  << std::endl;
763  return 1;
764  }
765  }
766 
767  for (it = ccfiles.begin (); it != ccfiles.end () && ! result; ++it)
768  {
769  std::string f = *it;
770  if (! vars["CXX"].empty ())
771  {
772  std::string b = basename (f, true), o;
773  if (! outputfile.empty ())
774  {
775  if (link)
776  o = b + ".o";
777  else
778  o = outputfile;
779  }
780  else
781  o = b + ".o";
782  objfiles += (" " + o);
783  std::string cmd = vars["CXX"] + " -c "
784  + vars["CPPFLAGS"] + " "
785  + vars["CXXPICFLAG"] + " "
786  + vars["ALL_CXXFLAGS"] + " "
787  + pass_on_options + " "
788  + incflags + " " + defs + " "
789  + quote_path (f) + " -o " + quote_path (o);
790  result = run_command (cmd, printonly);
791  }
792  else
793  {
794  std::cerr << "mkoctfile: no way to compile C++ file " << f
795  << std::endl;
796  return 1;
797  }
798  }
799 
800  if (link && ! objfiles.empty () && ! result)
801  {
802  if (link_stand_alone)
803  {
804  if (! vars["LD_CXX"].empty ())
805  {
806  std::string cmd = vars["LD_CXX"] + " "
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"];
817  result = run_command (cmd, printonly);
818  }
819  else
820  {
821  std::cerr
822  << "mkoctfile: no way to link stand-alone executable file"
823  << std::endl;
824  return 1;
825  }
826  }
827  else
828  {
829  std::string cmd = vars["DL_LD"] + " "
830  + vars["ALL_CXXFLAGS"] + " "
831  + vars["DL_LDFLAGS"] + " "
832  + pass_on_options
833  + " -o " + octfile + " "
834  + objfiles + " " + libfiles + " "
835  + ldflags + " "
836  + vars["LFLAGS"] + " -loctinterp -loctave "
837  + vars["OCT_LINK_OPTS"] + " "
838  + vars["OCT_LINK_DEPS"];
839  result = run_command (cmd, printonly);
840  }
841 
842  if (strip)
843  {
844  std::string cmd = "strip " + octfile;
845  result = run_command (cmd, printonly);
846  }
847  }
848 
849  return result;
850 }
static std::string get_octave_home(void)
Definition: shared-fcns.h:87
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:120
static std::string usage_msg
bool octave_wifexited_wrapper(int status)
Definition: wait-wrappers.c:85
static std::string help_msg
static std::string subst_octave_home(const std::string &s)
Definition: shared-fcns.h:100
int unlink(const std::string &name)
Definition: file-ops.cc:648
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
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
int argc
Definition: load-save.cc:633
static std::map< std::string, std::string > vars
Definition: mkoctfile.in.cc:47
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)
s
Definition: file-io.cc:2682
bool ends_with(const std::string &s, const std::string &suffix)
int main(int argc, char **argv)
octave_value arg
Definition: pr-output.cc:3440
string_vector argv
Definition: load-save.cc:635
static bool debug
static void initialize(void)
static octave_idx_type link(octave_idx_type s, octave_idx_type t, octave_idx_type *pp)
Definition: colamd.cc:105
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
Definition: ov-struct.cc:1688
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:941
int octave_unlink_wrapper(const char *nm)
bool strcmp(const T &str_a, const T &str_b)
True if strings are the same.
Definition: oct-string.cc:112
#define OCTAVE_VERSION
Definition: mkoctfile.in.cc:50
octave_value retval
Definition: data.cc:6294
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
Definition: lu.cc:138
int octave_wexitstatus_wrapper(int status)
With real return the complex result
Definition: data.cc:3375
static octave_idx_type find(octave_idx_type i, octave_idx_type *pp)
Definition: colamd.cc:112
#define OCTAVE_PREFIX
Definition: mkoctfile.in.cc:54
charNDArray max(char d, const charNDArray &m)
Definition: chNDArray.cc:228
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
Definition: lookup.cc:239
b
Definition: cellfun.cc:398
static std::string get_variable(const char *name, const std::string &defval)
static std::string get_line(FILE *fp)
Definition: mkoctfile.in.cc:82
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
Definition: utils.cc:854
static std::string quote_path(const std::string &s)