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

« back to all changes in this revision

Viewing changes to CSparse/MATLAB/CSparse/cs_make.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] = cs_make (f)
 
1
function [objfiles, timestamp_out] = cs_make (f)
2
2
%CS_MAKE compiles CSparse for use in MATLAB.
3
3
%   Usage:
4
4
%       cs_make
19
19
%       (1) Create a source code file CSparse/Source/cs_mynewfunc.c.
20
20
%       (2) Create a help file, CSparse/MATLAB/CSparse/cs_mynewfunc.m.
21
21
%           This is very useful, but not strictly required.
22
 
%       (3) Add the prototype of cs_mynewfunc to CSparse/Source/cs.h.
 
22
%       (3) Add the prototype of cs_mynewfunc to CSparse/Include/cs.h.
23
23
%       (4) Create its MATLAB mexFunction, CSparse/MATLAB/cs_mynewfunc_mex.c.
24
24
%       (5) Edit cs_make.m, and add 'cs_mynewfunc' to the 'cs' and 'csm' lists.
25
25
%       (6) Type 'cs_make' in the CSparse/MATLAB/CSparse directory.
39
39
%
40
40
%   See also MEX.
41
41
 
42
 
%   Copyright 2006, Timothy A. Davis.
 
42
%   Copyright 2006-2007, Timothy A. Davis.
43
43
%   http://www.cise.ufl.edu/research/sparse
44
44
 
 
45
fprintf ('Compiling CSparse\n') ;
 
46
 
45
47
% CSparse source files, in ../../Source, such as ../../Source/cs_add.c.
46
48
% Note that not all CSparse source files have their own mexFunction.
47
49
cs = { 'cs_add', 'cs_amd', 'cs_chol', 'cs_cholsol', 'cs_counts', ...
56
58
    'cs_leaf', 'cs_randperm' } ;
57
59
    % add cs_mynewfunc to the above list
58
60
 
 
61
details = 1 ;
 
62
kk = 0 ;
59
63
csm = { } ;
60
64
if (nargin == 0)
61
65
    force = 0 ;
65
69
    csm = {f} ;
66
70
else
67
71
    force = f ;
68
 
    if (force)
 
72
    details = details | (force > 1) ;                                       %#ok
 
73
    if (force & details)                                                    %#ok
69
74
        fprintf ('cs_make: re-compiling everything\n') ;
70
75
    end
71
76
end
 
77
if (force)
 
78
    fprintf ('Compiling CSparse\n') ;
 
79
end
72
80
 
73
81
if (isempty (csm))
74
82
    % mexFunctions, of the form cs_add_mex.c, etc, in this directory
81
89
        % add cs_mynewfunc to the above list
82
90
end
83
91
 
84
 
if (ispc)
 
92
try
 
93
    % ispc does not appear in MATLAB 5.3
 
94
    pc = ispc ;
 
95
catch
 
96
    % if ispc fails, assume we are on a Windows PC if it's not unix
 
97
    pc = ~isunix ;
 
98
end
 
99
 
 
100
if (pc)
85
101
    obj = '.obj' ;
86
102
else
87
103
    obj = '.o' ;
88
104
end
89
105
 
90
 
srcdir = sprintf ('..%s..%sSource%s', filesep, filesep, filesep) ;
91
 
hfile = [srcdir 'cs.h'] ;
 
106
srcdir = '../../Source/' ;
 
107
hfile = '../../Include/cs.h' ;
92
108
 
93
109
% compile each CSparse source file
94
 
[anysrc timestamp] = compile_source ('', 'cs_mex', obj, hfile, force) ;
 
110
[anysrc timestamp kk] = compile_source ('', 'cs_mex', obj, hfile, force, ...
 
111
    kk, details) ;
95
112
CS = ['cs_mex' obj] ;
96
113
if (nargout > 0)
97
114
    objfiles = ['..' filesep 'CSparse' filesep 'cs_mex' obj] ;
98
115
end
99
116
for i = 1:length (cs)
100
 
    [s t] = compile_source (srcdir, cs {i}, obj, hfile, force) ;
 
117
    [s t kk] = compile_source (srcdir, cs {i}, obj, hfile, force, kk, details) ;
101
118
    timestamp = max (timestamp, t) ;
102
 
    anysrc = anysrc || s ;
103
 
    CS = [CS ' ' cs{i} obj] ;       %#ok
 
119
    anysrc = anysrc | s ;                                                   %#ok
 
120
    CS = [CS ' ' cs{i} obj] ;                                               %#ok
104
121
    if (nargout > 0)
105
122
        objfiles = [objfiles ' ..' filesep 'CSparse' filesep cs{i} obj] ;   %#ok
106
123
    end
111
128
for i = 1:length (csm)
112
129
    [s t] = cs_must_compile ('', csm{i}, '_mex', obj, hfile, force) ;
113
130
    timestamp = max (timestamp, t) ;
114
 
    if (anysrc || s)
115
 
        cmd = sprintf ('mex -O -I../../Source %s_mex.c %s -output %s\n', ...
 
131
    if (anysrc | s)                                                         %#ok
 
132
        cmd = sprintf ('mex -O -I../../Include %s_mex.c %s -output %s', ...
116
133
            csm{i}, CS, csm{i}) ;
117
 
        fprintf ('%s', cmd) ;
118
 
        eval (cmd) ;
 
134
        kk = do_cmd (cmd, kk, details) ;
119
135
    end
120
136
end
121
137
 
 
138
fprintf ('\n') ;
 
139
if (nargout > 1)
 
140
    timestamp_out = timestamp ;
 
141
end
 
142
 
 
143
if (force)
 
144
    fprintf ('CSparse successfully compiled.\n') ;
 
145
end
 
146
 
122
147
%-------------------------------------------------------------------------------
123
 
function [s,t] = compile_source (srcdir, f, obj, hfile, force)
 
148
function [s,t,kk] = compile_source (srcdir, f, obj, hfile, force, kk, details)
124
149
% compile a source code file in ../../Source, leaving object file in
125
150
% this directory.
126
151
[s t] = cs_must_compile (srcdir, f, '', obj, hfile, force) ;
127
152
if (s)
128
 
    cmd = sprintf ('mex -O -c -I../../Source %s%s.c\n', srcdir, f) ;
129
 
    fprintf ('%s', cmd) ;
130
 
    eval (cmd) ;
131
 
end
 
153
    cmd = sprintf ('mex -O -c -I../../Include %s%s.c', srcdir, f) ;
 
154
    kk = do_cmd (cmd, kk, details) ;
 
155
end
 
156
 
 
157
%-------------------------------------------------------------------------------
 
158
function kk = do_cmd (s, kk, details)
 
159
%DO_CMD: evaluate a command, and either print it or print a "."
 
160
if (details)
 
161
    fprintf ('%s\n', s) ;
 
162
else
 
163
    if (mod (kk, 60) == 0)
 
164
        fprintf ('\n') ;
 
165
    end
 
166
    kk = kk + 1 ;
 
167
    fprintf ('.') ;
 
168
end
 
169
eval (s) ;