source: wscript

Last change on this file was c1303c6, checked in by Paul Brossier <piem@piem.org>, 4 months ago

[waf] add support for watchos

  • Property mode set to 100644
File size: 29.7 KB
RevLine 
[5c411dc]1#! /usr/bin/python
[110ac90]2#
[21ee709]3# usage:
[46b00690]4#   $ python waf --help
5#
6# example:
7#   $ ./waf distclean configure build
[21ee709]8#
[46b00690]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/ .
[000b090]12
[004b431]13import sys
[92ebdac]14import subprocess
[004b431]15
[000b090]16APPNAME = 'aubio'
[5820107]17
[b991cc1]18from this_version import *
[5820107]19
[255c4c8]20VERSION = get_aubio_version()
21LIB_VERSION = get_libaubio_version()
[e565c649]22
[46378b3]23top = '.'
24out = 'build'
[000b090]25
[6b14351]26def add_option_enable_disable(ctx, name, default = None,
27        help_str = None, help_disable_str = None):
[a93dab3]28    if help_str == None:
29        help_str = 'enable ' + name + ' support'
30    if help_disable_str == None:
31        help_disable_str = 'do not ' + help_str
32    ctx.add_option('--enable-' + name, action = 'store_true',
33            default = default,
34            dest = 'enable_' + name.replace('-','_'),
35            help = help_str)
36    ctx.add_option('--disable-' + name, action = 'store_false',
37            #default = default,
38            dest = 'enable_' + name.replace('-','_'),
39            help = help_disable_str )
[3819aca]40
[d41bc4d]41def options(ctx):
[b4ce693]42    ctx.add_option('--build-type', action = 'store',
43            default = "release",
44            choices = ('debug', 'release'),
45            dest = 'build_type',
[19237a7]46            help = 'whether to compile with (--build-type=release)' \
47                    ' or without (--build-type=debug)' \
48                    ' compiler opimizations [default: release]')
[f862b85]49    ctx.add_option('--debug', action = 'store_const',
50            dest = 'build_type', const = 'debug',
51            help = 'build in debug mode (see --build-type)')
[0cd3720]52    ctx.add_option('--nodeps', action = 'store_const',
53            dest = 'nodeps', const = 'debug',
54            help = 'build with no external dependencies')
[a93dab3]55    add_option_enable_disable(ctx, 'fftw3f', default = False,
56            help_str = 'compile with fftw3f instead of ooura (recommended)',
57            help_disable_str = 'do not compile with fftw3f')
58    add_option_enable_disable(ctx, 'fftw3', default = False,
59            help_str = 'compile with fftw3 instead of ooura',
60            help_disable_str = 'do not compile with fftw3')
[799d992]61    add_option_enable_disable(ctx, 'intelipp', default = False,
[986131d]62            help_str = 'use Intel IPP libraries (auto)',
63            help_disable_str = 'do not use Intel IPP libraries')
[a93dab3]64    add_option_enable_disable(ctx, 'complex', default = False,
65            help_str ='compile with C99 complex',
66            help_disable_str = 'do not use C99 complex (default)' )
67    add_option_enable_disable(ctx, 'jack', default = None,
68            help_str = 'compile with jack (auto)',
69            help_disable_str = 'disable jack support')
70    add_option_enable_disable(ctx, 'sndfile', default = None,
71            help_str = 'compile with sndfile (auto)',
72            help_disable_str = 'disable sndfile')
73    add_option_enable_disable(ctx, 'avcodec', default = None,
74            help_str = 'compile with libavcodec (auto)',
75            help_disable_str = 'disable libavcodec')
[3efb631]76    add_option_enable_disable(ctx, 'vorbis', default = None,
77            help_str = 'compile with libvorbis (auto)',
78            help_disable_str = 'disable libvorbis')
[1ba359c]79    add_option_enable_disable(ctx, 'flac', default = None,
80            help_str = 'compile with libFLAC (auto)',
81            help_disable_str = 'disable libflac')
[a93dab3]82    add_option_enable_disable(ctx, 'samplerate', default = None,
83            help_str = 'compile with samplerate (auto)',
84            help_disable_str = 'disable samplerate')
[d9d1010]85    add_option_enable_disable(ctx, 'rubberband', default = None,
86            help_str = 'compile with rubberband (auto)',
87            help_disable_str = 'disable rubberband')
[a93dab3]88    add_option_enable_disable(ctx, 'memcpy', default = True,
89            help_str = 'use memcpy hacks (default)',
90            help_disable_str = 'do not use memcpy hacks')
91    add_option_enable_disable(ctx, 'double', default = False,
92            help_str = 'compile in double precision mode',
93            help_disable_str = 'compile in single precision mode (default)')
[a3de4be]94    add_option_enable_disable(ctx, 'fat', default = False,
95            help_str = 'build fat binaries (darwin only)',
96            help_disable_str = 'do not build fat binaries (default)')
[0309a22]97    add_option_enable_disable(ctx, 'accelerate', default = None,
98            help_str = 'use Accelerate framework (darwin only) (auto)',
99            help_disable_str = 'do not use Accelerate framework')
[cc81763]100    add_option_enable_disable(ctx, 'apple-audio', default = None,
101            help_str = 'use CoreFoundation (darwin only) (auto)',
102            help_disable_str = 'do not use CoreFoundation framework')
[fe05d1f]103    add_option_enable_disable(ctx, 'blas', default = False,
104            help_str = 'use BLAS acceleration library (no)',
105            help_disable_str = 'do not use BLAS library')
[f61ffb9]106    add_option_enable_disable(ctx, 'atlas', default = False,
[fe05d1f]107            help_str = 'use ATLAS acceleration library (no)',
108            help_disable_str = 'do not use ATLAS library')
[f9a543e]109    add_option_enable_disable(ctx, 'wavread', default = True,
110            help_str = 'compile with source_wavread (default)',
111            help_disable_str = 'do not compile source_wavread')
112    add_option_enable_disable(ctx, 'wavwrite', default = True,
113            help_str = 'compile with source_wavwrite (default)',
114            help_disable_str = 'do not compile source_wavwrite')
[a93dab3]115
[a33d406]116    add_option_enable_disable(ctx, 'docs', default = None,
117            help_str = 'build documentation (auto)',
118            help_disable_str = 'do not build documentation')
119
[445e60f5]120    add_option_enable_disable(ctx, 'tests', default = True,
121            help_str = 'build tests (true)',
122            help_disable_str = 'do not build or run tests')
123
124    add_option_enable_disable(ctx, 'examples', default = True,
125            help_str = 'build examples (true)',
126            help_disable_str = 'do not build examples')
127
[a93dab3]128    ctx.add_option('--with-target-platform', type='string',
[19237a7]129            help='set target platform for cross-compilation',
130            dest='target_platform')
[a93dab3]131
132    ctx.load('compiler_c')
133    ctx.load('waf_unit_test')
134    ctx.load('gnu_dirs')
[18ec142]135    ctx.load('waf_gensyms', tooldir='.')
[000b090]136
[d41bc4d]137def configure(ctx):
[fc5e189]138    target_platform = sys.platform
139    if ctx.options.target_platform:
140        target_platform = ctx.options.target_platform
[fee0094]141
[0cd3720]142    if ctx.options.nodeps:
143        external_deps = [
144                'sndfile',
145                'samplerate',
146                'jack',
[e625579]147                'rubberband',
[0cd3720]148                'avcodec',
149                'blas',
150                'fftw3',
151                'fftw3f',
[e836160]152                'flac',
153                'vorbis',
[0cd3720]154        ]
155        for d in external_deps:
156            if not hasattr(ctx.options, 'enable_' + d):
157                raise ctx.errors.ConfigurationError ('--enable-%s missing from options' % d)
158            if getattr(ctx.options, 'enable_' + d) == True:
159                msg = 'Option --nodeps can not be used along with --enable-%s' % d
160                raise ctx.errors.ConfigurationError (msg)
161            elif getattr(ctx.options, 'enable_' + d) is None:
162                msg = 'Option --nodeps used but automatic detection with --enable-%s' % d
163                ctx.msg('Warning', msg)
164            setattr(ctx.options, 'enable_' + d, False)
165
[9fabad5]166    from waflib import Options
[fc5e189]167
168    if target_platform=='emscripten':
[9fabad5]169        ctx.load('c_emscripten')
170    else:
171        ctx.load('compiler_c')
172
173    ctx.load('waf_unit_test')
174    ctx.load('gnu_dirs')
[18ec142]175    ctx.load('waf_gensyms', tooldir='.')
[fee0094]176
[bef979a]177    # check for common headers
178    ctx.check(header_name='stdlib.h')
179    ctx.check(header_name='stdio.h')
180    ctx.check(header_name='math.h')
181    ctx.check(header_name='string.h')
[9d609355]182    ctx.check(header_name='errno.h')
[bef979a]183    ctx.check(header_name='limits.h')
[f334300]184    ctx.check(header_name='stdarg.h')
[d746ef8]185    ctx.check(header_name='getopt.h', mandatory = False)
[06cf47d]186    ctx.check(header_name='unistd.h', mandatory = False)
[bef979a]187
[a93dab3]188    ctx.env['DEST_OS'] = target_platform
189
[b4ce693]190    if ctx.options.build_type == "debug":
191        ctx.define('DEBUG', 1)
192    else:
193        ctx.define('NDEBUG', 1)
[578d3a2]194
[ae36035]195    if ctx.env.CC_NAME != 'msvc':
[c04346d]196        if ctx.options.build_type == "debug":
197            # no optimization in debug mode
[a6ba5d9f]198            ctx.env.prepend_value('CFLAGS', ['-O0'])
199        else:
[1539d4b]200            if target_platform == 'emscripten':
201                # -Oz for small js file generation
202                ctx.env.prepend_value('CFLAGS', ['-Oz'])
203            else:
[deaf39e]204                # default to -O2 in release mode
205                ctx.env.prepend_value('CFLAGS', ['-O2'])
[a6ba5d9f]206        # enable debug symbols and configure warnings
207        ctx.env.prepend_value('CFLAGS', ['-g', '-Wall', '-Wextra'])
[a341685]208    else:
[b4ce693]209        # enable debug symbols
[b0353ab]210        ctx.env.CFLAGS += ['/Z7']
211        # /FS flag available in msvc >= 12 (2013)
212        if 'MSVC_VERSION' in ctx.env and ctx.env.MSVC_VERSION >= 12:
213            ctx.env.CFLAGS += ['/FS']
[b4ce693]214        ctx.env.LINKFLAGS += ['/DEBUG', '/INCREMENTAL:NO']
215        # configure warnings
216        ctx.env.CFLAGS += ['/W4', '/D_CRT_SECURE_NO_WARNINGS']
[986131d]217        # ignore "possible loss of data" warnings
218        ctx.env.CFLAGS += ['/wd4305', '/wd4244', '/wd4245', '/wd4267']
219        # ignore "unreferenced formal parameter" warnings
220        ctx.env.CFLAGS += ['/wd4100']
[578d3a2]221        # set optimization level and runtime libs
[b4ce693]222        if (ctx.options.build_type == "release"):
223            ctx.env.CFLAGS += ['/Ox']
224            ctx.env.CFLAGS += ['/MD']
225        else:
226            assert(ctx.options.build_type == "debug")
227            ctx.env.CFLAGS += ['/MDd']
[578d3a2]228
[70a304e]229    ctx.check_cc(lib='m', uselib_store='M', mandatory=False)
230
[06dba46]231    if target_platform not in ['win32', 'win64']:
232        ctx.env.CFLAGS += ['-fPIC']
233    else:
234        ctx.define('HAVE_WIN_HACKS', 1)
235        ctx.env['cshlib_PATTERN'] = 'lib%s.dll'
[a93dab3]236
[a3de4be]237    if target_platform == 'darwin' and ctx.options.enable_fat:
[f7497ab]238        ctx.env.CFLAGS += ['-arch', 'arm64', '-arch', 'x86_64']
239        ctx.env.LINKFLAGS += ['-arch', 'arm64', '-arch', 'x86_64']
[da1709f]240        MINSDKVER="10.4"
241        ctx.env.CFLAGS += [ '-mmacosx-version-min=' + MINSDKVER ]
242        ctx.env.LINKFLAGS += [ '-mmacosx-version-min=' + MINSDKVER ]
[9209c79]243
[c1303c6]244    if target_platform in [ 'darwin', 'ios', 'iosimulator' ]:
[cc81763]245        if (ctx.options.enable_apple_audio != False):
246            ctx.env.FRAMEWORK += ['CoreFoundation', 'AudioToolbox']
247            ctx.define('HAVE_SOURCE_APPLE_AUDIO', 1)
248            ctx.define('HAVE_SINK_APPLE_AUDIO', 1)
[f61ffb9]249            ctx.msg('Checking for AudioToolbox.framework', 'yes')
250        else:
[19237a7]251            ctx.msg('Checking for AudioToolbox.framework', 'no (disabled)',
252                    color = 'YELLOW')
[0309a22]253        if (ctx.options.enable_accelerate != False):
254            ctx.define('HAVE_ACCELERATE', 1)
255            ctx.env.FRAMEWORK += ['Accelerate']
[f61ffb9]256            ctx.msg('Checking for Accelerate framework', 'yes')
257        else:
[19237a7]258            ctx.msg('Checking for Accelerate framework', 'no (disabled)',
259                    color = 'YELLOW')
[a93dab3]260
[c1303c6]261    if target_platform in [ 'ios', 'iosimulator', 'watchos', 'watchsimulator' ]:
[a93dab3]262        MINSDKVER="6.1"
[92ebdac]263        xcodeslct_output = subprocess.check_output (['xcode-select', '--print-path'])
264        XCODEPATH = xcodeslct_output.decode(sys.stdout.encoding).strip()
265        if target_platform == 'ios':
266            SDKNAME = "iPhoneOS"
267        elif target_platform == 'iosimulator':
268            SDKNAME = "iPhoneSimulator"
[c1303c6]269        elif target_platform == 'watchos':
270            SDKNAME = "WatchOS"
271        elif target_platform == 'watchsimulator':
272            SDKNAME = "WatchSimulator"
[92ebdac]273        else:
274            raise ctx.errors.ConfigurationError ("Error: unknown target platform '"
275                + target_platform + "'")
276        DEVROOT = "%(XCODEPATH)s/Platforms/%(SDKNAME)s.platform/Developer" % locals()
277        SDKROOT = "%(DEVROOT)s/SDKs/%(SDKNAME)s.sdk" % locals()
[a93dab3]278        ctx.env.CFLAGS += ['-std=c99']
[c1303c6]279        if ctx.options.enable_apple_audio != False and target_platform.startswith ('ios'):
[cc81763]280            ctx.define('HAVE_AUDIO_UNIT', 1)
281            #ctx.env.FRAMEWORK += ['CoreFoundation', 'AudioToolbox']
[a93dab3]282        if target_platform == 'ios':
[94b16497]283            ctx.env.CFLAGS += [ '-fembed-bitcode' ]
[7aa4aaa]284            ctx.env.CFLAGS += [ '-arch', 'arm64' ]
[a93dab3]285            ctx.env.CFLAGS += [ '-arch', 'armv7' ]
286            ctx.env.CFLAGS += [ '-arch', 'armv7s' ]
[7aa4aaa]287            ctx.env.LINKFLAGS += [ '-arch', 'arm64' ]
[a93dab3]288            ctx.env.LINKFLAGS += ['-arch', 'armv7']
289            ctx.env.LINKFLAGS += ['-arch', 'armv7s']
290            ctx.env.CFLAGS += [ '-miphoneos-version-min=' + MINSDKVER ]
291            ctx.env.LINKFLAGS += [ '-miphoneos-version-min=' + MINSDKVER ]
[2e3f88f]292        elif target_platform == 'iosimulator':
[a93dab3]293            ctx.env.CFLAGS += [ '-arch', 'x86_64' ]
[b16e592]294            ctx.env.CFLAGS += [ '-arch', 'arm64' ]
[a93dab3]295            ctx.env.LINKFLAGS += ['-arch', 'x86_64']
[b16e592]296            ctx.env.LINKFLAGS += ['-arch', 'arm64']
[a93dab3]297            ctx.env.CFLAGS += [ '-mios-simulator-version-min=' + MINSDKVER ]
298            ctx.env.LINKFLAGS += [ '-mios-simulator-version-min=' + MINSDKVER ]
[c1303c6]299        elif target_platform == 'watchos':
300            ctx.env.CFLAGS += [ '-arch', 'armv7' ]
301            ctx.env.CFLAGS += [ '-arch', 'armv7s' ]
302            ctx.env.LINKFLAGS += ['-arch', 'armv7']
303            ctx.env.LINKFLAGS += ['-arch', 'armv7s']
304            ctx.env.CFLAGS += [ '-mwatchos-version-min=' + MINSDKVER ]
305            ctx.env.LINKFLAGS += [ '-mwatchos-version-min=' + MINSDKVER ]
306        elif target_platform == 'watchsimulator':
307            ctx.env.CFLAGS += [ '-arch', 'x86_64' ]
308            ctx.env.CFLAGS += [ '-arch', 'arm64' ]
309            ctx.env.LINKFLAGS += ['-arch', 'x86_64']
310            ctx.env.LINKFLAGS += ['-arch', 'arm64']
311            ctx.env.CFLAGS += [ '-mwatchsimulator-version-min=' + MINSDKVER ]
312            ctx.env.LINKFLAGS += [ '-mwatchsimulator-version-min=' + MINSDKVER ]
[a93dab3]313        ctx.env.CFLAGS += [ '-isysroot' , SDKROOT]
314        ctx.env.LINKFLAGS += [ '-isysroot' , SDKROOT]
315
[fb5838a]316    if target_platform == 'emscripten':
[023e4b2]317        if ctx.options.build_type == "debug":
318            ctx.env.cshlib_PATTERN = '%s.js'
[6421221]319            ctx.env.LINKFLAGS += ['-s','ASSERTIONS=2']
320            ctx.env.LINKFLAGS += ['-s','SAFE_HEAP=1']
321            ctx.env.LINKFLAGS += ['-s','ALIASING_FUNCTION_POINTERS=0']
322            ctx.env.LINKFLAGS += ['-O0']
[023e4b2]323        else:
324            ctx.env.LINKFLAGS += ['-Oz']
325            ctx.env.cshlib_PATTERN = '%s.min.js'
[4b084a9]326
[342eb13e]327        # doesnt ship file system support in lib
[4b084a9]328        ctx.env.LINKFLAGS_cshlib += ['-s', 'NO_FILESYSTEM=1']
329        # put memory file inside generated js files for easier portability
330        ctx.env.LINKFLAGS += ['--memory-init-file', '0']
[fb5838a]331        ctx.env.cprogram_PATTERN = "%s.js"
[e717fae]332        ctx.env.cstlib_PATTERN = '%s.a'
[4b084a9]333
[342eb13e]334        # tell emscripten functions we want to expose
[f3f0d14]335        from python.lib.gen_external import get_c_declarations, \
[19237a7]336                get_cpp_objects_from_c_declarations, \
337                get_all_func_names_from_lib, \
[f3f0d14]338                generate_lib_from_c_declarations
[19237a7]339        # emscripten can't use double
340        c_decls = get_c_declarations(usedouble=False)
[873646d]341        objects = list(get_cpp_objects_from_c_declarations(c_decls))
[4b084a9]342        # ensure that aubio structs are exported
343        objects += ['fvec_t', 'cvec_t', 'fmat_t']
344        lib = generate_lib_from_c_declarations(objects, c_decls)
345        exported_funcnames = get_all_func_names_from_lib(lib)
346        c_mangled_names = ['_' + s for s in exported_funcnames]
[19237a7]347        ctx.env.LINKFLAGS_cshlib += ['-s',
348                'EXPORTED_FUNCTIONS=%s' % c_mangled_names]
[4b084a9]349
[a93dab3]350    # check support for C99 __VA_ARGS__ macros
351    check_c99_varargs = '''
[0318cc1]352#include <stdio.h>
353#define AUBIO_ERR(...) fprintf(stderr, __VA_ARGS__)
354'''
[a93dab3]355
356    if ctx.check_cc(fragment = check_c99_varargs,
357            type='cstlib',
[413d4bf]358            msg = 'Checking for C99 __VA_ARGS__ macro',
359            mandatory = False):
[a93dab3]360        ctx.define('HAVE_C99_VARARGS_MACROS', 1)
361
[06c6d7d]362    # show a message about enable_double status
[a93dab3]363    if (ctx.options.enable_double == True):
[06c6d7d]364        ctx.msg('Checking for size of smpl_t', 'double')
365        ctx.msg('Checking for size of lsmp_t', 'long double')
[a93dab3]366    else:
[06c6d7d]367        ctx.msg('Checking for size of smpl_t', 'float')
368        ctx.msg('Checking for size of lsmp_t', 'double')
[a93dab3]369
370    # optionally use complex.h
371    if (ctx.options.enable_complex == True):
372        ctx.check(header_name='complex.h')
[06c6d7d]373    else:
374        ctx.msg('Checking if complex.h is enabled', 'no')
[b701179]375
[986131d]376    # check for Intel IPP
377    if (ctx.options.enable_intelipp != False):
[19237a7]378        has_ipp_headers = ctx.check(header_name=['ippcore.h', 'ippvm.h',
379            'ipps.h'], mandatory = False)
[f3f0d14]380        has_ipp_libs = ctx.check(lib=['ippcore', 'ippvm', 'ipps'],
381                uselib_store='INTEL_IPP', mandatory = False)
382        if (has_ipp_headers and has_ipp_libs):
[986131d]383            ctx.msg('Checking if Intel IPP is available', 'yes')
384            ctx.define('HAVE_INTEL_IPP', 1)
385            if ctx.env.CC_NAME == 'msvc':
[19237a7]386                # force linking multi-threaded static IPP libraries on Windows
387                # with msvc
[986131d]388                ctx.define('_IPP_SEQUENTIAL_STATIC', 1)
389        else:
390            ctx.msg('Checking if Intel IPP is available', 'no')
[b701179]391
[a93dab3]392    # check for fftw3
393    if (ctx.options.enable_fftw3 != False or ctx.options.enable_fftw3f != False):
394        # one of fftwf or fftw3f
395        if (ctx.options.enable_fftw3f != False):
[badb525]396            ctx.check_cfg(package = 'fftw3f',
397                    args = '--cflags --libs fftw3f >= 3.0.0',
[795fcd9]398                    mandatory = ctx.options.enable_fftw3f)
[a93dab3]399            if (ctx.options.enable_double == True):
[795fcd9]400                ctx.msg('Warning',
401                        'fftw3f enabled, but compiling in double precision!')
[a93dab3]402        else:
[795fcd9]403            # fftw3f disabled, take most sensible one according to
404            # enable_double
[a93dab3]405            if (ctx.options.enable_double == True):
[badb525]406                ctx.check_cfg(package = 'fftw3',
407                        args = '--cflags --libs fftw3 >= 3.0.0.',
408                        mandatory = ctx.options.enable_fftw3)
[a93dab3]409            else:
[badb525]410                ctx.check_cfg(package = 'fftw3f',
411                        args = '--cflags --libs fftw3f >= 3.0.0',
[795fcd9]412                        mandatory = ctx.options.enable_fftw3)
[a93dab3]413        ctx.define('HAVE_FFTW3', 1)
414
[986131d]415    # fftw not enabled, use vDSP, intelIPP or ooura
[a93dab3]416    if 'HAVE_FFTW3F' in ctx.env.define_key:
417        ctx.msg('Checking for FFT implementation', 'fftw3f')
418    elif 'HAVE_FFTW3' in ctx.env.define_key:
419        ctx.msg('Checking for FFT implementation', 'fftw3')
420    elif 'HAVE_ACCELERATE' in ctx.env.define_key:
421        ctx.msg('Checking for FFT implementation', 'vDSP')
[986131d]422    elif 'HAVE_INTEL_IPP' in ctx.env.define_key:
423        ctx.msg('Checking for FFT implementation', 'Intel IPP')
[36f954a]424    else:
[a93dab3]425        ctx.msg('Checking for FFT implementation', 'ooura')
426
427    # check for libsndfile
428    if (ctx.options.enable_sndfile != False):
[badb525]429        ctx.check_cfg(package = 'sndfile',
430                args = '--cflags --libs sndfile >= 1.0.4',
[795fcd9]431                mandatory = ctx.options.enable_sndfile)
[a93dab3]432
433    # check for libsamplerate
[8be88e7]434    if (ctx.options.enable_double):
435        if (ctx.options.enable_samplerate):
[19237a7]436            ctx.fatal("Could not compile aubio in double precision mode' \
437                    ' with libsamplerate")
[8be88e7]438        else:
439            ctx.options.enable_samplerate = False
[19237a7]440            ctx.msg('Checking if using samplerate',
441                    'no (disabled in double precision mode)', color = 'YELLOW')
[a93dab3]442    if (ctx.options.enable_samplerate != False):
[badb525]443        ctx.check_cfg(package = 'samplerate',
444                args = '--cflags --libs samplerate >= 0.0.15',
[795fcd9]445                mandatory = ctx.options.enable_samplerate)
[a93dab3]446
[d9d1010]447    # check for librubberband
448    if (ctx.options.enable_rubberband != False):
[8e1328f]449        ctx.check_cfg(package = 'rubberband', atleast_version = '1.3',
[d9d1010]450                args = '--cflags --libs',
451                mandatory = ctx.options.enable_rubberband)
452
[a93dab3]453    # check for jack
454    if (ctx.options.enable_jack != False):
[eb99982]455        ctx.check_cfg(package = 'jack',
[795fcd9]456                args = '--cflags --libs',
457                mandatory = ctx.options.enable_jack)
[a93dab3]458
459    # check for libav
460    if (ctx.options.enable_avcodec != False):
[badb525]461        ctx.check_cfg(package = 'libavcodec',
462                args = '--cflags --libs libavcodec >= 54.35.0',
463                uselib_store = 'AVCODEC',
[795fcd9]464                mandatory = ctx.options.enable_avcodec)
[badb525]465        ctx.check_cfg(package = 'libavformat',
466                args = '--cflags --libs libavformat >= 52.3.0',
467                uselib_store = 'AVFORMAT',
[795fcd9]468                mandatory = ctx.options.enable_avcodec)
[badb525]469        ctx.check_cfg(package = 'libavutil',
470                args = '--cflags --libs libavutil >= 52.3.0',
471                uselib_store = 'AVUTIL',
[795fcd9]472                mandatory = ctx.options.enable_avcodec)
[badb525]473        ctx.check_cfg(package = 'libswresample',
[65b5381]474                args = '--cflags --libs libswresample >= 1.2.0',
[badb525]475                uselib_store = 'SWRESAMPLE',
[d82e7a4]476                mandatory = False)
477
478        msg_check = 'Checking for all libav libraries'
479        if 'HAVE_AVCODEC' not in ctx.env:
480            ctx.msg(msg_check, 'not found (missing avcodec)', color = 'YELLOW')
481        elif 'HAVE_AVFORMAT' not in ctx.env:
482            ctx.msg(msg_check, 'not found (missing avformat)', color = 'YELLOW')
483        elif 'HAVE_AVUTIL' not in ctx.env:
484            ctx.msg(msg_check, 'not found (missing avutil)', color = 'YELLOW')
[ae9b76b]485        elif 'HAVE_SWRESAMPLE' not in ctx.env :
486            resample_missing = 'not found (missing swresample)'
[c3b3b84]487            ctx.msg(msg_check, resample_missing, color = 'YELLOW')
[549928e]488        else:
[d82e7a4]489            ctx.msg(msg_check, 'yes')
490            ctx.define('HAVE_LIBAV', 1)
[a93dab3]491
[3efb631]492    # check for vorbisenc
493    if (ctx.options.enable_vorbis != False):
[4ed1e47]494        ctx.check_cfg(package = 'vorbisenc vorbis ogg',
[3efb631]495                args = '--cflags --libs',
496                uselib_store = 'VORBISENC',
497                mandatory = ctx.options.enable_vorbis)
498
[1ba359c]499    # check for flac
500    if (ctx.options.enable_flac != False):
501        ctx.check_cfg(package = 'flac',
502                args = '--cflags --libs',
503                uselib_store = 'FLAC',
504                mandatory = ctx.options.enable_flac)
505
[f9a543e]506    if (ctx.options.enable_wavread != False):
507        ctx.define('HAVE_WAVREAD', 1)
[19237a7]508    ctx.msg('Checking if using source_wavread',
509            ctx.options.enable_wavread and 'yes' or 'no')
[f9a543e]510    if (ctx.options.enable_wavwrite!= False):
511        ctx.define('HAVE_WAVWRITE', 1)
[19237a7]512    ctx.msg('Checking if using sink_wavwrite',
513            ctx.options.enable_wavwrite and 'yes' or 'no')
[5158c22]514
[fe05d1f]515    # use BLAS/ATLAS
516    if (ctx.options.enable_blas != False):
517        ctx.check_cfg(package = 'blas',
518                args = '--cflags --libs',
519                uselib_store='BLAS', mandatory = ctx.options.enable_blas)
520        if 'LIB_BLAS' in ctx.env:
521            blas_header = None
522            if ctx.env['LIBPATH_BLAS']:
523                if 'atlas' in ctx.env['LIBPATH_BLAS'][0]:
524                    blas_header = 'atlas/cblas.h'
525                elif 'openblas' in ctx.env['LIBPATH_BLAS'][0]:
526                    blas_header = 'openblas/cblas.h'
527            else:
528                blas_header = 'cblas.h'
529            ctx.check(header_name = blas_header, mandatory =
530                    ctx.options.enable_atlas)
[f0ce36a1]531
[a93dab3]532    # use memcpy hacks
533    if (ctx.options.enable_memcpy == True):
534        ctx.define('HAVE_MEMCPY_HACKS', 1)
535
536    # write configuration header
537    ctx.write_config_header('src/config.h')
538
[06c6d7d]539    # the following defines will be passed as arguments to the compiler
540    # instead of being written to src/config.h
[1910fed]541    ctx.define('HAVE_CONFIG_H', 1)
[06c6d7d]542
[a93dab3]543    # add some defines used in examples
544    ctx.define('AUBIO_PREFIX', ctx.env['PREFIX'])
545    ctx.define('PACKAGE', APPNAME)
546
[06c6d7d]547    # double precision mode
548    if (ctx.options.enable_double == True):
549        ctx.define('HAVE_AUBIO_DOUBLE', 1)
550
[a33d406]551    if (ctx.options.enable_docs != False):
552        # check if txt2man is installed, optional
553        try:
554          ctx.find_program('txt2man', var='TXT2MAN')
555        except ctx.errors.ConfigurationError:
556          ctx.to_log('txt2man was not found (ignoring)')
[000b090]557
[a33d406]558        # check if doxygen is installed, optional
559        try:
560          ctx.find_program('doxygen', var='DOXYGEN')
561        except ctx.errors.ConfigurationError:
562          ctx.to_log('doxygen was not found (ignoring)')
[52a25e5]563
[7800335]564        # check if sphinx-build is installed, optional
565        try:
566          ctx.find_program('sphinx-build', var='SPHINX')
567        except ctx.errors.ConfigurationError:
568          ctx.to_log('sphinx-build was not found (ignoring)')
569
[6ed0f4e]570def build(bld):
[985a5d1]571    bld.env['VERSION'] = VERSION
572    bld.env['LIB_VERSION'] = LIB_VERSION
573
[7b38f3f]574    # main source
[985a5d1]575    bld.recurse('src')
[fee0094]576
[7b38f3f]577    # add sub directories
[c1303c6]578    if bld.env['DEST_OS'] not in ['ios', 'iosimulator', 'watchos', 'watchsimulator', 'android']:
[9fabad5]579        if bld.env['DEST_OS']=='emscripten' and not bld.options.testcmd:
580            bld.options.testcmd = 'node %s'
[445e60f5]581        if bld.options.enable_examples:
582            bld.recurse('examples')
583        if bld.options.enable_tests:
584            bld.recurse('tests')
[985a5d1]585
[7b38f3f]586    # pkg-config template
[985a5d1]587    bld( source = 'aubio.pc.in' )
588
[7b38f3f]589    # documentation
590    txt2man(bld)
591    doxygen(bld)
592    sphinx(bld)
593
[9ffa590]594    from waflib.Tools import waf_unit_test
595    bld.add_post_fun(waf_unit_test.summary)
596    bld.add_post_fun(waf_unit_test.set_exit_code)
597
[7b38f3f]598def txt2man(bld):
[52a25e5]599    # build manpages from txt files using txt2man
[403e9dd]600    if bld.env['TXT2MAN']:
[985a5d1]601        from waflib import TaskGen
602        if 'MANDIR' not in bld.env:
[641e533]603            bld.env['MANDIR'] = bld.env['DATAROOTDIR'] + '/man'
[e3b77e8]604        bld.env.VERSION = VERSION
[403e9dd]605        rule_str = '${TXT2MAN} -t `basename ${TGT} | cut -f 1 -d . | tr a-z A-Z`'
606        rule_str += ' -r ${PACKAGE}\\ ${VERSION} -P ${PACKAGE}'
607        rule_str += ' -v ${PACKAGE}\\ User\\\'s\\ manual'
608        rule_str += ' -s 1 ${SRC} > ${TGT}'
[985a5d1]609        TaskGen.declare_chain(
[403e9dd]610                name      = 'txt2man',
611                rule      = rule_str,
612                ext_in    = '.txt',
[985a5d1]613                ext_out   = '.1',
614                reentrant = False,
615                install_path =  '${MANDIR}/man1',
616                )
[403e9dd]617        bld( source = bld.path.ant_glob('doc/*.txt') )
[985a5d1]618
[7b38f3f]619def doxygen(bld):
[52a25e5]620    # build documentation from source files using doxygen
621    if bld.env['DOXYGEN']:
[a24a84e]622        bld.env.VERSION = VERSION
[6383ca4]623        rule = '( cat ${SRC[0]} && echo PROJECT_NUMBER=${VERSION}'
624        rule += ' && echo OUTPUT_DIRECTORY=%s && echo HTML_OUTPUT=%s )'
[a24a84e]625        rule += ' | doxygen - > /dev/null'
[6383ca4]626        rule %= (os.path.abspath(out), 'api')
[a24a84e]627        bld( name = 'doxygen', rule = rule,
[6383ca4]628                source = ['doc/web.cfg']
629                    + bld.path.find_dir('src').ant_glob('**/*.h'),
630                target = bld.path.find_or_declare('api/index.html'),
631                cwd = bld.path.find_dir('doc'))
[2d64a24]632        # evaluate nodes lazily to prevent build directory traversal warnings
[6383ca4]633        bld.install_files('${DATAROOTDIR}/doc/libaubio-doc/api',
[2d64a24]634                bld.path.find_or_declare('api').ant_glob('**/*',
635                    generator=True), cwd=bld.path.find_or_declare('api'),
[6383ca4]636                relative_trick=True)
[7800335]637
[7b38f3f]638def sphinx(bld):
[6383ca4]639    # build documentation from source files using sphinx-build
640    try:
641        import aubio
642        has_aubio = True
643    except ImportError:
644        from waflib import Logs
645        Logs.pprint('YELLOW', "Sphinx manual: install aubio first")
646        has_aubio = False
647    if bld.env['SPHINX'] and has_aubio:
[e3b77e8]648        bld.env.VERSION = VERSION
[6383ca4]649        rule = '${SPHINX} -b html -D release=${VERSION}' \
650                ' -D version=${VERSION} -W -a -q' \
651                ' -d %s ' % os.path.join(os.path.abspath(out), 'doctrees')
652        rule += ' . %s' % os.path.join(os.path.abspath(out), 'manual')
653        bld( name = 'sphinx', rule = rule,
654                cwd = bld.path.find_dir('doc'),
655                source = bld.path.find_dir('doc').ant_glob('*.rst'),
656                target = bld.path.find_or_declare('manual/index.html'))
[2d64a24]657        # evaluate nodes lazily to prevent build directory traversal warnings
[6383ca4]658        bld.install_files('${DATAROOTDIR}/doc/libaubio-doc/manual',
[2d64a24]659                bld.path.find_or_declare('manual').ant_glob('**/*',
660                    generator=True), cwd=bld.path.find_or_declare('manual'),
[6383ca4]661                relative_trick=True)
[50d56cc]662
[7b38f3f]663# register the previous rules as build rules
664from waflib.Build import BuildContext
665
666class build_txt2man(BuildContext):
667    cmd = 'txt2man'
668    fun = 'txt2man'
669
670class build_manpages(BuildContext):
671    cmd = 'manpages'
672    fun = 'txt2man'
673
674class build_sphinx(BuildContext):
675    cmd = 'sphinx'
676    fun = 'sphinx'
677
678class build_doxygen(BuildContext):
679    cmd = 'doxygen'
680    fun = 'doxygen'
681
[30250de]682def shutdown(bld):
[985a5d1]683    from waflib import Logs
684    if bld.options.target_platform in ['ios', 'iosimulator']:
[19237a7]685        msg ='building for %s, contact the author for a commercial license' \
686                % bld.options.target_platform
[985a5d1]687        Logs.pprint('RED', msg)
688        msg ='   Paul Brossier <piem@aubio.org>'
689        Logs.pprint('RED', msg)
[b4d1ba1]690
691def dist(ctx):
[19237a7]692    ctx.excl  = ' **/.waf*'
693    ctx.excl += ' **/.git*'
694    ctx.excl += ' **/*~ **/*.pyc **/*.swp **/*.swo **/*.swn **/.lock-w*'
[b4d1ba1]695    ctx.excl += ' **/build/*'
[99d8cbb]696    ctx.excl += ' doc/_build'
697    ctx.excl += ' python/demos_*'
[22dd9dc]698    ctx.excl += ' **/python/gen **/python/build **/python/dist'
[981e7082]699    ctx.excl += ' **/python/ext/config.h'
[99d8cbb]700    ctx.excl += ' **/python/lib/aubio/_aubio.so'
701    ctx.excl += ' **.egg-info'
[a4afbac]702    ctx.excl += ' **/.eggs'
703    ctx.excl += ' **/.pytest_cache'
704    ctx.excl += ' **/.cache'
[22dd9dc]705    ctx.excl += ' **/**.zip **/**.tar.bz2'
[fcc11e9]706    ctx.excl += ' **.tar.bz2**'
[a93dab3]707    ctx.excl += ' **/doc/full/* **/doc/web/*'
[e57a7d4]708    ctx.excl += ' **/doc/full.cfg'
[b4d1ba1]709    ctx.excl += ' **/python/*.db'
710    ctx.excl += ' **/python.old/*'
[981e7082]711    ctx.excl += ' **/python/*/*.old'
[429ff6c]712    ctx.excl += ' **/python/lib/aubio/*.so'
[172b1fe]713    ctx.excl += ' **/python/tests/sounds'
[7b2d740]714    ctx.excl += ' **/**.asc'
[5e544f1]715    ctx.excl += ' **/dist*'
[73aac2a]716    ctx.excl += ' **/.DS_Store'
717    ctx.excl += ' **/.travis.yml'
[5e544f1]718    ctx.excl += ' **/.appveyor.yml'
[8142a7e]719    ctx.excl += ' **/.circleci/*'
[622b6dc]720    ctx.excl += ' **/azure-pipelines.yml'
[429ff6c]721    ctx.excl += ' **/.coverage*'
Note: See TracBrowser for help on using the repository browser.