Skip to content

Commit

Permalink
Fix file cleanup after downloading and extracting liblsl release.
Browse files Browse the repository at this point in the history
  • Loading branch information
cboulay committed Dec 30, 2020
1 parent 52303f4 commit 8fe8431
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lsl_get_dll.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
% Then check the sister liblsl/build/install/bin folder.
% Finally, check other platform-dependent locations.
lsl_fname = fullfile(binarypath, so_fname);
if ~exist(lsl_fname, 'file')
lsl_include_dir = fullfile(binarypath, 'include');
if ~exist(lsl_fname, 'file') || ~exist(lsl_include_dir, 'dir')
if exist(fullfile(script_dir, '..', 'liblsl', 'build', 'install', 'bin', so_fname), 'file')
lsl_fname = fullfile(script_dir, '..', 'liblsl', 'build', 'install', 'bin', so_fname);
lsl_include_dir = fullfile(script_dir, '..', 'liblsl', 'build', 'install', 'include');
Expand All @@ -59,7 +60,10 @@
end
end %if

if ~exist(lsl_fname,'file')
% If liblsl (with headers) could not be found in the default paths,
% then attempt to download it. On Unix, this will have to be installed
% manually. On PC and Mac, this will be extracted then cleaned up.
if ~exist(lsl_fname,'file') || ~exist(lsl_include_dir, 'dir')
disp(['Could not locate the file "' so_fname '" on your computer. Attempting to download...']);
LIBLSL_TAG = 'v1.14.0';
LIBLSL_VER = '1.14.0';
Expand Down Expand Up @@ -98,9 +102,6 @@
copyfile(fullfile(binarypath, 'liblsl_archive', 'bin', 'lsl.dll'), lsl_fname);
copyfile(fullfile(binarypath, 'liblsl_archive', 'lib', 'lsl.lib'),...
fullfile(binarypath, 'lsl.lib'));
lsl_include_dir = fullfile(binarypath, 'include');
copyfile(fullfile(binarypath, 'liblsl_archive', 'include'), lsl_include_dir);
rmdir(fullfile(binarypath, 'liblsl_archive'));
elseif ismac
% Use system tar because Matlab untar does not preserve symlinks.
mkdir(fullfile(binarypath, 'liblsl_archive'));
Expand All @@ -109,11 +110,14 @@
dylib_list = dir(fullfile(binarypath, '*.dylib'));
[~, lib_ix] = min(cellfun(@length, {dylib_list.name}));
lsl_fname = fullfile(dylib_list(lib_ix).folder, dylib_list(lib_ix).name);
lsl_include_dir = fullfile(binarypath, 'include');
copyfile(fullfile(binarypath, 'liblsl_archive', 'include'), lsl_include_dir);
rmdir(fullfile(binarypath, 'liblsl_archive'));
elseif isunix
error(['Reattempt build after manual installation of liblsl debian package:', ...
' sudo dpkg -i ' fullfile(binarypath, liblsl_url_fname)]);
end
% Grab include_dir and Cleanup no-longer-needed downloaded files.
if ispc || ismac
copyfile(fullfile(binarypath, 'liblsl_archive', 'include'), lsl_include_dir);
rmdir(fullfile(binarypath, 'liblsl_archive'), 's');
delete(fullfile(binarypath, liblsl_url_fname));
end
end

0 comments on commit 8fe8431

Please sign in to comment.