Skip to content

Commit 71c67cc

Browse files
committed
consolidate mex build code
1 parent d7b91ff commit 71c67cc

File tree

7 files changed

+52
-68
lines changed

7 files changed

+52
-68
lines changed

+stdlib/is_admin.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%% IS_ADMIN is the process run as root / admin (requires MEX)
22

33
function is_admin()
4-
error("need to 'buildtool mex' or 'legacy_mex_build()' first")
4+
error("buildtool mex")
55
end

+stdlib/is_char_device.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
if stdlib.isoctave()
1111
ok = S_ISCHR(stat(p).mode);
1212
else
13-
error("need to 'buildtool mex' or 'legacy_mex_build()' first")
13+
error("buildtool mex")
1414
end
1515

1616
end

+stdlib/set_permissions.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
% This function is written in C++ using STL <filesystem> and is only available in Matlab.
1212

1313
function set_permissions(~, ~, ~, ~)
14-
error("need to 'buildtool mex' or 'legacy_mex_build()' first")
14+
error("buildtool mex")
1515
end

Readme.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@ functions from the Matlab prompt:
3333
buildtool mex
3434
```
3535

36-
For Matlab R2022a and older, instead do: `legacy_mex_build()`
37-
3836
If just building MEX functions for the first time, to ensure the MEX functions are used instead of the plain Matlab script, one-time do a `clear all` in Matlab.
3937

40-
4138
## Java-based functions
4239

4340
Most Matlab-stdlib filesystem functions work without the

buildfile.m

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,15 @@
2020

2121
plan("publish") = matlab.buildtool.Task(Description="HTML inline doc generate", Actions=@publishTask);
2222

23-
23+
bindir = fullfile(plan.RootFolder, pkg_name);
2424
if isMATLABReleaseOlderThan("R2024b")
25-
plan("mex") = matlab.buildtool.Task(Actions=@legacyMexTask);
25+
plan("mex") = matlab.buildtool.Task(Actions=@(context)legacyMexTask(context, bindir));
2626
else
2727
plan("clean") = matlab.buildtool.tasks.CleanTask;
2828

2929
[compiler_id, compiler_opt] = get_compiler_options();
3030

31-
srcs = get_mex_sources(plan.RootFolder);
32-
33-
bindir = fullfile(plan.RootFolder, pkg_name);
34-
35-
for s = srcs
31+
for s = get_mex_sources()
3632
src = s{1};
3733
[~, name] = fileparts(src(1));
3834

@@ -46,8 +42,20 @@
4642
end
4743

4844

49-
function legacyMexTask(context)
50-
legacy_mex_build(context.Plan.RootFolder, fullfile(context.Plan.RootFolder, "+stdlib"))
45+
function legacyMexTask(context, bindir)
46+
47+
[compiler_id, compiler_opt] = get_compiler_options();
48+
49+
srcs = get_mex_sources(context.Plan.RootFolder);
50+
51+
%% build C++ mex
52+
% https://www.mathworks.com/help/matlab/ref/mex.html
53+
for s = srcs
54+
src = s{1};
55+
[~, name] = fileparts(src(1));
56+
disp("Building MEX target: " + name)
57+
mex(s{1}{:}, "-outdir", bindir, compiler_id, compiler_opt)
58+
end
5159
end
5260

5361

@@ -68,3 +76,35 @@ function publishTask(context)
6876
"https://github.com/geospace-code/matlab-stdlib", ...
6977
outdir)
7078
end
79+
80+
81+
function srcs = get_mex_sources()
82+
83+
limits = "src/limits_fs.cpp";
84+
85+
win = limits;
86+
if ispc
87+
win(end+1) = "src/windows.cpp";
88+
end
89+
90+
mac = "src/macos.cpp";
91+
92+
sym = "src/symlink_fs.cpp";
93+
94+
95+
srcs = {
96+
["src/is_admin.cpp", "src/admin_fs.cpp"] ...
97+
"src/is_char_device.cpp", ...
98+
"src/set_permissions.cpp", ...
99+
["src/is_rosetta.cpp", mac], ...
100+
["src/windows_shortname.cpp", win], ...
101+
};
102+
103+
%% new in R2024b
104+
if isMATLABReleaseOlderThan("R2024b")
105+
srcs{end+1} = ["src/is_symlink.cpp", win, sym];
106+
srcs{end+1} = ["src/create_symlink.cpp", win, sym];
107+
srcs{end+1} = ["src/read_symlink.cpp", win, sym];
108+
end
109+
110+
end

legacy_mex_build.m

Lines changed: 0 additions & 20 deletions
This file was deleted.

private/get_mex_sources.m

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)