1 | function mexpassmethod(PASSMETHODS, varargin) |
---|
2 | %MEXPASSMETHOD builds pass-method mex-files from C files |
---|
3 | % |
---|
4 | % PASSMETHODS argument can be: |
---|
5 | % Single pass-method name - the same as the C file name without '.c' |
---|
6 | % Cell array of strings containing pass-method names |
---|
7 | % 'all' - option automatically detects all C files matching *Pass.c pattern |
---|
8 | % |
---|
9 | % The second argument is a list of options passed to the 'mex' script |
---|
10 | % |
---|
11 | % Examples: mexpassmethod('DriftPass','-v') |
---|
12 | % mexpassmethod('all','-argcheck') |
---|
13 | % mexpassmethod({'DriftPass','BendLinearPass'}) |
---|
14 | % |
---|
15 | % Note: MEXPASSMETHOD automatically determines the host |
---|
16 | % platform and costructs -D<PLATFORM> option to feed to the |
---|
17 | % mex script. All pass-methods #incude elempass.h header file |
---|
18 | % which uses #if defined(PLATFORM) directive to select |
---|
19 | % between platform-specific branches |
---|
20 | % |
---|
21 | % See also: file:elempass.h |
---|
22 | |
---|
23 | PLATFORMOPTION = ['-D',computer,' ']; |
---|
24 | CURRENTDIR = pwd; |
---|
25 | cd(fileparts(which('DriftPass'))); |
---|
26 | cd user |
---|
27 | |
---|
28 | tmpfile = 0; |
---|
29 | %Additional platform-specific options for mex |
---|
30 | switch computer |
---|
31 | case 'SOL2' |
---|
32 | PLATFORMOPTION = [PLATFORMOPTION,'LDFLAGS=''-shared -W1,-M,',atroot,'/simulator/element/mexFunctionSOL2.map''',' ']; |
---|
33 | case 'GLNX86' |
---|
34 | PLATFORMOPTION = [PLATFORMOPTION,'LDFLAGS=''-pthread -shared -m32 -Wl,--version-script,',atroot,'/simulator/element/mexFunctionGLNX86.map''',' ']; |
---|
35 | case 'GLNXA64' |
---|
36 | PLATFORMOPTION = [PLATFORMOPTION,'LDFLAGS=''-pthread -shared -m64 -Wl,--version-script,',atroot,'/simulator/element/mexFunctionGLNXA64.map''',' ']; |
---|
37 | case 'MACI64' |
---|
38 | PLATFORMOPTION = [PLATFORMOPTION,'LDFLAGS=''-pthread -shared -m64''',' ']; |
---|
39 | end |
---|
40 | |
---|
41 | |
---|
42 | if ischar(PASSMETHODS) % one file name - convert to a cell array |
---|
43 | if strcmpi(PASSMETHODS,'all') |
---|
44 | % Find all files matching '*Pass.c' wildcard |
---|
45 | D = dir('*Pass.c'); |
---|
46 | PASSMETHODS = cell(size(D)); |
---|
47 | for i = 1:length(D) |
---|
48 | PASSMETHODS{i} = strrep(D(i).name,'.c',''); |
---|
49 | end |
---|
50 | else % Mex a single specifie pass-method |
---|
51 | PASSMETHODS={PASSMETHODS}; |
---|
52 | end |
---|
53 | end |
---|
54 | |
---|
55 | for i = 1:length(PASSMETHODS) |
---|
56 | |
---|
57 | PM = PASSMETHODS{i}; |
---|
58 | evalin('base',['clear ',PM]); |
---|
59 | MEXSTRING = ['mex ',PLATFORMOPTION]; |
---|
60 | if nargin==2 |
---|
61 | MEXSTRING = [MEXSTRING,varargin{1},' ']; |
---|
62 | end |
---|
63 | MEXSTRING = [MEXSTRING, PM,'.c ']; |
---|
64 | |
---|
65 | %message = sprintf('%s\n',MEXSTRING); |
---|
66 | %disp(message); |
---|
67 | |
---|
68 | if exist([pwd,'\',PM,'.c'],'file') | exist ([pwd,'/',PM,'.c'],'file') |
---|
69 | disp(MEXSTRING); |
---|
70 | evalin('base',MEXSTRING); |
---|
71 | else |
---|
72 | disp([PM,'.c',' - NOT FOUND! SKIP']); |
---|
73 | end |
---|
74 | |
---|
75 | end |
---|
76 | |
---|
77 | cd(CURRENTDIR); |
---|
78 | |
---|
79 | |
---|
80 | |
---|