Skip to content

Commit 03a658f

Browse files
committed
exe: feedback if fail, improve Windows compiler find hint and shell
this helps with MinGW on Windows in particular
1 parent d9330e7 commit 03a658f

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

buildfile.m

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ function build_exe(context)
199199
end
200200

201201
disp(cmd)
202-
system(cmd);
202+
[s, msg] = system(cmd);
203+
assert(s == 0, "Error %d: %s", s, msg)
203204
end
204205

205206
end
@@ -236,10 +237,18 @@ function build_exe(context)
236237
end
237238

238239
shell = string.empty;
239-
if ispc() && ~isempty(co)
240-
if startsWith(co.ShortName, ["INTEL", "MSVC"])
241-
shell = join([strcat('"',string(co.Details.CommandLineShell),'"'), ...
242-
co.Details.CommandLineShellArg], " ");
240+
if ispc()
241+
if isempty(co)
242+
if lang == "fortran" && contains(comp, "gfortran")
243+
shell = "set PATH=" + fileparts(comp) + pathsep + "%PATH%";
244+
end
245+
else
246+
if startsWith(co.ShortName, ["INTEL", "MSVC"])
247+
shell = join([strcat('"',string(co.Details.CommandLineShell),'"'), ...
248+
co.Details.CommandLineShellArg], " ");
249+
elseif co.ShortName == "mingw64-gfortran"
250+
shell = "set PATH=" + fileparts(comp) + pathsep + "%PATH%";
251+
end
243252
end
244253
end
245254

@@ -250,10 +259,10 @@ function build_exe(context)
250259

251260
[comp, shell] = get_compiler(lang);
252261

253-
if isempty(shell)
254-
outFlag = "-o";
255-
else
262+
if contains(shell, "Visual Studio")
256263
outFlag = "/Fo" + tempdir + " /link /out:";
264+
else
265+
outFlag = "-o";
257266
end
258267

259268

@@ -357,6 +366,14 @@ function build_exe(context)
357366
disp("on macOS, environment variables propagate in to GUI programs like Matlab by using 'launchctl setenv FC' and a reboot.")
358367
disp("if having trouble, try:")
359368
disp(" FC=gfortran matlab -batch 'buildtool exe'")
369+
elseif ispc()
370+
p = getenv('CMPLR_ROOT');
371+
if isempty(p)
372+
p = getenv("MW_MINGW64_LOC");
373+
end
374+
if ~isempty(p) && ~endsWith(p, ["bin", "bin/"])
375+
p = p + "/bin";
376+
end
360377
else
361378
p = '';
362379
end

0 commit comments

Comments
 (0)