source: wscript

fix/applefworks
Last change on this file was bcae79a, checked in by Paul Brossier <piem@piem.org>, 7 weeks ago

[waf] drop audio unit on ios

  • Property mode set to 100644
File size: 29.7 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
14import subprocess
15
16APPNAME = 'aubio'
17
18from this_version import *
19
20VERSION = get_aubio_version()
21LIB_VERSION = get_libaubio_version()
22
23top = '.'
24out = 'build'
25
26def add_option_enable_disable(ctx, name, default = None,
27        help_str = None, help_disable_str = None):
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 )
40
41def options(ctx):
42    ctx.add_option('--build-type', action = 'store',
43            default = "release",
44            choices = ('debug', 'release'),
45            dest = 'build_type',
46            help = 'whether to compile with (--build-type=release)' \
47                    ' or without (--build-type=debug)' \
48                    ' compiler opimizations [default: release]')
49    ctx.add_option('--debug', action = 'store_const',
50            dest = 'build_type', const = 'debug',
51            help = 'build in debug mode (see --build-type)')
52    ctx.add_option('--nodeps', action = 'store_const',
53            dest = 'nodeps', const = 'debug',
54            help = 'build with no external dependencies')
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')
61    add_option_enable_disable(ctx, 'intelipp', default = False,
62            help_str = 'use Intel IPP libraries (auto)',
63            help_disable_str = 'do not use Intel IPP libraries')
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')
76    add_option_enable_disable(ctx, 'vorbis', default = None,
77            help_str = 'compile with libvorbis (auto)',
78            help_disable_str = 'disable libvorbis')
79    add_option_enable_disable(ctx, 'flac', default = None,
80            help_str = 'compile with libFLAC (auto)',
81            help_disable_str = 'disable libflac')
82    add_option_enable_disable(ctx, 'samplerate', default = None,
83            help_str = 'compile with samplerate (auto)',
84            help_disable_str = 'disable samplerate')
85    add_option_enable_disable(ctx, 'rubberband', default = None,
86            help_str = 'compile with rubberband (auto)',
87            help_disable_str = 'disable rubberband')
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)')
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)')
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')
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')
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')
106    add_option_enable_disable(ctx, 'atlas', default = False,
107            help_str = 'use ATLAS acceleration library (no)',
108            help_disable_str = 'do not use ATLAS library')
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')
115
116    add_option_enable_disable(ctx, 'docs', default = None,
117            help_str = 'build documentation (auto)',
118            help_disable_str = 'do not build documentation')
119
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
128    ctx.add_option('--with-target-platform', type='string',
129            help='set target platform for cross-compilation',
130            dest='target_platform')
131
132    ctx.load('compiler_c')
133    ctx.load('waf_unit_test')
134    ctx.load('gnu_dirs')
135    ctx.load('waf_gensyms', tooldir='.')
136
137def configure(ctx):
138    target_platform = sys.platform
139    if ctx.options.target_platform:
140        target_platform = ctx.options.target_platform
141
142    if ctx.options.nodeps:
143        external_deps = [
144                'sndfile',
145                'samplerate',
146                'jack',
147                'rubberband',
148                'avcodec',
149                'blas',
150                'fftw3',
151                'fftw3f',
152                'flac',
153                'vorbis',
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
166    from waflib import Options
167
168    if target_platform=='emscripten':
169        ctx.load('c_emscripten')
170    else:
171        ctx.load('compiler_c')
172
173    ctx.load('waf_unit_test')
174    ctx.load('gnu_dirs')
175    ctx.load('waf_gensyms', tooldir='.')
176
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')
182    ctx.check(header_name='errno.h')
183    ctx.check(header_name='limits.h')
184    ctx.check(header_name='stdarg.h')
185    ctx.check(header_name='getopt.h', mandatory = False)
186    ctx.check(header_name='unistd.h', mandatory = False)
187
188    ctx.env['DEST_OS'] = target_platform
189
190    if ctx.options.build_type == "debug":
191        ctx.define('DEBUG', 1)
192    else:
193        ctx.define('NDEBUG', 1)
194
195    if ctx.env.CC_NAME != 'msvc':
196        if ctx.options.build_type == "debug":
197            # no optimization in debug mode
198            ctx.env.prepend_value('CFLAGS', ['-O0'])
199        else:
200            if target_platform == 'emscripten':
201                # -Oz for small js file generation
202                ctx.env.prepend_value('CFLAGS', ['-Oz'])
203            else:
204                # default to -O2 in release mode
205                ctx.env.prepend_value('CFLAGS', ['-O2'])
206        # enable debug symbols and configure warnings
207        ctx.env.prepend_value('CFLAGS', ['-g', '-Wall', '-Wextra'])
208    else:
209        # enable debug symbols
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']
214        ctx.env.LINKFLAGS += ['/DEBUG', '/INCREMENTAL:NO']
215        # configure warnings
216        ctx.env.CFLAGS += ['/W4', '/D_CRT_SECURE_NO_WARNINGS']
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']
221        # set optimization level and runtime libs
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']
228
229    ctx.check_cc(lib='m', uselib_store='M', mandatory=False)
230
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'
236
237    if target_platform == 'darwin' and ctx.options.enable_fat:
238        ctx.env.CFLAGS += ['-arch', 'arm64', '-arch', 'x86_64']
239        ctx.env.LINKFLAGS += ['-arch', 'arm64', '-arch', 'x86_64']
240        MINSDKVER="13.3"
241        ctx.env.CFLAGS += [ '-mmacosx-version-min=' + MINSDKVER ]
242        ctx.env.LINKFLAGS += [ '-mmacosx-version-min=' + MINSDKVER ]
243
244    if target_platform in [ 'darwin', 'ios', 'iosimulator' ]:
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)
249            ctx.msg('Checking for AudioToolbox.framework', 'yes')
250        else:
251            ctx.msg('Checking for AudioToolbox.framework', 'no (disabled)',
252                    color = 'YELLOW')
253        if (ctx.options.enable_accelerate != False):
254            ctx.define('HAVE_ACCELERATE', 1)
255            ctx.env.FRAMEWORK += ['Accelerate']
256            ctx.msg('Checking for Accelerate framework', 'yes')
257        else:
258            ctx.msg('Checking for Accelerate framework', 'no (disabled)',
259                    color = 'YELLOW')
260
261    if target_platform in [ 'ios', 'iosimulator', 'watchos', 'watchsimulator' ]:
262        MINSDKVER="16.4"
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"
269        elif target_platform == 'watchos':
270            SDKNAME = "WatchOS"
271        elif target_platform == 'watchsimulator':
272            SDKNAME = "WatchSimulator"
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()
278        ctx.env.CFLAGS += ['-std=c99']
279        if ctx.options.enable_apple_audio != False and target_platform.startswith ('ios'):
280            #ctx.define('HAVE_AUDIO_UNIT', 1)
281            #ctx.env.FRAMEWORK += ['CoreFoundation', 'AudioToolbox']
282            pass
283        if target_platform == 'ios':
284            ctx.env.CFLAGS += [ '-fembed-bitcode' ]
285            ctx.env.CFLAGS += [ '-arch', 'arm64' ]
286            #ctx.env.CFLAGS += [ '-arch', 'armv7' ]
287            #ctx.env.CFLAGS += [ '-arch', 'armv7s' ]
288            ctx.env.LINKFLAGS += [ '-arch', 'arm64' ]
289            #ctx.env.LINKFLAGS += ['-arch', 'armv7']
290            #ctx.env.LINKFLAGS += ['-arch', 'armv7s']
291            ctx.env.CFLAGS += [ '-miphoneos-version-min=' + MINSDKVER ]
292            ctx.env.LINKFLAGS += [ '-miphoneos-version-min=' + MINSDKVER ]
293        elif target_platform == 'iosimulator':
294            ctx.env.CFLAGS += [ '-arch', 'x86_64' ]
295            ctx.env.CFLAGS += [ '-arch', 'arm64' ]
296            ctx.env.LINKFLAGS += ['-arch', 'x86_64']
297            ctx.env.LINKFLAGS += ['-arch', 'arm64']
298            ctx.env.CFLAGS += [ '-mios-simulator-version-min=' + MINSDKVER ]
299            ctx.env.LINKFLAGS += [ '-mios-simulator-version-min=' + MINSDKVER ]
300        elif target_platform == 'watchos':
301            ctx.env.CFLAGS += [ '-arch', 'armv7' ]
302            ctx.env.CFLAGS += [ '-arch', 'armv7s' ]
303            ctx.env.LINKFLAGS += ['-arch', 'armv7']
304            ctx.env.LINKFLAGS += ['-arch', 'armv7s']
305            ctx.env.CFLAGS += [ '-mwatchos-version-min=' + MINSDKVER ]
306            ctx.env.LINKFLAGS += [ '-mwatchos-version-min=' + MINSDKVER ]
307        elif target_platform == 'watchsimulator':
308            ctx.env.CFLAGS += [ '-arch', 'x86_64' ]
309            ctx.env.CFLAGS += [ '-arch', 'arm64' ]
310            ctx.env.LINKFLAGS += ['-arch', 'x86_64']
311            ctx.env.LINKFLAGS += ['-arch', 'arm64']
312            ctx.env.CFLAGS += [ '-mwatchsimulator-version-min=' + MINSDKVER ]
313            ctx.env.LINKFLAGS += [ '-mwatchsimulator-version-min=' + MINSDKVER ]
314        ctx.env.CFLAGS += [ '-isysroot' , SDKROOT]
315        ctx.env.LINKFLAGS += [ '-isysroot' , SDKROOT]
316
317    if target_platform == 'emscripten':
318        if ctx.options.build_type == "debug":
319            ctx.env.cshlib_PATTERN = '%s.js'
320            ctx.env.LINKFLAGS += ['-s','ASSERTIONS=2']
321            ctx.env.LINKFLAGS += ['-s','SAFE_HEAP=1']
322            ctx.env.LINKFLAGS += ['-s','ALIASING_FUNCTION_POINTERS=0']
323            ctx.env.LINKFLAGS += ['-O0']
324        else:
325            ctx.env.LINKFLAGS += ['-Oz']
326            ctx.env.cshlib_PATTERN = '%s.min.js'
327
328        # doesnt ship file system support in lib
329        ctx.env.LINKFLAGS_cshlib += ['-s', 'NO_FILESYSTEM=1']
330        # put memory file inside generated js files for easier portability
331        ctx.env.LINKFLAGS += ['--memory-init-file', '0']
332        ctx.env.cprogram_PATTERN = "%s.js"
333        ctx.env.cstlib_PATTERN = '%s.a'
334
335        # tell emscripten functions we want to expose
336        from python.lib.gen_external import get_c_declarations, \
337                get_cpp_objects_from_c_declarations, \
338                get_all_func_names_from_lib, \
339                generate_lib_from_c_declarations
340        # emscripten can't use double
341        c_decls = get_c_declarations(usedouble=False)
342        objects = list(get_cpp_objects_from_c_declarations(c_decls))
343        # ensure that aubio structs are exported
344        objects += ['fvec_t', 'cvec_t', 'fmat_t']
345        lib = generate_lib_from_c_declarations(objects, c_decls)
346        exported_funcnames = get_all_func_names_from_lib(lib)
347        c_mangled_names = ['_' + s for s in exported_funcnames]
348        ctx.env.LINKFLAGS_cshlib += ['-s',
349                'EXPORTED_FUNCTIONS=%s' % c_mangled_names]
350
351    # check support for C99 __VA_ARGS__ macros
352    check_c99_varargs = '''
353#include <stdio.h>
354#define AUBIO_ERR(...) fprintf(stderr, __VA_ARGS__)
355'''
356
357    if ctx.check_cc(fragment = check_c99_varargs,
358            type='cstlib',
359            msg = 'Checking for C99 __VA_ARGS__ macro',
360            mandatory = False):
361        ctx.define('HAVE_C99_VARARGS_MACROS', 1)
362
363    # show a message about enable_double status
364    if (ctx.options.enable_double == True):
365        ctx.msg('Checking for size of smpl_t', 'double')
366        ctx.msg('Checking for size of lsmp_t', 'long double')
367    else:
368        ctx.msg('Checking for size of smpl_t', 'float')
369        ctx.msg('Checking for size of lsmp_t', 'double')
370
371    # optionally use complex.h
372    if (ctx.options.enable_complex == True):
373        ctx.check(header_name='complex.h')
374    else:
375        ctx.msg('Checking if complex.h is enabled', 'no')
376
377    # check for Intel IPP
378    if (ctx.options.enable_intelipp != False):
379        has_ipp_headers = ctx.check(header_name=['ippcore.h', 'ippvm.h',
380            'ipps.h'], mandatory = False)
381        has_ipp_libs = ctx.check(lib=['ippcore', 'ippvm', 'ipps'],
382                uselib_store='INTEL_IPP', mandatory = False)
383        if (has_ipp_headers and has_ipp_libs):
384            ctx.msg('Checking if Intel IPP is available', 'yes')
385            ctx.define('HAVE_INTEL_IPP', 1)
386            if ctx.env.CC_NAME == 'msvc':
387                # force linking multi-threaded static IPP libraries on Windows
388                # with msvc
389                ctx.define('_IPP_SEQUENTIAL_STATIC', 1)
390        else:
391            ctx.msg('Checking if Intel IPP is available', 'no')
392
393    # check for fftw3
394    if (ctx.options.enable_fftw3 != False or ctx.options.enable_fftw3f != False):
395        # one of fftwf or fftw3f
396        if (ctx.options.enable_fftw3f != False):
397            ctx.check_cfg(package = 'fftw3f',
398                    args = '--cflags --libs fftw3f >= 3.0.0',
399                    mandatory = ctx.options.enable_fftw3f)
400            if (ctx.options.enable_double == True):
401                ctx.msg('Warning',
402                        'fftw3f enabled, but compiling in double precision!')
403        else:
404            # fftw3f disabled, take most sensible one according to
405            # enable_double
406            if (ctx.options.enable_double == True):
407                ctx.check_cfg(package = 'fftw3',
408                        args = '--cflags --libs fftw3 >= 3.0.0.',
409                        mandatory = ctx.options.enable_fftw3)
410            else:
411                ctx.check_cfg(package = 'fftw3f',
412                        args = '--cflags --libs fftw3f >= 3.0.0',
413                        mandatory = ctx.options.enable_fftw3)
414        ctx.define('HAVE_FFTW3', 1)
415
416    # fftw not enabled, use vDSP, intelIPP or ooura
417    if 'HAVE_FFTW3F' in ctx.env.define_key:
418        ctx.msg('Checking for FFT implementation', 'fftw3f')
419    elif 'HAVE_FFTW3' in ctx.env.define_key:
420        ctx.msg('Checking for FFT implementation', 'fftw3')
421    elif 'HAVE_ACCELERATE' in ctx.env.define_key:
422        ctx.msg('Checking for FFT implementation', 'vDSP')
423    elif 'HAVE_INTEL_IPP' in ctx.env.define_key:
424        ctx.msg('Checking for FFT implementation', 'Intel IPP')
425    else:
426        ctx.msg('Checking for FFT implementation', 'ooura')
427
428    # check for libsndfile
429    if (ctx.options.enable_sndfile != False):
430        ctx.check_cfg(package = 'sndfile',
431                args = '--cflags --libs sndfile >= 1.0.4',
432                mandatory = ctx.options.enable_sndfile)
433
434    # check for libsamplerate
435    if (ctx.options.enable_double):
436        if (ctx.options.enable_samplerate):
437            ctx.fatal("Could not compile aubio in double precision mode' \
438                    ' with libsamplerate")
439        else:
440            ctx.options.enable_samplerate = False
441            ctx.msg('Checking if using samplerate',
442                    'no (disabled in double precision mode)', color = 'YELLOW')
443    if (ctx.options.enable_samplerate != False):
444        ctx.check_cfg(package = 'samplerate',
445                args = '--cflags --libs samplerate >= 0.0.15',
446                mandatory = ctx.options.enable_samplerate)
447
448    # check for librubberband
449    if (ctx.options.enable_rubberband != False):
450        ctx.check_cfg(package = 'rubberband', atleast_version = '1.3',
451                args = '--cflags --libs',
452                mandatory = ctx.options.enable_rubberband)
453
454    # check for jack
455    if (ctx.options.enable_jack != False):
456        ctx.check_cfg(package = 'jack',
457                args = '--cflags --libs',
458                mandatory = ctx.options.enable_jack)
459
460    # check for libav
461    if (ctx.options.enable_avcodec != False):
462        ctx.check_cfg(package = 'libavcodec',
463                args = '--cflags --libs libavcodec >= 54.35.0',
464                uselib_store = 'AVCODEC',
465                mandatory = ctx.options.enable_avcodec)
466        ctx.check_cfg(package = 'libavformat',
467                args = '--cflags --libs libavformat >= 52.3.0',
468                uselib_store = 'AVFORMAT',
469                mandatory = ctx.options.enable_avcodec)
470        ctx.check_cfg(package = 'libavutil',
471                args = '--cflags --libs libavutil >= 52.3.0',
472                uselib_store = 'AVUTIL',
473                mandatory = ctx.options.enable_avcodec)
474        ctx.check_cfg(package = 'libswresample',
475                args = '--cflags --libs libswresample >= 1.2.0',
476                uselib_store = 'SWRESAMPLE',
477                mandatory = False)
478
479        msg_check = 'Checking for all libav libraries'
480        if 'HAVE_AVCODEC' not in ctx.env:
481            ctx.msg(msg_check, 'not found (missing avcodec)', color = 'YELLOW')
482        elif 'HAVE_AVFORMAT' not in ctx.env:
483            ctx.msg(msg_check, 'not found (missing avformat)', color = 'YELLOW')
484        elif 'HAVE_AVUTIL' not in ctx.env:
485            ctx.msg(msg_check, 'not found (missing avutil)', color = 'YELLOW')
486        elif 'HAVE_SWRESAMPLE' not in ctx.env :
487            resample_missing = 'not found (missing swresample)'
488            ctx.msg(msg_check, resample_missing, color = 'YELLOW')
489        else:
490            ctx.msg(msg_check, 'yes')
491            ctx.define('HAVE_LIBAV', 1)
492
493    # check for vorbisenc
494    if (ctx.options.enable_vorbis != False):
495        ctx.check_cfg(package = 'vorbisenc vorbis ogg',
496                args = '--cflags --libs',
497                uselib_store = 'VORBISENC',
498                mandatory = ctx.options.enable_vorbis)
499
500    # check for flac
501    if (ctx.options.enable_flac != False):
502        ctx.check_cfg(package = 'flac',
503                args = '--cflags --libs',
504                uselib_store = 'FLAC',
505                mandatory = ctx.options.enable_flac)
506
507    if (ctx.options.enable_wavread != False):
508        ctx.define('HAVE_WAVREAD', 1)
509    ctx.msg('Checking if using source_wavread',
510            ctx.options.enable_wavread and 'yes' or 'no')
511    if (ctx.options.enable_wavwrite!= False):
512        ctx.define('HAVE_WAVWRITE', 1)
513    ctx.msg('Checking if using sink_wavwrite',
514            ctx.options.enable_wavwrite and 'yes' or 'no')
515
516    # use BLAS/ATLAS
517    if (ctx.options.enable_blas != False):
518        ctx.check_cfg(package = 'blas',
519                args = '--cflags --libs',
520                uselib_store='BLAS', mandatory = ctx.options.enable_blas)
521        if 'LIB_BLAS' in ctx.env:
522            blas_header = None
523            if ctx.env['LIBPATH_BLAS']:
524                if 'atlas' in ctx.env['LIBPATH_BLAS'][0]:
525                    blas_header = 'atlas/cblas.h'
526                elif 'openblas' in ctx.env['LIBPATH_BLAS'][0]:
527                    blas_header = 'openblas/cblas.h'
528            else:
529                blas_header = 'cblas.h'
530            ctx.check(header_name = blas_header, mandatory =
531                    ctx.options.enable_atlas)
532
533    # use memcpy hacks
534    if (ctx.options.enable_memcpy == True):
535        ctx.define('HAVE_MEMCPY_HACKS', 1)
536
537    # write configuration header
538    ctx.write_config_header('src/config.h')
539
540    # the following defines will be passed as arguments to the compiler
541    # instead of being written to src/config.h
542    ctx.define('HAVE_CONFIG_H', 1)
543
544    # add some defines used in examples
545    ctx.define('AUBIO_PREFIX', ctx.env['PREFIX'])
546    ctx.define('PACKAGE', APPNAME)
547
548    # double precision mode
549    if (ctx.options.enable_double == True):
550        ctx.define('HAVE_AUBIO_DOUBLE', 1)
551
552    if (ctx.options.enable_docs != False):
553        # check if txt2man is installed, optional
554        try:
555          ctx.find_program('txt2man', var='TXT2MAN')
556        except ctx.errors.ConfigurationError:
557          ctx.to_log('txt2man was not found (ignoring)')
558
559        # check if doxygen is installed, optional
560        try:
561          ctx.find_program('doxygen', var='DOXYGEN')
562        except ctx.errors.ConfigurationError:
563          ctx.to_log('doxygen was not found (ignoring)')
564
565        # check if sphinx-build is installed, optional
566        try:
567          ctx.find_program('sphinx-build', var='SPHINX')
568        except ctx.errors.ConfigurationError:
569          ctx.to_log('sphinx-build was not found (ignoring)')
570
571def build(bld):
572    bld.env['VERSION'] = VERSION
573    bld.env['LIB_VERSION'] = LIB_VERSION
574
575    # main source
576    bld.recurse('src')
577
578    # add sub directories
579    if bld.env['DEST_OS'] not in ['ios', 'iosimulator', 'watchos', 'watchsimulator', 'android']:
580        if bld.env['DEST_OS']=='emscripten' and not bld.options.testcmd:
581            bld.options.testcmd = 'node %s'
582        if bld.options.enable_examples:
583            bld.recurse('examples')
584        if bld.options.enable_tests:
585            bld.recurse('tests')
586
587    # pkg-config template
588    bld( source = 'aubio.pc.in' )
589
590    # documentation
591    txt2man(bld)
592    doxygen(bld)
593    sphinx(bld)
594
595    from waflib.Tools import waf_unit_test
596    bld.add_post_fun(waf_unit_test.summary)
597    bld.add_post_fun(waf_unit_test.set_exit_code)
598
599def txt2man(bld):
600    # build manpages from txt files using txt2man
601    if bld.env['TXT2MAN']:
602        from waflib import TaskGen
603        if 'MANDIR' not in bld.env:
604            bld.env['MANDIR'] = bld.env['DATAROOTDIR'] + '/man'
605        bld.env.VERSION = VERSION
606        rule_str = '${TXT2MAN} -t `basename ${TGT} | cut -f 1 -d . | tr a-z A-Z`'
607        rule_str += ' -r ${PACKAGE}\\ ${VERSION} -P ${PACKAGE}'
608        rule_str += ' -v ${PACKAGE}\\ User\\\'s\\ manual'
609        rule_str += ' -s 1 ${SRC} > ${TGT}'
610        TaskGen.declare_chain(
611                name      = 'txt2man',
612                rule      = rule_str,
613                ext_in    = '.txt',
614                ext_out   = '.1',
615                reentrant = False,
616                install_path =  '${MANDIR}/man1',
617                )
618        bld( source = bld.path.ant_glob('doc/*.txt') )
619
620def doxygen(bld):
621    # build documentation from source files using doxygen
622    if bld.env['DOXYGEN']:
623        bld.env.VERSION = VERSION
624        rule = '( cat ${SRC[0]} && echo PROJECT_NUMBER=${VERSION}'
625        rule += ' && echo OUTPUT_DIRECTORY=%s && echo HTML_OUTPUT=%s )'
626        rule += ' | doxygen - > /dev/null'
627        rule %= (os.path.abspath(out), 'api')
628        bld( name = 'doxygen', rule = rule,
629                source = ['doc/web.cfg']
630                    + bld.path.find_dir('src').ant_glob('**/*.h'),
631                target = bld.path.find_or_declare('api/index.html'),
632                cwd = bld.path.find_dir('doc'))
633        # evaluate nodes lazily to prevent build directory traversal warnings
634        bld.install_files('${DATAROOTDIR}/doc/libaubio-doc/api',
635                bld.path.find_or_declare('api').ant_glob('**/*',
636                    generator=True), cwd=bld.path.find_or_declare('api'),
637                relative_trick=True)
638
639def sphinx(bld):
640    # build documentation from source files using sphinx-build
641    try:
642        import aubio
643        has_aubio = True
644    except ImportError:
645        from waflib import Logs
646        Logs.pprint('YELLOW', "Sphinx manual: install aubio first")
647        has_aubio = False
648    if bld.env['SPHINX'] and has_aubio:
649        bld.env.VERSION = VERSION
650        rule = '${SPHINX} -b html -D release=${VERSION}' \
651                ' -D version=${VERSION} -W -a -q' \
652                ' -d %s ' % os.path.join(os.path.abspath(out), 'doctrees')
653        rule += ' . %s' % os.path.join(os.path.abspath(out), 'manual')
654        bld( name = 'sphinx', rule = rule,
655                cwd = bld.path.find_dir('doc'),
656                source = bld.path.find_dir('doc').ant_glob('*.rst'),
657                target = bld.path.find_or_declare('manual/index.html'))
658        # evaluate nodes lazily to prevent build directory traversal warnings
659        bld.install_files('${DATAROOTDIR}/doc/libaubio-doc/manual',
660                bld.path.find_or_declare('manual').ant_glob('**/*',
661                    generator=True), cwd=bld.path.find_or_declare('manual'),
662                relative_trick=True)
663
664# register the previous rules as build rules
665from waflib.Build import BuildContext
666
667class build_txt2man(BuildContext):
668    cmd = 'txt2man'
669    fun = 'txt2man'
670
671class build_manpages(BuildContext):
672    cmd = 'manpages'
673    fun = 'txt2man'
674
675class build_sphinx(BuildContext):
676    cmd = 'sphinx'
677    fun = 'sphinx'
678
679class build_doxygen(BuildContext):
680    cmd = 'doxygen'
681    fun = 'doxygen'
682
683def shutdown(bld):
684    from waflib import Logs
685    if bld.options.target_platform in ['ios', 'iosimulator']:
686        msg ='building for %s, contact the author for a commercial license' \
687                % bld.options.target_platform
688        Logs.pprint('RED', msg)
689        msg ='   Paul Brossier <piem@aubio.org>'
690        Logs.pprint('RED', msg)
691
692def dist(ctx):
693    ctx.excl  = ' **/.waf*'
694    ctx.excl += ' **/.git*'
695    ctx.excl += ' **/*~ **/*.pyc **/*.swp **/*.swo **/*.swn **/.lock-w*'
696    ctx.excl += ' **/build/*'
697    ctx.excl += ' doc/_build'
698    ctx.excl += ' python/demos_*'
699    ctx.excl += ' **/python/gen **/python/build **/python/dist'
700    ctx.excl += ' **/python/ext/config.h'
701    ctx.excl += ' **/python/lib/aubio/_aubio.so'
702    ctx.excl += ' **.egg-info'
703    ctx.excl += ' **/.eggs'
704    ctx.excl += ' **/.pytest_cache'
705    ctx.excl += ' **/.cache'
706    ctx.excl += ' **/**.zip **/**.tar.bz2'
707    ctx.excl += ' **.tar.bz2**'
708    ctx.excl += ' **/doc/full/* **/doc/web/*'
709    ctx.excl += ' **/doc/full.cfg'
710    ctx.excl += ' **/python/*.db'
711    ctx.excl += ' **/python.old/*'
712    ctx.excl += ' **/python/*/*.old'
713    ctx.excl += ' **/python/lib/aubio/*.so'
714    ctx.excl += ' **/python/tests/sounds'
715    ctx.excl += ' **/**.asc'
716    ctx.excl += ' **/dist*'
717    ctx.excl += ' **/.DS_Store'
718    ctx.excl += ' **/.travis.yml'
719    ctx.excl += ' **/.appveyor.yml'
720    ctx.excl += ' **/.circleci/*'
721    ctx.excl += ' **/azure-pipelines.yml'
722    ctx.excl += ' **/.coverage*'
Note: See TracBrowser for help on using the repository browser.