|
1 | | -function lsl_fname = lsl_get_dll(binarypath, debugging) |
| 1 | +function [lsl_fname, lsl_include_dir] = lsl_get_dll(binarypath, debugging) |
2 | 2 | % Search for the lsl library |
3 | 3 | % [lsl_fname] = lsl_get_dll(binarypath, debugging) |
4 | 4 | % |
|
11 | 11 | % Out: |
12 | 12 | % lsl_fname : the filename of the library |
13 | 13 |
|
| 14 | +script_dir = fileparts(mfilename('fullpath')); |
14 | 15 | if ~exist('binarypath','var') || isempty(binarypath) |
15 | | - binarypath = fullfile(fileparts(mfilename('fullpath')), 'bin'); |
| 16 | + binarypath = fullfile(script_dir, 'bin'); |
16 | 17 | end |
17 | 18 | if ~exist('debugging','var') || isempty(debugging) |
18 | 19 | debugging = false; |
19 | 20 | end |
20 | 21 |
|
21 | 22 | if ispc |
| 23 | + prefix = ''; |
22 | 24 | ext = '.dll'; |
23 | 25 | elseif ismac |
| 26 | + prefix = 'lib'; |
24 | 27 | ext = '.dylib'; |
25 | 28 | elseif isunix |
| 29 | + prefix = 'lib'; |
26 | 30 | ext = '.so'; |
27 | 31 | else |
28 | | - error('Your operating system is not supported by this version of the lab streaming layer API.'); |
29 | | -end |
30 | | - |
31 | | -if contains(computer,'64') |
32 | | - bitness = '64'; |
33 | | -else |
34 | | - bitness = '32'; |
| 32 | + error('Operating system not recognized. Cannot identify liblsl binaries.'); |
35 | 33 | end |
36 | 34 |
|
37 | 35 | if debugging |
|
40 | 38 | debug = ''; |
41 | 39 | end |
42 | 40 |
|
43 | | -so_fname = sprintf('liblsl%s%s%s', bitness, debug, ext); |
44 | | -lsl_fname = fullfile(binarypath, so_fname); |
| 41 | +so_fname = sprintf('%slsl%s%s', prefix, debug, ext); |
45 | 42 |
|
| 43 | +% First check ./bin/ for the shared object. |
| 44 | +% Then check the sister liblsl/build/install/bin folder. |
| 45 | +% Finally, check other platform-dependent locations. |
| 46 | +lsl_fname = fullfile(binarypath, so_fname); |
46 | 47 | if ~exist(lsl_fname, 'file') |
47 | | - if ispc |
48 | | - new_sopath = fullfile(binarypath, 'lsl.dll'); |
49 | | - elseif ismac && exist(fullfile(binarypath, 'liblsl.dylib'), 'file') |
50 | | - new_sopath = fullfile(binarypath, 'liblsl.dylib'); |
51 | | - elseif exist('/usr/lib/liblsl.so', 'file') |
52 | | - new_sopath = fullfile('/usr/lib/liblsl.so'); |
53 | | - else |
54 | | - new_sopath = fullfile('/usr/lib/', so_fname); |
| 48 | + if exist(fullfile(script_dir, '..', 'liblsl', 'build', 'install', 'bin', so_fname), 'file') |
| 49 | + lsl_fname = fullfile(script_dir, '..', 'liblsl', 'build', 'install', 'bin', so_fname); |
| 50 | + lsl_include_dir = fullfile(script_dir, '..', 'liblsl', 'build', 'install', 'include'); |
| 51 | + elseif ispc |
| 52 | + % TODO: Anywhere else to check on PC? |
| 53 | + elseif ismac |
| 54 | + % TODO: After liblsl gets a homebrew distribution, check there. |
| 55 | + elseif exist(fullfile('/usr/lib', so_fname), 'file') |
| 56 | + % Linux: Check /usr/lib |
| 57 | + lsl_fname = fullfile('/usr/lib', so_fname); |
| 58 | + lsl_include_dir = '/usr/include'; |
55 | 59 | end |
56 | | - if exist(new_sopath, 'file') |
57 | | - lsl_fname = new_sopath; |
58 | | - end %if |
59 | 60 | end %if |
60 | 61 |
|
61 | 62 | if ~exist(lsl_fname,'file') |
|
70 | 71 | elseif ismac |
71 | 72 | liblsl_url_fname = ['liblsl-' LIBLSL_VER '-OSX_amd64.tar.bz2']; |
72 | 73 | elseif isunix |
73 | | - liblsl_url_fname = ['liblsl-' LIBLSL_VER '-focal_amd64.deb']; |
| 74 | + % Check (xenial vs) bionic vs focal |
| 75 | + filetext = fileread('/etc/lsb-release'); |
| 76 | + expr = '[^\n]*DISTRIB_CODENAME=(?<code>\w+)[^\n]*'; |
| 77 | + res = regexp(filetext,expr,'names'); |
| 78 | + liblsl_url_fname = ['liblsl-' LIBLSL_VER '-' res.code '_amd64.deb']; |
74 | 79 | end |
75 | 80 | try |
76 | 81 | websave(fullfile(binarypath, liblsl_url_fname),... |
77 | 82 | [liblsl_url liblsl_url_fname]); |
78 | 83 | catch ME |
79 | | - disp(['Unable to download ' liblsl_url]); |
| 84 | + disp(['Unable to download ' liblsl_url liblsl_url_fname]); |
| 85 | + if isunix |
| 86 | + extra_step = 'install it'; |
| 87 | + else |
| 88 | + extra_step = ['extract it to ' fullfile(binarypath, 'liblsl_archive')]; |
| 89 | + end |
| 90 | + disp(['You will have to manually download a liblsl release from https://github.com/sccn/liblsl/releases and ' extra_step ... |
| 91 | + ' or build liblsl yourself, before reattempting to build the mex files.']); |
80 | 92 | rethrow(ME); |
81 | 93 | end |
82 | 94 | if ispc |
|
86 | 98 | copyfile(fullfile(binarypath, 'liblsl_archive', 'bin', 'lsl.dll'), lsl_fname); |
87 | 99 | copyfile(fullfile(binarypath, 'liblsl_archive', 'lib', 'lsl.lib'),... |
88 | 100 | fullfile(binarypath, 'lsl.lib')); |
| 101 | + lsl_include_dir = fullfile(binarypath, 'include'); |
| 102 | + copyfile(fullfile(binarypath, 'liblsl_archive', 'include'), lsl_include_dir); |
| 103 | + rmdir(fullfile(binarypath, 'liblsl_archive')); |
89 | 104 | elseif ismac |
90 | 105 | % Use system tar because Matlab untar does not preserve symlinks. |
91 | 106 | mkdir(fullfile(binarypath, 'liblsl_archive')); |
|
94 | 109 | dylib_list = dir(fullfile(binarypath, '*.dylib')); |
95 | 110 | [~, lib_ix] = min(cellfun(@length, {dylib_list.name})); |
96 | 111 | lsl_fname = fullfile(dylib_list(lib_ix).folder, dylib_list(lib_ix).name); |
| 112 | + lsl_include_dir = fullfile(binarypath, 'include'); |
| 113 | + copyfile(fullfile(binarypath, 'liblsl_archive', 'include'), lsl_include_dir); |
| 114 | + rmdir(fullfile(binarypath, 'liblsl_archive')); |
97 | 115 | elseif isunix |
98 | | - error(['liblsl debian package must be installed manually:', ... |
| 116 | + error(['Reattempt build after manual installation of liblsl debian package:', ... |
99 | 117 | ' sudo dpkg -i ' fullfile(binarypath, liblsl_url_fname)]); |
100 | 118 | end |
101 | 119 | end |
102 | | - |
103 | | -end |
104 | | - |
|
0 commit comments