Skip to content

Commit dddac9f

Browse files
committed
buildfile: try harder to find non-Mex fortran compiler
1 parent 88df116 commit dddac9f

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

buildfile.m

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,7 @@ function build_exe(context)
143143
case "fortran"
144144
comp = getenv("FC");
145145
if isempty(comp)
146-
disp("set FC environment variable to the Fortran compiler path, or do 'mex -setup fortran'")
147-
if ismac()
148-
p = '/opt/homebrew/bin/';
149-
for fc = ["flang", "gfortran"]
150-
comp = stdlib.which(fc, p);
151-
if ~isempty(comp)
152-
% disp(lang + " compiler: " + comp)
153-
setenv("FC", comp);
154-
return
155-
end
156-
end
157-
disp("on macOS, environment variables propagate in to GUI programs like Matlab by using 'launchctl setenv FC' and a reboot. Or by using 'FC=gfortran matlab -batch buildtool exe'")
158-
end
146+
comp = get_fortran_compiler();
159147
end
160148
case "c++"
161149
comp = getenv("CXX");
@@ -174,7 +162,6 @@ function build_exe(context)
174162
% disp(lang + " compiler: " + co.ShortName + " " + co.Name + " " + co.Version + " " + comp)
175163
end
176164

177-
178165
shell = string.empty;
179166
if ispc() && ~isempty(co)
180167
disp("Shell: " + co.Details.CommandLineShell)
@@ -298,3 +285,28 @@ function build_exe(context)
298285
end
299286

300287
end
288+
289+
290+
function comp = get_fortran_compiler()
291+
292+
disp("set FC environment variable to the Fortran compiler path, or do 'mex -setup fortran'")
293+
294+
if ismac()
295+
p = '/opt/homebrew/bin/';
296+
disp("on macOS, environment variables propagate in to GUI programs like Matlab by using 'launchctl setenv FC' and a reboot.")
297+
disp("if having trouble, try:")
298+
disp(" FC=gfortran matlab -batch 'buildtool exe'")
299+
else
300+
p = '';
301+
end
302+
303+
for fc = ["flang", "gfortran", "ifx"]
304+
comp = stdlib.which(fc, p);
305+
if ~isempty(comp)
306+
% disp(lang + " compiler: " + comp)
307+
setenv("FC", comp);
308+
return
309+
end
310+
end
311+
312+
end

0 commit comments

Comments
 (0)