1 | #! /usr/bin/python |
---|
2 | # |
---|
3 | # usage: |
---|
4 | # $ python waf --help |
---|
5 | # |
---|
6 | # example: |
---|
7 | # $ ./waf distclean configure build |
---|
8 | # |
---|
9 | # Note: aubio uses the waf build system, which relies on Python. Provided you |
---|
10 | # have Python installed, you do *not* need to install anything to build aubio. |
---|
11 | # For more info about waf, see http://code.google.com/p/waf/ . |
---|
12 | |
---|
13 | APPNAME = 'aubio' |
---|
14 | |
---|
15 | # source VERSION |
---|
16 | for l in open('VERSION').readlines(): exec (l.strip()) |
---|
17 | |
---|
18 | VERSION = '.'.join ([str(x) for x in [ |
---|
19 | AUBIO_MAJOR_VERSION, |
---|
20 | AUBIO_MINOR_VERSION, |
---|
21 | AUBIO_PATCH_VERSION |
---|
22 | ]]) + AUBIO_VERSION_STATUS |
---|
23 | |
---|
24 | LIB_VERSION = '.'.join ([str(x) for x in [ |
---|
25 | LIBAUBIO_LT_CUR, |
---|
26 | LIBAUBIO_LT_REV, |
---|
27 | LIBAUBIO_LT_AGE]]) |
---|
28 | |
---|
29 | top = '.' |
---|
30 | out = 'build' |
---|
31 | |
---|
32 | def add_option_enable_disable(ctx, name, default = None, |
---|
33 | help_str = None, help_disable_str = None): |
---|
34 | if help_str == None: |
---|
35 | help_str = 'enable ' + name + ' support' |
---|
36 | if help_disable_str == None: |
---|
37 | help_disable_str = 'do not ' + help_str |
---|
38 | ctx.add_option('--enable-' + name, action = 'store_true', |
---|
39 | default = default, |
---|
40 | dest = 'enable_' + name.replace('-','_'), |
---|
41 | help = help_str) |
---|
42 | ctx.add_option('--disable-' + name, action = 'store_false', |
---|
43 | #default = default, |
---|
44 | dest = 'enable_' + name.replace('-','_'), |
---|
45 | help = help_disable_str ) |
---|
46 | |
---|
47 | def options(ctx): |
---|
48 | add_option_enable_disable(ctx, 'fftw3f', default = False, |
---|
49 | help_str = 'compile with fftw3f instead of ooura (recommended)', |
---|
50 | help_disable_str = 'do not compile with fftw3f') |
---|
51 | add_option_enable_disable(ctx, 'fftw3', default = False, |
---|
52 | help_str = 'compile with fftw3 instead of ooura', |
---|
53 | help_disable_str = 'do not compile with fftw3') |
---|
54 | add_option_enable_disable(ctx, 'complex', default = False, |
---|
55 | help_str ='compile with C99 complex', |
---|
56 | help_disable_str = 'do not use C99 complex (default)' ) |
---|
57 | add_option_enable_disable(ctx, 'jack', default = None, |
---|
58 | help_str = 'compile with jack (auto)', |
---|
59 | help_disable_str = 'disable jack support') |
---|
60 | add_option_enable_disable(ctx, 'sndfile', default = None, |
---|
61 | help_str = 'compile with sndfile (auto)', |
---|
62 | help_disable_str = 'disable sndfile') |
---|
63 | add_option_enable_disable(ctx, 'avcodec', default = None, |
---|
64 | help_str = 'compile with libavcodec (auto)', |
---|
65 | help_disable_str = 'disable libavcodec') |
---|
66 | add_option_enable_disable(ctx, 'samplerate', default = None, |
---|
67 | help_str = 'compile with samplerate (auto)', |
---|
68 | help_disable_str = 'disable samplerate') |
---|
69 | add_option_enable_disable(ctx, 'memcpy', default = True, |
---|
70 | help_str = 'use memcpy hacks (default)', |
---|
71 | help_disable_str = 'do not use memcpy hacks') |
---|
72 | add_option_enable_disable(ctx, 'double', default = False, |
---|
73 | help_str = 'compile in double precision mode', |
---|
74 | help_disable_str = 'compile in single precision mode (default)') |
---|
75 | |
---|
76 | ctx.add_option('--with-target-platform', type='string', |
---|
77 | help='set target platform for cross-compilation', dest='target_platform') |
---|
78 | |
---|
79 | ctx.load('compiler_c') |
---|
80 | ctx.load('waf_unit_test') |
---|
81 | ctx.load('gnu_dirs') |
---|
82 | |
---|
83 | def configure(ctx): |
---|
84 | from waflib import Options |
---|
85 | ctx.load('compiler_c') |
---|
86 | ctx.load('waf_unit_test') |
---|
87 | ctx.load('gnu_dirs') |
---|
88 | |
---|
89 | target_platform = Options.platform |
---|
90 | if ctx.options.target_platform: |
---|
91 | target_platform = ctx.options.target_platform |
---|
92 | ctx.env['DEST_OS'] = target_platform |
---|
93 | |
---|
94 | if 'CL.exe' not in ctx.env.CC[0]: |
---|
95 | ctx.env.CFLAGS += ['-g', '-Wall', '-Wextra'] |
---|
96 | else: |
---|
97 | ctx.env.CFLAGS += ['-Wall'] |
---|
98 | |
---|
99 | if target_platform not in ['win32', 'win64']: |
---|
100 | ctx.env.CFLAGS += ['-fPIC'] |
---|
101 | else: |
---|
102 | ctx.define('HAVE_WIN_HACKS', 1) |
---|
103 | ctx.env['cshlib_PATTERN'] = 'lib%s.dll' |
---|
104 | |
---|
105 | if target_platform == 'darwin': |
---|
106 | ctx.env.CFLAGS += ['-arch', 'i386', '-arch', 'x86_64'] |
---|
107 | ctx.env.LINKFLAGS += ['-arch', 'i386', '-arch', 'x86_64'] |
---|
108 | ctx.env.FRAMEWORK = ['CoreFoundation', 'AudioToolbox', 'Accelerate'] |
---|
109 | ctx.define('HAVE_ACCELERATE', 1) |
---|
110 | |
---|
111 | if target_platform in [ 'ios', 'iosimulator' ]: |
---|
112 | ctx.define('HAVE_ACCELERATE', 1) |
---|
113 | ctx.define('TARGET_OS_IPHONE', 1) |
---|
114 | ctx.env.FRAMEWORK = ['CoreFoundation', 'AudioToolbox', 'Accelerate'] |
---|
115 | SDKVER="7.0" |
---|
116 | MINSDKVER="6.1" |
---|
117 | ctx.env.CFLAGS += ['-std=c99'] |
---|
118 | if target_platform == 'ios': |
---|
119 | DEVROOT = "/Applications/Xcode.app/Contents" |
---|
120 | DEVROOT += "/Developer/Platforms/iPhoneOS.platform/Developer" |
---|
121 | SDKROOT = "%(DEVROOT)s/SDKs/iPhoneOS%(SDKVER)s.sdk" % locals() |
---|
122 | ctx.env.CFLAGS += [ '-arch', 'arm64' ] |
---|
123 | ctx.env.CFLAGS += [ '-arch', 'armv7' ] |
---|
124 | ctx.env.CFLAGS += [ '-arch', 'armv7s' ] |
---|
125 | ctx.env.LINKFLAGS += [ '-arch', 'arm64' ] |
---|
126 | ctx.env.LINKFLAGS += ['-arch', 'armv7'] |
---|
127 | ctx.env.LINKFLAGS += ['-arch', 'armv7s'] |
---|
128 | ctx.env.CFLAGS += [ '-miphoneos-version-min=' + MINSDKVER ] |
---|
129 | ctx.env.LINKFLAGS += [ '-miphoneos-version-min=' + MINSDKVER ] |
---|
130 | else: |
---|
131 | DEVROOT = "/Applications/Xcode.app/Contents" |
---|
132 | DEVROOT += "/Developer/Platforms/iPhoneSimulator.platform/Developer" |
---|
133 | SDKROOT = "%(DEVROOT)s/SDKs/iPhoneSimulator%(SDKVER)s.sdk" % locals() |
---|
134 | ctx.env.CFLAGS += [ '-arch', 'i386' ] |
---|
135 | ctx.env.CFLAGS += [ '-arch', 'x86_64' ] |
---|
136 | ctx.env.LINKFLAGS += ['-arch', 'i386'] |
---|
137 | ctx.env.LINKFLAGS += ['-arch', 'x86_64'] |
---|
138 | ctx.env.CFLAGS += [ '-mios-simulator-version-min=' + MINSDKVER ] |
---|
139 | ctx.env.LINKFLAGS += [ '-mios-simulator-version-min=' + MINSDKVER ] |
---|
140 | ctx.env.CFLAGS += [ '-isysroot' , SDKROOT] |
---|
141 | ctx.env.LINKFLAGS += [ '-isysroot' , SDKROOT] |
---|
142 | |
---|
143 | # check for required headers |
---|
144 | ctx.check(header_name='stdlib.h') |
---|
145 | ctx.check(header_name='stdio.h') |
---|
146 | ctx.check(header_name='math.h') |
---|
147 | ctx.check(header_name='string.h') |
---|
148 | ctx.check(header_name='limits.h') |
---|
149 | |
---|
150 | # check support for C99 __VA_ARGS__ macros |
---|
151 | check_c99_varargs = ''' |
---|
152 | #include <stdio.h> |
---|
153 | #define AUBIO_ERR(...) fprintf(stderr, __VA_ARGS__) |
---|
154 | ''' |
---|
155 | |
---|
156 | if ctx.check_cc(fragment = check_c99_varargs, |
---|
157 | type='cstlib', |
---|
158 | msg = 'Checking for C99 __VA_ARGS__ macro', |
---|
159 | mandatory = False): |
---|
160 | ctx.define('HAVE_C99_VARARGS_MACROS', 1) |
---|
161 | |
---|
162 | # double precision mode |
---|
163 | if (ctx.options.enable_double == True): |
---|
164 | ctx.define('HAVE_AUBIO_DOUBLE', 1) |
---|
165 | else: |
---|
166 | ctx.define('HAVE_AUBIO_DOUBLE', 0) |
---|
167 | |
---|
168 | # optionally use complex.h |
---|
169 | if (ctx.options.enable_complex == True): |
---|
170 | ctx.check(header_name='complex.h') |
---|
171 | |
---|
172 | # check for fftw3 |
---|
173 | if (ctx.options.enable_fftw3 != False or ctx.options.enable_fftw3f != False): |
---|
174 | # one of fftwf or fftw3f |
---|
175 | if (ctx.options.enable_fftw3f != False): |
---|
176 | ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0', |
---|
177 | args = '--cflags --libs', mandatory = False) |
---|
178 | if (ctx.options.enable_double == True): |
---|
179 | ctx.msg('Warning', 'fftw3f enabled, but compiling in double precision!') |
---|
180 | else: |
---|
181 | # fftw3f not enabled, take most sensible one according to enable_double |
---|
182 | if (ctx.options.enable_double == True): |
---|
183 | ctx.check_cfg(package = 'fftw3', atleast_version = '3.0.0', |
---|
184 | args = '--cflags --libs', mandatory = False) |
---|
185 | else: |
---|
186 | ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0', |
---|
187 | args = '--cflags --libs', mandatory = False) |
---|
188 | ctx.define('HAVE_FFTW3', 1) |
---|
189 | |
---|
190 | # fftw not enabled, use vDSP or ooura |
---|
191 | if 'HAVE_FFTW3F' in ctx.env.define_key: |
---|
192 | ctx.msg('Checking for FFT implementation', 'fftw3f') |
---|
193 | elif 'HAVE_FFTW3' in ctx.env.define_key: |
---|
194 | ctx.msg('Checking for FFT implementation', 'fftw3') |
---|
195 | elif 'HAVE_ACCELERATE' in ctx.env.define_key: |
---|
196 | ctx.msg('Checking for FFT implementation', 'vDSP') |
---|
197 | else: |
---|
198 | ctx.msg('Checking for FFT implementation', 'ooura') |
---|
199 | |
---|
200 | # check for libsndfile |
---|
201 | if (ctx.options.enable_sndfile != False): |
---|
202 | ctx.check_cfg(package = 'sndfile', atleast_version = '1.0.4', |
---|
203 | args = '--cflags --libs', mandatory = False) |
---|
204 | |
---|
205 | # check for libsamplerate |
---|
206 | if (ctx.options.enable_samplerate != False): |
---|
207 | ctx.check_cfg(package = 'samplerate', atleast_version = '0.0.15', |
---|
208 | args = '--cflags --libs', mandatory = False) |
---|
209 | |
---|
210 | # check for jack |
---|
211 | if (ctx.options.enable_jack != False): |
---|
212 | ctx.check_cfg(package = 'jack', |
---|
213 | args = '--cflags --libs', mandatory = False) |
---|
214 | |
---|
215 | # check for libav |
---|
216 | if (ctx.options.enable_avcodec != False): |
---|
217 | ctx.check_cfg(package = 'libavcodec', atleast_version = '54.35.0', |
---|
218 | args = '--cflags --libs', uselib_store = 'AVCODEC', mandatory = False) |
---|
219 | ctx.check_cfg(package = 'libavformat', atleast_version = '52.3.0', |
---|
220 | args = '--cflags --libs', uselib_store = 'AVFORMAT', mandatory = False) |
---|
221 | ctx.check_cfg(package = 'libavutil', atleast_version = '52.3.0', |
---|
222 | args = '--cflags --libs', uselib_store = 'AVUTIL', mandatory = False) |
---|
223 | ctx.check_cfg(package = 'libavresample', atleast_version = '1.0.1', |
---|
224 | args = '--cflags --libs', uselib_store = 'AVRESAMPLE', mandatory = False) |
---|
225 | if all ( 'HAVE_' + i in ctx.env.define_key |
---|
226 | for i in ['AVCODEC', 'AVFORMAT', 'AVUTIL', 'AVRESAMPLE'] ): |
---|
227 | ctx.define('HAVE_LIBAV', 1) |
---|
228 | ctx.msg('Checking for all libav libraries', 'yes') |
---|
229 | else: |
---|
230 | ctx.msg('Checking for all libav libraries', 'not found', color = 'YELLOW') |
---|
231 | |
---|
232 | ctx.define('HAVE_WAVREAD', 1) |
---|
233 | ctx.define('HAVE_WAVWRITE', 1) |
---|
234 | |
---|
235 | # use memcpy hacks |
---|
236 | if (ctx.options.enable_memcpy == True): |
---|
237 | ctx.define('HAVE_MEMCPY_HACKS', 1) |
---|
238 | else: |
---|
239 | ctx.define('HAVE_MEMCPY_HACKS', 0) |
---|
240 | |
---|
241 | # write configuration header |
---|
242 | ctx.write_config_header('src/config.h') |
---|
243 | |
---|
244 | # add some defines used in examples |
---|
245 | ctx.define('AUBIO_PREFIX', ctx.env['PREFIX']) |
---|
246 | ctx.define('PACKAGE', APPNAME) |
---|
247 | |
---|
248 | # check if txt2man is installed, optional |
---|
249 | try: |
---|
250 | ctx.find_program('txt2man', var='TXT2MAN') |
---|
251 | except ctx.errors.ConfigurationError: |
---|
252 | ctx.to_log('txt2man was not found (ignoring)') |
---|
253 | |
---|
254 | # check if doxygen is installed, optional |
---|
255 | try: |
---|
256 | ctx.find_program('doxygen', var='DOXYGEN') |
---|
257 | except ctx.errors.ConfigurationError: |
---|
258 | ctx.to_log('doxygen was not found (ignoring)') |
---|
259 | |
---|
260 | def build(bld): |
---|
261 | bld.env['VERSION'] = VERSION |
---|
262 | bld.env['LIB_VERSION'] = LIB_VERSION |
---|
263 | |
---|
264 | # add sub directories |
---|
265 | bld.recurse('src') |
---|
266 | if bld.env['DEST_OS'] not in ['ios', 'iosimulator']: |
---|
267 | pass |
---|
268 | if bld.env['DEST_OS'] not in ['ios', 'iosimulator', 'android']: |
---|
269 | bld.recurse('examples') |
---|
270 | bld.recurse('tests') |
---|
271 | |
---|
272 | bld( source = 'aubio.pc.in' ) |
---|
273 | |
---|
274 | # build manpages from txt files using txt2man |
---|
275 | if bld.env['TXT2MAN']: |
---|
276 | from waflib import TaskGen |
---|
277 | if 'MANDIR' not in bld.env: |
---|
278 | bld.env['MANDIR'] = bld.env['PREFIX'] + '/share/man' |
---|
279 | rule_str = '${TXT2MAN} -t `basename ${TGT} | cut -f 1 -d . | tr a-z A-Z`' |
---|
280 | rule_str += ' -r ${PACKAGE}\\ ${VERSION} -P ${PACKAGE}' |
---|
281 | rule_str += ' -v ${PACKAGE}\\ User\\\'s\\ manual' |
---|
282 | rule_str += ' -s 1 ${SRC} > ${TGT}' |
---|
283 | TaskGen.declare_chain( |
---|
284 | name = 'txt2man', |
---|
285 | rule = rule_str, |
---|
286 | ext_in = '.txt', |
---|
287 | ext_out = '.1', |
---|
288 | reentrant = False, |
---|
289 | install_path = '${MANDIR}/man1', |
---|
290 | ) |
---|
291 | bld( source = bld.path.ant_glob('doc/*.txt') ) |
---|
292 | |
---|
293 | # build documentation from source files using doxygen |
---|
294 | if bld.env['DOXYGEN']: |
---|
295 | bld( name = 'doxygen', rule = 'doxygen ${SRC} > /dev/null', |
---|
296 | source = 'doc/web.cfg', |
---|
297 | cwd = 'doc') |
---|
298 | bld.install_files( '${PREFIX}' + '/share/doc/libaubio-doc', |
---|
299 | bld.path.ant_glob('doc/web/html/**'), |
---|
300 | cwd = bld.path.find_dir ('doc/web'), |
---|
301 | relative_trick = True) |
---|
302 | |
---|
303 | def shutdown(bld): |
---|
304 | from waflib import Logs |
---|
305 | if bld.options.target_platform in ['ios', 'iosimulator']: |
---|
306 | msg ='building for %s, contact the author for a commercial license' % bld.options.target_platform |
---|
307 | Logs.pprint('RED', msg) |
---|
308 | msg =' Paul Brossier <piem@aubio.org>' |
---|
309 | Logs.pprint('RED', msg) |
---|
310 | |
---|
311 | def dist(ctx): |
---|
312 | ctx.excl = ' **/.waf-1* **/*~ **/*.pyc **/*.swp **/.lock-w* **/.git*' |
---|
313 | ctx.excl += ' **/build/*' |
---|
314 | ctx.excl += ' **/python/gen **/python/build **/python/dist' |
---|
315 | ctx.excl += ' **/**.zip **/**.tar.bz2' |
---|
316 | ctx.excl += ' **/doc/full/* **/doc/web/*' |
---|
317 | ctx.excl += ' **/python/*.db' |
---|
318 | ctx.excl += ' **/python.old/*' |
---|
319 | ctx.excl += ' **/python/tests/sounds' |
---|