@@ -131,16 +131,17 @@ function compile(solvers, mexdir, fortd, gateways, options)
131131
132132% Finally, set `compiler_options` so that `extra_compiler_options` is appended to the compiler flags
133133% when MEX is called with `compiler_options`. See Append Compiler Options in
134- % https://www.mathworks.com/help/matlab/ref/mex.html
134+ % https://www.mathworks.com/help/matlab/ref/mex.html , particularly for what `flags_name` should be.
135135% N.B.: on Windows with MinGW, the compiler is gfortran, and the option should be passed via
136- % FCFLAGS rather than COMPFLAGS.
136+ % FCFLAGS rather than COMPFLAGS. This seems to be undocumented.
137137if ispc && contains(compiler_manufacturer , ' intel' ) % on Windows with Microsoft Visual Studio compilers
138- compiler_options = [ ' COMPFLAGS="$COMPFLAGS ' , extra_compiler_options , ' " ' ] ;
138+ flags_name = ' COMPFLAGS' ;
139139elseif ispc && contains(compiler_manufacturer , ' gnu' ) % on Windows with MinGW
140- compiler_options = [ ' FCFLAGS="$FCFLAGS ' , extra_compiler_options , ' " ' ] ;
140+ flags_name = ' FCFLAGS' ;
141141else % with MinGW (on Windows), macOS, and Linux compilers
142- compiler_options = [ ' FFLAGS="$FFLAGS ' , extra_compiler_options , ' " ' ] ;
142+ flags_name = ' FFLAGS' ;
143143end
144+ compiler_options = append_flags(flags_name , extra_compiler_options );
144145
145146% Zaikun 20240216: The following is a workaround for https://github.com/libprima/prima/issues/161,
146147% where MEX fails due to incompatibility between the new linker of Xcode 15 on macOS and Intel oneAPI 2023.
@@ -150,7 +151,7 @@ function compile(solvers, mexdir, fortd, gateways, options)
150151% the latter is suggested at https://www.mathworks.com/help/matlab/ref/mex.html.
151152linker_options = ' ' ;
152153if ismac && contains(compiler_manufacturer , ' intel' ) % macOS with Intel compiler
153- linker_options = ' LDFLAGSVER="$LDFLAGSVER -undefined dynamic_lookup" ' ;
154+ linker_options = append_flags( ' LDFLAGSVER' , ' -undefined dynamic_lookup' ) ;
154155end
155156
156157% MEX options shared by all compiling processes below.
@@ -411,3 +412,12 @@ function prepare_work_dir(directory)
411412modo_files = [list_mod_files(dir_name ), list_obj_files(dir_name )];
412413
413414return
415+
416+
417+ function flags = append_flags(flags_name , extra_flags )
418+ % APPEND_FLAGS returns a string that can be passed to MEX to append `extra_flags` to the existing
419+ % flags specified by `flags_name`.
420+
421+ flags = [flags_name , ' ="$' , flags_name , ' ' , extra_flags , ' "' ];
422+
423+ return
0 commit comments