source: wscript @ 7436353

feature/autosinkfeature/cnnfeature/crepefix/ffmpeg5
Last change on this file since 7436353 was 1ba359c, checked in by Paul Brossier <piem@piem.org>, 6 years ago

[waf] add flac detection

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