|
1 | | -function set_compiler_options(compiler_options) |
| 1 | +function success = set_compiler_options(compiler_options) |
2 | 2 | %Configure the compiler options by editing the mexopts files. It is hacky!!! |
3 | 3 |
|
4 | 4 | if ~isunix || ismac |
5 | 5 | error('Configuration of compiler options supports only Linux.') |
6 | 6 | end |
7 | 7 |
|
| 8 | +success = false; |
| 9 | + |
8 | 10 | mfilepath = fileparts(mfilename('fullpath')); % The directory containing this setup script |
9 | 11 |
|
10 | 12 | % Modify mexopts files in `config_dir` after making backups. |
11 | 13 | config_dir = fullfile(matlabroot, 'bin', 'glnxa64', 'mexopts'); |
12 | 14 | config_files = {dir(fullfile(config_dir, 'gfortran*.xml')).name}; |
13 | 15 | fileattrib(config_dir, '+w'); |
| 16 | +if ~iswritable(config_dir) |
| 17 | + warning('The directory %s is not writable. Compile options not set.', config_dir); |
| 18 | + return; |
| 19 | +end |
14 | 20 | for ifile = 1 : length(config_files) |
15 | 21 | cfile = fullfile(config_dir, config_files{ifile}); |
16 | 22 | fileattrib(cfile, '+w') |
| 23 | + if ~iswritable(cfile) |
| 24 | + warning('The file %s is not writable. Compile options not set.', cfile); |
| 25 | + return; |
| 26 | + end |
17 | 27 |
|
18 | 28 | cfile_orig = fullfile(config_dir, [config_files{ifile}, '.orig']); |
19 | 29 | if ~exist(cfile_orig, 'file') |
@@ -41,15 +51,22 @@ function set_compiler_options(compiler_options) |
41 | 51 | % We delete it so that MEX will be reconfigured according to `config_files`. |
42 | 52 | % Why not making a backup for it? Because the existing version may be generated using the modified |
43 | 53 | % `config_files` when this script was called the last time (N.B.: `mex_setup_file` does not exist |
44 | | -% in a fresh installation of MATLAB), in which case it would be wrong to store % this copy and |
| 54 | +% in a fresh installation of MATLAB), in which case it would be wrong to store this copy and |
45 | 55 | % restore `mex_setup_file` using it. |
46 | 56 | mex_setup_file = fullfile(prefdir, ['mex_FORTRAN_', computer('arch'), '.xml']); |
47 | 57 | if exist(mex_setup_file, 'file') |
48 | 58 | fileattrib(prefdir, '+w'); |
| 59 | + if ~iswritable(prefdir) |
| 60 | + warning('The directory %s is not writable. The modified compile options may not take effect.', prefdir); |
| 61 | + end |
49 | 62 | fileattrib(mex_setup_file, '+w'); |
| 63 | + if ~iswritable(mex_setup_file) |
| 64 | + warning('The file %s is not writable. The modified compile options may not take effect.', mex_setup_file); |
| 65 | + end |
50 | 66 | delete(mex_setup_file); |
51 | 67 | end |
52 | 68 |
|
53 | 69 | fprintf('\nCompiler options set to \n\n%s\n\n', compiler_options); |
| 70 | +success = true; |
54 | 71 |
|
55 | 72 | return |
0 commit comments