ce6ee8bf6412c8098238d2dd4976699673e8814a
[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 # read from VERSION
17 for l in open('VERSION').readlines(): exec (l.strip())
18
19 VERSION = '.'.join \
20         ([str(x) for x in [AUBIO_MAJOR_VERSION, AUBIO_MINOR_VERSION, AUBIO_PATCH_VERSION]]) \
21         + AUBIO_VERSION_STATUS
22 LIB_VERSION = '.'.join \
23         ([str(x) for x in [LIBAUBIO_LT_CUR, LIBAUBIO_LT_REV, LIBAUBIO_LT_AGE]])
24
25 import os.path, sys
26 if os.path.exists('src/config.h') or os.path.exists('Makefile'):
27     print "Please run 'make distclean' to clean-up autotools files before using waf"
28     sys.exit(1)
29
30 top = '.'
31 out = 'build'
32
33 def options(ctx):
34   ctx.add_option('--enable-double', action='store_true', default=False,
35       help='compile aubio in double precision mode')
36   ctx.add_option('--disable-double', dest='enable_double',
37       action='store_false',
38       help='compile aubio in single precision mode')
39   ctx.add_option('--enable-fftw3f', action='store_true', default=False,
40       help='compile with fftw3f instead of ooura (recommended)')
41   ctx.add_option('--disable-fftw3f', dest='enable_fftw3f',
42   ctx.add_option('--enable-fftw3', action='store_true', default=None,
43       help='compile with fftw3 instead of ooura (recommended)')
44   ctx.add_option('--disable-fftw3', dest='enable_fftw3',
45       action='store_false',
46       help='compile with ooura instead of fftw3f')
47   ctx.add_option('--enable-fftw3', action='store_true', default=False,
48       help='compile with fftw3 instead of ooura (recommended in double precision)')
49   ctx.add_option('--disable-fftw3', dest='enable-fftw3', action='store_false'.
50       help='compile with ooura instead of fftw3')
51   ctx.add_option('--enable-complex', action='store_true', default=False,
52       help='compile with C99 complex')
53   ctx.add_option('--disable-complex', dest='enable_complex',
54       action='store_false',
55       help='compile without C99 complex')
56   ctx.add_option('--enable-jack', action='store_true', default=None,
57       help='compile with jack support')
58   ctx.add_option('--disable-jack', dest='enable_jack', action='store_false',
59       help='compile without jack support')
60   ctx.add_option('--enable-lash', action='store_true', default=None,
61       help='compile with lash support')
62   ctx.add_option('--disable-lash', dest='enable_lash', action='store_false',
63       help='compile without lash support')
64   ctx.add_option('--enable-sndfile', action='store_true', default=None,
65       help='compile with libsndfile support')
66   ctx.add_option('--disable-sndfile', dest='enable_sndfile',
67       action='store_false',
68       help='compile without libsndfile support')
69   ctx.add_option('--enable-samplerate', action='store_true', default=None,
70       help='compile with libsamplerate support')
71   ctx.add_option('--disable-samplerate', dest='enable_samplerate',
72       action='store_false',
73       help='compile without libsamplerate support')
74   ctx.add_option('--with-target-platform', type='string',
75       help='set target platform for cross-compilation', dest='target_platform')
76   ctx.load('compiler_c')
77   ctx.load('waf_unit_test')
78
79 def configure(ctx):
80   from waflib import Options
81   ctx.load('compiler_c')
82   ctx.load('waf_unit_test')
83   ctx.env.CFLAGS += ['-g', '-Wall', '-Wextra']
84
85   if Options.options.target_platform:
86     Options.platform = Options.options.target_platform
87
88   if Options.platform == 'win32':
89     ctx.env['shlib_PATTERN'] = 'lib%s.dll'
90
91   if Options.platform == 'darwin':
92     ctx.env.CFLAGS += ['-arch', 'i386', '-arch', 'x86_64']
93     ctx.env.LINKFLAGS += ['-arch', 'i386', '-arch', 'x86_64']
94     ctx.env.CC = 'llvm-gcc-4.2'
95     ctx.env.LINK_CC = 'llvm-gcc-4.2'
96     ctx.env.FRAMEWORK = ['CoreFoundation', 'AudioToolbox', 'Accelerate']
97     ctx.define('HAVE_ACCELERATE', 1)
98
99   if Options.platform == 'ios':
100     ctx.env.CC = 'clang'
101     ctx.env.LD = 'clang'
102     ctx.env.LINK_CC = 'clang'
103     SDKVER="6.1"
104     DEVROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer"
105     SDKROOT="%(DEVROOT)s/SDKs/iPhoneOS%(SDKVER)s.sdk" % locals()
106     ctx.env.FRAMEWORK = ['CoreFoundation', 'AudioToolbox', 'Accelerate']
107     ctx.define('HAVE_ACCELERATE', 1)
108     ctx.env.CFLAGS += [ '-miphoneos-version-min=6.1', '-arch', 'armv7',
109             '--sysroot=%s' % SDKROOT]
110     ctx.env.LINKFLAGS += ['-std=c99', '-arch', 'armv7', '--sysroot=%s' %
111             SDKROOT]
112
113   # check for required headers
114   ctx.check(header_name='stdlib.h')
115   ctx.check(header_name='stdio.h')
116   ctx.check(header_name='math.h')
117   ctx.check(header_name='string.h')
118   ctx.check(header_name='limits.h')
119
120   # check support for C99 __VA_ARGS__ macros
121   check_c99_varargs = '''
122 #include <stdio.h>
123 #define AUBIO_ERR(...) fprintf(stderr, __VA_ARGS__)
124 '''
125   if ctx.check_cc(fragment = check_c99_varargs,
126       type='cstlib',
127       msg = 'Checking for C99 __VA_ARGS__ macro'):
128     ctx.define('HAVE_C99_VARARGS_MACROS', 1)
129
130   # optionally use complex.h
131   if (Options.options.enable_complex == True):
132     ctx.check(header_name='complex.h')
133
134   # check dependencies
135   if (Options.options.enable_sndfile != False):
136       ctx.check_cfg(package = 'sndfile', atleast_version = '1.0.4',
137         args = '--cflags --libs', mandatory = False)
138   if (Options.options.enable_samplerate != False):
139       ctx.check_cfg(package = 'samplerate', atleast_version = '0.0.15',
140         args = '--cflags --libs', mandatory = False)
141
142   # double precision mode
143   if (Options.options.enable_double == True):
144     ctx.define('HAVE_AUBIO_DOUBLE', 1)
145   else:
146     ctx.define('HAVE_AUBIO_DOUBLE', 0)
147
148   # optional dependancies using pkg-config
149   if (Options.options.enable_fftw3 != False or Options.options.enable_fftw3f != False):
150     # one of fftwf or fftw3f
151     if (Options.options.enable_fftw3f != False):
152       ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0',
153           args = '--cflags --libs', mandatory = False)
154       if (Options.options.enable_double == True):
155         ctx.msg('Warning', 'fftw3f enabled, but aubio compiled in double precision!')
156     else:
157       # fftw3f not enabled, take most sensible one according to enable_double
158       if (Options.options.enable_double == True):
159         ctx.check_cfg(package = 'fftw3', atleast_version = '3.0.0',
160             args = '--cflags --libs', mandatory = False)
161       else:
162         ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0',
163             args = '--cflags --libs', mandatory = False)
164     ctx.define('HAVE_FFTW3', 1)
165   else:
166     # fftw disabled, use ooura
167     if 'HAVE_ACCELERATE' in ctx.env.define_key:
168         ctx.msg('Checking for FFT implementation', 'vDSP')
169     else:
170         ctx.msg('Checking for FFT implementation', 'ooura')
171     pass
172
173   if (Options.options.enable_jack != False):
174     ctx.check_cfg(package = 'jack', atleast_version = '0.15.0',
175     args = '--cflags --libs', mandatory = False)
176
177   if (Options.options.enable_lash != False):
178     ctx.check_cfg(package = 'lash-1.0', atleast_version = '0.5.0',
179     args = '--cflags --libs', uselib_store = 'LASH', mandatory = False)
180
181   # write configuration header
182   ctx.write_config_header('src/config.h')
183
184   # add some defines used in examples
185   ctx.define('AUBIO_PREFIX', ctx.env['PREFIX'])
186   ctx.define('PACKAGE', APPNAME)
187
188   # check if docbook-to-man is installed, optional
189   try:
190     ctx.find_program('docbook-to-man', var='DOCBOOKTOMAN')
191   except ctx.errors.ConfigurationError:
192     ctx.to_log('docbook-to-man was not found (ignoring)')
193
194 def build(bld):
195   bld.env['VERSION'] = VERSION
196   bld.env['LIB_VERSION'] = LIB_VERSION
197
198   # add sub directories
199   bld.recurse('src')
200   from waflib import Options
201   if Options.platform != 'ios':
202       bld.recurse('examples')
203       bld.recurse('tests')
204
205   """
206   # create the aubio.pc file for pkg-config
207   if ctx.env['TARGET_PLATFORM'] == 'linux':
208     aubiopc = ctx.new_task_gen('subst')
209     aubiopc.source = 'aubio.pc.in'
210     aubiopc.target = 'aubio.pc'
211     aubiopc.install_path = '${PREFIX}/lib/pkgconfig'
212
213   # build manpages from sgml files
214   if ctx.env['DOCBOOKTOMAN']:
215     import TaskGen
216     TaskGen.declare_chain(
217         name    = 'docbooktoman',
218         rule    = '${DOCBOOKTOMAN} ${SRC} > ${TGT}',
219         ext_in  = '.sgml',
220         ext_out = '.1',
221         reentrant = 0,
222     )
223     manpages = ctx.new_task_gen(name = 'docbooktoman',
224         source=ctx.path.ant_glob('doc/*.sgml'))
225     ctx.install_files('${MANDIR}/man1', ctx.path.ant_glob('doc/*.1'))
226
227   # install woodblock sound
228   bld.install_files('${PREFIX}/share/sounds/aubio/',
229       'sounds/woodblock.aiff')
230   """
231
232 def shutdown(bld):
233     from waflib import Options, Logs
234     if Options.platform == 'ios':
235           msg ='aubio built for ios, contact the author for a commercial license'
236           Logs.pprint('RED', msg)
237           msg ='   Paul Brossier <piem@aubio.org>'
238           Logs.pprint('RED', msg)