%DIPMEX   Compile a MEX-file that uses DIPlib
%
% SYNOPSIS:
%  dipmex filename.c
%  dipmex('filename.c')
%
% NOTES:
%  This function uses the MEX function, which first needs to
%  be configured by
%     mex -setup
%
%  If your MEX-file is composed of more than one C-file, or
%  if you need to link other external libraries, look the code
%  in this file and adjust where necessary.

% Cris Luengo, July 2004.
% 24 February 2005: Added Win32 compilation
% 13 July 2007:     Defining DML_HAS_MWSIZE for newer MATLAB versions.
% 5 January 2008:   Changes to work with new DML naming.
% 4 June 2008:      Added to DIPimage toolbox.

function dipmex(filename)
if nargin<0 | ~ischar(filename)
   error('filename expected');
end
dml = dip_dmllibfile;
[dippath,dml] = fileparts(dml);
dippath = fileparts(dippath);
dml = dml(4:end);
if matlabversion>=7.3
   mxopt = '-DDML_HAS_MWSIZE';
else
   mxopt = '-DTHIS_IS_A_ZERO_STATEMENT';
end
if ispc
   mex(filename,fullfile(dippath,'lib',['lib',dml,'.lib']),...
                fullfile(dippath,'lib','libdipio.lib'),...
                fullfile(dippath,'lib','libdip.lib'),...
                ['-I"',fullfile(dippath,'include',''),'"'],...
                '-DWIN32',mxopt);
else
   mex(filename,['-l',dml],'-ldipio','-ldip',...
       ['-L',fullfile(dippath,'lib')],...
       ['-I',fullfile(dippath,'include')],...
       mxopt);
end
