wscript: add option to disable libsamplerate
[aubio.git] / wscript
1 #! /usr/bin/python
2
3 #  - doc: add doxygen
4 #  - tests: move to new unit test system 
5
6 APPNAME = 'aubio'
7 VERSION = '0.3.3'
8 LIB_VERSION = '2.1.1'
9 srcdir = '.'
10 blddir = 'build'
11
12 def init(opt):
13   pass
14
15 def set_options(opt):
16   opt.add_option('--enable-double', action='store_true', default=False,
17       help='compile aubio in double precision mode')
18   opt.add_option('--disable-fftw3f', action='store_true', default=False,
19       help='compile with fftw3 instead of fftw3f')
20   opt.add_option('--enable-complex', action='store_true', default=False,
21       help='compile with C99 complex')
22   opt.add_option('--disable-jack', action='store_true', default=False,
23       help='compile without jack support')
24   opt.add_option('--disable-lash', action='store_true', default=False,
25       help='compile without lash support')
26   opt.add_option('--disable-libsamplerate', action='store_true', default=False,
27       help='compile without libsamplerate support')
28   opt.add_option('--with-target-platform', type='string',
29       help='set target platform for cross-compilation', dest='target_platform')
30   opt.tool_options('compiler_cc')
31   opt.tool_options('compiler_cxx')
32   opt.tool_options('gnu_dirs')
33   opt.tool_options('UnitTest')
34
35 def configure(conf):
36   import Options
37   conf.check_tool('compiler_cc')
38   conf.check_tool('compiler_cxx')
39   conf.check_tool('gnu_dirs') # helpful for autotools transition and .pc generation
40   conf.check_tool('misc') # needed for subst
41
42   if Options.options.target_platform:
43     Options.platform = Options.options.target_platform
44
45   if Options.platform == 'win32':
46     conf.env['shlib_PATTERN'] = 'lib%s.dll'
47
48   # check for required headers
49   conf.check(header_name='stdlib.h')
50   conf.check(header_name='stdio.h')
51   conf.check(header_name='math.h')
52   conf.check(header_name='string.h')
53   conf.check(header_name='limits.h')
54
55   # optionally use complex.h
56   if (Options.options.enable_complex == True):
57     conf.check(header_name='complex.h')
58
59   # check dependencies
60   conf.check_cfg(package = 'sndfile', atleast_version = '1.0.4',
61     args = '--cflags --libs')
62   if (Options.options.disable_libsamplerate == False):
63       conf.check_cfg(package = 'libsamplerate', atleast_version = '0.0.15',
64         args = '--cflags --libs')
65
66   # double precision mode
67   if (Options.options.enable_double == True):
68     conf.define('HAVE_AUBIO_DOUBLE', 1)
69   else:
70     conf.define('HAVE_AUBIO_DOUBLE', 0)
71
72   # one of fftwf or fftw3f
73   if (Options.options.disable_fftw3f == True):
74     conf.check_cfg(package = 'fftw3', atleast_version = '3.0.0',
75         args = '--cflags --libs')
76   else:
77     # fftw3f not disabled, take most sensible one according to enable_double
78     if (Options.options.enable_double == True):
79       conf.check_cfg(package = 'fftw3', atleast_version = '3.0.0',
80           args = '--cflags --libs')
81     else:
82       conf.check_cfg(package = 'fftw3f', atleast_version = '3.0.0',
83           args = '--cflags --libs')
84
85   # optional dependancies
86   if (Options.options.disable_jack == False):
87     conf.check_cfg(package = 'jack', atleast_version = '0.15.0',
88     args = '--cflags --libs')
89   if (Options.options.disable_lash == False):
90     conf.check_cfg(package = 'lash-1.0', atleast_version = '0.5.0',
91     args = '--cflags --libs', uselib_store = 'LASH')
92
93   # swig
94   if conf.find_program('swig', var='SWIG', mandatory = False):
95     conf.check_tool('swig', tooldir='swig')
96     conf.check_swig_version('1.3.27')
97
98     # python
99     if conf.find_program('python', mandatory = False):
100       conf.check_tool('python')
101       conf.check_python_version((2,4,2))
102       conf.check_python_headers()
103
104   # check support for C99 __VA_ARGS__ macros
105   check_c99_varargs = '''
106 #include <stdio.h>
107 #define AUBIO_ERR(...) fprintf(stderr, __VA_ARGS__)
108 '''
109   if conf.check_cc(fragment = check_c99_varargs, 
110       type='cstaticlib', 
111       msg = 'Checking for C99 __VA_ARGS__ macro'):
112     conf.define('HAVE_C99_VARARGS_MACROS', 1)
113
114   # write configuration header
115   conf.write_config_header('src/config.h')
116
117   # add some defines used in examples 
118   conf.define('AUBIO_PREFIX', conf.env['PREFIX'])
119   conf.define('PACKAGE', APPNAME)
120
121   # check if docbook-to-man is installed, optional
122   conf.find_program('docbook-to-man', var='DOCBOOKTOMAN', mandatory=False)
123
124 def build(bld):
125   bld.env['VERSION'] = VERSION 
126   bld.env['LIB_VERSION'] = LIB_VERSION 
127
128   # add sub directories
129   bld.add_subdirs('src examples')
130   if bld.env['SWIG']:
131     if bld.env['PYTHON']:
132       bld.add_subdirs('python/aubio python')
133
134   # create the aubio.pc file for pkg-config
135   aubiopc = bld.new_task_gen('subst')
136   aubiopc.source = 'aubio.pc.in'
137   aubiopc.target = 'aubio.pc'
138   aubiopc.install_path = '${PREFIX}/lib/pkgconfig'
139
140   # build manpages from sgml files
141   if bld.env['DOCBOOKTOMAN']:
142     import TaskGen
143     TaskGen.declare_chain(
144         name    = 'docbooktoman',
145         rule    = '${DOCBOOKTOMAN} ${SRC} > ${TGT}',
146         ext_in  = '.sgml',
147         ext_out = '.1',
148         reentrant = 0,
149     )
150     manpages = bld.new_task_gen(name = 'docbooktoman', 
151         source=bld.path.ant_glob('doc/*.sgml'))
152     bld.install_files('${MANDIR}/man1', bld.path.ant_glob('doc/*.1'))
153
154   # install woodblock sound
155   bld.install_files('${PREFIX}/share/sounds/aubio/', 
156       'sounds/woodblock.aiff')
157
158   # build and run the unit tests
159   build_tests(bld)
160   import UnitTest
161   bld.add_post_fun(UnitTest.summary)
162
163 def shutdown(bld):
164   pass
165
166 # loop over all *.c filenames in tests/src to build them all
167 # target name is filename.c without the .c
168 def build_tests(bld):
169   for target_name in bld.path.ant_glob('tests/src/**/*.c').split():
170     this_target = bld.new_task_gen(
171         features = 'cc cprogram test',
172         source = target_name,
173         target = target_name.split('.')[0],
174         includes = 'src',
175         defines = 'AUBIO_UNSTABLE_API=1',
176         uselib_local = 'aubio')
177     # phasevoc-jack also needs jack 
178     if target_name.endswith('test-phasevoc-jack.c'):
179       this_target.includes = ['src', 'examples']
180       this_target.uselib_local = ['aubio']
181       this_target.uselib = ['JACK']
182       this_target.source += ' examples/jackio.c'