-
Notifications
You must be signed in to change notification settings - Fork 14
/
build_mex.m
46 lines (41 loc) · 1.3 KB
/
build_mex.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
% Build mex bindings
% For Octave on Linux, you need the package liboctave-dev installed
% You also need the liblsl64 binary in the bin folder and a configured
% C compiler (mex -setup)
orig_path = pwd(); % Will change back to this when done.
ext = ['.' mexext];
script_dir = fileparts(mfilename('fullpath'));
files = dir('mex/*.c');
% Find liblsl, possibly downloading it if it can't be found locally.
[lsl_fname, lsl_include_dir] = lsl_get_dll();
% Build cell array of libray dependencies (liblsl and maybe others)
libs = {};
if contains(lsl_fname, '32')
libs{end+1} = '-llsl32';
elseif contains(lsl_fname, '64')
libs{end+1} = '-llsl64';
else
libs{end+1} = '-llsl';
end
if isunix
libs{end+1} = '-ldl';
end
disp('Building mex files. This may take a few minutes.');
binarypath = fullfile(script_dir, 'bin');
cd(binarypath);
for i = 1:length(files)
f = files(i);
[~, base, ~] = fileparts(f.name);
targetstats = dir([base, ext]);
if isempty(targetstats) || f.datenum > targetstats.datenum
mex(['-I', lsl_include_dir], '-L.', ['-L', fileparts(lsl_fname)], ...
libs{:}, ['../mex/', f.name]);
else
disp([base, ext, ' up to date']);
end
end
if ismac
targ_lib = dir('lsl_loadlib_.mexmac*');
system(['install_name_tool -add_rpath "@loader_path/" ', targ_lib.name]);
end
cd(orig_path);