# HG changeset patch # User John W. Eaton # Date 1582047945 18000 # Node ID 5b37e5e03bb5996037e79b0ba18bbb7cf74b5130 # Parent 4963f23b145cb6f64620ed65c8544457b55f6c56 mkoctfile.cc: accept -R2017b and -R2018a mex options * mkoctfile.cc (create_interleaved_complex_file): New function. If creating mex file with the -R2018a option, create temporary source file to hold symbol that will be used to identify the file as expecting interleaved complex data. (main): Accept -R2017b and -R2018a options. If creating mex file and have interleaved complex data, call create_interleaved_complex file and add the file name to the list of cfiles to compile. diff -r 4963f23b145c -r 5b37e5e03bb5 src/mkoctfile.in.cc --- a/src/mkoctfile.in.cc Tue Feb 18 12:34:04 2020 -0500 +++ b/src/mkoctfile.in.cc Tue Feb 18 12:45:45 2020 -0500 @@ -601,6 +601,32 @@ } static std::string +create_interleaved_complex_file (void) +{ + std::string tmpl = get_temp_directory () + "/oct-XXXXXX.c"; + + char *ctmpl = new char [tmpl.length () + 1]; + + ctmpl = strcpy (ctmpl, tmpl.c_str ()); + + // mkostemps will open the file and return a file descriptor. We + // won't worry about closing it because we will need the file until we + // are done and then the file will be closed when mkoctfile exits. + int fd = octave_mkostemps_wrapper (ctmpl, 2); + + // Make C++ string from filled-in template. + std::string retval (ctmpl); + delete [] ctmpl; + + // Write symbol definition to file. + FILE *fid = fdopen (fd, "w"); + fputs ("const int __mx_has_interleaved_complex__ = 1;\n", fid); + fclose (fid); + + return retval; +} + +static std::string tmp_objfile_name (void) { std::string tmpl = get_temp_directory () + "/oct-XXXXXX.o"; @@ -657,6 +683,11 @@ bool depend = false; bool printonly = false; bool output_file_option = false; + bool creating_mex_file = false; + bool r2017b_option = false; + bool r2018a_option = false; + // The default for this may change in the future. + bool mx_has_interleaved_complex = false; for (int i = 1; i < argc; i++) { @@ -737,6 +768,27 @@ { std::cerr << "warning: -largeArrayDims and -compatibleArrayDims are accepted for compatibility, but ignored" << std::endl; } + else if (arg == "-R2017b") + { + if (r2018a_option) + { + std::cerr << "mkoctfile: only one of -R2017b and -R2018a may be used" << std::endl; + return 1; + } + + r2017b_option = true; + } + else if (arg == "-R2018a") + { + if (r2017b_option) + { + std::cerr << "mkoctfile: only one of -R2017b and -R2018a may be used" << std::endl; + return 1; + } + + r2018a_option = true; + mx_has_interleaved_complex = true; + } else if (starts_with (arg, "-Wl,") || starts_with (arg, "-l") || starts_with (arg, "-L") || starts_with (arg, "-R")) { @@ -807,6 +859,8 @@ } else if (arg == "-mex" || arg == "--mex") { + creating_mex_file = true; + incflags += " -I."; #if defined (_MSC_VER) ldflags += " -Wl,-export:mexFunction"; @@ -847,10 +901,37 @@ octfile = file; } - if (output_ext == ".mex" - && vars["ALL_CFLAGS"].find ("-g") != std::string::npos) + if (creating_mex_file) { - defs += " -DMEX_DEBUG"; + if (vars["ALL_CFLAGS"].find ("-g") != std::string::npos) + defs += " -DMEX_DEBUG"; + + if (mx_has_interleaved_complex) + { + defs += " -DMX_HAS_INTERLEAVED_COMPLEX=1"; + + if (! compile_only) + { + // Create tmp C source file that defines an extern symbol + // that can be checked when loading the mex file to + // determine that the file was compiled expecting + // interleaved complex values. + + std::string tmp_file = create_interleaved_complex_file (); + + cfiles.push_back (tmp_file); + } + } + } + else + { + if (r2017b_option) + std::cerr << "warning: -R2017b option ignored unless creating mex file" + << std::endl; + + if (r2018a_option) + std::cerr << "warning: -R2018a option ignored unless creating mex file" + << std::endl; } if (compile_only && output_file_option