source: wscript @ a0f0f00

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since a0f0f00 was ae36035, checked in by Paul Brossier <piem@piem.org>, 9 years ago

wscript: use ctx.env.CC_NAME to check if using msvc

  • Property mode set to 100644
File size: 15.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
13APPNAME = 'aubio'
[5820107]14
[6b14351]15# source VERSION
[5820107]16for l in open('VERSION').readlines(): exec (l.strip())
17
[6b14351]18VERSION = '.'.join ([str(x) for x in [
19    AUBIO_MAJOR_VERSION,
20    AUBIO_MINOR_VERSION,
21    AUBIO_PATCH_VERSION
22    ]]) + AUBIO_VERSION_STATUS
[e565c649]23
[6b14351]24LIB_VERSION = '.'.join ([str(x) for x in [
25    LIBAUBIO_LT_CUR,
26    LIBAUBIO_LT_REV,
27    LIBAUBIO_LT_AGE]])
[e565c649]28
[46378b3]29top = '.'
30out = 'build'
[000b090]31
[6b14351]32def add_option_enable_disable(ctx, name, default = None,
33        help_str = None, help_disable_str = None):
[a93dab3]34    if help_str == None:
35        help_str = 'enable ' + name + ' support'
36    if help_disable_str == None:
37        help_disable_str = 'do not ' + help_str
38    ctx.add_option('--enable-' + name, action = 'store_true',
39            default = default,
40            dest = 'enable_' + name.replace('-','_'),
41            help = help_str)
42    ctx.add_option('--disable-' + name, action = 'store_false',
43            #default = default,
44            dest = 'enable_' + name.replace('-','_'),
45            help = help_disable_str )
[3819aca]46
[d41bc4d]47def options(ctx):
[a93dab3]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, 'complex', default = False,
55            help_str ='compile with C99 complex',
56            help_disable_str = 'do not use C99 complex (default)' )
57    add_option_enable_disable(ctx, 'jack', default = None,
58            help_str = 'compile with jack (auto)',
59            help_disable_str = 'disable jack support')
60    add_option_enable_disable(ctx, 'sndfile', default = None,
61            help_str = 'compile with sndfile (auto)',
62            help_disable_str = 'disable sndfile')
63    add_option_enable_disable(ctx, 'avcodec', default = None,
64            help_str = 'compile with libavcodec (auto)',
65            help_disable_str = 'disable libavcodec')
66    add_option_enable_disable(ctx, 'samplerate', default = None,
67            help_str = 'compile with samplerate (auto)',
68            help_disable_str = 'disable samplerate')
69    add_option_enable_disable(ctx, 'memcpy', default = True,
70            help_str = 'use memcpy hacks (default)',
71            help_disable_str = 'do not use memcpy hacks')
72    add_option_enable_disable(ctx, 'double', default = False,
73            help_str = 'compile in double precision mode',
74            help_disable_str = 'compile in single precision mode (default)')
[a3de4be]75    add_option_enable_disable(ctx, 'fat', default = False,
76            help_str = 'build fat binaries (darwin only)',
77            help_disable_str = 'do not build fat binaries (default)')
[0309a22]78    add_option_enable_disable(ctx, 'accelerate', default = None,
79            help_str = 'use Accelerate framework (darwin only) (auto)',
80            help_disable_str = 'do not use Accelerate framework')
[cc81763]81    add_option_enable_disable(ctx, 'apple-audio', default = None,
82            help_str = 'use CoreFoundation (darwin only) (auto)',
83            help_disable_str = 'do not use CoreFoundation framework')
[f0ce36a1]84    add_option_enable_disable(ctx, 'atlas', default = None,
85            help_str = 'use Atlas library (auto)',
86            help_disable_str = 'do not use Atlas library')
[a93dab3]87
[a33d406]88    add_option_enable_disable(ctx, 'docs', default = None,
89            help_str = 'build documentation (auto)',
90            help_disable_str = 'do not build documentation')
91
[a93dab3]92    ctx.add_option('--with-target-platform', type='string',
93            help='set target platform for cross-compilation', dest='target_platform')
94
95    ctx.load('compiler_c')
96    ctx.load('waf_unit_test')
97    ctx.load('gnu_dirs')
[000b090]98
[d41bc4d]99def configure(ctx):
[a93dab3]100    from waflib import Options
101    ctx.load('compiler_c')
102    ctx.load('waf_unit_test')
103    ctx.load('gnu_dirs')
[06dba46]104
[bef979a]105    # check for common headers
106    ctx.check(header_name='stdlib.h')
107    ctx.check(header_name='stdio.h')
108    ctx.check(header_name='math.h')
109    ctx.check(header_name='string.h')
110    ctx.check(header_name='limits.h')
[d746ef8]111    ctx.check(header_name='getopt.h', mandatory = False)
[06cf47d]112    ctx.check(header_name='unistd.h', mandatory = False)
[bef979a]113
[a93dab3]114    target_platform = Options.platform
115    if ctx.options.target_platform:
116        target_platform = ctx.options.target_platform
117    ctx.env['DEST_OS'] = target_platform
118
[ae36035]119    if ctx.env.CC_NAME != 'msvc':
[a341685]120        ctx.env.CFLAGS += ['-g', '-Wall', '-Wextra']
121    else:
[aa5237d]122        ctx.env.CFLAGS += ['/W4']
[a341685]123
[70a304e]124    ctx.check_cc(lib='m', uselib_store='M', mandatory=False)
125
[06dba46]126    if target_platform not in ['win32', 'win64']:
127        ctx.env.CFLAGS += ['-fPIC']
128    else:
129        ctx.define('HAVE_WIN_HACKS', 1)
130        ctx.env['cshlib_PATTERN'] = 'lib%s.dll'
[a93dab3]131
[a3de4be]132    if target_platform == 'darwin' and ctx.options.enable_fat:
[a93dab3]133        ctx.env.CFLAGS += ['-arch', 'i386', '-arch', 'x86_64']
134        ctx.env.LINKFLAGS += ['-arch', 'i386', '-arch', 'x86_64']
[da1709f]135        MINSDKVER="10.4"
136        ctx.env.CFLAGS += [ '-mmacosx-version-min=' + MINSDKVER ]
137        ctx.env.LINKFLAGS += [ '-mmacosx-version-min=' + MINSDKVER ]
[9209c79]138
139    if target_platform in [ 'darwin', 'ios', 'iosimulator']:
[cc81763]140        if (ctx.options.enable_apple_audio != False):
141            ctx.env.FRAMEWORK += ['CoreFoundation', 'AudioToolbox']
142            ctx.define('HAVE_SOURCE_APPLE_AUDIO', 1)
143            ctx.define('HAVE_SINK_APPLE_AUDIO', 1)
[0309a22]144        if (ctx.options.enable_accelerate != False):
145            ctx.define('HAVE_ACCELERATE', 1)
146            ctx.env.FRAMEWORK += ['Accelerate']
[a93dab3]147
148    if target_platform in [ 'ios', 'iosimulator' ]:
149        MINSDKVER="6.1"
150        ctx.env.CFLAGS += ['-std=c99']
[536bf70]151        if (ctx.options.enable_apple_audio != False):
[cc81763]152            ctx.define('HAVE_AUDIO_UNIT', 1)
153            #ctx.env.FRAMEWORK += ['CoreFoundation', 'AudioToolbox']
[a93dab3]154        if target_platform == 'ios':
155            DEVROOT = "/Applications/Xcode.app/Contents"
156            DEVROOT += "/Developer/Platforms/iPhoneOS.platform/Developer"
[e11ce489]157            SDKROOT = "%(DEVROOT)s/SDKs/iPhoneOS.sdk" % locals()
[94b16497]158            ctx.env.CFLAGS += [ '-fembed-bitcode' ]
[7aa4aaa]159            ctx.env.CFLAGS += [ '-arch', 'arm64' ]
[a93dab3]160            ctx.env.CFLAGS += [ '-arch', 'armv7' ]
161            ctx.env.CFLAGS += [ '-arch', 'armv7s' ]
[7aa4aaa]162            ctx.env.LINKFLAGS += [ '-arch', 'arm64' ]
[a93dab3]163            ctx.env.LINKFLAGS += ['-arch', 'armv7']
164            ctx.env.LINKFLAGS += ['-arch', 'armv7s']
165            ctx.env.CFLAGS += [ '-miphoneos-version-min=' + MINSDKVER ]
166            ctx.env.LINKFLAGS += [ '-miphoneos-version-min=' + MINSDKVER ]
167        else:
168            DEVROOT = "/Applications/Xcode.app/Contents"
169            DEVROOT += "/Developer/Platforms/iPhoneSimulator.platform/Developer"
[e11ce489]170            SDKROOT = "%(DEVROOT)s/SDKs/iPhoneSimulator.sdk" % locals()
[a93dab3]171            ctx.env.CFLAGS += [ '-arch', 'i386' ]
172            ctx.env.CFLAGS += [ '-arch', 'x86_64' ]
173            ctx.env.LINKFLAGS += ['-arch', 'i386']
174            ctx.env.LINKFLAGS += ['-arch', 'x86_64']
175            ctx.env.CFLAGS += [ '-mios-simulator-version-min=' + MINSDKVER ]
176            ctx.env.LINKFLAGS += [ '-mios-simulator-version-min=' + MINSDKVER ]
177        ctx.env.CFLAGS += [ '-isysroot' , SDKROOT]
178        ctx.env.LINKFLAGS += [ '-isysroot' , SDKROOT]
179
[fb5838a]180    if target_platform == 'emscripten':
181        import os.path
182        ctx.env.CFLAGS += [ '-I' + os.path.join(os.environ['EMSCRIPTEN'], 'system', 'include') ]
183        ctx.env.CFLAGS += ['-Oz']
184        ctx.env.cprogram_PATTERN = "%s.js"
185        if (ctx.options.enable_atlas != True):
186            ctx.options.enable_atlas = False
187
[a93dab3]188    # check support for C99 __VA_ARGS__ macros
189    check_c99_varargs = '''
[0318cc1]190#include <stdio.h>
191#define AUBIO_ERR(...) fprintf(stderr, __VA_ARGS__)
192'''
[a93dab3]193
194    if ctx.check_cc(fragment = check_c99_varargs,
195            type='cstlib',
[413d4bf]196            msg = 'Checking for C99 __VA_ARGS__ macro',
197            mandatory = False):
[a93dab3]198        ctx.define('HAVE_C99_VARARGS_MACROS', 1)
199
[06c6d7d]200    # show a message about enable_double status
[a93dab3]201    if (ctx.options.enable_double == True):
[06c6d7d]202        ctx.msg('Checking for size of smpl_t', 'double')
203        ctx.msg('Checking for size of lsmp_t', 'long double')
[a93dab3]204    else:
[06c6d7d]205        ctx.msg('Checking for size of smpl_t', 'float')
206        ctx.msg('Checking for size of lsmp_t', 'double')
[a93dab3]207
208    # optionally use complex.h
209    if (ctx.options.enable_complex == True):
210        ctx.check(header_name='complex.h')
[06c6d7d]211    else:
212        ctx.msg('Checking if complex.h is enabled', 'no')
[a93dab3]213
214    # check for fftw3
215    if (ctx.options.enable_fftw3 != False or ctx.options.enable_fftw3f != False):
216        # one of fftwf or fftw3f
217        if (ctx.options.enable_fftw3f != False):
218            ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0',
[795fcd9]219                    args = '--cflags --libs',
220                    mandatory = ctx.options.enable_fftw3f)
[a93dab3]221            if (ctx.options.enable_double == True):
[795fcd9]222                ctx.msg('Warning',
223                        'fftw3f enabled, but compiling in double precision!')
[a93dab3]224        else:
[795fcd9]225            # fftw3f disabled, take most sensible one according to
226            # enable_double
[a93dab3]227            if (ctx.options.enable_double == True):
228                ctx.check_cfg(package = 'fftw3', atleast_version = '3.0.0',
[795fcd9]229                        args = '--cflags --libs', mandatory =
230                        ctx.options.enable_fftw3)
[a93dab3]231            else:
232                ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0',
[795fcd9]233                        args = '--cflags --libs',
234                        mandatory = ctx.options.enable_fftw3)
[a93dab3]235        ctx.define('HAVE_FFTW3', 1)
236
237    # fftw not enabled, use vDSP or ooura
238    if 'HAVE_FFTW3F' in ctx.env.define_key:
239        ctx.msg('Checking for FFT implementation', 'fftw3f')
240    elif 'HAVE_FFTW3' in ctx.env.define_key:
241        ctx.msg('Checking for FFT implementation', 'fftw3')
242    elif 'HAVE_ACCELERATE' in ctx.env.define_key:
243        ctx.msg('Checking for FFT implementation', 'vDSP')
[36f954a]244    else:
[a93dab3]245        ctx.msg('Checking for FFT implementation', 'ooura')
246
247    # check for libsndfile
248    if (ctx.options.enable_sndfile != False):
249        ctx.check_cfg(package = 'sndfile', atleast_version = '1.0.4',
[795fcd9]250                args = '--cflags --libs',
251                mandatory = ctx.options.enable_sndfile)
[a93dab3]252
253    # check for libsamplerate
254    if (ctx.options.enable_samplerate != False):
255        ctx.check_cfg(package = 'samplerate', atleast_version = '0.0.15',
[795fcd9]256                args = '--cflags --libs',
257                mandatory = ctx.options.enable_samplerate)
[a93dab3]258
259    # check for jack
260    if (ctx.options.enable_jack != False):
[eb99982]261        ctx.check_cfg(package = 'jack',
[795fcd9]262                args = '--cflags --libs',
263                mandatory = ctx.options.enable_jack)
[a93dab3]264
265    # check for libav
266    if (ctx.options.enable_avcodec != False):
267        ctx.check_cfg(package = 'libavcodec', atleast_version = '54.35.0',
[795fcd9]268                args = '--cflags --libs', uselib_store = 'AVCODEC',
269                mandatory = ctx.options.enable_avcodec)
[a93dab3]270        ctx.check_cfg(package = 'libavformat', atleast_version = '52.3.0',
[795fcd9]271                args = '--cflags --libs', uselib_store = 'AVFORMAT',
272                mandatory = ctx.options.enable_avcodec)
[a93dab3]273        ctx.check_cfg(package = 'libavutil', atleast_version = '52.3.0',
[795fcd9]274                args = '--cflags --libs', uselib_store = 'AVUTIL',
275                mandatory = ctx.options.enable_avcodec)
[a93dab3]276        ctx.check_cfg(package = 'libavresample', atleast_version = '1.0.1',
[795fcd9]277                args = '--cflags --libs', uselib_store = 'AVRESAMPLE',
278                mandatory = ctx.options.enable_avcodec)
[eb68991]279        if all ( 'HAVE_' + i in ctx.env
[549928e]280                for i in ['AVCODEC', 'AVFORMAT', 'AVUTIL', 'AVRESAMPLE'] ):
281            ctx.define('HAVE_LIBAV', 1)
282            ctx.msg('Checking for all libav libraries', 'yes')
283        else:
284            ctx.msg('Checking for all libav libraries', 'not found', color = 'YELLOW')
[a93dab3]285
[5158c22]286    ctx.define('HAVE_WAVREAD', 1)
[52ca8a3]287    ctx.define('HAVE_WAVWRITE', 1)
[5158c22]288
[f0ce36a1]289    # use ATLAS
290    if (ctx.options.enable_atlas != False):
291        ctx.check(header_name = 'atlas/cblas.h', mandatory = ctx.options.enable_atlas)
292        #ctx.check(lib = 'lapack', uselib_store = 'LAPACK', mandatory = ctx.options.enable_atlas)
293        ctx.check(lib = 'cblas', uselib_store = 'BLAS', mandatory = ctx.options.enable_atlas)
294
[a93dab3]295    # use memcpy hacks
296    if (ctx.options.enable_memcpy == True):
297        ctx.define('HAVE_MEMCPY_HACKS', 1)
298
299    # write configuration header
300    ctx.write_config_header('src/config.h')
301
[06c6d7d]302    # the following defines will be passed as arguments to the compiler
303    # instead of being written to src/config.h
304
[a93dab3]305    # add some defines used in examples
306    ctx.define('AUBIO_PREFIX', ctx.env['PREFIX'])
307    ctx.define('PACKAGE', APPNAME)
308
[06c6d7d]309    # double precision mode
310    if (ctx.options.enable_double == True):
311        ctx.define('HAVE_AUBIO_DOUBLE', 1)
312
[a33d406]313    if (ctx.options.enable_docs != False):
314        # check if txt2man is installed, optional
315        try:
316          ctx.find_program('txt2man', var='TXT2MAN')
317        except ctx.errors.ConfigurationError:
318          ctx.to_log('txt2man was not found (ignoring)')
[000b090]319
[a33d406]320        # check if doxygen is installed, optional
321        try:
322          ctx.find_program('doxygen', var='DOXYGEN')
323        except ctx.errors.ConfigurationError:
324          ctx.to_log('doxygen was not found (ignoring)')
[52a25e5]325
[6ed0f4e]326def build(bld):
[985a5d1]327    bld.env['VERSION'] = VERSION
328    bld.env['LIB_VERSION'] = LIB_VERSION
329
330    # add sub directories
331    bld.recurse('src')
332    if bld.env['DEST_OS'] not in ['ios', 'iosimulator', 'android']:
333        bld.recurse('examples')
334        bld.recurse('tests')
335
336    bld( source = 'aubio.pc.in' )
337
[52a25e5]338    # build manpages from txt files using txt2man
[403e9dd]339    if bld.env['TXT2MAN']:
[985a5d1]340        from waflib import TaskGen
341        if 'MANDIR' not in bld.env:
342            bld.env['MANDIR'] = bld.env['PREFIX'] + '/share/man'
[403e9dd]343        rule_str = '${TXT2MAN} -t `basename ${TGT} | cut -f 1 -d . | tr a-z A-Z`'
344        rule_str += ' -r ${PACKAGE}\\ ${VERSION} -P ${PACKAGE}'
345        rule_str += ' -v ${PACKAGE}\\ User\\\'s\\ manual'
346        rule_str += ' -s 1 ${SRC} > ${TGT}'
[985a5d1]347        TaskGen.declare_chain(
[403e9dd]348                name      = 'txt2man',
349                rule      = rule_str,
350                ext_in    = '.txt',
[985a5d1]351                ext_out   = '.1',
352                reentrant = False,
353                install_path =  '${MANDIR}/man1',
354                )
[403e9dd]355        bld( source = bld.path.ant_glob('doc/*.txt') )
[985a5d1]356
[52a25e5]357    # build documentation from source files using doxygen
358    if bld.env['DOXYGEN']:
359        bld( name = 'doxygen', rule = 'doxygen ${SRC} > /dev/null',
360                source = 'doc/web.cfg',
[b0ab6ef]361                cwd = 'doc')
[52a25e5]362        bld.install_files( '${PREFIX}' + '/share/doc/libaubio-doc',
363                bld.path.ant_glob('doc/web/html/**'),
364                cwd = bld.path.find_dir ('doc/web'),
365                relative_trick = True)
[50d56cc]366
[30250de]367def shutdown(bld):
[985a5d1]368    from waflib import Logs
369    if bld.options.target_platform in ['ios', 'iosimulator']:
370        msg ='building for %s, contact the author for a commercial license' % bld.options.target_platform
371        Logs.pprint('RED', msg)
372        msg ='   Paul Brossier <piem@aubio.org>'
373        Logs.pprint('RED', msg)
[b4d1ba1]374
375def dist(ctx):
376    ctx.excl  = ' **/.waf-1* **/*~ **/*.pyc **/*.swp **/.lock-w* **/.git*'
377    ctx.excl += ' **/build/*'
[22dd9dc]378    ctx.excl += ' **/python/gen **/python/build **/python/dist'
379    ctx.excl += ' **/**.zip **/**.tar.bz2'
[a93dab3]380    ctx.excl += ' **/doc/full/* **/doc/web/*'
[b4d1ba1]381    ctx.excl += ' **/python/*.db'
382    ctx.excl += ' **/python.old/*'
[172b1fe]383    ctx.excl += ' **/python/tests/sounds'
[7b2d740]384    ctx.excl += ' **/**.asc'
[73aac2a]385    ctx.excl += ' **/.DS_Store'
386    ctx.excl += ' **/.travis.yml'
Note: See TracBrowser for help on using the repository browser.