forked from MTG/essentia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wscript
137 lines (97 loc) · 4.05 KB
/
wscript
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import platform
APPNAME = 'essentia'
VERSION = open('VERSION', 'r').read().strip('\n')
top = '.'
out = 'build'
def options(ctx):
ctx.load('compiler_cxx compiler_c')
ctx.recurse('src')
ctx.add_option('--with-cpptests', action='store_true',
dest='WITH_CPPTESTS', default=False,
help='build the c++ tests')
ctx.add_option('--mode', action='store',
dest='MODE', default="release",
help='debug or release')
def configure(ctx):
print('→ configuring the project in ' + ctx.path.abspath())
ctx.env.VERSION = VERSION
ctx.env.WITH_CPPTESTS = ctx.options.WITH_CPPTESTS
# compiler flags
ctx.env.CXXFLAGS = [ '-pipe', '-Wall' ]
# define this to be stricter, but sometimes some libraries can give problems...
#ctx.env.CXXFLAGS += [ '-Werror' ]
if ctx.options.MODE == 'debug':
print ('→ Building in debug mode')
ctx.env.CXXFLAGS += [ '-g' ]
elif ctx.options.MODE == 'release':
print ('→ Building in release mode')
ctx.env.CXXFLAGS += [ '-O2' ] # '-march=native' ] # '-msse3', '-mfpmath=sse' ]
else:
raise ValueError('mode should be either "debug" or "release"')
# required if we want to use libessentia.a to be linked in the python bindings
# (dynamic library, needs -fPIC)
ctx.env.CXXFLAGS += [ '-fPIC' ]
# global defines
ctx.env.DEFINES = []
if sys.platform == 'darwin':
# force the use of clang as compiler, we don't want gcc anymore on mac
ctx.env.CC = 'clang'
ctx.env.CXX = 'clang++'
ctx.env.DEFINES += [ 'GTEST_HAS_TR1_TUPLE=0' ]
ctx.env.CXXFLAGS = [ '-stdlib=libc++', '-std=c++11', '-Wno-gnu' ]
ctx.env.LINKFLAGS = [ '-stdlib=libc++' ]
# for defining static const variables in header
ctx.env.CXXFLAGS += [ '-Wno-static-float-init' ]
# add /usr/local/include as the brew formula for yaml doesn't have
# the cflags properly set
ctx.env.CXXFLAGS += [ '-I/usr/local/include' ]
ctx.load('compiler_cxx compiler_c')
# write pkg-config file
prefix = os.path.normpath(ctx.options.prefix)
opts = { 'prefix': prefix,
'version': ctx.env.VERSION,
}
pcfile = '''prefix=%(prefix)s
libdir=${prefix}/lib
includedir=${prefix}/include
Name: libessentia
Description: audio analysis library -- development files
Version: %(version)s
Libs: -L${libdir} -lfftw3 -lyaml -lavcodec -lavformat -lavutil -lsamplerate -ltag -lfftw3f -lgaia2
Cflags: -I${includedir}/essentia I${includedir}/essentia/scheduler I${includedir}/essentia/streaming I${includedir}/essentia/utils
''' % opts
pcfile = '\n'.join([ l.strip() for l in pcfile.split('\n') ])
ctx.env.pcfile = pcfile
#open('build/essentia.pc', 'w').write(pcfile) # we'll do it later on the build stage
ctx.recurse('src')
def adjust(objs, path):
return [ '%s/%s' % (path, obj) for obj in objs ]
def build(ctx):
print('→ building from ' + ctx.path.abspath())
ctx.recurse('src')
if ctx.env.WITH_CPPTESTS:
# missing -lpthread flag on Ubuntu
if platform.dist()[0] == 'Ubuntu':
ext_paths = ['/usr/lib/i386-linux-gnu', '/usr/lib/x86_64-linux-gnu']
ctx.read_shlib('pthread', paths=ext_paths)
ctx.env.USES += ' pthread'
ctx.program(
source = ctx.path.ant_glob('test/src/basetest/*.cpp test/3rdparty/gtest-1.6.0/src/gtest-all.cc '),
target = 'basetest',
includes = [ 'test/3rdparty/gtest-1.6.0/include',
'test/3rdparty/gtest-1.6.0' ] + adjust(ctx.env.INCLUDES, 'src'),
install_path = None,
use = 'essentia ' + ctx.env.USES
)
def run_tests(ctx):
os.system(out + '/basetest')
def run_python_tests(ctx):
os.system('python test/src/unittest/all_tests.py')
def ipython(ctx):
os.system('ipython --pylab')
def doc(ctx):
os.system('doc/build_sphinx_doc.sh')