source: wscript @ 94b16497

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

wscript: add '-fembed-bitcode' when building for iOS (closes #31)

  • Property mode set to 100644
File size: 14.4 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
13APPNAME = 'aubio'
14
15# source VERSION
16for l in open('VERSION').readlines(): exec (l.strip())
17
18VERSION = '.'.join ([str(x) for x in [
19    AUBIO_MAJOR_VERSION,
20    AUBIO_MINOR_VERSION,
21    AUBIO_PATCH_VERSION
22    ]]) + AUBIO_VERSION_STATUS
23
24LIB_VERSION = '.'.join ([str(x) for x in [
25    LIBAUBIO_LT_CUR,
26    LIBAUBIO_LT_REV,
27    LIBAUBIO_LT_AGE]])
28
29top = '.'
30out = 'build'
31
32def add_option_enable_disable(ctx, name, default = None,
33        help_str = None, help_disable_str = None):
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 )
46
47def options(ctx):
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)')
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)')
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')
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')
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')
87
88    ctx.add_option('--with-target-platform', type='string',
89            help='set target platform for cross-compilation', dest='target_platform')
90
91    ctx.load('compiler_c')
92    ctx.load('waf_unit_test')
93    ctx.load('gnu_dirs')
94
95def configure(ctx):
96    from waflib import Options
97    ctx.load('compiler_c')
98    ctx.load('waf_unit_test')
99    ctx.load('gnu_dirs')
100
101    target_platform = Options.platform
102    if ctx.options.target_platform:
103        target_platform = ctx.options.target_platform
104    ctx.env['DEST_OS'] = target_platform
105
106    if 'CL.exe' not in ctx.env.CC[0]:
107        ctx.env.CFLAGS += ['-g', '-Wall', '-Wextra']
108    else:
109        ctx.env.CFLAGS += ['-Wall']
110
111    if target_platform not in ['win32', 'win64']:
112        ctx.env.CFLAGS += ['-fPIC']
113    else:
114        ctx.define('HAVE_WIN_HACKS', 1)
115        ctx.env['cshlib_PATTERN'] = 'lib%s.dll'
116
117    if target_platform == 'darwin' and ctx.options.enable_fat:
118        ctx.env.CFLAGS += ['-arch', 'i386', '-arch', 'x86_64']
119        ctx.env.LINKFLAGS += ['-arch', 'i386', '-arch', 'x86_64']
120
121    if target_platform in [ 'darwin', 'ios', 'iosimulator']:
122        if (ctx.options.enable_apple_audio != False):
123            ctx.env.FRAMEWORK += ['CoreFoundation', 'AudioToolbox']
124            ctx.define('HAVE_SOURCE_APPLE_AUDIO', 1)
125            ctx.define('HAVE_SINK_APPLE_AUDIO', 1)
126        if (ctx.options.enable_accelerate != False):
127            ctx.define('HAVE_ACCELERATE', 1)
128            ctx.env.FRAMEWORK += ['Accelerate']
129
130    if target_platform in [ 'ios', 'iosimulator' ]:
131        MINSDKVER="6.1"
132        ctx.env.CFLAGS += ['-std=c99']
133        if (ctx.options.enable_apple_audio != False):
134            ctx.define('HAVE_AUDIO_UNIT', 1)
135            #ctx.env.FRAMEWORK += ['CoreFoundation', 'AudioToolbox']
136        if target_platform == 'ios':
137            DEVROOT = "/Applications/Xcode.app/Contents"
138            DEVROOT += "/Developer/Platforms/iPhoneOS.platform/Developer"
139            SDKROOT = "%(DEVROOT)s/SDKs/iPhoneOS.sdk" % locals()
140            ctx.env.CFLAGS += [ '-fembed-bitcode' ]
141            ctx.env.CFLAGS += [ '-arch', 'arm64' ]
142            ctx.env.CFLAGS += [ '-arch', 'armv7' ]
143            ctx.env.CFLAGS += [ '-arch', 'armv7s' ]
144            ctx.env.LINKFLAGS += [ '-arch', 'arm64' ]
145            ctx.env.LINKFLAGS += ['-arch', 'armv7']
146            ctx.env.LINKFLAGS += ['-arch', 'armv7s']
147            ctx.env.CFLAGS += [ '-miphoneos-version-min=' + MINSDKVER ]
148            ctx.env.LINKFLAGS += [ '-miphoneos-version-min=' + MINSDKVER ]
149        else:
150            DEVROOT = "/Applications/Xcode.app/Contents"
151            DEVROOT += "/Developer/Platforms/iPhoneSimulator.platform/Developer"
152            SDKROOT = "%(DEVROOT)s/SDKs/iPhoneSimulator.sdk" % locals()
153            ctx.env.CFLAGS += [ '-arch', 'i386' ]
154            ctx.env.CFLAGS += [ '-arch', 'x86_64' ]
155            ctx.env.LINKFLAGS += ['-arch', 'i386']
156            ctx.env.LINKFLAGS += ['-arch', 'x86_64']
157            ctx.env.CFLAGS += [ '-mios-simulator-version-min=' + MINSDKVER ]
158            ctx.env.LINKFLAGS += [ '-mios-simulator-version-min=' + MINSDKVER ]
159        ctx.env.CFLAGS += [ '-isysroot' , SDKROOT]
160        ctx.env.LINKFLAGS += [ '-isysroot' , SDKROOT]
161
162    # check for required headers
163    ctx.check(header_name='stdlib.h')
164    ctx.check(header_name='stdio.h')
165    ctx.check(header_name='math.h')
166    ctx.check(header_name='string.h')
167    ctx.check(header_name='limits.h')
168
169    # check support for C99 __VA_ARGS__ macros
170    check_c99_varargs = '''
171#include <stdio.h>
172#define AUBIO_ERR(...) fprintf(stderr, __VA_ARGS__)
173'''
174
175    if ctx.check_cc(fragment = check_c99_varargs,
176            type='cstlib',
177            msg = 'Checking for C99 __VA_ARGS__ macro',
178            mandatory = False):
179        ctx.define('HAVE_C99_VARARGS_MACROS', 1)
180
181    # double precision mode
182    if (ctx.options.enable_double == True):
183        ctx.define('HAVE_AUBIO_DOUBLE', 1)
184    else:
185        ctx.define('HAVE_AUBIO_DOUBLE', 0)
186
187    # optionally use complex.h
188    if (ctx.options.enable_complex == True):
189        ctx.check(header_name='complex.h')
190
191    # check for fftw3
192    if (ctx.options.enable_fftw3 != False or ctx.options.enable_fftw3f != False):
193        # one of fftwf or fftw3f
194        if (ctx.options.enable_fftw3f != False):
195            ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0',
196                    args = '--cflags --libs',
197                    mandatory = ctx.options.enable_fftw3f)
198            if (ctx.options.enable_double == True):
199                ctx.msg('Warning',
200                        'fftw3f enabled, but compiling in double precision!')
201        else:
202            # fftw3f disabled, take most sensible one according to
203            # enable_double
204            if (ctx.options.enable_double == True):
205                ctx.check_cfg(package = 'fftw3', atleast_version = '3.0.0',
206                        args = '--cflags --libs', mandatory =
207                        ctx.options.enable_fftw3)
208            else:
209                ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0',
210                        args = '--cflags --libs',
211                        mandatory = ctx.options.enable_fftw3)
212        ctx.define('HAVE_FFTW3', 1)
213
214    # fftw not enabled, use vDSP or ooura
215    if 'HAVE_FFTW3F' in ctx.env.define_key:
216        ctx.msg('Checking for FFT implementation', 'fftw3f')
217    elif 'HAVE_FFTW3' in ctx.env.define_key:
218        ctx.msg('Checking for FFT implementation', 'fftw3')
219    elif 'HAVE_ACCELERATE' in ctx.env.define_key:
220        ctx.msg('Checking for FFT implementation', 'vDSP')
221    else:
222        ctx.msg('Checking for FFT implementation', 'ooura')
223
224    # check for libsndfile
225    if (ctx.options.enable_sndfile != False):
226        ctx.check_cfg(package = 'sndfile', atleast_version = '1.0.4',
227                args = '--cflags --libs',
228                mandatory = ctx.options.enable_sndfile)
229
230    # check for libsamplerate
231    if (ctx.options.enable_samplerate != False):
232        ctx.check_cfg(package = 'samplerate', atleast_version = '0.0.15',
233                args = '--cflags --libs',
234                mandatory = ctx.options.enable_samplerate)
235
236    # check for jack
237    if (ctx.options.enable_jack != False):
238        ctx.check_cfg(package = 'jack',
239                args = '--cflags --libs',
240                mandatory = ctx.options.enable_jack)
241
242    # check for libav
243    if (ctx.options.enable_avcodec != False):
244        ctx.check_cfg(package = 'libavcodec', atleast_version = '54.35.0',
245                args = '--cflags --libs', uselib_store = 'AVCODEC',
246                mandatory = ctx.options.enable_avcodec)
247        ctx.check_cfg(package = 'libavformat', atleast_version = '52.3.0',
248                args = '--cflags --libs', uselib_store = 'AVFORMAT',
249                mandatory = ctx.options.enable_avcodec)
250        ctx.check_cfg(package = 'libavutil', atleast_version = '52.3.0',
251                args = '--cflags --libs', uselib_store = 'AVUTIL',
252                mandatory = ctx.options.enable_avcodec)
253        ctx.check_cfg(package = 'libavresample', atleast_version = '1.0.1',
254                args = '--cflags --libs', uselib_store = 'AVRESAMPLE',
255                mandatory = ctx.options.enable_avcodec)
256        if all ( 'HAVE_' + i in ctx.env
257                for i in ['AVCODEC', 'AVFORMAT', 'AVUTIL', 'AVRESAMPLE'] ):
258            ctx.define('HAVE_LIBAV', 1)
259            ctx.msg('Checking for all libav libraries', 'yes')
260        else:
261            ctx.msg('Checking for all libav libraries', 'not found', color = 'YELLOW')
262
263    ctx.define('HAVE_WAVREAD', 1)
264    ctx.define('HAVE_WAVWRITE', 1)
265
266    # use ATLAS
267    if (ctx.options.enable_atlas != False):
268        ctx.check(header_name = 'atlas/cblas.h', mandatory = ctx.options.enable_atlas)
269        #ctx.check(lib = 'lapack', uselib_store = 'LAPACK', mandatory = ctx.options.enable_atlas)
270        ctx.check(lib = 'cblas', uselib_store = 'BLAS', mandatory = ctx.options.enable_atlas)
271
272    # use memcpy hacks
273    if (ctx.options.enable_memcpy == True):
274        ctx.define('HAVE_MEMCPY_HACKS', 1)
275    else:
276        ctx.define('HAVE_MEMCPY_HACKS', 0)
277
278    # write configuration header
279    ctx.write_config_header('src/config.h')
280
281    # add some defines used in examples
282    ctx.define('AUBIO_PREFIX', ctx.env['PREFIX'])
283    ctx.define('PACKAGE', APPNAME)
284
285    # check if txt2man is installed, optional
286    try:
287      ctx.find_program('txt2man', var='TXT2MAN')
288    except ctx.errors.ConfigurationError:
289      ctx.to_log('txt2man was not found (ignoring)')
290
291    # check if doxygen is installed, optional
292    try:
293      ctx.find_program('doxygen', var='DOXYGEN')
294    except ctx.errors.ConfigurationError:
295      ctx.to_log('doxygen was not found (ignoring)')
296
297def build(bld):
298    bld.env['VERSION'] = VERSION
299    bld.env['LIB_VERSION'] = LIB_VERSION
300
301    # add sub directories
302    bld.recurse('src')
303    if bld.env['DEST_OS'] not in ['ios', 'iosimulator']:
304        pass
305    if bld.env['DEST_OS'] not in ['ios', 'iosimulator', 'android']:
306        bld.recurse('examples')
307        bld.recurse('tests')
308
309    bld( source = 'aubio.pc.in' )
310
311    # build manpages from txt files using txt2man
312    if bld.env['TXT2MAN']:
313        from waflib import TaskGen
314        if 'MANDIR' not in bld.env:
315            bld.env['MANDIR'] = bld.env['PREFIX'] + '/share/man'
316        rule_str = '${TXT2MAN} -t `basename ${TGT} | cut -f 1 -d . | tr a-z A-Z`'
317        rule_str += ' -r ${PACKAGE}\\ ${VERSION} -P ${PACKAGE}'
318        rule_str += ' -v ${PACKAGE}\\ User\\\'s\\ manual'
319        rule_str += ' -s 1 ${SRC} > ${TGT}'
320        TaskGen.declare_chain(
321                name      = 'txt2man',
322                rule      = rule_str,
323                ext_in    = '.txt',
324                ext_out   = '.1',
325                reentrant = False,
326                install_path =  '${MANDIR}/man1',
327                )
328        bld( source = bld.path.ant_glob('doc/*.txt') )
329
330    # build documentation from source files using doxygen
331    if bld.env['DOXYGEN']:
332        bld( name = 'doxygen', rule = 'doxygen ${SRC} > /dev/null',
333                source = 'doc/web.cfg',
334                cwd = 'doc')
335        bld.install_files( '${PREFIX}' + '/share/doc/libaubio-doc',
336                bld.path.ant_glob('doc/web/html/**'),
337                cwd = bld.path.find_dir ('doc/web'),
338                relative_trick = True)
339
340def shutdown(bld):
341    from waflib import Logs
342    if bld.options.target_platform in ['ios', 'iosimulator']:
343        msg ='building for %s, contact the author for a commercial license' % bld.options.target_platform
344        Logs.pprint('RED', msg)
345        msg ='   Paul Brossier <piem@aubio.org>'
346        Logs.pprint('RED', msg)
347
348def dist(ctx):
349    ctx.excl  = ' **/.waf-1* **/*~ **/*.pyc **/*.swp **/.lock-w* **/.git*'
350    ctx.excl += ' **/build/*'
351    ctx.excl += ' **/python/gen **/python/build **/python/dist'
352    ctx.excl += ' **/**.zip **/**.tar.bz2'
353    ctx.excl += ' **/doc/full/* **/doc/web/*'
354    ctx.excl += ' **/python/*.db'
355    ctx.excl += ' **/python.old/*'
356    ctx.excl += ' **/python/tests/sounds'
357    ctx.excl += ' **/**.asc'
Note: See TracBrowser for help on using the repository browser.