-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile_msndfile.m
95 lines (80 loc) · 2.63 KB
/
compile_msndfile.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
function compile_msndfile(varargin)
% COMPILE_MSNDFILE Compile msndfile.
%
% COMPILE_MSNDFILE will compile the msndfile suite of Mex extensions and copy
% the resulting binaries into the package directory '+msndfile'.
%
% Input parameters
% ----------------
%
% COMPILE_MSNDFILE has the following options (passed as parameter/value pairs):
%
% Name | Type | Description | Default
% ==================================================================================
% Debug | logical | whether to build msndfile with debug symbols | false
% Destdir | char | where to install the package directory | '.'
% PkgDir | char | the name of the package directory | '+msndfile'
%
%% input parsing
%
p = inputParser();
p.addParamValue('Debug' , false , @islogical);
p.addParamValue('Destdir' , '.' , @(x) ischar(x) && isdir(x));
p.addParamValue('PkgDir' , '+msndfile' , @ischar);
p.parse(varargin{:});
%
%% build variables
%
% define whether to create a debug build
do_debug = p.Results.Debug;
% the installation prefix
inst_prefix = p.Results.Destdir;
% the name of the package directory
pkg_dir = p.Results.PkgDir;
%
%% compile
%
mex_opts = '';
if ~verLessThan('matlab', '7.1')
mex_opts = [mex_opts ' -largeArrayDims'];
end
% -fno-reorder-blocks needed with GCC >= 4.5, otherwise Matlab crashes
extra_flags = '-std=c11 -fno-reorder-blocks';
src_dir = 'src/+msndfile';
% the build directory
if do_debug
mex_opts = [mex_opts ' -g'];
build_prefix = 'debug';
else
build_prefix = 'build';
end
out_dir = [build_prefix '/' pkg_dir];
src1 = [src_dir '/read.c ' ...
src_dir '/utils.c ' ...
src_dir '/read_utils.c'];
src2 = [src_dir '/blockread.c ' ...
src_dir '/utils.c ' ...
src_dir '/audio_files.c'];
if ispc
cmd1 = ['mex ' mex_opts ' -LWin -l''sndfile-1'' -IWin ' src1 ' -outdir ' out_dir ' COMPFLAGS="$COMPFLAGS ' extra_flags '"'];
cmd2 = ['mex ' mex_opts ' -LWin -l''sndfile-1'' -IWin ' src2 ' -outdir ' out_dir ' COMPFLAGS="$COMPFLAGS ' extra_flags '"'];
else
cmd1 = ['mex ' mex_opts ' -lsndfile ' src1 ' -outdir ' out_dir ' CFLAGS="\$CFLAGS ' extra_flags '"'];
cmd2 = ['mex ' mex_opts ' -lsndfile ' src2 ' -outdir ' out_dir ' CFLAGS="\$CFLAGS ' extra_flags '"'];
end
if ~exist(out_dir, 'dir')
mkdir('.', out_dir);
end
eval(cmd1);
eval(cmd2);
%
%% install
%
install_dir = [inst_prefix '/' pkg_dir];
copyfile(out_dir, install_dir);
copyfile([src_dir '/*.m'], install_dir);
if ispc
disp('Copying libsndfile...');
copyfile('Win/libsndfile-1.dll', install_dir);
end
disp('Done!');