1
function [objfiles, timestamp_out] = cs_make_helper (f, docomplex)
2
%CS_MAKE_HELPER compiles CXSparse for use in MATLAB.
4
% [objfiles, timestamp] = cs_make (f, docomplex)
6
% With f=0, only those files needing to be
7
% compiled are compiled (like the Unix/Linux/GNU "make" command, but not
8
% requiring "make"). If f is a nonzero number, all files are compiled.
9
% If f is a string, only that mexFunction is compiled. For example,
10
% cs_make ('cs_add') just compiles the cs_add mexFunction. This option is
11
% useful when developing a single new mexFunction. This function can only be
12
% used if the current directory is CXSparse/MATLAB/CSparse. Returns a list of
13
% the object files in CXSparse, and the latest modification time of any source
16
% NOTE: if your compiler does not support the ANSI C99 complex type, the
17
% CXSparse mexFunctions will not support complex sparse matrices.
19
% To add a new function and its MATLAB mexFunction to CXSparse:
21
% (1) Create a source code file CXSparse/Source/cs_mynewfunc.c.
22
% (2) Create a help file, CXSparse/MATLAB/CSparse/cs_mynewfunc.m.
23
% This is very useful, but not strictly required.
24
% (3) Add the prototype of cs_mynewfunc to CXSparse/Include/cs.h.
25
% (4) Create its MATLAB mexFunction, CXSparse/MATLAB/cs_mynewfunc_mex.c.
26
% (5) Edit cs_make.m, and add 'cs_mynewfunc' to the 'cs' and 'csm' lists.
27
% (6) Type 'cs_make' in the CXSparse/MATLAB/CSparse directory.
28
% If all goes well, your new function is ready for use in MATLAB.
30
% (7) Optionally add 'cs_mynewfunc' to CXSparse/Source/Makefile
31
% and CXSparse/MATLAB/CSparse/Makefile, if you want to use the
32
% Unix/Linux/GNU make command instead of cs_make.m. See where
33
% 'cs_add' and 'cs_add_mex' appear in those files, and add
34
% 'cs_mynewfunc' accordingly.
35
% (8) Optionally add 'cs_mynewfunc' to Tcov/Makefile, and add additional
36
% test code to cs_test.c, and add MATLAB test code to MATLAB/Test/*.
39
% cs_make_helper (1,1) ; % compile everything
40
% cs_make ('cs_chol', 1) ; % just compile cs_chol mexFunction
44
% Copyright 2006-2007, Timothy A. Davis.
45
% http://www.cise.ufl.edu/research/sparse
47
mexcmd = 'mex -DCS_LONG -I../../../UFconfig' ;
48
if (~isempty (strfind (computer, '64')))
49
mexcmd = [mexcmd ' -largeArrayDims'] ;
57
mexcmd = [mexcmd ' -DNCOMPLEX'] ;
60
% CSparse source files, in ../../Source, such as ../../Source/cs_add.c.
61
% Note that not all CSparse source files have their own mexFunction.
62
cs = { 'cs_add', 'cs_amd', 'cs_chol', 'cs_cholsol', 'cs_counts', ...
63
'cs_cumsum', 'cs_dfs', 'cs_dmperm', 'cs_droptol', 'cs_dropzeros', ...
64
'cs_dupl', 'cs_entry', 'cs_etree', 'cs_fkeep', 'cs_gaxpy', 'cs_happly', ...
65
'cs_house', 'cs_ipvec', 'cs_load', 'cs_lsolve', 'cs_ltsolve', 'cs_lu', ...
66
'cs_lusol', 'cs_malloc', 'cs_maxtrans', 'cs_multiply', 'cs_norm', ...
67
'cs_permute', 'cs_pinv', 'cs_post', 'cs_print', 'cs_pvec', 'cs_qr', ...
68
'cs_qrsol', 'cs_scatter', 'cs_scc', 'cs_schol', 'cs_sqr', 'cs_symperm', ...
69
'cs_tdfs', 'cs_transpose', 'cs_compress', 'cs_updown', 'cs_usolve', ...
70
'cs_utsolve', 'cs_util', 'cs_reach', 'cs_spsolve', 'cs_ereach', ...
71
'cs_leaf', 'cs_randperm' } ;
72
% add cs_mynewfunc to the above list
80
fprintf ('cs_make: compiling ../../Source files and %s_mex.c\n', f) ;
85
details = details | (force > 1) ; %#ok
86
if (force & details) %#ok
87
fprintf ('cs_make: re-compiling everything\n') ;
92
% mexFunctions, of the form cs_add_mex.c, etc, in this directory
93
csm = { 'cs_add', 'cs_amd', 'cs_chol', 'cs_cholsol', 'cs_counts', ...
94
'cs_dmperm', 'cs_droptol', 'cs_etree', 'cs_gaxpy', 'cs_lsolve', ...
95
'cs_ltsolve', 'cs_lu', 'cs_lusol', 'cs_multiply', 'cs_permute', ...
96
'cs_print', 'cs_qr', 'cs_qrsol', 'cs_scc', 'cs_symperm', 'cs_thumb', ...
97
'cs_transpose', 'cs_sparse', 'cs_updown', 'cs_usolve', ...
98
'cs_utsolve', 'cs_randperm', 'cs_sqr' } ;
99
% add cs_mynewfunc to the above list
104
% ispc does not appear in MATLAB 5.3
107
% if ispc fails, assume we are on a Windows PC if it's not unix
117
srcdir = '../../Source/' ;
118
hfile = '../../Include/cs.h' ;
120
% compile each CSparse source file
121
[anysrc timestamp kk] = compile_source ('', 'cs_mex', obj, hfile, force, ...
122
mexcmd, kk, details) ;
123
CS = ['cs_mex' obj] ;
125
objfiles = ['..' filesep 'CSparse' filesep 'cs_mex' obj] ;
127
for i = 1:length (cs)
129
[s t kk] = compile_source (srcdir, cs{i}, obj, hfile, force, mexcmd, ...
131
timestamp = max (timestamp, t) ;
132
anysrc = anysrc | s ; %#ok
133
CS = [CS ' ' cs{i} obj] ; %#ok
135
objfiles = [objfiles ' ..' filesep 'CSparse' filesep cs{i} obj] ; %#ok
141
csrc = [ 'cs_cl_' csrc(4:end) ] ;
142
CS = [CS ' ' csrc obj] ; %#ok
144
objfiles = [objfiles ' ..' filesep 'CSparse' filesep csrc obj] ;%#ok
147
copyfile (['../../Source/' cs{i} '.c'], [csrc '.c'], 'f') ;
149
fprintf ('%s\n', ['cp -f ../../Source/' cs{i} '.c ' csrc '.c']);
151
cmd = sprintf ('%s -DCS_COMPLEX -O -c -I../../Include %s.c\n', ...
153
kk = do_cmd (cmd, kk, details) ;
159
% compile each CSparse mexFunction
161
for i = 1:length (csm)
162
[s t] = cs_must_compile ('', csm{i}, '_mex', obj, hfile, force) ;
163
timestamp = max (timestamp, t) ;
165
cmd = sprintf ('%s -O -I../../Include %s_mex.c %s -output %s\n', ...
166
mexcmd, csm{i}, CS, csm{i}) ;
167
kk = do_cmd (cmd, kk, details) ;
172
timestamp_out = timestamp ;
177
%-------------------------------------------------------------------------------
178
function [s,t,kk] = compile_source (srcdir, f, obj, hfile, force, mexcmd, ...
180
% compile a source code file in ../../Source, leaving object file in
182
[s t] = cs_must_compile (srcdir, f, '', obj, hfile, force) ;
184
cmd = sprintf ('%s -O -c -I../../Include %s%s.c\n', mexcmd, srcdir, f) ;
185
kk = do_cmd (cmd, kk, details) ;
188
%-------------------------------------------------------------------------------
189
function kk = do_cmd (s, kk, details)
190
%DO_CMD: evaluate a command, and either print it or print a "."
194
if (mod (kk, 60) == 0)