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