1function [objfiles, timestamp] = cs_make (f, docomplex)
2%CS_MAKE compiles CXSparse for use in MATLAB.
3%   Usage:
4%       cs_make
5%       [objfiles, timestamp] = cs_make (f, docomplex)
6%
7%   With no input arguments, or with f=0, only those files needing to be
8%   compiled are compiled (like the "make" command, but not
9%   requiring "make").  If f is a nonzero number, all files are compiled.
10%   If f is a string, only that mexFunction is compiled.  For example,
11%   cs_make ('cs_add') just compiles the cs_add mexFunction.  This option is
12%   useful when developing a single new mexFunction.  This function can only be
13%   used if the current directory is CXSparse/MATLAB/CSparse.  Returns a list of
14%   the object files in CXSparse, and the latest modification time of any source
15%   codes.
16%
17%   NOTE: if your compiler does not support the ANSI C99 complex type (most
18%   notably Microsoft Windows), the CXSparse mexFunctions will not support
19%   complex sparse matrices.  The complex case is not attempted if docomplex is
20%   zero.
21%
22%   To add a new function and its MATLAB mexFunction to CXSparse:
23%
24%       (1) Create a source code file CXSparse/Source/cs_mynewfunc.c.
25%       (2) Create a help file, CXSparse/MATLAB/CSparse/cs_mynewfunc.m.
26%           This is very useful, but not strictly required.
27%       (3) Add the prototype of cs_mynewfunc to CXSparse/Include/cs.h.
28%       (4) Create its MATLAB mexFunction, CXSparse/MATLAB/cs_mynewfunc_mex.c.
29%       (5) Edit cs_make.m, and add 'cs_mynewfunc' to the 'cs' and 'csm' lists.
30%       (6) Type 'cs_make' in the CXSparse/MATLAB/CSparse directory.
31%           If all goes well, your new function is ready for use in MATLAB.
32%
33%       (7) Optionally add 'cs_mynewfunc' to CXSparse/Source/Makefile
34%           and CXSparse/MATLAB/CSparse/Makefile, if you want to use the
35%           make command instead of cs_make.m.  See where
36%           'cs_add' and 'cs_add_mex' appear in those files, and add
37%           'cs_mynewfunc' accordingly.
38%       (8) Optionally add 'cs_mynewfunc' to Tcov/Makefile, and add additional
39%           test code to cs_test.c, and add MATLAB test code to MATLAB/Test/*.
40%
41%   Example:
42%       cs_make                  % compile everything
43%       cs_make ('cs_chol') ;    % just compile cs_chol mexFunction
44%
45%   See also MEX.
46
47% Copyright 2006-2012, Timothy A. Davis, http://www.suitesparse.com
48
49if (nargin < 1)
50    f = 0 ;
51end
52if (nargin < 2)
53    docomplex = 1 ;
54end
55
56try
57    % ispc does not appear in MATLAB 5.3
58    pc = ispc ;
59catch
60    % if ispc fails, assume we are on a Windows PC if it's not unix
61    pc = ~isunix ;
62end
63
64if (pc)
65    docomplex = 0 ;
66end
67
68if (docomplex == 0)
69    % do not attempt to compile with complex matrices
70    [objfiles, timestamp] = cs_make_helper (f, 0) ;
71else
72    try
73        % try with complex support
74        [objfiles, timestamp] = cs_make_helper (f, 1) ;
75    catch me
76        % oops - that failed, try without complex support
77        disp (me.message)
78        fprintf ('retrying without complex matrix support\n') ;
79        [objfiles, timestamp] = cs_make_helper (f, 0) ;
80    end
81end
82
83if (f > 0)
84    fprintf ('CXSparse successfully installed.\n') ;
85end
86
87