1function grbcover (what) 2%GBCOVER compile ../Test/* for statement coverage testing 3% 4% This function compiles just the mexFunctions in ../Test. 5% It does not compile the GraphBLAS library itself. 6% 7% See also: grbcover_edit, grbmake 8 9% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 10% SPDX-License-Identifier: Apache-2.0 11 12if (ispc) 13 error ('The tests in Tcov are not ported to Windows') ; 14end 15 16% compile the mexFunctions 17 18if (nargin < 1) 19 what = '' ; 20end 21 22make_all = (isequal (what, 'all')) ; 23 24% get a list of the GraphBLAS mexFunctions 25mexfunctions = dir ('../Test/GB_mex_*.c') ; 26 27% remove GB_mex_tricount and GB_mex_bfs from the list of mexFunctions 28nmex = length (mexfunctions) ; 29for k = nmex:-1:1 30 if (isequal (mexfunctions (k).name, 'GB_mex_tricount.c')) || ... 31 (isequal (mexfunctions (k).name, 'GB_mex_bfs.c')) 32 mexfunctions (k) = [ ] ; 33 end 34end 35 36% list of C files to compile 37cfiles = [ dir('../Test/GB_mx_*.c') ; ... 38 dir('../Demo/Source/usercomplex.c') ; ... 39 dir('../Demo/Source/simple_*.c') ; ... 40 dir('../Demo/Source/random_matrix.c') ; ... 41 dir('../Demo/Source/wathen.c') ; ... 42 dir('../Demo/Source/mis_*.c') ; ... 43 dir('../Demo/Source/prand.c') ; ... 44 dir('../Demo/Source/*pagerank*.c') ; ... 45 dir('../Demo/Source/*rowscale.c') ; ... 46 dir('../Demo/Source/isequal.c') ; ... 47 dir('GB_cover_util.c') ; ] ; 48 49% list of *.h and template file dependencies 50hfiles = [ dir('../Test/*.h') ; ... 51 dir('../Test/Template/*.c') ] ; 52 53% list of include directories 54inc = '-Itmp_include -I../Test -I../Test/Template' ; 55 56need_rename = ~verLessThan ('matlab', '9.10') ; 57 58addpath ../Test 59addpath ../Test/spok 60 61flags = '-g -DGBCOVER -R2018a' ; 62if (need_rename) 63 flags = [flags ' -DGBRENAME=1 '] ; 64end 65 66fprintf ('\nCompiling GraphBLAS tests\nplease wait [') ; 67 68try 69 if (strncmp (computer, 'GLNX', 4)) 70 % remove -ansi from CFLAGS and replace it with -std=c11 71 cc = mex.getCompilerConfigurations ('C', 'Selected') ; 72 env = cc.Details.SetEnv ; 73 c1 = strfind (env, 'CFLAGS=') ; 74 q = strfind (env, '"') ; 75 q = q (q > c1) ; 76 if (~isempty (c1) && length (q) > 1) 77 c2 = q (2) ; 78 cflags = env (c1:c2) ; % the CFLAGS="..." string 79 ansi = strfind (cflags, '-ansi') ; 80 if (~isempty (ansi)) 81 cflags = [cflags(1:ansi-1) '-std=c11' cflags(ansi+5:end)] ; 82 flags = [flags ' ' cflags] ; 83 fprintf ('compiling with -std=c11 instead of default -ansi\n') ; 84 end 85 end 86 end 87end 88 89libraries = sprintf ('-L%s -lgraphblas_tcov', pwd) ; 90 91if (ismac) 92 % Mac (do 'make install' for GraphBLAS first) 93% flags = [ flags ' CFLAGS="$CXXFLAGS -Xpreprocessor -fopenmp" ' ] ; 94% flags = [ flags ' CXXFLAGS="$CXXFLAGS -Xpreprocessor -fopenmp" ' ] ; 95% flags = [ flags ' LDFLAGS="$LDFLAGS -fopenmp"' ] ; 96else 97 % Linux 98 flags = [ flags ' CFLAGS="$CXXFLAGS -fopenmp -fPIC -Wno-pragmas" '] ; 99 flags = [ flags ' CXXFLAGS="$CXXFLAGS -fopenmp -fPIC -Wno-pragmas" '] ; 100 flags = [ flags ' LDFLAGS="$LDFLAGS -fopenmp -fPIC" '] ; 101end 102 103dryrun = false ; 104 105% Find the last modification time of any hfile. 106% These are #include'd into source files. 107htime = 0 ; 108for k = 1:length (hfiles) 109 t = datenum (hfiles (k).date) ; 110 htime = max (htime, t) ; 111end 112 113% compile any source files that need compiling 114any_c_compiled = false ; 115objlist = '' ; 116for k = 1:length (cfiles) 117 118 % get the full cfile filename and modification time 119 cfile = [(cfiles (k).folder) filesep (cfiles (k).name)] ; 120 tc = datenum (cfiles(k).date) ; 121 122 % get the object file name 123 ofile = cfiles(k).name ; 124 objfile = [ ofile(1:end-2) '.o' ] ; 125 126 % get the object file modification time 127 ofiles {k} = objfile ; 128 objlist = [ objlist ' ' objfile ] ; 129 dobj = dir (objfile) ; 130 if (isempty (dobj)) 131 % there is no object file; the cfile must be compiled 132 tobj = 0 ; 133 else 134 tobj = datenum (dobj.date) ; 135 end 136 137 % compile the cfile if it is newer than its object file, or any hfile 138 if (make_all || tc > tobj || htime > tobj) 139 % compile the cfile 140 fprintf ('.') ; 141 % fprintf ('%s\n', cfile) ; 142 mexcmd = sprintf ('mex -c %s -silent %s %s', flags, inc, cfile) ; 143 if (dryrun) 144 fprintf ('%s\n', mexcmd) ; 145 else 146 eval (mexcmd) ; 147 end 148 any_c_compiled = true ; 149 end 150end 151 152if (ismac) 153 objlist = [objlist ' libgraphblas_tcov.dylib'] ; 154end 155 156% compile the mexFunctions 157for k = 1:length (mexfunctions) 158 159 % get the mexFunction filename and modification time 160 mexfunc = mexfunctions (k).name ; 161 mexfunction = [(mexfunctions (k).folder) filesep mexfunc] ; 162 tc = datenum (mexfunctions(k).date) ; 163 164 % get the compiled mexFunction modification time 165 mexfunction_compiled = [ mexfunc(1:end-2) '.' mexext ] ; 166 dobj = dir (mexfunction_compiled) ; 167 if (isempty (dobj)) 168 % there is no compiled mexFunction; it must be compiled 169 tobj = 0 ; 170 else 171 tobj = datenum (dobj.date) ; 172 end 173 174 % compile if it is newer than its object file, or if any cfile was compiled 175 if (make_all || tc > tobj || any_c_compiled) 176 % compile the mexFunction 177 mexcmd = sprintf ('mex -silent %s %s %s %s %s', ... 178 flags, inc, mexfunction, objlist, libraries) ; 179 fprintf ('.', mexfunction) ; 180 % fprintf ('%s\n', mexfunction) ; 181 if (dryrun) 182 fprintf ('%s\n', mexcmd) ; 183 else 184 eval (mexcmd) ; 185 end 186 end 187end 188 189fprintf (']\n') ; 190 191