Skip to content

Commit 1ad73dd

Browse files
committed
find_fortran: check exists before test
1 parent 7298e91 commit 1ad73dd

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

+stdlib/+sys/find_fortran_compiler.m

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@
1616
end
1717

1818
% stops upon finding first working Fortran compiler
19-
FCs = ["gfortran", "ifx", "ifort", "flang", "nvfortran", "nagfor", ...
20-
"ftn", ... % Cray
21-
"xlf2008", ... % IBM XL
22-
"f95", ... % Absoft
23-
];
19+
FCs = ["gfortran", "ifx", "flang", "nvfortran", "nagfor", "ftn"];
2420

2521
if strlength(FC) > 0
2622
FCs = [FC, FCs];
@@ -30,14 +26,21 @@
3026
fn = fstem + ".f90";
3127
rfn = fstem + ".exe";
3228

33-
prog = 'use iso_fortran_env; print *,compiler_version(); end program';
29+
prog = 'program; use iso_fortran_env; print *,compiler_version(); end program';
3430
fid = fopen(fn, 'wt');
3531
fprintf(fid, '%s\n', prog);
3632
fclose(fid);
3733

38-
for fc = FCs
34+
for f = FCs
35+
fc = stdlib.fileio.which(f);
36+
if isempty(fc)
37+
continue
38+
end
39+
3940
[stat, ~] = system(fc + " " + fn + " -o" + rfn); % gobble error messages
40-
if stat ~= 0, continue, end
41+
if stat ~= 0
42+
continue
43+
end
4144

4245
[stat, msg] = system(rfn);
4346
if stat == 0
@@ -46,6 +49,8 @@
4649
end
4750
end
4851

49-
if stat ~= 0, fc = string.empty; end
52+
if ~isempty(fc) && stat ~= 0
53+
fc = string.empty;
54+
end
5055

5156
end

0 commit comments

Comments
 (0)