File: datapixxmakemex.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (246 lines) | stat: -rw-r--r-- 14,374 bytes parent folder | download
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
function datapixxmakemex()

    if (IsOSX)
        VPIXXDIR = '/Users/kleinerm/projects/';
        CPYCMD = 'cp ';
        DELCMD = 'rm ';
    elseif (IsLinux)
        if Is64Bit || IsARM
          VPIXXDIR = '/home/kleinerm/projects/';
        else
          VPIXXDIR = '/media/sf_kleinerm/projects/';
        end

        CPYCMD = 'cp ';
        DELCMD = 'rm ';
    elseif (IsWin)
        VPIXXDIR = 'T:/projects/';
        if exist('C:/Users/kleinerm/Documents/GitHub/', 'dir')
            VPIXXDIR = 'C:/Users/kleinerm/Documents/GitHub/';
        end

        if exist('C:/Users/mario/Documents/GitHub/', 'dir')
            VPIXXDIR = 'C:/Users/mario/Documents/GitHub/';
        end

        CPYCMD = 'copy ';
        DELCMD = 'del ';
    end

    if ~IsWin
        PTBDIR = [VPIXXDIR 'OpenGLPsychtoolbox/Psychtoolbox-3/'];
    else
        PTBDIR = [VPIXXDIR 'Psychtoolbox-3/'];
    end

    % Start constructing mex command
    S = 'mex -v';   % -v for verbose output.

    if IsOctave
        % -s for stripping the files under Octave:
        S = [S ' -s'];
    end

    S = [S ' -DPTBMODULE_Datapixx'];

    if IsOctave
        S = [S ' -DPTBOCTAVE3MEX'];
    else
        % Build it backwards compatible with Matlab releases before R2014b:
        S = [S ' -largeArrayDims -DMEX_DOUBLE_HANDLE'];
    end

    if IsLinux
        if ~IsOctave
            S = [S ' CFLAGS=''$CFLAGS -fPIC -std=gnu99 -fexceptions'' '];
        else
            S = [S ' -fexceptions'];
        end
    end

    S = [S ' -I' VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/src'];
    S = [S ' -I' VPIXXDIR 'VPixx_Software_Tools/libdpx/src'];
    S = [S ' -I' PTBDIR 'PsychSourceGL/Source/Common/Base'];
    S = [S ' -I' PTBDIR 'PsychSourceGL/Source/Common/Screen'];

    if (IsOSX)
        S = [S ' -I' VPIXXDIR 'VPixx_Software_Tools/libusb'];
        S = [S ' -I' PTBDIR 'PsychSourceGL/Source/OSX/Base'];
        S = [S ' -I' PTBDIR 'PsychSourceGL/Source/OSX/Screen'];
        S = [S ' -I' PTBDIR 'PsychSourceGL/Source/OSX/Fonts'];
    elseif (IsLinux)
        S = [S ' -I' VPIXXDIR 'VPixx_Software_Tools/libusb'];
        S = [S ' -I' PTBDIR 'PsychSourceGL/Source/Linux/Base'];
        S = [S ' -I' PTBDIR 'PsychSourceGL/Source/Linux/Screen'];
    elseif (IsWin)
        if ~IsOctave
            % Include this folder only on Matlab (or other MSVC builds). It contains a stdint.h file
            % previously located in the src/ folder directly. This stdint.h file lacks definitions of
            % int32_t, int64_t et al., but overrides Octave's / MinGW's stdint.h files which do define
            % those needed data types! Strangely this override was never a problem on Octave 4.2.x and
            % earlier. Apparently the type defines came from an alternate source, but i could not track
            % it down in multiple hours, so screw this - a hack it is :(
            S = [S ' -I' VPIXXDIR 'VPixx_Software_Tools/libusb_win32/libusb-win32-src-0.1.12.2/src/include'];
        end
        S = [S ' -I' VPIXXDIR 'VPixx_Software_Tools/libusb_win32/libusb-win32-src-0.1.12.2/src'];
        S = [S ' -I' PTBDIR 'PsychSourceGL/Source/Windows/Base'];
        S = [S ' -I' PTBDIR 'PsychSourceGL/Source/Windows/Screen'];
        S = [S ' -DWIN_BUILD'];    % libdpx DPxOpen mod under Windows
    end

    S = [S ' ' VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/src/PsychDatapixx.c'];
    S = [S ' ' VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/src/RegisterProject.c'];
    S = [S ' ' VPIXXDIR 'VPixx_Software_Tools/libdpx/src/libdpx.c'];
    S = [S ' ' PTBDIR 'PsychSourceGL/Source/Common/Base/MiniBox.c'];
    S = [S ' ' PTBDIR 'PsychSourceGL/Source/Common/Base/ProjectTable.c'];
    S = [S ' ' PTBDIR 'PsychSourceGL/Source/Common/Base/PsychAuthors.c'];
    S = [S ' ' PTBDIR 'PsychSourceGL/Source/Common/Base/PsychCellGlue.c'];
    S = [S ' ' PTBDIR 'PsychSourceGL/Source/Common/Base/PsychError.c'];
    S = [S ' ' PTBDIR 'PsychSourceGL/Source/Common/Base/PsychHelp.c'];
    S = [S ' ' PTBDIR 'PsychSourceGL/Source/Common/Base/PsychInit.c'];
    S = [S ' ' PTBDIR 'PsychSourceGL/Source/Common/Base/PsychInstrument.c'];
    S = [S ' ' PTBDIR 'PsychSourceGL/Source/Common/Base/PsychMemory.c'];
    S = [S ' ' PTBDIR 'PsychSourceGL/Source/Common/Base/PsychRegisterProject.c'];
    S = [S ' ' PTBDIR 'PsychSourceGL/Source/Common/Base/PsychStructGlue.c'];
    S = [S ' ' PTBDIR 'PsychSourceGL/Source/Common/Base/PsychVersioning.c'];
    S = [S ' ' PTBDIR 'PsychSourceGL/Source/Common/Base/PsychScriptingGlue.c'];
    S = [S ' ' PTBDIR 'PsychSourceGL/Source/Common/Base/PsychScriptingGlueMatlab.c'];
    S = [S ' ' PTBDIR 'PsychSourceGL/Source/Common/Base/MODULEVersion.c'];

    if (IsOSX)
        S = [S ' ' VPIXXDIR 'VPixx_Software_Tools/libusb/descriptors.c'];
        S = [S ' ' VPIXXDIR 'VPixx_Software_Tools/libusb/error.c'];
        S = [S ' ' VPIXXDIR 'VPixx_Software_Tools/libusb/usb.c'];
        S = [S ' ' VPIXXDIR 'VPixx_Software_Tools/libusb/darwin.c'];
        S = [S ' ' PTBDIR 'PsychSourceGL/Source/OSX/Base/PsychTimeGlue.c'];
        if IsOctave
            S = [S ' ''-mmacosx-version-min=10.11'' '];
            S = [S ' ''-Wl,-headerpad_max_install_names,-framework,ApplicationServices,-framework,CoreServices,-framework,CoreFoundation,-framework,Carbon,-framework,CoreAudio,-framework,IOKit'' '];
        else
            S = [S ' CFLAGS="\$CFLAGS -mmacosx-version-min=10.11" LDFLAGS="\$LDFLAGS -mmacosx-version-min=10.11 -framework ApplicationServices -framework CoreServices -framework CoreFoundation -framework Carbon -framework CoreAudio -framework IOKit" '];
        end
        if (IsOctave)
            S = [S ' --output ' VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/octave/macosx/Datapixx.mex'];
        else
            if (Is64Bit)
                S = [S ' -output ' VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/matlab/macosx64/Datapixx'];
            else
                S = [S ' -output ' VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/matlab/macosx/Datapixx'];
            end
        end
    elseif (IsLinux)
        S = [S ' ' VPIXXDIR 'VPixx_Software_Tools/libusb/descriptors.c'];
        S = [S ' ' VPIXXDIR 'VPixx_Software_Tools/libusb/error.c'];
        S = [S ' ' VPIXXDIR 'VPixx_Software_Tools/libusb/usb.c'];
        S = [S ' ' VPIXXDIR 'VPixx_Software_Tools/libusb/linux.c'];
        S = [S ' ' PTBDIR 'PsychSourceGL/Source/Linux/Base/PsychTimeGlue.c'];
        S = [S ' -lc'];     % Because Mario says so
        S = [S ' -lrt'];    % for clock_getres() and other clock_*()
        S = [S ' -ldl'];    % for dlsym() etc. use in PsychTimeGlue.c.

        if (IsOctave)
            if (Is64Bit)
                S = [S ' --output ' VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/octave/linux64/Datapixx.mex'];
            else
                S = [S ' --output ' VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/octave/linux/Datapixx.mex'];
            end
        else
            if (Is64Bit)
                S = [S ' -output ' VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/matlab/linux64/Datapixx'];
            else
                S = [S ' -output ' VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/matlab/linux/Datapixx'];
            end
        end
    elseif (IsWin)
        S = [S ' ' PTBDIR 'PsychSourceGL/Source/Windows/Base/PsychTimeGlue.c'];
        if (Is64Bit)
            if IsOctave
                % We use a stub-loader which runtime loads and manually links the DLL.
                % For unknown reasons, simply using the libusb0.dll for 64-Bit MSVC does
                % not work, but crash. Manually loading this way otoh. works fine with the
                % same DLL. Go figure!
                S = [S ' ' VPIXXDIR 'VPixx_Software_Tools/libusb_win32/libusb-win32-device-bin-0.1.12.2/lib/dynamic/libusb_dyn.c'];
            else
                S = [S ' -L' VPIXXDIR 'VPixx_Software_Tools/libusb_win32/libusb-win32-device-bin-0.1.12.2/lib/msvc_x64 -llibusb'];
            end
        else
            if IsOctave
                S = [S ' ' VPIXXDIR 'VPixx_Software_Tools/libusb_win32/libusb-win32-device-bin-0.1.12.2/lib/gcc/libusb.a'];
            else
                S = [S ' -L' VPIXXDIR 'VPixx_Software_Tools/libusb_win32/libusb-win32-device-bin-0.1.12.2/lib/msvc -llibusb'];
            end
        end
        if (IsOctave)
            S = [S ' -lWinmm']; % for timeGetTime() et al
            S = [S ' --output ' VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/octave/win32/Datapixx.mex'];
        else
            S = [S ' -L"C:/Program Files/Microsoft Visual Studio/VC98/Lib" -lWinmm']; % for timeGetTime() et al
            if (Is64Bit)
                S = [S ' -output ' VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/matlab/win64/Datapixx.mexw64'];
            else
                S = [S ' -output ' VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/matlab/win32/Datapixx.mexw32'];
            end
        end
    end

    eval(strrep(S, '/', filesep));

    %   Move mex file to final destination, and clean up any temporary build files.
    %   Octave puts object files in same folders as source files, and we have to delete them manually.
    %   Matlab is a bit smarter, putting the object files in the current directory, then immediately cleaning them up.
    if (IsOctave)
        v = sscanf(version, '%i.%i.%i');
        system(strrep([DELCMD VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/src/*.o'], '/', filesep));
        system(strrep([DELCMD VPIXXDIR 'VPixx_Software_Tools/libdpx/src/*.o'], '/', filesep));
        system(strrep([DELCMD PTBDIR 'PsychSourceGL/Source/Common/Base/*.o'], '/', filesep));
        % system(strrep([DELCMD PTBDIR 'PsychSourceGL/Source/Common/Screen/*.o'], '/', filesep));
        if IsOSX(1)
            system(strrep([DELCMD VPIXXDIR 'VPixx_Software_Tools/libusb/*.o'], '/', filesep));
            system(strrep([DELCMD PTBDIR 'PsychSourceGL/Source/OSX/Base/*.o'], '/', filesep));
            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));
            % We require Octave-5 or later:
            if Is64Bit
                system(strrep([CPYCMD VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/octave/linux64/Datapixx.mex ' PTBDIR 'Psychtoolbox/PsychBasic/Octave5LinuxFiles64'], '/', filesep));
            else
                if IsARM
                    system(strrep([CPYCMD VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/octave/linux/Datapixx.mex ' PTBDIR 'Psychtoolbox/PsychBasic/Octave3LinuxFilesARM'], '/', filesep));
                else
                    system(strrep([CPYCMD VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/octave/linux/Datapixx.mex ' PTBDIR 'Psychtoolbox/PsychBasic/Octave3LinuxFiles'], '/', filesep));
                end
            end
        elseif IsWin
            system(strrep([DELCMD PTBDIR 'PsychSourceGL/Source/Windows/Base/*.o'], '/', filesep));
            if Is64Bit
                system(strrep([CPYCMD VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/octave/win32/Datapixx.mex ' PTBDIR 'Psychtoolbox/PsychBasic/Octave8WindowsFiles64'], '/', filesep));
            else
                system(strrep([CPYCMD VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/octave/win32/Datapixx.mex ' PTBDIR 'Psychtoolbox/PsychBasic/Octave8WindowsFiles'], '/', filesep));
            end
        end
    else
        if (IsOSX(1))           % 64-bit MATLAB on OS X
            system(strrep([CPYCMD VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/matlab/macosx64/Datapixx.' mexext ' ' PTBDIR 'Psychtoolbox/PsychBasic'], '/', filesep));
        elseif (IsOSX)          % 32-bit MATLAB on OS X
            system(strrep([CPYCMD VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/matlab/macosx/Datapixx.' mexext ' ' PTBDIR 'Psychtoolbox/PsychBasic'], '/', filesep));
            system(strrep([CPYCMD VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/matlab/macosx/Datapixx.' mexext ' ' VPIXXDIR 'git_Psychtoolbox-3/Psychtoolbox/PsychBasic'], '/', filesep));
        elseif (IsLinux(1))     % 64-bit MATLAB on Linux
            system(strrep([CPYCMD VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/matlab/linux64/Datapixx.' mexext ' ' PTBDIR 'Psychtoolbox/PsychBasic'], '/', filesep));
        elseif (IsLinux)        % 32-bit MATLAB on Linux
            system(strrep([CPYCMD VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/matlab/linux/Datapixx.' mexext ' ' PTBDIR 'Psychtoolbox/PsychBasic'], '/', filesep));
        elseif (IsWin(1))       % 64-bit MATLAB on Windows
            system(strrep([CPYCMD VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/matlab/win64/Datapixx.mexw64 ' PTBDIR 'Psychtoolbox/PsychBasic/MatlabWindowsFilesR2007a'], '/', filesep));
        elseif (IsWin)          % 32-bit MATLAB on Windows
            system(strrep([CPYCMD VPIXXDIR 'VPixx_Software_Tools/DatapixxToolbox_trunk/mexdev/build/matlab/win32/Datapixx.mexw32 ' PTBDIR 'Psychtoolbox/PsychBasic/MatlabWindowsFilesR2007a'], '/', filesep));
            system(strrep([CPYCMD VPIXXDIR 'svn_Software/DatapixxToolbox_trunk/mexdev/build/matlab/win32/Datapixx.mexw32 ' VPIXXDIR 'git_Psychtoolbox-3/Psychtoolbox/PsychBasic/MatlabWindowsFilesR2007a'], '/', filesep));
        end
    end

return;