~logan/ubuntu/trusty/suitesparse/4.2.1-3ubuntu1

« back to all changes in this revision

Viewing changes to CXSparse/MATLAB/CSparse/private/cs_make_helper.m

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2007-05-29 09:36:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529093629-zowquo0b7slkk6nc
Tags: 3.0.0-2
* suitesparse builds properly twice in a row
* Bug fix: "suitesparse - FTBFS: Broken build depens: libgfortran1-dev",
  thanks to Bastian Blank (Closes: #426349).
* Bug fix: "suitesparse_3.0.0-1: FTBFS: build-depends on
  libgfortran1-dev", thanks to Steve Langasek (Closes: #426354).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function [objfiles, timestamp_out] = cs_make_helper (f, docomplex)
 
2
%CS_MAKE_HELPER compiles CXSparse for use in MATLAB.
 
3
%   Usage:
 
4
%       [objfiles, timestamp] = cs_make (f, docomplex)
 
5
%
 
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
 
14
%   codes.
 
15
%
 
16
%   NOTE: if your compiler does not support the ANSI C99 complex type, the
 
17
%   CXSparse mexFunctions will not support complex sparse matrices.
 
18
%
 
19
%   To add a new function and its MATLAB mexFunction to CXSparse:
 
20
%
 
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.
 
29
%
 
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/*.
 
37
%
 
38
%   Example:
 
39
%       cs_make_helper (1,1) ;      % compile everything
 
40
%       cs_make ('cs_chol', 1) ;    % just compile cs_chol mexFunction
 
41
%
 
42
%   See also MEX.
 
43
 
 
44
%   Copyright 2006-2007, Timothy A. Davis.
 
45
%   http://www.cise.ufl.edu/research/sparse
 
46
 
 
47
mexcmd = 'mex -DCS_LONG -I../../../UFconfig' ;
 
48
if (~isempty (strfind (computer, '64')))
 
49
    mexcmd = [mexcmd ' -largeArrayDims'] ;
 
50
end
 
51
 
 
52
if (nargin < 2)
 
53
    docomplex = 1 ;
 
54
end
 
55
 
 
56
if (~docomplex)
 
57
    mexcmd = [mexcmd ' -DNCOMPLEX'] ;
 
58
end
 
59
 
 
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
 
73
 
 
74
details = 1 ;
 
75
kk = 0 ;
 
76
csm = { } ;
 
77
if (nargin == 0)
 
78
    force = 0 ;
 
79
elseif (ischar (f))
 
80
    fprintf ('cs_make: compiling ../../Source files and %s_mex.c\n', f) ;
 
81
    force = 0 ;
 
82
    csm = {f} ;
 
83
else
 
84
    force = f ;
 
85
    details = details | (force > 1) ;                                       %#ok
 
86
    if (force & details)                                                    %#ok
 
87
        fprintf ('cs_make: re-compiling everything\n') ;
 
88
    end
 
89
end
 
90
 
 
91
if (isempty (csm))
 
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
 
100
end
 
101
 
 
102
 
 
103
try
 
104
    % ispc does not appear in MATLAB 5.3
 
105
    pc = ispc ;
 
106
catch
 
107
    % if ispc fails, assume we are on a Windows PC if it's not unix
 
108
    pc = ~isunix ;
 
109
end
 
110
 
 
111
if (pc)
 
112
    obj = '.obj' ;
 
113
else
 
114
    obj = '.o' ;
 
115
end
 
116
 
 
117
srcdir = '../../Source/' ;
 
118
hfile = '../../Include/cs.h' ;
 
119
 
 
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] ;
 
124
if (nargout > 0)
 
125
    objfiles = ['..' filesep 'CSparse' filesep 'cs_mex' obj] ;
 
126
end
 
127
for i = 1:length (cs)
 
128
 
 
129
    [s t kk] = compile_source (srcdir, cs{i}, obj, hfile, force, mexcmd, ...
 
130
        kk, details) ;
 
131
    timestamp = max (timestamp, t) ;
 
132
    anysrc = anysrc | s ;                                                   %#ok
 
133
    CS = [CS ' ' cs{i} obj] ;                                               %#ok
 
134
    if (nargout > 0)
 
135
        objfiles = [objfiles ' ..' filesep 'CSparse' filesep cs{i} obj] ;   %#ok
 
136
    end
 
137
 
 
138
    % complex version:
 
139
    if (docomplex)
 
140
        csrc = cs {i} ;
 
141
        csrc = [ 'cs_cl_' csrc(4:end) ] ;
 
142
        CS = [CS ' ' csrc obj] ;            %#ok
 
143
        if (nargout > 0)
 
144
            objfiles = [objfiles ' ..' filesep 'CSparse' filesep csrc obj] ;%#ok
 
145
        end
 
146
        if (s)
 
147
            copyfile (['../../Source/' cs{i} '.c'], [csrc '.c'], 'f') ;
 
148
            if (details)
 
149
                fprintf ('%s\n', ['cp -f ../../Source/' cs{i} '.c ' csrc '.c']);
 
150
            end
 
151
            cmd = sprintf ('%s -DCS_COMPLEX -O -c -I../../Include %s.c\n', ...
 
152
                mexcmd, csrc) ;
 
153
            kk = do_cmd (cmd, kk, details) ;
 
154
        end
 
155
    end
 
156
 
 
157
end
 
158
 
 
159
% compile each CSparse mexFunction
 
160
obj = ['.' mexext] ;
 
161
for i = 1:length (csm)
 
162
    [s t] = cs_must_compile ('', csm{i}, '_mex', obj, hfile, force) ;
 
163
    timestamp = max (timestamp, t) ;
 
164
    if (anysrc | s)                                                         %#ok
 
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) ;
 
168
    end
 
169
end
 
170
 
 
171
if (nargout > 1)
 
172
    timestamp_out = timestamp ;
 
173
end
 
174
 
 
175
fprintf ('\n') ;
 
176
 
 
177
%-------------------------------------------------------------------------------
 
178
function [s,t,kk] = compile_source (srcdir, f, obj, hfile, force, mexcmd, ...
 
179
    kk, details)
 
180
% compile a source code file in ../../Source, leaving object file in
 
181
% this directory.
 
182
[s t] = cs_must_compile (srcdir, f, '', obj, hfile, force) ;
 
183
if (s)
 
184
    cmd = sprintf ('%s -O -c -I../../Include %s%s.c\n', mexcmd, srcdir, f) ;
 
185
    kk = do_cmd (cmd, kk, details) ;
 
186
end
 
187
 
 
188
%-------------------------------------------------------------------------------
 
189
function kk = do_cmd (s, kk, details)
 
190
%DO_CMD: evaluate a command, and either print it or print a "."
 
191
if (details)
 
192
    fprintf ('%s', s) ;
 
193
else
 
194
    if (mod (kk, 60) == 0)
 
195
        fprintf ('\n') ;
 
196
    end
 
197
    kk = kk + 1 ;
 
198
    fprintf ('.') ;
 
199
end
 
200
eval (s) ;