Skip to content

Commit

Permalink
SetupPsychtoolbox et al.: Prep-work for Octave 9.1 enablement for macOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
kleinerm committed Mar 25, 2024
1 parent b867b86 commit e4f45b7
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 23 deletions.
9 changes: 7 additions & 2 deletions PsychSourceGL/Source/datapixxmakemex.m
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,13 @@ function datapixxmakemex()
if IsOSX(1)
system(strrep([DELCMD VPIXXDIR 'VPixx_Software_Tools/libusb/*.o'], '/', filesep));
system(strrep([DELCMD PTBDIR 'PsychSourceGL/Source/OSX/Base/*.o'], '/', filesep));
system(strrep([CPYCMD VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/octave/macosx/Datapixx.mex ' PTBDIR 'Psychtoolbox/PsychBasic/Octave8OSXFiles64'], '/', filesep));
osxsetoctaverpath('Datapixx', [PTBDIR 'Psychtoolbox/PsychBasic/Octave8OSXFiles64/']);
if IsARM
system(strrep([CPYCMD VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/octave/macosx/Datapixx.mex ' PTBDIR 'Psychtoolbox/PsychBasic/Octave8OSXFilesARM64'], '/', filesep));
osxsetoctaverpath('Datapixx', [PTBDIR 'Psychtoolbox/PsychBasic/Octave8OSXFilesARM64/']);
else
system(strrep([CPYCMD VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/octave/macosx/Datapixx.mex ' PTBDIR 'Psychtoolbox/PsychBasic/Octave8OSXFiles64'], '/', filesep));
osxsetoctaverpath('Datapixx', [PTBDIR 'Psychtoolbox/PsychBasic/Octave8OSXFiles64/']);
end
elseif IsLinux
system(strrep([DELCMD VPIXXDIR 'VPixx_Software_Tools/libusb/*.o'], '/', filesep));
system(strrep([DELCMD PTBDIR 'PsychSourceGL/Source/Linux/Base/*.o'], '/', filesep));
Expand Down
2 changes: 1 addition & 1 deletion PsychSourceGL/Source/osxmakeit.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function osxmakeit(mode)

if mode==0
% Build Screen:
% Depends: GStreamer-1.0 (actually 1.18.0+), libdc1394-2, libusb-1.0
% Depends: GStreamer-1.0 (actually 1.18.0+), libdc1394-2

% Must build tinyexr separately, because it needs C++ compile
% incompatible with the C/Obj-C compile in the main mex cmd below:
Expand Down
6 changes: 5 additions & 1 deletion PsychSourceGL/Source/osxmakeitoctave3.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ function osxmakeitoctave3(mode)
% function osxsetoctaverpath().
dst = [PsychtoolboxRoot 'PsychBasic/Octave8OSXFiles64/'];

if IsARM
dst = [PsychtoolboxRoot 'PsychBasic/Octave8OSXFilesARM64/'];
end

if ~IsOSX(1) || ~IsOctave
error('osxmakeitoctave3 only works with a 64-Bit version of Octave 8 for macOS!');
end
Expand Down Expand Up @@ -34,7 +38,7 @@ function osxmakeitoctave3(mode)

if mode==0
% Build Screen:
% Depends: GStreamer-1.18+, libdc1394-2, libusb-1.0
% Depends: GStreamer-1.18+, libdc1394-2

% Need to build the PsychCocoaGlue.c separately as Objective-C code,
% whereas the mex call below only compiles C-Code and links it with the
Expand Down
26 changes: 17 additions & 9 deletions PsychSourceGL/Source/osxsetoctaverpath.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ function osxsetoctaverpath(mexfname, mexpath)
% runtime libraries into the mex file folder of PTB, so the mex
% files should always find a dylib for the currently running Octave.

if ~IsOSX(1) || ~IsOctave
error('osxsetoctaverpath only works with a 64-Bit version of HomeBrew Octave-8.4.0 for macOS!');
if ~IsOSX(1) || ~IsOctave || ~compare_versions(version, '9.1.0', '==')
error('osxsetoctaverpath only works with a 64-Bit version of HomeBrew Octave-9.1.0 for macOS!');
end

% If no mex filename given, iterate over 'mexpath' - or the default install
% location of mex files - and apply the rpath editing to each mex file there:
if nargin < 1 || isempty(mexfname)
if nargin < 2 || isempty(mexpath)
mexpath = [PsychtoolboxRoot 'PsychBasic/Octave8OSXFiles64/'];
if IsARM
mexpath = [PsychtoolboxRoot 'PsychBasic/Octave8OSXFilesARM64/'];
else
mexpath = [PsychtoolboxRoot 'PsychBasic/Octave8OSXFiles64/'];
end
end

d = dir (mexpath);
Expand All @@ -51,16 +55,20 @@ function osxsetoctaverpath(mexfname, mexpath)
% This is how the libdir should be defined automatically:
libdir = GetOctlibDir;

% This is sadly how we have to do it with Octave on macOS 13 due to
% This is sadly how we have to do it with Octave on macOS 13-14 due to
% the latest macOS linker crap - Hardcoding the path for a Octave install
% from HomeBrew. Yes, this is sad...
libdir = '/usr/local/opt/octave/lib/octave/8.4.0';
if IsARM
libdir = '/opt/homebrew/opt/octave/lib/octave/9.1.0';
else
libdir = '/usr/local/opt/octave/lib/octave/9.1.0';
end

% Replace absolute path to liboctinterp.11.dylib with @rpath:
system(['install_name_tool -change ' libdir '/liboctinterp.11.dylib @rpath/liboctinterp.dylib ' mexfname]);
% Replace absolute path to liboctinterp.12.dylib with @rpath:
system(['install_name_tool -change ' libdir '/liboctinterp.12.dylib @rpath/liboctinterp.dylib ' mexfname]);

% Replace absolute path to liboctave.10.dylib with @rpath:
system(['install_name_tool -change ' libdir '/liboctave.10.dylib @rpath/liboctave.dylib ' mexfname]);
% Replace absolute path to liboctave.11.dylib with @rpath:
system(['install_name_tool -change ' libdir '/liboctave.11.dylib @rpath/liboctave.dylib ' mexfname]);

% Add one single rpath: @loader_path. This is the path to our folder where our
% mex file is stored. If we place symlinks to liboctave.dylib and liboctinterp.dylib
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion Psychtoolbox/PsychGLImageProcessing/PsychVulkan.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
% History:
% 28-Jun-2020 mk Written.

global GL;
global GL; %#ok<GVMIS>
persistent verbosity;
persistent supported;
persistent vulkan;
Expand Down
10 changes: 5 additions & 5 deletions Psychtoolbox/PsychtoolboxPostInstallRoutine.m
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function PsychtoolboxPostInstallRoutine(isUpdate, flavor)
end

% No Apple Silicon Matlab/Octave support yet. Only Rosetta 2 emulated Intel.
if IsOSX && IsARM
if IsOSX && IsARM && ~exist('WaitSecs.mexmaca64', 'file')
fprintf('Psychtoolbox does not yet work on native Matlab or Octave for Apple Silicon Macs with 64-Bit ARM architecture.\n');
fprintf('You may get a minimally functional Psychtoolbox by installing and running Matlab or Octave for 64-Bit Intel\n');
fprintf('under Rosetta 2 emulation.\n');
Expand Down Expand Up @@ -427,8 +427,8 @@ function PsychtoolboxPostInstallRoutine(isUpdate, flavor)
fprintf('Press any key to confirm you read and understand this message.\n');
pause;
end
elseif ismember(octavemajorv, [6,7,8]) && IsOSX
% Octave 6 - 8 can share the same mex files built against Octave 8:
elseif ismember(octavemajorv, [6,7,8,9]) && IsOSX
% Octave 6 - 9 can share the same mex files built against Octave 8:
rdir = [PsychtoolboxRoot 'PsychBasic' filesep 'Octave8'];
else
% Everything else (aka other OS'es) goes by Octave major version:
Expand Down Expand Up @@ -484,7 +484,7 @@ function PsychtoolboxPostInstallRoutine(isUpdate, flavor)
fprintf('=====================================================================\n\n');
end

if (IsOSX && (~ismember(octavemajorv, [6,7,8]))) || ...
if (IsOSX && (~ismember(octavemajorv, [6,7,8,9]))) || ...
(IsWin && (octavemajorv ~= 7 || ~ismember(octaveminorv, [3]))) || ...
(IsLinux && ((octavemajorv < 4 && ~IsARM) || (octavemajorv == 4 && octaveminorv < 4) || (octavemajorv > 8)))
fprintf('\n\n===============================================================================================\n');
Expand All @@ -494,7 +494,7 @@ function PsychtoolboxPostInstallRoutine(isUpdate, flavor)
fprintf('WARNING: using the latest stable version of the Octave 4.4, 5.x, 6.x, 7.x or maybe 8.x series.\n');
fprintf('WARNING: You can get Psychtoolbox for other, or more recent, versions of Octave from NeuroDebian.\n');
elseif IsOSX
fprintf('WARNING: only using Octave 6 or Octave 7 or Octave 8 with this version of Psychtoolbox.\n');
fprintf('WARNING: only using Octave 6 or Octave 7 or Octave 8 or Octave 9 with this version of Psychtoolbox.\n');
else
% On Windows we only care about 7.3 atm:
fprintf('WARNING: only using Octave 7.3 with this version of Psychtoolbox.\n');
Expand Down
12 changes: 8 additions & 4 deletions Psychtoolbox/SetupPsychtoolbox.m
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,21 @@ function SetupPsychtoolbox(tryNonInteractiveSetup)
% Apples trainwreck needs special treatment. If Psychtoolbox has been
% downloaded via a webbrowser as a zip file or tgz file and then
% extracted, then all binary executable files like .dylib's and
% .mexmaci64 mex files will have the com.apple.quarantine attribute set
% to prevent them from working in any meaningfully user fixable way -
% mex files will have the com.apple.quarantine attribute set to
% prevent them from working in any meaningfully user fixable way -
% Thanks Apple! Use the xattr command to remove the quarantine flag.
fprintf('Trying to fixup Apple macOS broken security workflow by removing the quarantine flag from our mex files...\n\n');

if IsOctave
% Fix the Octave mex files:
[rc, msg] = system(['xattr -d com.apple.quarantine ' p filesep 'PsychBasic/Octave8OSXFiles64/*.mex 2>&1']);
if IsARM
[rc, msg] = system(['xattr -d com.apple.quarantine ' p filesep 'PsychBasic/Octave8OSXFilesARM64/*.mex 2>&1']);
else
[rc, msg] = system(['xattr -d com.apple.quarantine ' p filesep 'PsychBasic/Octave8OSXFiles64/*.mex 2>&1']);
end
else
% Fix the Matlab mex files:
[rc, msg] = system(['xattr -d com.apple.quarantine ' p filesep 'PsychBasic/*.mexmaci64']);
[rc, msg] = system(['xattr -d com.apple.quarantine ' p filesep 'PsychBasic/*.' mexext]);
end

% Fix the DrawText plugin and other plugins:
Expand Down

0 comments on commit e4f45b7

Please sign in to comment.