source: wscript @ 3d2e481

sampler
Last change on this file since 3d2e481 was 8fcbd37, checked in by Paul Brossier <piem@piem.org>, 8 years ago

wscript: check for pthread.h libpthread

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