7 # $ ./waf distclean configure build
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/ .
18 for l in open('VERSION').readlines(): exec (l.strip())
20 def get_git_revision_hash( short=True):
24 return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
26 fpath, fname = os.path.split(program)
31 for path in os.environ["PATH"].split(os.pathsep):
32 path = path.strip('"')
33 exe_file = os.path.join(path, program)
39 print('no git found on this system : can\'t get sha')
43 aubio_dir = os.path.abspath(os.curdir)
44 if not os.path.exists(aubio_dir):
45 raise SystemError("git / root folder not found")
46 gitcmd = ['git','-C',aubio_dir ,'rev-parse']
48 gitcmd.append('--short')
50 return str(subprocess.check_output(gitcmd).strip())
53 # append sha to version in alpha release
54 if AUBIO_VERSION_STATUS and '~alpha' in AUBIO_VERSION_STATUS :
55 AUBIO_GIT_SHA = get_git_revision_hash()
57 AUBIO_VERSION_STATUS = '~git'+AUBIO_GIT_SHA
62 VERSION = '.'.join ([str(x) for x in [
66 ]]) + AUBIO_VERSION_STATUS
68 LIB_VERSION = '.'.join ([str(x) for x in [
76 def add_option_enable_disable(ctx, name, default = None,
77 help_str = None, help_disable_str = None):
79 help_str = 'enable ' + name + ' support'
80 if help_disable_str == None:
81 help_disable_str = 'do not ' + help_str
82 ctx.add_option('--enable-' + name, action = 'store_true',
84 dest = 'enable_' + name.replace('-','_'),
86 ctx.add_option('--disable-' + name, action = 'store_false',
88 dest = 'enable_' + name.replace('-','_'),
89 help = help_disable_str )
92 ctx.add_option('--build-type', action = 'store',
94 choices = ('debug', 'release'),
96 help = 'whether to compile with (--build-type=release) or without (--build-type=debug) '\
97 ' compiler opimizations [default: release]')
98 add_option_enable_disable(ctx, 'fftw3f', default = False,
99 help_str = 'compile with fftw3f instead of ooura (recommended)',
100 help_disable_str = 'do not compile with fftw3f')
101 add_option_enable_disable(ctx, 'fftw3', default = False,
102 help_str = 'compile with fftw3 instead of ooura',
103 help_disable_str = 'do not compile with fftw3')
104 add_option_enable_disable(ctx, 'complex', default = False,
105 help_str ='compile with C99 complex',
106 help_disable_str = 'do not use C99 complex (default)' )
107 add_option_enable_disable(ctx, 'jack', default = None,
108 help_str = 'compile with jack (auto)',
109 help_disable_str = 'disable jack support')
110 add_option_enable_disable(ctx, 'sndfile', default = None,
111 help_str = 'compile with sndfile (auto)',
112 help_disable_str = 'disable sndfile')
113 add_option_enable_disable(ctx, 'avcodec', default = None,
114 help_str = 'compile with libavcodec (auto)',
115 help_disable_str = 'disable libavcodec')
116 add_option_enable_disable(ctx, 'samplerate', default = None,
117 help_str = 'compile with samplerate (auto)',
118 help_disable_str = 'disable samplerate')
119 add_option_enable_disable(ctx, 'memcpy', default = True,
120 help_str = 'use memcpy hacks (default)',
121 help_disable_str = 'do not use memcpy hacks')
122 add_option_enable_disable(ctx, 'double', default = False,
123 help_str = 'compile in double precision mode',
124 help_disable_str = 'compile in single precision mode (default)')
125 add_option_enable_disable(ctx, 'fat', default = False,
126 help_str = 'build fat binaries (darwin only)',
127 help_disable_str = 'do not build fat binaries (default)')
128 add_option_enable_disable(ctx, 'accelerate', default = None,
129 help_str = 'use Accelerate framework (darwin only) (auto)',
130 help_disable_str = 'do not use Accelerate framework')
131 add_option_enable_disable(ctx, 'apple-audio', default = None,
132 help_str = 'use CoreFoundation (darwin only) (auto)',
133 help_disable_str = 'do not use CoreFoundation framework')
134 add_option_enable_disable(ctx, 'atlas', default = False,
135 help_str = 'use Atlas library (no)',
136 help_disable_str = 'do not use Atlas library')
137 add_option_enable_disable(ctx, 'wavread', default = True,
138 help_str = 'compile with source_wavread (default)',
139 help_disable_str = 'do not compile source_wavread')
140 add_option_enable_disable(ctx, 'wavwrite', default = True,
141 help_str = 'compile with source_wavwrite (default)',
142 help_disable_str = 'do not compile source_wavwrite')
144 add_option_enable_disable(ctx, 'docs', default = None,
145 help_str = 'build documentation (auto)',
146 help_disable_str = 'do not build documentation')
148 ctx.add_option('--with-target-platform', type='string',
149 help='set target platform for cross-compilation', dest='target_platform')
151 ctx.load('compiler_c')
152 ctx.load('waf_unit_test')
156 from waflib import Options
157 ctx.load('compiler_c')
158 ctx.load('waf_unit_test')
161 # check for common headers
162 ctx.check(header_name='stdlib.h')
163 ctx.check(header_name='stdio.h')
164 ctx.check(header_name='math.h')
165 ctx.check(header_name='string.h')
166 ctx.check(header_name='limits.h')
167 ctx.check(header_name='stdarg.h')
168 ctx.check(header_name='getopt.h', mandatory = False)
169 ctx.check(header_name='unistd.h', mandatory = False)
171 target_platform = sys.platform
172 if ctx.options.target_platform:
173 target_platform = ctx.options.target_platform
174 ctx.env['DEST_OS'] = target_platform
176 ctx.define('AUBIO_VERSION',VERSION)
177 ctx.define('AUBIO_MAJOR_VERSION',AUBIO_MAJOR_VERSION)
178 ctx.define('AUBIO_MINOR_VERSION',AUBIO_MINOR_VERSION)
179 ctx.define('AUBIO_PATCH_VERSION',AUBIO_PATCH_VERSION)
180 ctx.define('AUBIO_VERSION_STATUS',AUBIO_VERSION_STATUS)
181 # ctx.define('AUBIO_GIT_SHA',AUBIO_GIT_SHA)
182 if ctx.options.build_type == "debug":
183 ctx.define('DEBUG', 1)
185 ctx.define('NDEBUG', 1)
187 if ctx.env.CC_NAME != 'msvc':
188 if ctx.options.build_type == "debug":
189 # no optimization in debug mode
190 ctx.env.prepend_value('CFLAGS', ['-O0'])
192 # default to -O2 in release mode
193 ctx.env.prepend_value('CFLAGS', ['-O2'])
194 # enable debug symbols and configure warnings
195 ctx.env.prepend_value('CFLAGS', ['-g', '-Wall', '-Wextra'])
197 # enable debug symbols
198 ctx.env.CFLAGS += ['/Z7', '/FS']
199 ctx.env.LINKFLAGS += ['/DEBUG', '/INCREMENTAL:NO']
201 ctx.env.CFLAGS += ['/W4', '/D_CRT_SECURE_NO_WARNINGS']
202 # set optimization level and runtime libs
203 if (ctx.options.build_type == "release"):
204 ctx.env.CFLAGS += ['/Ox']
205 ctx.env.CFLAGS += ['/MD']
207 assert(ctx.options.build_type == "debug")
208 ctx.env.CFLAGS += ['/MDd']
210 ctx.check_cc(lib='m', uselib_store='M', mandatory=False)
212 if target_platform not in ['win32', 'win64']:
213 ctx.env.CFLAGS += ['-fPIC']
215 ctx.define('HAVE_WIN_HACKS', 1)
216 ctx.env['cshlib_PATTERN'] = 'lib%s.dll'
218 if target_platform == 'darwin' and ctx.options.enable_fat:
219 ctx.env.CFLAGS += ['-arch', 'i386', '-arch', 'x86_64']
220 ctx.env.LINKFLAGS += ['-arch', 'i386', '-arch', 'x86_64']
222 ctx.env.CFLAGS += [ '-mmacosx-version-min=' + MINSDKVER ]
223 ctx.env.LINKFLAGS += [ '-mmacosx-version-min=' + MINSDKVER ]
225 if target_platform in [ 'darwin', 'ios', 'iosimulator']:
226 if (ctx.options.enable_apple_audio != False):
227 ctx.env.FRAMEWORK += ['CoreFoundation', 'AudioToolbox']
228 ctx.define('HAVE_SOURCE_APPLE_AUDIO', 1)
229 ctx.define('HAVE_SINK_APPLE_AUDIO', 1)
230 ctx.msg('Checking for AudioToolbox.framework', 'yes')
232 ctx.msg('Checking for AudioToolbox.framework', 'no (disabled)', color = 'YELLOW')
233 if (ctx.options.enable_accelerate != False):
234 ctx.define('HAVE_ACCELERATE', 1)
235 ctx.env.FRAMEWORK += ['Accelerate']
236 ctx.msg('Checking for Accelerate framework', 'yes')
238 ctx.msg('Checking for Accelerate framework', 'no (disabled)', color = 'YELLOW')
240 if target_platform in [ 'ios', 'iosimulator' ]:
242 ctx.env.CFLAGS += ['-std=c99']
243 if (ctx.options.enable_apple_audio != False):
244 ctx.define('HAVE_AUDIO_UNIT', 1)
245 #ctx.env.FRAMEWORK += ['CoreFoundation', 'AudioToolbox']
246 if target_platform == 'ios':
247 DEVROOT = "/Applications/Xcode.app/Contents"
248 DEVROOT += "/Developer/Platforms/iPhoneOS.platform/Developer"
249 SDKROOT = "%(DEVROOT)s/SDKs/iPhoneOS.sdk" % locals()
250 ctx.env.CFLAGS += [ '-fembed-bitcode' ]
251 ctx.env.CFLAGS += [ '-arch', 'arm64' ]
252 ctx.env.CFLAGS += [ '-arch', 'armv7' ]
253 ctx.env.CFLAGS += [ '-arch', 'armv7s' ]
254 ctx.env.LINKFLAGS += [ '-arch', 'arm64' ]
255 ctx.env.LINKFLAGS += ['-arch', 'armv7']
256 ctx.env.LINKFLAGS += ['-arch', 'armv7s']
257 ctx.env.CFLAGS += [ '-miphoneos-version-min=' + MINSDKVER ]
258 ctx.env.LINKFLAGS += [ '-miphoneos-version-min=' + MINSDKVER ]
260 DEVROOT = "/Applications/Xcode.app/Contents"
261 DEVROOT += "/Developer/Platforms/iPhoneSimulator.platform/Developer"
262 SDKROOT = "%(DEVROOT)s/SDKs/iPhoneSimulator.sdk" % locals()
263 ctx.env.CFLAGS += [ '-arch', 'i386' ]
264 ctx.env.CFLAGS += [ '-arch', 'x86_64' ]
265 ctx.env.LINKFLAGS += ['-arch', 'i386']
266 ctx.env.LINKFLAGS += ['-arch', 'x86_64']
267 ctx.env.CFLAGS += [ '-mios-simulator-version-min=' + MINSDKVER ]
268 ctx.env.LINKFLAGS += [ '-mios-simulator-version-min=' + MINSDKVER ]
269 ctx.env.CFLAGS += [ '-isysroot' , SDKROOT]
270 ctx.env.LINKFLAGS += [ '-isysroot' , SDKROOT]
272 if target_platform == 'emscripten':
274 ctx.env.CFLAGS += [ '-I' + os.path.join(os.environ['EMSCRIPTEN'], 'system', 'include') ]
275 ctx.env.CFLAGS += ['-Oz']
276 ctx.env.cprogram_PATTERN = "%s.js"
277 if (ctx.options.enable_atlas != True):
278 ctx.options.enable_atlas = False
280 # check support for C99 __VA_ARGS__ macros
281 check_c99_varargs = '''
283 #define AUBIO_ERR(...) fprintf(stderr, __VA_ARGS__)
286 if ctx.check_cc(fragment = check_c99_varargs,
288 msg = 'Checking for C99 __VA_ARGS__ macro',
290 ctx.define('HAVE_C99_VARARGS_MACROS', 1)
292 # show a message about enable_double status
293 if (ctx.options.enable_double == True):
294 ctx.msg('Checking for size of smpl_t', 'double')
295 ctx.msg('Checking for size of lsmp_t', 'long double')
297 ctx.msg('Checking for size of smpl_t', 'float')
298 ctx.msg('Checking for size of lsmp_t', 'double')
300 # optionally use complex.h
301 if (ctx.options.enable_complex == True):
302 ctx.check(header_name='complex.h')
304 ctx.msg('Checking if complex.h is enabled', 'no')
307 if (ctx.options.enable_fftw3 != False or ctx.options.enable_fftw3f != False):
308 # one of fftwf or fftw3f
309 if (ctx.options.enable_fftw3f != False):
310 ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0',
311 args = '--cflags --libs',
312 mandatory = ctx.options.enable_fftw3f)
313 if (ctx.options.enable_double == True):
315 'fftw3f enabled, but compiling in double precision!')
317 # fftw3f disabled, take most sensible one according to
319 if (ctx.options.enable_double == True):
320 ctx.check_cfg(package = 'fftw3', atleast_version = '3.0.0',
321 args = '--cflags --libs', mandatory =
322 ctx.options.enable_fftw3)
324 ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0',
325 args = '--cflags --libs',
326 mandatory = ctx.options.enable_fftw3)
327 ctx.define('HAVE_FFTW3', 1)
329 # fftw not enabled, use vDSP or ooura
330 if 'HAVE_FFTW3F' in ctx.env.define_key:
331 ctx.msg('Checking for FFT implementation', 'fftw3f')
332 elif 'HAVE_FFTW3' in ctx.env.define_key:
333 ctx.msg('Checking for FFT implementation', 'fftw3')
334 elif 'HAVE_ACCELERATE' in ctx.env.define_key:
335 ctx.msg('Checking for FFT implementation', 'vDSP')
337 ctx.msg('Checking for FFT implementation', 'ooura')
339 # check for libsndfile
340 if (ctx.options.enable_sndfile != False):
341 ctx.check_cfg(package = 'sndfile', atleast_version = '1.0.4',
342 args = '--cflags --libs',
343 mandatory = ctx.options.enable_sndfile)
345 # check for libsamplerate
346 if (ctx.options.enable_double):
347 if (ctx.options.enable_samplerate):
348 ctx.fatal("Could not compile aubio in double precision mode with libsamplerate")
350 ctx.options.enable_samplerate = False
351 ctx.msg('Checking if using samplerate', 'no (disabled in double precision mode)',
353 if (ctx.options.enable_samplerate != False):
354 ctx.check_cfg(package = 'samplerate', atleast_version = '0.0.15',
355 args = '--cflags --libs',
356 mandatory = ctx.options.enable_samplerate)
359 if (ctx.options.enable_jack != False):
360 ctx.check_cfg(package = 'jack',
361 args = '--cflags --libs',
362 mandatory = ctx.options.enable_jack)
365 if (ctx.options.enable_avcodec != False):
366 ctx.check_cfg(package = 'libavcodec', atleast_version = '54.35.0',
367 args = '--cflags --libs', uselib_store = 'AVCODEC',
368 mandatory = ctx.options.enable_avcodec)
369 ctx.check_cfg(package = 'libavformat', atleast_version = '52.3.0',
370 args = '--cflags --libs', uselib_store = 'AVFORMAT',
371 mandatory = ctx.options.enable_avcodec)
372 ctx.check_cfg(package = 'libavutil', atleast_version = '52.3.0',
373 args = '--cflags --libs', uselib_store = 'AVUTIL',
374 mandatory = ctx.options.enable_avcodec)
375 ctx.check_cfg(package = 'libavresample', atleast_version = '1.0.1',
376 args = '--cflags --libs', uselib_store = 'AVRESAMPLE',
377 mandatory = ctx.options.enable_avcodec)
378 if all ( 'HAVE_' + i in ctx.env
379 for i in ['AVCODEC', 'AVFORMAT', 'AVUTIL', 'AVRESAMPLE'] ):
380 ctx.define('HAVE_LIBAV', 1)
381 ctx.msg('Checking for all libav libraries', 'yes')
383 ctx.msg('Checking for all libav libraries', 'not found', color = 'YELLOW')
385 if (ctx.options.enable_wavread != False):
386 ctx.define('HAVE_WAVREAD', 1)
387 ctx.msg('Checking if using source_wavread', ctx.options.enable_wavread and 'yes' or 'no')
388 if (ctx.options.enable_wavwrite!= False):
389 ctx.define('HAVE_WAVWRITE', 1)
390 ctx.msg('Checking if using sink_wavwrite', ctx.options.enable_wavwrite and 'yes' or 'no')
393 if (ctx.options.enable_atlas != False):
394 ctx.check(header_name = 'atlas/cblas.h', mandatory = ctx.options.enable_atlas)
395 #ctx.check(lib = 'lapack', uselib_store = 'LAPACK', mandatory = ctx.options.enable_atlas)
396 ctx.check(lib = 'cblas', uselib_store = 'BLAS', mandatory = ctx.options.enable_atlas)
399 if (ctx.options.enable_memcpy == True):
400 ctx.define('HAVE_MEMCPY_HACKS', 1)
402 # write configuration header
403 ctx.write_config_header('src/config.h')
405 # the following defines will be passed as arguments to the compiler
406 # instead of being written to src/config.h
407 ctx.define('HAVE_CONFIG_H', 1)
409 # add some defines used in examples
410 ctx.define('AUBIO_PREFIX', ctx.env['PREFIX'])
411 ctx.define('PACKAGE', APPNAME)
413 # double precision mode
414 if (ctx.options.enable_double == True):
415 ctx.define('HAVE_AUBIO_DOUBLE', 1)
417 if (ctx.options.enable_docs != False):
418 # check if txt2man is installed, optional
420 ctx.find_program('txt2man', var='TXT2MAN')
421 except ctx.errors.ConfigurationError:
422 ctx.to_log('txt2man was not found (ignoring)')
424 # check if doxygen is installed, optional
426 ctx.find_program('doxygen', var='DOXYGEN')
427 except ctx.errors.ConfigurationError:
428 ctx.to_log('doxygen was not found (ignoring)')
430 # check if sphinx-build is installed, optional
432 ctx.find_program('sphinx-build', var='SPHINX')
433 except ctx.errors.ConfigurationError:
434 ctx.to_log('sphinx-build was not found (ignoring)')
437 bld.env['VERSION'] = VERSION
438 bld.env['LIB_VERSION'] = LIB_VERSION
443 # add sub directories
444 if bld.env['DEST_OS'] not in ['ios', 'iosimulator', 'android']:
445 bld.recurse('examples')
448 # pkg-config template
449 bld( source = 'aubio.pc.in' )
457 # build manpages from txt files using txt2man
458 if bld.env['TXT2MAN']:
459 from waflib import TaskGen
460 if 'MANDIR' not in bld.env:
461 bld.env['MANDIR'] = bld.env['DATAROOTDIR'] + '/man'
462 bld.env.VERSION = VERSION
463 rule_str = '${TXT2MAN} -t `basename ${TGT} | cut -f 1 -d . | tr a-z A-Z`'
464 rule_str += ' -r ${PACKAGE}\\ ${VERSION} -P ${PACKAGE}'
465 rule_str += ' -v ${PACKAGE}\\ User\\\'s\\ manual'
466 rule_str += ' -s 1 ${SRC} > ${TGT}'
467 TaskGen.declare_chain(
473 install_path = '${MANDIR}/man1',
475 bld( source = bld.path.ant_glob('doc/*.txt') )
478 # build documentation from source files using doxygen
479 if bld.env['DOXYGEN']:
480 bld( name = 'doxygen', rule = 'doxygen ${SRC} > /dev/null',
481 source = 'doc/web.cfg',
482 target = '../doc/web/html/index.html',
484 bld.install_files( '${DATAROOTDIR}' + '/doc/libaubio-doc',
485 bld.path.ant_glob('doc/web/html/**'),
486 cwd = bld.path.find_dir ('doc/web'),
487 relative_trick = True)
490 # build documentation from source files using sphinx-build
491 # note: build in ../doc/_build/html, otherwise waf wont install unsigned files
492 if bld.env['SPHINX']:
493 bld.env.VERSION = VERSION
494 bld( name = 'sphinx',
495 rule = '${SPHINX} -b html -D release=${VERSION} -D version=${VERSION} -a -q `dirname ${SRC}` `dirname ${TGT}`',
496 source = 'doc/conf.py',
497 target = '../doc/_build/html/index.html')
498 bld.install_files( '${DATAROOTDIR}' + '/doc/libaubio-doc/sphinx',
499 bld.path.ant_glob('doc/_build/html/**'),
500 cwd = bld.path.find_dir('doc/_build/html'),
501 relative_trick = True)
503 # register the previous rules as build rules
504 from waflib.Build import BuildContext
506 class build_txt2man(BuildContext):
510 class build_manpages(BuildContext):
514 class build_sphinx(BuildContext):
518 class build_doxygen(BuildContext):
523 from waflib import Logs
524 if bld.options.target_platform in ['ios', 'iosimulator']:
525 msg ='building for %s, contact the author for a commercial license' % bld.options.target_platform
526 Logs.pprint('RED', msg)
527 msg =' Paul Brossier <piem@aubio.org>'
528 Logs.pprint('RED', msg)
531 ctx.excl = ' **/.waf* **/*~ **/*.pyc **/*.swp **/*.swo **/*.swn **/.lock-w* **/.git*'
532 ctx.excl += ' **/build/*'
533 ctx.excl += ' doc/_build'
534 ctx.excl += ' python/demos_*'
535 ctx.excl += ' **/python/gen **/python/build **/python/dist'
536 ctx.excl += ' **/python/ext/config.h'
537 ctx.excl += ' **/python/lib/aubio/_aubio.so'
538 ctx.excl += ' **.egg-info'
539 ctx.excl += ' **/**.zip **/**.tar.bz2'
540 ctx.excl += ' **.tar.bz2'
541 ctx.excl += ' **/doc/full/* **/doc/web/*'
542 ctx.excl += ' **/doc/full.cfg'
543 ctx.excl += ' **/python/*.db'
544 ctx.excl += ' **/python.old/*'
545 ctx.excl += ' **/python/*/*.old'
546 ctx.excl += ' **/python/tests/sounds'
547 ctx.excl += ' **/**.asc'
548 ctx.excl += ' **/dist*'
549 ctx.excl += ' **/.DS_Store'
550 ctx.excl += ' **/.travis.yml'
551 ctx.excl += ' **/.landscape.yml'
552 ctx.excl += ' **/.appveyor.yml'