source: wscript @ aab682e

feature/autosinkfeature/constantqfeature/pitchshiftfeature/pydocstringsfeature/timestretchsampler
Last change on this file since aab682e was aab682e, checked in by Martin Hermant <martin.hermant@gmail.com>, 3 years ago

unify version parsing in Version.py

  • Property mode set to 100644
File size: 20.5 KB
Line 
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
13import sys
14
15APPNAME = 'aubio'
16
17# source VERSION
18
19
20from Version import *
21
22
23VERSION = '.'.join ([str(x) for x in [
24    AUBIO_MAJOR_VERSION,
25    AUBIO_MINOR_VERSION,
26    AUBIO_PATCH_VERSION
27    ]]) + AUBIO_VERSION_STATUS
28
29LIB_VERSION = '.'.join ([str(x) for x in [
30    LIBAUBIO_LT_CUR,
31    LIBAUBIO_LT_REV,
32    LIBAUBIO_LT_AGE]])
33
34top = '.'
35out = 'build'
36
37def add_option_enable_disable(ctx, name, default = None,
38        help_str = None, help_disable_str = None):
39    if help_str == None:
40        help_str = 'enable ' + name + ' support'
41    if help_disable_str == None:
42        help_disable_str = 'do not ' + help_str
43    ctx.add_option('--enable-' + name, action = 'store_true',
44            default = default,
45            dest = 'enable_' + name.replace('-','_'),
46            help = help_str)
47    ctx.add_option('--disable-' + name, action = 'store_false',
48            #default = default,
49            dest = 'enable_' + name.replace('-','_'),
50            help = help_disable_str )
51
52def options(ctx):
53    ctx.add_option('--build-type', action = 'store',
54            default = "release",
55            choices = ('debug', 'release'),
56            dest = 'build_type',
57            help = 'whether to compile with (--build-type=release) or without (--build-type=debug) '\
58              ' compiler opimizations [default: release]')
59    add_option_enable_disable(ctx, 'fftw3f', default = False,
60            help_str = 'compile with fftw3f instead of ooura (recommended)',
61            help_disable_str = 'do not compile with fftw3f')
62    add_option_enable_disable(ctx, 'fftw3', default = False,
63            help_str = 'compile with fftw3 instead of ooura',
64            help_disable_str = 'do not compile with fftw3')
65    add_option_enable_disable(ctx, 'complex', default = False,
66            help_str ='compile with C99 complex',
67            help_disable_str = 'do not use C99 complex (default)' )
68    add_option_enable_disable(ctx, 'jack', default = None,
69            help_str = 'compile with jack (auto)',
70            help_disable_str = 'disable jack support')
71    add_option_enable_disable(ctx, 'sndfile', default = None,
72            help_str = 'compile with sndfile (auto)',
73            help_disable_str = 'disable sndfile')
74    add_option_enable_disable(ctx, 'avcodec', default = None,
75            help_str = 'compile with libavcodec (auto)',
76            help_disable_str = 'disable libavcodec')
77    add_option_enable_disable(ctx, 'samplerate', default = None,
78            help_str = 'compile with samplerate (auto)',
79            help_disable_str = 'disable samplerate')
80    add_option_enable_disable(ctx, 'memcpy', default = True,
81            help_str = 'use memcpy hacks (default)',
82            help_disable_str = 'do not use memcpy hacks')
83    add_option_enable_disable(ctx, 'double', default = False,
84            help_str = 'compile in double precision mode',
85            help_disable_str = 'compile in single precision mode (default)')
86    add_option_enable_disable(ctx, 'fat', default = False,
87            help_str = 'build fat binaries (darwin only)',
88            help_disable_str = 'do not build fat binaries (default)')
89    add_option_enable_disable(ctx, 'accelerate', default = None,
90            help_str = 'use Accelerate framework (darwin only) (auto)',
91            help_disable_str = 'do not use Accelerate framework')
92    add_option_enable_disable(ctx, 'apple-audio', default = None,
93            help_str = 'use CoreFoundation (darwin only) (auto)',
94            help_disable_str = 'do not use CoreFoundation framework')
95    add_option_enable_disable(ctx, 'atlas', default = False,
96            help_str = 'use Atlas library (no)',
97            help_disable_str = 'do not use Atlas library')
98    add_option_enable_disable(ctx, 'wavread', default = True,
99            help_str = 'compile with source_wavread (default)',
100            help_disable_str = 'do not compile source_wavread')
101    add_option_enable_disable(ctx, 'wavwrite', default = True,
102            help_str = 'compile with source_wavwrite (default)',
103            help_disable_str = 'do not compile source_wavwrite')
104
105    add_option_enable_disable(ctx, 'docs', default = None,
106            help_str = 'build documentation (auto)',
107            help_disable_str = 'do not build documentation')
108
109    ctx.add_option('--with-target-platform', type='string',
110            help='set target platform for cross-compilation', dest='target_platform')
111
112    ctx.load('compiler_c')
113    ctx.load('waf_unit_test')
114    ctx.load('gnu_dirs')
115
116def configure(ctx):
117    from waflib import Options
118    ctx.load('compiler_c')
119    ctx.load('waf_unit_test')
120    ctx.load('gnu_dirs')
121
122    # check for common headers
123    ctx.check(header_name='stdlib.h')
124    ctx.check(header_name='stdio.h')
125    ctx.check(header_name='math.h')
126    ctx.check(header_name='string.h')
127    ctx.check(header_name='limits.h')
128    ctx.check(header_name='stdarg.h')
129    ctx.check(header_name='getopt.h', mandatory = False)
130    ctx.check(header_name='unistd.h', mandatory = False)
131
132    target_platform = sys.platform
133    if ctx.options.target_platform:
134        target_platform = ctx.options.target_platform
135    ctx.env['DEST_OS'] = target_platform
136
137    ctx.define('AUBIO_VERSION',VERSION)
138    ctx.define('AUBIO_MAJOR_VERSION',AUBIO_MAJOR_VERSION)
139    ctx.define('AUBIO_MINOR_VERSION',AUBIO_MINOR_VERSION)
140    ctx.define('AUBIO_PATCH_VERSION',AUBIO_PATCH_VERSION)
141    ctx.define('AUBIO_VERSION_STATUS',AUBIO_VERSION_STATUS)
142   
143    if ctx.options.build_type == "debug":
144        ctx.define('DEBUG', 1)
145    else:
146        ctx.define('NDEBUG', 1)
147
148    if ctx.env.CC_NAME != 'msvc':
149        if ctx.options.build_type == "debug":
150            # no optimization in debug mode
151            ctx.env.prepend_value('CFLAGS', ['-O0'])
152        else:
153            # default to -O2 in release mode
154            ctx.env.prepend_value('CFLAGS', ['-O2'])
155        # enable debug symbols and configure warnings
156        ctx.env.prepend_value('CFLAGS', ['-g', '-Wall', '-Wextra'])
157    else:
158        # enable debug symbols
159        ctx.env.CFLAGS += ['/Z7', '/FS']
160        ctx.env.LINKFLAGS += ['/DEBUG', '/INCREMENTAL:NO']
161        # configure warnings
162        ctx.env.CFLAGS += ['/W4', '/D_CRT_SECURE_NO_WARNINGS']
163        # set optimization level and runtime libs
164        if (ctx.options.build_type == "release"):
165            ctx.env.CFLAGS += ['/Ox']
166            ctx.env.CFLAGS += ['/MD']
167        else:
168            assert(ctx.options.build_type == "debug")
169            ctx.env.CFLAGS += ['/MDd']
170
171    ctx.check_cc(lib='m', uselib_store='M', mandatory=False)
172
173    if target_platform not in ['win32', 'win64']:
174        ctx.env.CFLAGS += ['-fPIC']
175    else:
176        ctx.define('HAVE_WIN_HACKS', 1)
177        ctx.env['cshlib_PATTERN'] = 'lib%s.dll'
178
179    if target_platform == 'darwin' and ctx.options.enable_fat:
180        ctx.env.CFLAGS += ['-arch', 'i386', '-arch', 'x86_64']
181        ctx.env.LINKFLAGS += ['-arch', 'i386', '-arch', 'x86_64']
182        MINSDKVER="10.4"
183        ctx.env.CFLAGS += [ '-mmacosx-version-min=' + MINSDKVER ]
184        ctx.env.LINKFLAGS += [ '-mmacosx-version-min=' + MINSDKVER ]
185
186    if target_platform in [ 'darwin', 'ios', 'iosimulator']:
187        if (ctx.options.enable_apple_audio != False):
188            ctx.env.FRAMEWORK += ['CoreFoundation', 'AudioToolbox']
189            ctx.define('HAVE_SOURCE_APPLE_AUDIO', 1)
190            ctx.define('HAVE_SINK_APPLE_AUDIO', 1)
191            ctx.msg('Checking for AudioToolbox.framework', 'yes')
192        else:
193            ctx.msg('Checking for AudioToolbox.framework', 'no (disabled)', color = 'YELLOW')
194        if (ctx.options.enable_accelerate != False):
195            ctx.define('HAVE_ACCELERATE', 1)
196            ctx.env.FRAMEWORK += ['Accelerate']
197            ctx.msg('Checking for Accelerate framework', 'yes')
198        else:
199            ctx.msg('Checking for Accelerate framework', 'no (disabled)', color = 'YELLOW')
200
201    if target_platform in [ 'ios', 'iosimulator' ]:
202        MINSDKVER="6.1"
203        ctx.env.CFLAGS += ['-std=c99']
204        if (ctx.options.enable_apple_audio != False):
205            ctx.define('HAVE_AUDIO_UNIT', 1)
206            #ctx.env.FRAMEWORK += ['CoreFoundation', 'AudioToolbox']
207        if target_platform == 'ios':
208            DEVROOT = "/Applications/Xcode.app/Contents"
209            DEVROOT += "/Developer/Platforms/iPhoneOS.platform/Developer"
210            SDKROOT = "%(DEVROOT)s/SDKs/iPhoneOS.sdk" % locals()
211            ctx.env.CFLAGS += [ '-fembed-bitcode' ]
212            ctx.env.CFLAGS += [ '-arch', 'arm64' ]
213            ctx.env.CFLAGS += [ '-arch', 'armv7' ]
214            ctx.env.CFLAGS += [ '-arch', 'armv7s' ]
215            ctx.env.LINKFLAGS += [ '-arch', 'arm64' ]
216            ctx.env.LINKFLAGS += ['-arch', 'armv7']
217            ctx.env.LINKFLAGS += ['-arch', 'armv7s']
218            ctx.env.CFLAGS += [ '-miphoneos-version-min=' + MINSDKVER ]
219            ctx.env.LINKFLAGS += [ '-miphoneos-version-min=' + MINSDKVER ]
220        else:
221            DEVROOT = "/Applications/Xcode.app/Contents"
222            DEVROOT += "/Developer/Platforms/iPhoneSimulator.platform/Developer"
223            SDKROOT = "%(DEVROOT)s/SDKs/iPhoneSimulator.sdk" % locals()
224            ctx.env.CFLAGS += [ '-arch', 'i386' ]
225            ctx.env.CFLAGS += [ '-arch', 'x86_64' ]
226            ctx.env.LINKFLAGS += ['-arch', 'i386']
227            ctx.env.LINKFLAGS += ['-arch', 'x86_64']
228            ctx.env.CFLAGS += [ '-mios-simulator-version-min=' + MINSDKVER ]
229            ctx.env.LINKFLAGS += [ '-mios-simulator-version-min=' + MINSDKVER ]
230        ctx.env.CFLAGS += [ '-isysroot' , SDKROOT]
231        ctx.env.LINKFLAGS += [ '-isysroot' , SDKROOT]
232
233    if target_platform == 'emscripten':
234        import os.path
235        ctx.env.CFLAGS += [ '-I' + os.path.join(os.environ['EMSCRIPTEN'], 'system', 'include') ]
236        ctx.env.CFLAGS += ['-Oz']
237        ctx.env.cprogram_PATTERN = "%s.js"
238        if (ctx.options.enable_atlas != True):
239            ctx.options.enable_atlas = False
240
241    # check support for C99 __VA_ARGS__ macros
242    check_c99_varargs = '''
243#include <stdio.h>
244#define AUBIO_ERR(...) fprintf(stderr, __VA_ARGS__)
245'''
246
247    if ctx.check_cc(fragment = check_c99_varargs,
248            type='cstlib',
249            msg = 'Checking for C99 __VA_ARGS__ macro',
250            mandatory = False):
251        ctx.define('HAVE_C99_VARARGS_MACROS', 1)
252
253    # show a message about enable_double status
254    if (ctx.options.enable_double == True):
255        ctx.msg('Checking for size of smpl_t', 'double')
256        ctx.msg('Checking for size of lsmp_t', 'long double')
257    else:
258        ctx.msg('Checking for size of smpl_t', 'float')
259        ctx.msg('Checking for size of lsmp_t', 'double')
260
261    # optionally use complex.h
262    if (ctx.options.enable_complex == True):
263        ctx.check(header_name='complex.h')
264    else:
265        ctx.msg('Checking if complex.h is enabled', 'no')
266
267    # check for fftw3
268    if (ctx.options.enable_fftw3 != False or ctx.options.enable_fftw3f != False):
269        # one of fftwf or fftw3f
270        if (ctx.options.enable_fftw3f != False):
271            ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0',
272                    args = '--cflags --libs',
273                    mandatory = ctx.options.enable_fftw3f)
274            if (ctx.options.enable_double == True):
275                ctx.msg('Warning',
276                        'fftw3f enabled, but compiling in double precision!')
277        else:
278            # fftw3f disabled, take most sensible one according to
279            # enable_double
280            if (ctx.options.enable_double == True):
281                ctx.check_cfg(package = 'fftw3', atleast_version = '3.0.0',
282                        args = '--cflags --libs', mandatory =
283                        ctx.options.enable_fftw3)
284            else:
285                ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0',
286                        args = '--cflags --libs',
287                        mandatory = ctx.options.enable_fftw3)
288        ctx.define('HAVE_FFTW3', 1)
289
290    # fftw not enabled, use vDSP or ooura
291    if 'HAVE_FFTW3F' in ctx.env.define_key:
292        ctx.msg('Checking for FFT implementation', 'fftw3f')
293    elif 'HAVE_FFTW3' in ctx.env.define_key:
294        ctx.msg('Checking for FFT implementation', 'fftw3')
295    elif 'HAVE_ACCELERATE' in ctx.env.define_key:
296        ctx.msg('Checking for FFT implementation', 'vDSP')
297    else:
298        ctx.msg('Checking for FFT implementation', 'ooura')
299
300    # check for libsndfile
301    if (ctx.options.enable_sndfile != False):
302        ctx.check_cfg(package = 'sndfile', atleast_version = '1.0.4',
303                args = '--cflags --libs',
304                mandatory = ctx.options.enable_sndfile)
305
306    # check for libsamplerate
307    if (ctx.options.enable_double):
308        if (ctx.options.enable_samplerate):
309            ctx.fatal("Could not compile aubio in double precision mode with libsamplerate")
310        else:
311            ctx.options.enable_samplerate = False
312            ctx.msg('Checking if using samplerate', 'no (disabled in double precision mode)',
313                    color = 'YELLOW')
314    if (ctx.options.enable_samplerate != False):
315        ctx.check_cfg(package = 'samplerate', atleast_version = '0.0.15',
316                args = '--cflags --libs',
317                mandatory = ctx.options.enable_samplerate)
318
319    # check for jack
320    if (ctx.options.enable_jack != False):
321        ctx.check_cfg(package = 'jack',
322                args = '--cflags --libs',
323                mandatory = ctx.options.enable_jack)
324
325    # check for libav
326    if (ctx.options.enable_avcodec != False):
327        ctx.check_cfg(package = 'libavcodec', atleast_version = '54.35.0',
328                args = '--cflags --libs', uselib_store = 'AVCODEC',
329                mandatory = ctx.options.enable_avcodec)
330        ctx.check_cfg(package = 'libavformat', atleast_version = '52.3.0',
331                args = '--cflags --libs', uselib_store = 'AVFORMAT',
332                mandatory = ctx.options.enable_avcodec)
333        ctx.check_cfg(package = 'libavutil', atleast_version = '52.3.0',
334                args = '--cflags --libs', uselib_store = 'AVUTIL',
335                mandatory = ctx.options.enable_avcodec)
336        ctx.check_cfg(package = 'libavresample', atleast_version = '1.0.1',
337                args = '--cflags --libs', uselib_store = 'AVRESAMPLE',
338                mandatory = ctx.options.enable_avcodec)
339        if all ( 'HAVE_' + i in ctx.env
340                for i in ['AVCODEC', 'AVFORMAT', 'AVUTIL', 'AVRESAMPLE'] ):
341            ctx.define('HAVE_LIBAV', 1)
342            ctx.msg('Checking for all libav libraries', 'yes')
343        else:
344            ctx.msg('Checking for all libav libraries', 'not found', color = 'YELLOW')
345
346    if (ctx.options.enable_wavread != False):
347        ctx.define('HAVE_WAVREAD', 1)
348    ctx.msg('Checking if using source_wavread', ctx.options.enable_wavread and 'yes' or 'no')
349    if (ctx.options.enable_wavwrite!= False):
350        ctx.define('HAVE_WAVWRITE', 1)
351    ctx.msg('Checking if using sink_wavwrite', ctx.options.enable_wavwrite and 'yes' or 'no')
352
353    # use ATLAS
354    if (ctx.options.enable_atlas != False):
355        ctx.check(header_name = 'atlas/cblas.h', mandatory = ctx.options.enable_atlas)
356        #ctx.check(lib = 'lapack', uselib_store = 'LAPACK', mandatory = ctx.options.enable_atlas)
357        ctx.check(lib = 'cblas', uselib_store = 'BLAS', mandatory = ctx.options.enable_atlas)
358
359    # use memcpy hacks
360    if (ctx.options.enable_memcpy == True):
361        ctx.define('HAVE_MEMCPY_HACKS', 1)
362
363    # write configuration header
364    ctx.write_config_header('src/config.h')
365
366    # the following defines will be passed as arguments to the compiler
367    # instead of being written to src/config.h
368    ctx.define('HAVE_CONFIG_H', 1)
369
370    # add some defines used in examples
371    ctx.define('AUBIO_PREFIX', ctx.env['PREFIX'])
372    ctx.define('PACKAGE', APPNAME)
373
374    # double precision mode
375    if (ctx.options.enable_double == True):
376        ctx.define('HAVE_AUBIO_DOUBLE', 1)
377
378    if (ctx.options.enable_docs != False):
379        # check if txt2man is installed, optional
380        try:
381          ctx.find_program('txt2man', var='TXT2MAN')
382        except ctx.errors.ConfigurationError:
383          ctx.to_log('txt2man was not found (ignoring)')
384
385        # check if doxygen is installed, optional
386        try:
387          ctx.find_program('doxygen', var='DOXYGEN')
388        except ctx.errors.ConfigurationError:
389          ctx.to_log('doxygen was not found (ignoring)')
390
391        # check if sphinx-build is installed, optional
392        try:
393          ctx.find_program('sphinx-build', var='SPHINX')
394        except ctx.errors.ConfigurationError:
395          ctx.to_log('sphinx-build was not found (ignoring)')
396
397def build(bld):
398    bld.env['VERSION'] = VERSION
399    bld.env['LIB_VERSION'] = LIB_VERSION
400
401    # main source
402    bld.recurse('src')
403
404    # add sub directories
405    if bld.env['DEST_OS'] not in ['ios', 'iosimulator', 'android']:
406        bld.recurse('examples')
407        bld.recurse('tests')
408
409    # pkg-config template
410    bld( source = 'aubio.pc.in' )
411
412    # documentation
413    txt2man(bld)
414    doxygen(bld)
415    sphinx(bld)
416
417def txt2man(bld):
418    # build manpages from txt files using txt2man
419    if bld.env['TXT2MAN']:
420        from waflib import TaskGen
421        if 'MANDIR' not in bld.env:
422            bld.env['MANDIR'] = bld.env['DATAROOTDIR'] + '/man'
423        bld.env.VERSION = VERSION
424        rule_str = '${TXT2MAN} -t `basename ${TGT} | cut -f 1 -d . | tr a-z A-Z`'
425        rule_str += ' -r ${PACKAGE}\\ ${VERSION} -P ${PACKAGE}'
426        rule_str += ' -v ${PACKAGE}\\ User\\\'s\\ manual'
427        rule_str += ' -s 1 ${SRC} > ${TGT}'
428        TaskGen.declare_chain(
429                name      = 'txt2man',
430                rule      = rule_str,
431                ext_in    = '.txt',
432                ext_out   = '.1',
433                reentrant = False,
434                install_path =  '${MANDIR}/man1',
435                )
436        bld( source = bld.path.ant_glob('doc/*.txt') )
437
438def doxygen(bld):
439    # build documentation from source files using doxygen
440    if bld.env['DOXYGEN']:
441        bld( name = 'doxygen', rule = 'doxygen ${SRC} > /dev/null',
442                source = 'doc/web.cfg',
443                target = '../doc/web/html/index.html',
444                cwd = 'doc')
445        bld.install_files( '${DATAROOTDIR}' + '/doc/libaubio-doc',
446                bld.path.ant_glob('doc/web/html/**'),
447                cwd = bld.path.find_dir ('doc/web'),
448                relative_trick = True)
449
450def sphinx(bld):
451    # build documentation from source files using sphinx-build
452    # note: build in ../doc/_build/html, otherwise waf wont install unsigned files
453    if bld.env['SPHINX']:
454        bld.env.VERSION = VERSION
455        bld( name = 'sphinx',
456                rule = '${SPHINX} -b html -D release=${VERSION} -D version=${VERSION} -a -q `dirname ${SRC}` `dirname ${TGT}`',
457                source = 'doc/conf.py',
458                target = '../doc/_build/html/index.html')
459        bld.install_files( '${DATAROOTDIR}' + '/doc/libaubio-doc/sphinx',
460                bld.path.ant_glob('doc/_build/html/**'),
461                cwd = bld.path.find_dir('doc/_build/html'),
462                relative_trick = True)
463
464# register the previous rules as build rules
465from waflib.Build import BuildContext
466
467class build_txt2man(BuildContext):
468    cmd = 'txt2man'
469    fun = 'txt2man'
470
471class build_manpages(BuildContext):
472    cmd = 'manpages'
473    fun = 'txt2man'
474
475class build_sphinx(BuildContext):
476    cmd = 'sphinx'
477    fun = 'sphinx'
478
479class build_doxygen(BuildContext):
480    cmd = 'doxygen'
481    fun = 'doxygen'
482
483def shutdown(bld):
484    from waflib import Logs
485    if bld.options.target_platform in ['ios', 'iosimulator']:
486        msg ='building for %s, contact the author for a commercial license' % bld.options.target_platform
487        Logs.pprint('RED', msg)
488        msg ='   Paul Brossier <piem@aubio.org>'
489        Logs.pprint('RED', msg)
490
491def dist(ctx):
492    ctx.excl  = ' **/.waf* **/*~ **/*.pyc **/*.swp **/*.swo **/*.swn **/.lock-w* **/.git*'
493    ctx.excl += ' **/build/*'
494    ctx.excl += ' doc/_build'
495    ctx.excl += ' python/demos_*'
496    ctx.excl += ' **/python/gen **/python/build **/python/dist'
497    ctx.excl += ' **/python/ext/config.h'
498    ctx.excl += ' **/python/lib/aubio/_aubio.so'
499    ctx.excl += ' **.egg-info'
500    ctx.excl += ' **/**.zip **/**.tar.bz2'
501    ctx.excl += ' **.tar.bz2'
502    ctx.excl += ' **/doc/full/* **/doc/web/*'
503    ctx.excl += ' **/doc/full.cfg'
504    ctx.excl += ' **/python/*.db'
505    ctx.excl += ' **/python.old/*'
506    ctx.excl += ' **/python/*/*.old'
507    ctx.excl += ' **/python/tests/sounds'
508    ctx.excl += ' **/**.asc'
509    ctx.excl += ' **/dist*'
510    ctx.excl += ' **/.DS_Store'
511    ctx.excl += ' **/.travis.yml'
512    ctx.excl += ' **/.landscape.yml'
513    ctx.excl += ' **/.appveyor.yml'
Note: See TracBrowser for help on using the repository browser.