wscript: wrap lines, remove old autotools check
[aubio.git] / wscript
1 #! /usr/bin/python
2 #
3 # waf build script, see http://code.google.com/p/waf/
4 # usage:
5 #     $ waf distclean configure build
6 # get it:
7 #     $ svn co http://waf.googlecode.com/svn/trunk /path/to/waf
8 #     $ alias waf=/path/to/waf/waf-light
9 #
10 # TODO
11 #  - doc: add doxygen
12 #  - tests: move to new unit test system
13
14 APPNAME = 'aubio'
15
16 # source VERSION
17 for l in open('VERSION').readlines(): exec (l.strip())
18
19 VERSION = '.'.join ([str(x) for x in [
20     AUBIO_MAJOR_VERSION,
21     AUBIO_MINOR_VERSION,
22     AUBIO_PATCH_VERSION
23     ]]) + AUBIO_VERSION_STATUS
24
25 LIB_VERSION = '.'.join ([str(x) for x in [
26     LIBAUBIO_LT_CUR,
27     LIBAUBIO_LT_REV,
28     LIBAUBIO_LT_AGE]])
29
30 top = '.'
31 out = 'build'
32
33 def add_option_enable_disable(ctx, name, default = None,
34         help_str = None, help_disable_str = None):
35   if help_str == None:
36       help_str = 'enable ' + name + ' support'
37   if help_disable_str == None:
38       help_disable_str = 'do not ' + help_str
39   ctx.add_option('--enable-' + name, action = 'store_true'
40           default = default,
41           dest = 'enable_' + name.replace('-','_'),
42           help = help_str)
43   ctx.add_option('--disable-' + name, action = 'store_false',
44           #default = default,
45           dest = 'enable_' + name.replace('-','_'),
46           help = help_disable_str )
47
48 def options(ctx):
49   add_option_enable_disable(ctx, 'fftw3f', default = False,
50           help_str = 'compile with fftw3f instead of ooura (recommended)',
51           help_disable_str = 'do not compile with fftw3f')
52   add_option_enable_disable(ctx, 'fftw3', default = False,
53           help_str = 'compile with fftw3 instead of ooura',
54           help_disable_str = 'do not compile with fftw3')
55   add_option_enable_disable(ctx, 'complex', default = False,
56           help_str ='compile with C99 complex',
57           help_disable_str = 'do not use C99 complex (default)' )
58   add_option_enable_disable(ctx, 'jack', default = None,
59           help_str = 'compile with jack (auto)',
60           help_disable_str = 'disable jack support')
61   add_option_enable_disable(ctx, 'sndfile', default = None,
62           help_str = 'compile with sndfile (auto)',
63           help_disable_str = 'disable sndfile')
64   add_option_enable_disable(ctx, 'avcodec', default = None,
65           help_str = 'compile with libavcodec (auto)',
66           help_disable_str = 'disable libavcodec')
67   add_option_enable_disable(ctx, 'samplerate', default = None,
68           help_str = 'compile with samplerate (auto)',
69           help_disable_str = 'disable samplerate')
70   add_option_enable_disable(ctx, 'memcpy', default = True,
71           help_str = 'use memcpy hacks (default)',
72           help_disable_str = 'do not use memcpy hacks')
73   add_option_enable_disable(ctx, 'double', default = False,
74           help_str = 'compile aubio in double precision mode',
75           help_disable_str = 'compile aubio in single precision mode (default)')
76
77   ctx.add_option('--with-target-platform', type='string',
78       help='set target platform for cross-compilation', dest='target_platform')
79   ctx.load('compiler_c')
80   ctx.load('waf_unit_test')
81   ctx.load('gnu_dirs')
82
83 def configure(ctx):
84   from waflib import Options
85   ctx.load('compiler_c')
86   ctx.load('waf_unit_test')
87   ctx.load('gnu_dirs')
88   ctx.env.CFLAGS += ['-g', '-Wall', '-Wextra', '-fPIC']
89
90   target_platform = Options.platform
91   if ctx.options.target_platform:
92     target_platform = ctx.options.target_platform
93   ctx.env['DEST_OS'] = target_platform
94
95   if target_platform == 'win32':
96     ctx.env['shlib_PATTERN'] = 'lib%s.dll'
97
98   if target_platform == 'darwin':
99     ctx.env.CFLAGS += ['-arch', 'i386', '-arch', 'x86_64']
100     ctx.env.LINKFLAGS += ['-arch', 'i386', '-arch', 'x86_64']
101     ctx.env.FRAMEWORK = ['CoreFoundation', 'AudioToolbox', 'Accelerate']
102     ctx.define('HAVE_ACCELERATE', 1)
103
104   if target_platform in [ 'ios', 'iosimulator' ]:
105     ctx.define('HAVE_ACCELERATE', 1)
106     ctx.define('TARGET_OS_IPHONE', 1)
107     ctx.env.FRAMEWORK = ['CoreFoundation', 'AudioToolbox', 'Accelerate']
108     SDKVER="7.0"
109     MINSDKVER="6.1"
110     ctx.env.CFLAGS += ['-std=c99']
111     if target_platform == 'ios':
112         DEVROOT = "/Applications/Xcode.app/Contents"
113         DEVROOT += "/Developer/Platforms/iPhoneOS.platform/Developer"
114         SDKROOT = "%(DEVROOT)s/SDKs/iPhoneOS%(SDKVER)s.sdk" % locals()
115         ctx.env.CFLAGS += [ '-arch', 'arm64' ]
116         ctx.env.CFLAGS += [ '-arch', 'armv7' ]
117         ctx.env.CFLAGS += [ '-arch', 'armv7s' ]
118         ctx.env.LINKFLAGS += [ '-arch', 'arm64' ]
119         ctx.env.LINKFLAGS += ['-arch', 'armv7']
120         ctx.env.LINKFLAGS += ['-arch', 'armv7s']
121         ctx.env.CFLAGS += [ '-miphoneos-version-min=' + MINSDKVER ]
122         ctx.env.LINKFLAGS += [ '-miphoneos-version-min=' + MINSDKVER ]
123     else:
124         DEVROOT = "/Applications/Xcode.app/Contents"
125         DEVROOT += "/Developer/Platforms/iPhoneSimulator.platform/Developer"
126         SDKROOT = "%(DEVROOT)s/SDKs/iPhoneSimulator%(SDKVER)s.sdk" % locals()
127         ctx.env.CFLAGS += [ '-arch', 'i386' ]
128         ctx.env.CFLAGS += [ '-arch', 'x86_64' ]
129         ctx.env.LINKFLAGS += ['-arch', 'i386']
130         ctx.env.LINKFLAGS += ['-arch', 'x86_64']
131         ctx.env.CFLAGS += [ '-mios-simulator-version-min=' + MINSDKVER ]
132         ctx.env.LINKFLAGS += [ '-mios-simulator-version-min=' + MINSDKVER ]
133     ctx.env.CFLAGS += [ '-isysroot' , SDKROOT]
134     ctx.env.LINKFLAGS += [ '-isysroot' , SDKROOT]
135
136   # check for required headers
137   ctx.check(header_name='stdlib.h')
138   ctx.check(header_name='stdio.h')
139   ctx.check(header_name='math.h')
140   ctx.check(header_name='string.h')
141   ctx.check(header_name='limits.h')
142
143   # check support for C99 __VA_ARGS__ macros
144   check_c99_varargs = '''
145 #include <stdio.h>
146 #define AUBIO_ERR(...) fprintf(stderr, __VA_ARGS__)
147 '''
148   if ctx.check_cc(fragment = check_c99_varargs,
149       type='cstlib',
150       msg = 'Checking for C99 __VA_ARGS__ macro'):
151     ctx.define('HAVE_C99_VARARGS_MACROS', 1)
152
153   # optionally use complex.h
154   if (ctx.options.enable_complex == True):
155     ctx.check(header_name='complex.h')
156
157   # check dependencies
158   if (ctx.options.enable_sndfile != False):
159       ctx.check_cfg(package = 'sndfile', atleast_version = '1.0.4',
160         args = '--cflags --libs', mandatory = False)
161   if (ctx.options.enable_samplerate != False):
162       ctx.check_cfg(package = 'samplerate', atleast_version = '0.0.15',
163         args = '--cflags --libs', mandatory = False)
164
165   # double precision mode
166   if (ctx.options.enable_double == True):
167     ctx.define('HAVE_AUBIO_DOUBLE', 1)
168   else:
169     ctx.define('HAVE_AUBIO_DOUBLE', 0)
170
171   # optional dependancies using pkg-config
172   if (ctx.options.enable_fftw3 != False or ctx.options.enable_fftw3f != False):
173     # one of fftwf or fftw3f
174     if (ctx.options.enable_fftw3f != False):
175       ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0',
176           args = '--cflags --libs', mandatory = False)
177       if (ctx.options.enable_double == True):
178         ctx.msg('Warning', 'fftw3f enabled, but compiling in double precision!')
179     else:
180       # fftw3f not enabled, take most sensible one according to enable_double
181       if (ctx.options.enable_double == True):
182         ctx.check_cfg(package = 'fftw3', atleast_version = '3.0.0',
183             args = '--cflags --libs', mandatory = False)
184       else:
185         ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0',
186             args = '--cflags --libs', mandatory = False)
187     ctx.define('HAVE_FFTW3', 1)
188
189   # fftw disabled, use ooura
190   if 'HAVE_FFTW3F' in ctx.env.define_key:
191     ctx.msg('Checking for FFT implementation', 'fftw3f')
192   elif 'HAVE_FFTW3' in ctx.env.define_key:
193     ctx.msg('Checking for FFT implementation', 'fftw3')
194   elif 'HAVE_ACCELERATE' in ctx.env.define_key:
195     ctx.msg('Checking for FFT implementation', 'vDSP')
196   else:
197     ctx.msg('Checking for FFT implementation', 'ooura')
198
199   # use memcpy hacks
200   if (ctx.options.enable_memcpy == True):
201     ctx.define('HAVE_MEMCPY_HACKS', 1)
202   else:
203     ctx.define('HAVE_MEMCPY_HACKS', 0)
204
205   if (ctx.options.enable_jack != False):
206     ctx.check_cfg(package = 'jack', atleast_version = '0.15.0',
207     args = '--cflags --libs', mandatory = False)
208
209   if (ctx.options.enable_avcodec != False):
210     ctx.check_cfg(package = 'libavcodec', atleast_version = '54.35.0',
211     args = '--cflags --libs', uselib_store = 'AVCODEC', mandatory = False)
212     ctx.check_cfg(package = 'libavformat', atleast_version = '52.3.0',
213     args = '--cflags --libs', uselib_store = 'AVFORMAT', mandatory = False)
214     ctx.check_cfg(package = 'libavutil', atleast_version = '52.3.0',
215     args = '--cflags --libs', uselib_store = 'AVUTIL', mandatory = False)
216     ctx.check_cfg(package = 'libavresample', atleast_version = '1.0.1',
217     args = '--cflags --libs', uselib_store = 'AVRESAMPLE', mandatory = False)
218
219   # write configuration header
220   ctx.write_config_header('src/config.h')
221
222   # add some defines used in examples
223   ctx.define('AUBIO_PREFIX', ctx.env['PREFIX'])
224   ctx.define('PACKAGE', APPNAME)
225
226   # check if txt2man is installed, optional
227   try:
228     ctx.find_program('txt2man', var='TXT2MAN')
229   except ctx.errors.ConfigurationError:
230     ctx.to_log('txt2man was not found (ignoring)')
231
232 def build(bld):
233     bld.env['VERSION'] = VERSION
234     bld.env['LIB_VERSION'] = LIB_VERSION
235
236     # add sub directories
237     bld.recurse('src')
238     if bld.env['DEST_OS'] not in ['ios', 'iosimulator']:
239         pass
240     if bld.env['DEST_OS'] not in ['ios', 'iosimulator', 'android']:
241         bld.recurse('examples')
242         bld.recurse('tests')
243
244     bld( source = 'aubio.pc.in' )
245
246     # build manpages from sgml files
247     if bld.env['TXT2MAN']:
248         from waflib import TaskGen
249         if 'MANDIR' not in bld.env:
250             bld.env['MANDIR'] = bld.env['PREFIX'] + '/share/man'
251         rule_str = '${TXT2MAN} -t `basename ${TGT} | cut -f 1 -d . | tr a-z A-Z`'
252         rule_str += ' -r ${PACKAGE}\\ ${VERSION} -P ${PACKAGE}'
253         rule_str += ' -v ${PACKAGE}\\ User\\\'s\\ manual'
254         rule_str += ' -s 1 ${SRC} > ${TGT}'
255         TaskGen.declare_chain(
256                 name      = 'txt2man',
257                 rule      = rule_str,
258                 #rule      = '${TXT2MAN} -p -P aubio -s 1 -r aubio-0.4.0 ${SRC} > ${TGT}',
259                 ext_in    = '.txt',
260                 ext_out   = '.1',
261                 reentrant = False,
262                 install_path =  '${MANDIR}/man1',
263                 )
264         bld( source = bld.path.ant_glob('doc/*.txt') )
265
266     """
267     bld(rule = 'doxygen ${SRC}', source = 'web.cfg') #, target = 'doc/web/index.html')
268     """
269
270
271 def shutdown(bld):
272     from waflib import Logs
273     if bld.options.target_platform in ['ios', 'iosimulator']:
274         msg ='building for %s, contact the author for a commercial license' % bld.options.target_platform
275         Logs.pprint('RED', msg)
276         msg ='   Paul Brossier <piem@aubio.org>'
277         Logs.pprint('RED', msg)
278
279 def dist(ctx):
280     ctx.excl  = ' **/.waf-1* **/*~ **/*.pyc **/*.swp **/.lock-w* **/.git*'
281     ctx.excl += ' **/build/*'
282     ctx.excl += ' **/python/gen **/python/build **/python/dist'
283     ctx.excl += ' **/**.zip **/**.tar.bz2'
284     ctx.excl += ' **/doc/full/*'
285     ctx.excl += ' **/python/*.db'
286     ctx.excl += ' **/python.old/*'