Skip to content

Commit

Permalink
Add LM base shared infrastructure and config, also for Linux no-op case.
Browse files Browse the repository at this point in the history
  • Loading branch information
kleinerm committed Nov 3, 2024
1 parent ce8ddc1 commit 3b6e13f
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 3 deletions.
26 changes: 26 additions & 0 deletions PsychSourceGL/Source/Common/Base/MiniBox.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,29 @@ psych_bool PsychIsMasterThread(void)
{
return(PsychIsCurrentThreadEqualToId(masterthread));
}

#ifdef PSYCH_NOLM

// Stub functions for mex files without license management:
// License checking and management disabled in this build. Just return "Success":
psych_bool PsychIsLicensed(const char* featureName) {
// Specific feature enabled request? The answer is always "No":
if (featureName)
return(FALSE);

// Licensed as a whole? A resounding "Yes":
return(TRUE);
}

void PsychFeatureUsed(const char* featureName)
{
(void) featureName;
}

PsychError PsychManageLicense(void)
{
PsychCopyOutDoubleArg(1, kPsychArgOptional, 0);
return(PsychError_none);
}

#endif
5 changes: 5 additions & 0 deletions PsychSourceGL/Source/Common/Base/Psych.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ extern "C" {
#include "PsychTimeGlue.h"
#include "PsychInstrument.h"

// Define prototypes needed for license management, regardless if used or not:
psych_bool PsychIsLicensed(const char* featureName);
void PsychFeatureUsed(const char* featureName);
PsychError PsychManageLicense(void);

#ifndef PTBINSCRIPTINGGLUE
// This is provided by the project. We do not
// include it when building PsychScriptingGlue.cc
Expand Down
9 changes: 8 additions & 1 deletion PsychSourceGL/Source/Common/Base/PsychScriptingGlueMatlab.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,18 @@ PTB_EXPORT void mexFunction(int nlhs, mxArray *plhs[], int nrhs, CONSTmxArray *p

// This one dumps all registered subfunctions of a module into a struct array of text strings.
// Needed by our automatic documentation generator script to find out about subfunctions of a module:
PsychRegister((char*) "DescribeModuleFunctionsHelper", &PsychDescribeModuleFunctions);
PsychRegister((char*) "DescribeModuleFunctionsHelper", &PsychDescribeModuleFunctions);

// License management support for users to (de-)activate machine licenses and query their status:
PsychRegister((char*) "ManageLicense", &PsychManageLicense);

firstTime = FALSE;
}

// Abort here if machine is not actively licensed, except for use of WaitSecs():
if (strcmp(PsychGetModuleName(), "WaitSecs") && !PsychIsLicensed(NULL))
mexErrMsgTxt("This Psychtoolbox function is currently not licensed for use on this machine.");

// Increment call recursion level for this invocation of the module:
recLevel++;
if (recLevel >= MAX_RECURSIONLEVEL) {
Expand Down
13 changes: 13 additions & 0 deletions PsychSourceGL/Source/Linux/Base/PsychPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
*/

#include "PsychPlatformConstants.h"
#include <sys/user.h>

//these control build switches
#define PSYCH_SYSTEM PSYCH_LINUX
Expand All @@ -45,3 +46,15 @@
#endif

#define PSYCH_DEBUG PSYCH_ON

#ifndef PSYCH_NOLM

#if !defined(__aarch64__) && !defined(__x86_64__)
#define PSYCH_NOLM 1
#else
#if !defined(PTB_USE_WAYLAND) && !defined(PTB_USE_WAYLAND_PRESENT) && defined(PAGE_SIZE) && (PAGE_SIZE == 4096)
#define PSYCH_NOLM 1
#endif
#endif

#endif
37 changes: 35 additions & 2 deletions PsychSourceGL/Source/linuxmakeitoctave3.m
Original file line number Diff line number Diff line change
Expand Up @@ -287,28 +287,61 @@ function linuxmakeitoctave3(mode, neurodebianbuild)
% as a C++ piece of art, which can't expand wildcards anymore.
function mex(varargin)
inargs = {varargin{:}};

if IsARM
pluginsuffix = 'ARM';
else
pluginsuffix = 'Intel';
end

if Is64Bit
pluginsuffix = [pluginsuffix '64'];
else
pluginsuffix = [pluginsuffix '32'];
end

outargs = {"--mex"};
outargs = {outargs{:}, sprintf("-L%sPsychBasic/PsychPlugins", PsychtoolboxRoot)};
outargs = {outargs{:}, sprintf("-L%sPsychBasic/PsychPlugins/%s", PsychtoolboxRoot, pluginsuffix)};
outargs = {outargs{:}, "-fexceptions"}; % Explicit exception handling for Octave on RaspberryPi OS.
outargs = {outargs{:}, "-s"};

usewayland = 0;
for i = 1:length(inargs)
if ~isempty(strfind(inargs{i}, '-DPTB_USE_WAYLAND'))
usewayland = 1;
end

if ~isempty(strfind(inargs{i}, '*'))
outargs = {outargs{:}, glob(inargs{i})};
else
outargs = {outargs{:}, inargs{i}};
end
end

[rc, pagesize] = system('getconf PAGESIZE');
if rc == 0
pagesize = str2num(pagesize);
else
pagesize = NaN;
end

if Is64Bit && (usewayland || (pagesize ~= 4096))
outargs = {outargs{:}, "-lLexActivator"};
end

args = cellstr(char(outargs));

% Try-Catch protect actual mkoctfile build, using customized LDFLAGS setting,
% restoring original setting after (failed) build:
oldldflags = getenv('LDFLAGS');
try
% Set LDFLAGS to add an rpath to the Psychtoolbox/PsychBasic/PsychPlugins folder,
% so our custom runtime plugins can be found and load-time linked into our mex files:
setenv('LDFLAGS', [oldldflags " -Wl,-rpath='$ORIGIN/../PsychPlugins' -Wl,-rpath='$ORIGIN/../../PsychPlugins'"])
% and its arch specific subfolders 'pluginsuffix', so our custom runtime plugins
% can be found and load-time linked into our mex files:
setenv('LDFLAGS', [oldldflags " -Wl,-rpath='$ORIGIN/../PsychPlugins' -Wl,-rpath='$ORIGIN/../../PsychPlugins'" ...
sprintf(" -Wl,-rpath='$ORIGIN/../PsychPlugins/%s' -Wl,-rpath='$ORIGIN/../../PsychPlugins/%s'", ...
pluginsuffix, pluginsuffix)]);

% Build it, with customized LDFLAGS:
mkoctfile (args{:});
Expand Down
1 change: 1 addition & 0 deletions Psychtoolbox/PsychBasic/PsychPlugins/Psychtoolbox.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REFEQzAxQjgyQTY1QzdBMjhGQzdGOURCMkJDRUM2MzQ=.5y00OkLTS3+ZZT06pCeUVe3zwx/f7FBKDZGYS4Y7N2TeASFpYb+s2xI2uJFQUxkRYaNPS/JSiSjdsZSBjv56zX3DNzlXnRH9zFi8NyDDwbZ6r8S5WqCVUWwRIVj1tGNmM0S8PjL48iqtlBHxzpRr0b3Y83xbNeBEjtvIYv6dXjbH1xzpRf+pYBd0393/xErsGU/V24vVByeC7qVjQshW8gway5TBmCAjFGTWVjQTpbfR4zpnV2OPri37SRY3U1e7XUO3U9PCRGSe8STfktDz9eMaenDmZ8BaHhiprqml6ZvVeGticpA9ogEFHETdvfVmyiBntyE2wplyOi3BA0m2PSIOMhREDvY5bajIcyvqjl2WHk0pNuTnPUuvM38oWT+65EiD8fTAvI6fNIBms8gV8Qwq+UWGXfj4CRVf7hbEC6wDwHlXQ80l1sPyI4KsFsCo/FXxPVUDeDZyLax9bNJIrr0bNrtKJhbcbPpgRKpJOkZjQyM+YHViSJAisvemgG3VQGUJ/dAm+REwa2csm4hbHQ3d0rd54+PyyfRZhMUqQN/8ThXIe5nnKKvK9L7OHyUP9qC75tGt/TsXPip4kv+bPk4/niFICQ/Ik6VJNusIMgRgqrOggfyaw5viRZhfgboa4HHMM3ekzhjoqv1uOejfqPsPvZGBL7d1VyXDofNUaS5m3/Q/lu6GUVQPe8yoXE4RqlD4U3R0nuH8cBAbWwV6xsUVFmc6vKzrrz6pjV89cEe87axq9jtc7crnXoZORdVYr3rChcesz8VP5mZ1wcYEaPuwadx4+P3or3lmik7D0QuE/mNgq64lhC8Hzb7+nR8r

0 comments on commit 3b6e13f

Please sign in to comment.