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