1function SuiteSparse_install (do_demo)
2%SuiteSparse_install: compiles and installs all of SuiteSparse
3% A Suite of Sparse matrix packages, authored or co-authored by Tim Davis.
4%
5% Packages in SuiteSparse:
6%
7% GraphBLAS      graph algorithms via sparse linear algebra (graphblas.org)
8% Mongoose       graph partitioner
9% SLIP_LU        solve sparse Ax=b exactly
10% UMFPACK        sparse LU factorization (multifrontal)
11% CHOLMOD        sparse Cholesky factorization, and many other operations
12% AMD            sparse symmetric approximate minimum degree ordering
13% COLAMD         sparse column approximate minimum degree ordering
14% CAMD           constrained AMD
15% CCOLAMD        constrained COLAMD
16% CSparse        a Concise Sparse matrix package (32-bit or 64-bit, real only)
17% CXSparse       extended version of CSparse (32-bit/64-bit/real/complex)
18% ssget          interface to SuiteSparse Matrix Collection
19% KLU            sparse LU factorization (left-looking)
20% BTF            permutation to block triangular form (like dmperm)
21% LDL            sparse LDL' factorization
22% SuiteSparseCollection   tools for managing the SuiteSparse Matrix Collection
23% RBio           read/write Rutherford/Boeing files
24% SSMULT         sparse matrix times sparse matrix
25% MESHND         2D and 3D regular mesh generation and nested dissection
26% FACTORIZE      an object-oriented solver for x=A\b
27% SPARSEINV      sparse inverse subset; computes entries of inv(sparse(A))
28% MATLAB_Tools   various simple m-files and demos
29% SuiteSparseQR  sparse QR factorization
30% spqr_rank      MATLAB toolbox for sparse rank deficient matrices
31%
32% Example:
33%    SuiteSparse_install        % compile and prompt to run each package's demo
34%    SuiteSparse_install(0)     % compile but do not run the demo
35%    SuiteSparse_install(1)     % compile and run the demos with no prompts
36%    help SuiteSparse           % for more details
37%
38% See also AMD, COLAMD, CAMD, CCOLAMD, CHOLMOD, UMFPACK, CSPARSE, CXSPARSE,
39%      ssget, RBio, SuiteSparseCollection, KLU, BTF, MESHND, SSMULT, LINFACTOR,
40%      SPOK, SPQR_RANK, SuiteSparse, SPQR, PATHTOOL, PATH, FACTORIZE,
41%      SPARSEINV, Mongoose, GraphBLAS, SLIP_LU.
42%
43% This script installs the full-featured CXSparse rather than CSparse.
44%
45% If you get errors building or using METIS, just remove the metis-5.1.0
46% folder.  This often occurs on Windows.
47%
48% Copyright 1990-2020, Timothy A. Davis, http://suitesparse.com.
49% In collaboration with (in alphabetical order): Patrick Amestoy, David
50% Bateman, Jinhao Chen.  Yanqing Chen, Iain Duff, Les Foster, William Hager,
51% Scott Kolodziej, Chris Lourenco, Stefan Larimore, Erick Moreno-Centeno,
52% Ekanathan Palamadai, Sivasankaran Rajamanickam, Sanjay Ranka, Wissam
53% Sid-Lakhdar, Nuri Yeralan.
54
55%-------------------------------------------------------------------------------
56% initializations
57%-------------------------------------------------------------------------------
58
59paths = { } ;
60SuiteSparse = pwd ;
61
62% determine the MATLAB version (6.1, 6.5, 7.0, ...)
63v = version ;
64pc = ispc ;
65
66% print the introduction
67help SuiteSparse_install
68
69fprintf ('\nInstalling SuiteSparse for MATLAB version %s\n\n', v) ;
70failed = cell (1,0) ;
71
72% add SuiteSparse to the path
73paths = add_to_path (paths, SuiteSparse) ;
74
75%-------------------------------------------------------------------------------
76% compile and install the packages
77%-------------------------------------------------------------------------------
78
79% compile and install UMFPACK
80try
81    paths = add_to_path (paths, [SuiteSparse '/UMFPACK/MATLAB']) ;
82    umfpack_make ;
83catch me
84    disp (me.message) ;
85    fprintf ('UMFPACK not installed\n') ;
86    failed {end+1} = 'umfpack' ;
87end
88
89% compile and install CHOLMOD
90try
91    paths = add_to_path (paths, [SuiteSparse '/CHOLMOD/MATLAB']) ;
92    cholmod_make ;
93catch me
94    disp (me.message) ;
95    fprintf ('CHOLMOD not installed\n') ;
96    failed {end+1} = 'cholmod' ;
97end
98
99% compile and install AMD
100try
101    paths = add_to_path (paths, [SuiteSparse '/AMD/MATLAB']) ;
102    amd_make ;
103catch me
104    disp (me.message) ;
105    fprintf ('AMD not installed\n') ;
106    failed {end+1} = 'amd' ;
107end
108
109% compile and install COLAMD
110try
111    paths = add_to_path (paths, [SuiteSparse '/COLAMD/MATLAB']) ;
112    colamd_make ;
113catch me
114    disp (me.message) ;
115    fprintf ('COLAMD not installed\n') ;
116    failed {end+1} = 'colamd' ;
117end
118
119% compile and install CCOLAMD
120try
121    paths = add_to_path (paths, [SuiteSparse '/CCOLAMD/MATLAB']) ;
122    ccolamd_make ;
123catch me
124    disp (me.message) ;
125    fprintf ('CCOLAMD not installed\n') ;
126    failed {end+1} = 'ccolamd' ;
127end
128
129% compile and install CAMD
130try
131    paths = add_to_path (paths, [SuiteSparse '/CAMD/MATLAB']) ;
132    camd_make ;
133catch me
134    disp (me.message) ;
135    fprintf ('CAMD not installed\n') ;
136    failed {end+1} = 'camd' ;
137end
138
139% install ssget, unless it's already in the path
140try
141    % if this fails, then ssget is not yet installed
142    index = ssget ;
143    fprintf ('ssget already installed:\n') ;
144    which ssget
145catch
146    index = [ ] ;
147end
148if (isempty (index))
149    % ssget is not installed.  Use SuiteSparse/ssget
150    fprintf ('Installing SuiteSparse/ssget\n') ;
151    try
152        paths = add_to_path (paths, [SuiteSparse '/ssget']) ;
153    catch me
154        disp (me.message) ;
155        fprintf ('ssget not installed\n') ;
156        failed {end+1} = 'ssget' ;
157    end
158end
159
160% compile and install CXSparse
161try
162    paths = add_to_path (paths, [SuiteSparse '/CXSparse/MATLAB/Demo']) ;
163    paths = add_to_path (paths, [SuiteSparse '/CXSparse/MATLAB/CSparse']) ;
164    fprintf ('Compiling CXSparse:\n') ;
165    if (pc)
166	% Windows does not support ANSI C99 complex, which CXSparse requires
167	cs_make (1, 0) ;
168    else
169	cs_make (1) ;
170    end
171catch me
172    disp (me.message) ;
173    fprintf ('CXSparse not installed\n') ;
174    failed {end+1} = 'cxsparse' ;
175end
176
177% compile and install LDL
178try
179    paths = add_to_path (paths, [SuiteSparse '/LDL/MATLAB']) ;
180    ldl_make ;
181catch me
182    disp (me.message) ;
183    fprintf ('LDL not installed\n') ;
184    failed {end+1} = 'ldl' ;
185end
186
187% compile and install BTF
188try
189    paths = add_to_path (paths, [SuiteSparse '/BTF/MATLAB']) ;
190    btf_make ;
191catch me
192    disp (me.message) ;
193    fprintf ('BTF not installed\n') ;
194    failed {end+1} = 'btf' ;
195end
196
197% compile and install KLU
198try
199    paths = add_to_path (paths, [SuiteSparse '/KLU/MATLAB']) ;
200    klu_make ;
201catch me
202    disp (me.message) ;
203    fprintf ('KLU not installed\n') ;
204    failed {end+1} = 'klu' ;
205end
206
207% compile and install SuiteSparseQR
208try
209    if (pc)
210        fprintf ('Note that SuiteSparseQR will not compile with the lcc\n') ;
211        fprintf ('compiler provided with MATLAB on Windows\n') ;
212    end
213    paths = add_to_path (paths, [SuiteSparse '/SPQR/MATLAB']) ;
214    spqr_make ;
215catch me
216    disp (me.message) ;
217    fprintf ('SuiteSparseQR not installed\n') ;
218    failed {end+1} = 'spqr' ;
219end
220
221% compile and install RBio
222try
223    paths = add_to_path (paths, [SuiteSparse '/RBio/RBio']) ;
224    RBmake ;
225catch me
226    disp (me.message) ;
227    fprintf ('RBio not installed.\n') ;
228    failed {end+1} = 'rbio' ;
229end
230
231% install MATLAB_Tools/*
232try
233    paths = add_to_path (paths, [SuiteSparse '/MATLAB_Tools']) ;
234    paths = add_to_path (paths, [SuiteSparse '/MATLAB_Tools/Factorize']) ;
235    paths = add_to_path (paths, [SuiteSparse '/MATLAB_Tools/MESHND']) ;
236    paths = add_to_path (paths, [SuiteSparse '/MATLAB_Tools/LINFACTOR']) ;
237    paths = add_to_path (paths, [SuiteSparse '/MATLAB_Tools/find_components']) ;
238    paths = add_to_path (paths, [SuiteSparse '/MATLAB_Tools/GEE']) ;
239    paths = add_to_path (paths, [SuiteSparse '/MATLAB_Tools/shellgui']) ;
240    paths = add_to_path (paths, [SuiteSparse '/MATLAB_Tools/waitmex']) ;
241    paths = add_to_path (paths, [SuiteSparse '/MATLAB_Tools/spqr_rank']) ;
242    paths = add_to_path (paths, [SuiteSparse '/MATLAB_Tools/spqr_rank/SJget']) ;
243    fprintf ('MATLAB_Tools installed\n') ;
244catch me
245    disp (me.message) ;
246    fprintf ('MATLAB_Tools not installed\n') ;
247    failed {end+1} = 'matlab_tools' ;
248end
249
250% compile and install SuiteSparseCollection
251try
252    % do not try to compile with large-file I/O for MATLAB 6.5 or earlier
253    paths = add_to_path (paths, [SuiteSparse '/MATLAB_Tools/SuiteSparseCollection']) ;
254    ss_install (verLessThan ('matlab', '7.0')) ;
255catch me
256    disp (me.message) ;
257    fprintf ('SuiteSparseCollection not installed\n') ;
258    failed {end+1} = 'SuiteSparseCollection' ;
259end
260
261% compile and install SSMULT
262try
263    paths = add_to_path (paths, [SuiteSparse '/MATLAB_Tools/SSMULT']) ;
264    ssmult_install ;
265catch me
266    disp (me.message) ;
267    fprintf ('SSMULT not installed\n') ;
268    failed {end+1} = 'ssmult' ;
269end
270
271% compile and install dimacs10
272try
273    paths = add_to_path (paths, [SuiteSparse '/MATLAB_Tools/dimacs10']) ;
274    dimacs10_install (0) ;
275catch me
276    disp (me.message) ;
277    fprintf ('MATLAB_Tools/dimacs10 not installed\n') ;
278    failed {end+1} = 'dimacs10' ;
279end
280
281% compile and install spok
282try
283    paths = add_to_path (paths, [SuiteSparse '/MATLAB_Tools/spok']) ;
284    spok_install ;
285catch me
286    disp (me.message) ;
287    fprintf ('MATLAB_Tools/spok not installed\n') ;
288    failed {end+1} = 'spok' ;
289end
290
291%{
292% compile and install PIRO_BAND
293try
294    paths = add_to_path (paths, [SuiteSparse '/PIRO_BAND/MATLAB']) ;
295    piro_band_make ;
296catch me
297    disp (me.message) ;
298    fprintf ('PIRO_BAND not installed\n') ;
299end
300%}
301
302% compile and install sparsinv
303try
304    paths = add_to_path (paths, [SuiteSparse '/MATLAB_Tools/sparseinv']) ;
305    sparseinv_install ;
306catch me
307    disp (me.message) ;
308    fprintf ('MATLAB_Tools/sparseinv not installed\n') ;
309    failed {end+1} = 'sparseinv' ;
310end
311
312% compile and install Mongoose
313try
314    paths = add_to_path (paths, [SuiteSparse '/Mongoose/MATLAB']) ;
315    mongoose_make (0) ;
316catch me
317    disp (me.message) ;
318    fprintf ('Mongoose not installed\n') ;
319    failed {end+1} = 'mongoose' ;
320end
321
322% compile and install GraphBLAS
323try
324    paths = add_to_path (paths, [SuiteSparse '/GraphBLAS/build']) ;
325    paths = add_to_path (paths, [SuiteSparse '/GraphBLAS/GraphBLAS/demo']) ;
326    paths = add_to_path (paths, [SuiteSparse '/GraphBLAS/GraphBLAS']) ;
327    cd ('@GrB/private') ;
328    gbmake ;
329catch me
330    disp (me.message) ;
331    fprintf ('GraphBLAS not installed\n') ;
332    failed {end+1} = 'GraphBLAS' ;
333end
334
335% compile and install SLIP_LU
336try
337    paths = add_to_path (paths, [SuiteSparse '/SLIP_LU/MATLAB']) ;
338    SLIP_install (do_demo) ;
339catch me
340    disp (me.message) ;
341    fprintf ('SLIP_LU not installed\n') ;
342    failed {end+1} = 'SLIP_LU' ;
343end
344
345%-------------------------------------------------------------------------------
346% post-install wrapup
347%-------------------------------------------------------------------------------
348
349cd (SuiteSparse)
350fprintf ('SuiteSparse is now installed.\n\n') ;
351
352nfail = length (failed) ;
353if (nfail > 0)
354    fprintf ('packages not installed: ') ;
355    for k = 1:nfail
356        fprintf ('%s ', failed {k}) ;
357    end
358    fprintf ('\n') ;
359end
360
361% run the demo, if requested
362if (nargin < 1)
363    % ask if demo should be run
364    y = input ('Hit enter to run the SuiteSparse demo (or "n" to quit): ', 's');
365    if (isempty (y))
366        y = 'y' ;
367    end
368    do_demo = (y (1) ~= 'n') ;
369    do_pause = true ;
370else
371    % run the demo without pausing
372    do_pause = false ;
373end
374if (do_demo)
375    try
376	SuiteSparse_demo ([ ], do_pause) ;
377    catch me
378        disp (me.message) ;
379	fprintf ('SuiteSparse demo failed\n') ;
380    end
381end
382
383% print the list of new directories added to the path
384fprintf ('\nSuiteSparse installation is complete.  The following paths\n') ;
385fprintf ('have been added for this session.  Use pathtool to add them\n') ;
386fprintf ('permanently.  If you cannot save the new path because of file\n');
387fprintf ('permissions, then add these commands to your startup.m file.\n') ;
388fprintf ('Type "doc startup" and "doc pathtool" for more information.\n\n') ;
389for k = 1:length (paths)
390    fprintf ('addpath %s\n', paths {k}) ;
391end
392cd (SuiteSparse)
393
394fprintf ('\nSuiteSparse for MATLAB %s installation complete\n', v) ;
395
396%-------------------------------------------------------------------------------
397function paths = add_to_path (paths, newpath)
398% add a path
399cd (newpath) ;
400addpath (newpath) ;
401paths = [paths { newpath } ] ;
402