comparison src/mkoctfile.in.cc @ 28124:5b37e5e03bb5

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.
author John W. Eaton <jwe@octave.org>
date Tue, 18 Feb 2020 12:45:45 -0500
parents cf59b503db2a
children 7818c5b07403
comparison
equal deleted inserted replaced
28123:4963f23b145c 28124:5b37e5e03bb5
599 599
600 return tempd; 600 return tempd;
601 } 601 }
602 602
603 static std::string 603 static std::string
604 create_interleaved_complex_file (void)
605 {
606 std::string tmpl = get_temp_directory () + "/oct-XXXXXX.c";
607
608 char *ctmpl = new char [tmpl.length () + 1];
609
610 ctmpl = strcpy (ctmpl, tmpl.c_str ());
611
612 // mkostemps will open the file and return a file descriptor. We
613 // won't worry about closing it because we will need the file until we
614 // are done and then the file will be closed when mkoctfile exits.
615 int fd = octave_mkostemps_wrapper (ctmpl, 2);
616
617 // Make C++ string from filled-in template.
618 std::string retval (ctmpl);
619 delete [] ctmpl;
620
621 // Write symbol definition to file.
622 FILE *fid = fdopen (fd, "w");
623 fputs ("const int __mx_has_interleaved_complex__ = 1;\n", fid);
624 fclose (fid);
625
626 return retval;
627 }
628
629 static std::string
604 tmp_objfile_name (void) 630 tmp_objfile_name (void)
605 { 631 {
606 std::string tmpl = get_temp_directory () + "/oct-XXXXXX.o"; 632 std::string tmpl = get_temp_directory () + "/oct-XXXXXX.o";
607 633
608 char *ctmpl = new char [tmpl.length () + 1]; 634 char *ctmpl = new char [tmpl.length () + 1];
655 bool compile_only = false; 681 bool compile_only = false;
656 bool link_stand_alone = false; 682 bool link_stand_alone = false;
657 bool depend = false; 683 bool depend = false;
658 bool printonly = false; 684 bool printonly = false;
659 bool output_file_option = false; 685 bool output_file_option = false;
686 bool creating_mex_file = false;
687 bool r2017b_option = false;
688 bool r2018a_option = false;
689 // The default for this may change in the future.
690 bool mx_has_interleaved_complex = false;
660 691
661 for (int i = 1; i < argc; i++) 692 for (int i = 1; i < argc; i++)
662 { 693 {
663 std::string arg = argv[i]; 694 std::string arg = argv[i];
664 695
735 } 766 }
736 else if (arg == "-largeArrayDims" || arg == "-compatibleArrayDims") 767 else if (arg == "-largeArrayDims" || arg == "-compatibleArrayDims")
737 { 768 {
738 std::cerr << "warning: -largeArrayDims and -compatibleArrayDims are accepted for compatibility, but ignored" << std::endl; 769 std::cerr << "warning: -largeArrayDims and -compatibleArrayDims are accepted for compatibility, but ignored" << std::endl;
739 } 770 }
771 else if (arg == "-R2017b")
772 {
773 if (r2018a_option)
774 {
775 std::cerr << "mkoctfile: only one of -R2017b and -R2018a may be used" << std::endl;
776 return 1;
777 }
778
779 r2017b_option = true;
780 }
781 else if (arg == "-R2018a")
782 {
783 if (r2017b_option)
784 {
785 std::cerr << "mkoctfile: only one of -R2017b and -R2018a may be used" << std::endl;
786 return 1;
787 }
788
789 r2018a_option = true;
790 mx_has_interleaved_complex = true;
791 }
740 else if (starts_with (arg, "-Wl,") || starts_with (arg, "-l") 792 else if (starts_with (arg, "-Wl,") || starts_with (arg, "-l")
741 || starts_with (arg, "-L") || starts_with (arg, "-R")) 793 || starts_with (arg, "-L") || starts_with (arg, "-R"))
742 { 794 {
743 ldflags += (' ' + arg); 795 ldflags += (' ' + arg);
744 } 796 }
805 { 857 {
806 link_stand_alone = true; 858 link_stand_alone = true;
807 } 859 }
808 else if (arg == "-mex" || arg == "--mex") 860 else if (arg == "-mex" || arg == "--mex")
809 { 861 {
862 creating_mex_file = true;
863
810 incflags += " -I."; 864 incflags += " -I.";
811 #if defined (_MSC_VER) 865 #if defined (_MSC_VER)
812 ldflags += " -Wl,-export:mexFunction"; 866 ldflags += " -Wl,-export:mexFunction";
813 #endif 867 #endif
814 output_ext = ".mex"; 868 output_ext = ".mex";
845 899
846 if (! file.empty () && octfile.empty ()) 900 if (! file.empty () && octfile.empty ())
847 octfile = file; 901 octfile = file;
848 } 902 }
849 903
850 if (output_ext == ".mex" 904 if (creating_mex_file)
851 && vars["ALL_CFLAGS"].find ("-g") != std::string::npos) 905 {
852 { 906 if (vars["ALL_CFLAGS"].find ("-g") != std::string::npos)
853 defs += " -DMEX_DEBUG"; 907 defs += " -DMEX_DEBUG";
908
909 if (mx_has_interleaved_complex)
910 {
911 defs += " -DMX_HAS_INTERLEAVED_COMPLEX=1";
912
913 if (! compile_only)
914 {
915 // Create tmp C source file that defines an extern symbol
916 // that can be checked when loading the mex file to
917 // determine that the file was compiled expecting
918 // interleaved complex values.
919
920 std::string tmp_file = create_interleaved_complex_file ();
921
922 cfiles.push_back (tmp_file);
923 }
924 }
925 }
926 else
927 {
928 if (r2017b_option)
929 std::cerr << "warning: -R2017b option ignored unless creating mex file"
930 << std::endl;
931
932 if (r2018a_option)
933 std::cerr << "warning: -R2018a option ignored unless creating mex file"
934 << std::endl;
854 } 935 }
855 936
856 if (compile_only && output_file_option 937 if (compile_only && output_file_option
857 && (cfiles.size () + ccfiles.size () + f77files.size ()) > 1) 938 && (cfiles.size () + ccfiles.size () + f77files.size ()) > 1)
858 { 939 {