wscript, src/wscpript: use ctx.options.target_platform, always build .a, indent and...
[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 add_option_enable_disable(ctx, name, default = None, 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', default = default,
39           dest = 'enable_' + name,
40           help = help_str)
41   ctx.add_option('--disable-' + name, action = 'store_false',
42           #default = default,
43           dest = 'enable_' + name,
44           help = help_disable_str )
45
46 def options(ctx):
47   add_option_enable_disable(ctx, 'double', default = False,
48           help_str = 'compile aubio in double precision mode')
49   add_option_enable_disable(ctx, 'fftw3f', default = False,
50           help_str = 'compile with fftw3f instead of ooura (recommended)', 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', help_disable_str = 'do not compile with fftw3')
53   add_option_enable_disable(ctx, 'complex', default = False,
54           help_str ='compile with C99 complex', help_disable_str = 'do not use C99 complex (default)' )
55   add_option_enable_disable(ctx, 'jack', default = None,
56           help_str = 'compile with jack (auto)', help_disable_str = 'disable jack support')
57   add_option_enable_disable(ctx, 'lash', default = None,
58           help_str = 'compile with LASH (auto)', help_disable_str = 'disable LASH' )
59   add_option_enable_disable(ctx, 'sndfile', default = None,
60           help_str = 'compile with sndfile (auto)', help_disable_str = 'disable sndfile')
61   add_option_enable_disable(ctx, 'samplerate', default = None,
62           help_str = 'compile with samplerate (auto)', help_disable_str = 'disable samplerate')
63
64   ctx.add_option('--with-target-platform', type='string',
65       help='set target platform for cross-compilation', dest='target_platform')
66   ctx.load('compiler_c')
67   ctx.load('waf_unit_test')
68   ctx.load('gnu_dirs')
69
70 def configure(ctx):
71   from waflib import Options
72   ctx.load('compiler_c')
73   ctx.load('waf_unit_test')
74   ctx.load('gnu_dirs')
75   ctx.env.CFLAGS += ['-g', '-Wall', '-Wextra']
76
77   target_platform = Options.platform
78   if ctx.options.target_platform:
79     target_platform = ctx.options.target_platform
80   ctx.env['DEST_OS'] = target_platform
81
82   if target_platform == 'win32':
83     ctx.env['shlib_PATTERN'] = 'lib%s.dll'
84
85   if target_platform == 'darwin':
86     ctx.env.CFLAGS += ['-arch', 'i386', '-arch', 'x86_64']
87     ctx.env.LINKFLAGS += ['-arch', 'i386', '-arch', 'x86_64']
88     ctx.env.FRAMEWORK = ['CoreFoundation', 'AudioToolbox', 'Accelerate']
89     ctx.define('HAVE_ACCELERATE', 1)
90
91   if target_platform in [ 'ios', 'iosimulator' ]:
92     ctx.define('HAVE_ACCELERATE', 1)
93     ctx.define('TARGET_OS_IPHONE', 1)
94     ctx.env.FRAMEWORK = ['CoreFoundation', 'AudioToolbox', 'Accelerate']
95     SDKVER="7.0"
96     MINSDKVER="6.1"
97     ctx.env.CFLAGS += ['-std=c99']
98     if target_platform == 'ios':
99         DEVROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer"
100         SDKROOT="%(DEVROOT)s/SDKs/iPhoneOS%(SDKVER)s.sdk" % locals()
101         ctx.env.CFLAGS += [ '-arch', 'arm64' ]
102         ctx.env.CFLAGS += [ '-arch', 'armv7' ]
103         ctx.env.CFLAGS += [ '-arch', 'armv7s' ]
104         ctx.env.LINKFLAGS += [ '-arch', 'arm64' ]
105         ctx.env.LINKFLAGS += ['-arch', 'armv7']
106         ctx.env.LINKFLAGS += ['-arch', 'armv7s']
107         ctx.env.CFLAGS += [ '-miphoneos-version-min=' + MINSDKVER ]
108         ctx.env.LINKFLAGS += [ '-miphoneos-version-min=' + MINSDKVER ]
109     else:
110         DEVROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer"
111         SDKROOT="%(DEVROOT)s/SDKs/iPhoneSimulator%(SDKVER)s.sdk" % locals()
112         ctx.env.CFLAGS += [ '-arch', 'i386' ]
113         ctx.env.CFLAGS += [ '-arch', 'x86_64' ]
114         ctx.env.LINKFLAGS += ['-arch', 'i386']
115         ctx.env.LINKFLAGS += ['-arch', 'x86_64']
116         ctx.env.CFLAGS += [ '-mios-simulator-version-min=' + MINSDKVER ]
117         ctx.env.LINKFLAGS += [ '-mios-simulator-version-min=' + MINSDKVER ]
118     ctx.env.CFLAGS += [ '-isysroot' , SDKROOT]
119     ctx.env.LINKFLAGS += [ '-isysroot' , SDKROOT]
120
121   # check for required headers
122   ctx.check(header_name='stdlib.h')
123   ctx.check(header_name='stdio.h')
124   ctx.check(header_name='math.h')
125   ctx.check(header_name='string.h')
126   ctx.check(header_name='limits.h')
127
128   # check support for C99 __VA_ARGS__ macros
129   check_c99_varargs = '''
130 #include <stdio.h>
131 #define AUBIO_ERR(...) fprintf(stderr, __VA_ARGS__)
132 '''
133   if ctx.check_cc(fragment = check_c99_varargs,
134       type='cstlib',
135       msg = 'Checking for C99 __VA_ARGS__ macro'):
136     ctx.define('HAVE_C99_VARARGS_MACROS', 1)
137
138   # optionally use complex.h
139   if (ctx.options.enable_complex == True):
140     ctx.check(header_name='complex.h')
141
142   # check dependencies
143   if (ctx.options.enable_sndfile != False):
144       ctx.check_cfg(package = 'sndfile', atleast_version = '1.0.4',
145         args = '--cflags --libs', mandatory = False)
146   if (ctx.options.enable_samplerate != False):
147       ctx.check_cfg(package = 'samplerate', atleast_version = '0.0.15',
148         args = '--cflags --libs', mandatory = False)
149
150   # double precision mode
151   if (ctx.options.enable_double == True):
152     ctx.define('HAVE_AUBIO_DOUBLE', 1)
153   else:
154     ctx.define('HAVE_AUBIO_DOUBLE', 0)
155
156   # optional dependancies using pkg-config
157   if (ctx.options.enable_fftw3 != False or ctx.options.enable_fftw3f != False):
158     # one of fftwf or fftw3f
159     if (ctx.options.enable_fftw3f != False):
160       ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0',
161           args = '--cflags --libs', mandatory = False)
162       if (ctx.options.enable_double == True):
163         ctx.msg('Warning', 'fftw3f enabled, but aubio compiled in double precision!')
164     else:
165       # fftw3f not enabled, take most sensible one according to enable_double
166       if (ctx.options.enable_double == True):
167         ctx.check_cfg(package = 'fftw3', atleast_version = '3.0.0',
168             args = '--cflags --libs', mandatory = False)
169       else:
170         ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0',
171             args = '--cflags --libs', mandatory = False)
172     ctx.define('HAVE_FFTW3', 1)
173
174   # fftw disabled, use ooura
175   if 'HAVE_FFTW3F' in ctx.env.define_key:
176     ctx.msg('Checking for FFT implementation', 'fftw3f')
177   elif 'HAVE_FFTW3' in ctx.env.define_key:
178     ctx.msg('Checking for FFT implementation', 'fftw3')
179   elif 'HAVE_ACCELERATE' in ctx.env.define_key:
180     ctx.msg('Checking for FFT implementation', 'vDSP')
181   else:
182     ctx.msg('Checking for FFT implementation', 'ooura')
183
184   if (ctx.options.enable_jack != False):
185     ctx.check_cfg(package = 'jack', atleast_version = '0.15.0',
186     args = '--cflags --libs', mandatory = False)
187
188   if (ctx.options.enable_lash != False):
189     ctx.check_cfg(package = 'lash-1.0', atleast_version = '0.5.0',
190     args = '--cflags --libs', uselib_store = 'LASH', mandatory = False)
191
192   # write configuration header
193   ctx.write_config_header('src/config.h')
194
195   # add some defines used in examples
196   ctx.define('AUBIO_PREFIX', ctx.env['PREFIX'])
197   ctx.define('PACKAGE', APPNAME)
198
199   # check if docbook-to-man is installed, optional
200   try:
201     ctx.find_program('docbook-to-man', var='DOCBOOKTOMAN')
202   except ctx.errors.ConfigurationError:
203     ctx.to_log('docbook-to-man was not found (ignoring)')
204
205 def build(bld):
206     bld.env['VERSION'] = VERSION
207     bld.env['LIB_VERSION'] = LIB_VERSION
208
209     # add sub directories
210     bld.recurse('src')
211     if bld.env['DEST_OS'] not in ['ios', 'iosimulator']:
212         pass
213     if bld.env['DEST_OS'] not in ['ios', 'iosimulator', 'android']:
214         bld.recurse('examples')
215         bld.recurse('tests')
216
217     bld( source = 'aubio.pc.in' )
218
219     # build manpages from sgml files
220     if bld.env['DOCBOOKTOMAN']:
221         from waflib import TaskGen
222         if 'MANDIR' not in bld.env:
223             bld.env['MANDIR'] = bld.env['PREFIX'] + '/share/man'
224         TaskGen.declare_chain(
225                 name      = 'docbooktoman',
226                 rule      = '${DOCBOOKTOMAN} ${SRC} > ${TGT}',
227                 ext_in    = '.sgml',
228                 ext_out   = '.1',
229                 reentrant = False,
230                 install_path =  '${MANDIR}/man1',
231                 )
232         bld( source = bld.path.ant_glob('doc/*.sgml') )
233
234     """
235     bld(rule = 'doxygen ${SRC}', source = 'web.cfg') #, target = 'doc/web/index.html')
236     """
237
238
239 def shutdown(bld):
240     from waflib import Logs
241     if bld.options.target_platform in ['ios', 'iosimulator']:
242         msg ='building for %s, contact the author for a commercial license' % bld.options.target_platform
243         Logs.pprint('RED', msg)
244         msg ='   Paul Brossier <piem@aubio.org>'
245         Logs.pprint('RED', msg)
246
247 def dist(ctx):
248     ctx.excl  = ' **/.waf-1* **/*~ **/*.pyc **/*.swp **/.lock-w* **/.git*'
249     ctx.excl += ' **/build/*'
250     ctx.excl += ' **/python/gen **/python/build **/python/dist'
251     ctx.excl += ' **/**.zip **/**.tar.bz2'
252     ctx.excl += ' **/doc/full/*'
253     ctx.excl += ' **/python/*.db'
254     ctx.excl += ' **/python.old/*'