Skip to content

Commit 4f71ac9

Browse files
committed
buildtool: functionalize
1 parent 80868e6 commit 4f71ac9

File tree

1 file changed

+44
-49
lines changed

1 file changed

+44
-49
lines changed

buildfile.m

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -99,27 +99,12 @@ function publishTask(context)
9999
function subprocess_build_c(context)
100100

101101
td = context.Plan.RootFolder + "/test";
102-
src_c = td + "/main.c";
102+
src = td + "/main.c";
103103
exe = td + "/printer_c.exe";
104104

105-
ccObj = mex.getCompilerConfigurations('c');
106-
107-
cc = ccObj.Details.CompilerExecutable;
108-
109-
outFlag = "-o";
110-
shell = "";
111-
shell_arg = "";
112-
msvcLike = ispc && endsWith(cc, "cl");
113-
if msvcLike
114-
shell = strtrim(ccObj.Details.CommandLineShell);
115-
shell_arg = ccObj.Details.CommandLineShellArg;
116-
outFlag = "/link /out:";
117-
end
118-
119-
cmd = join([cc, src_c, outFlag, exe]);
120-
if shell ~= ""
121-
cmd = join([shell, shell_arg, cmd]);
122-
end
105+
cmd = get_build_cmd("c", src);
106+
if isempty(cmd), return, end
107+
cmd = join([cmd, exe]);
123108

124109
[r, m] = system(cmd);
125110
if r ~= 0
@@ -135,24 +120,9 @@ function subprocess_build_cpp(context)
135120
src = td + "/sleep.cpp";
136121
exe = td + "/sleep.exe";
137122

138-
co = mex.getCompilerConfigurations('c++');
139-
140-
cpp = co.Details.CompilerExecutable;
141-
142-
outFlag = "-o";
143-
shell = "";
144-
shell_arg = "";
145-
msvcLike = ispc && endsWith(cpp, "cl");
146-
if msvcLike
147-
shell = strtrim(co.Details.CommandLineShell);
148-
shell_arg = co.Details.CommandLineShellArg;
149-
outFlag = "/link /out:";
150-
end
151-
152-
cmd = join([cpp, src, outFlag, exe]);
153-
if shell ~= ""
154-
cmd = join([shell, shell_arg, cmd]);
155-
end
123+
cmd = get_build_cmd("c++", src);
124+
if isempty(cmd), return, end
125+
cmd = join([cmd, exe]);
156126

157127
[r, m] = system(cmd);
158128
if r ~= 0
@@ -168,24 +138,49 @@ function subprocess_build_fortran(context)
168138
src = td + "/main.f90";
169139
exe = td + "/printer_fortran.exe";
170140

171-
fcObj = mex.getCompilerConfigurations('Fortran');
172-
if isempty(fcObj)
173-
fc = getenv("FC");
174-
if isempty(fc)
175-
warning("set FC environment variable to the Fortran compiler executable, or do 'mex -setup fortran' to configure the Fortran compiler")
176-
return
141+
cmd = get_build_cmd("Fortran", src);
142+
if isempty(cmd), return, end
143+
cmd = join([cmd, exe]);
144+
145+
[r, m] = system(cmd);
146+
if r ~= 0
147+
warning("failed to build TestSubprocess " + exe + " " + m)
148+
end
149+
150+
end
151+
152+
153+
function cmd = get_build_cmd(lang, src)
154+
155+
cmd = string.empty;
156+
157+
co = mex.getCompilerConfigurations(lang);
158+
if isempty(co)
159+
if lang == "Fortran"
160+
fc = getenv("FC");
161+
if isempty(fc)
162+
warning("set FC environment variable to the Fortran compiler executable, or do 'mex -setup fortran' to configure the Fortran compiler")
163+
end
177164
end
165+
warning(lang + " compiler not found")
166+
return
178167
else
179-
fc = fcObj.Details.CompilerExecutable;
168+
comp = co.Details.CompilerExecutable;
180169
end
181170

182171
outFlag = "-o";
172+
shell = "";
173+
shell_arg = "";
174+
msvcLike = ispc && endsWith(comp, "cl");
175+
if msvcLike
176+
shell = strtrim(co.Details.CommandLineShell);
177+
shell_arg = co.Details.CommandLineShellArg;
178+
outFlag = "/link /out:";
179+
end
183180

184-
cmd = join([fc, src, outFlag, exe]);
185-
186-
[r, m] = system(cmd);
187-
if r ~= 0
188-
warning("failed to build TestSubprocess printer_fortran.exe " + m)
181+
cmd = join([comp, src, outFlag]);
182+
if shell ~= ""
183+
cmd = join([shell, shell_arg, cmd]);
189184
end
190185

191186
end

0 commit comments

Comments
 (0)