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