[5c411dc] | 1 | #! /usr/bin/python |
---|
[110ac90] | 2 | # |
---|
[21ee709] | 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 |
---|
[ee36175] | 11 | # - doc: add doxygen |
---|
[110ac90] | 12 | # - tests: move to new unit test system |
---|
[000b090] | 13 | |
---|
| 14 | APPNAME = 'aubio' |
---|
[5820107] | 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]]) |
---|
[e565c649] | 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' using waf" |
---|
| 28 | sys.exit(1) |
---|
| 29 | |
---|
[46378b3] | 30 | top = '.' |
---|
| 31 | out = 'build' |
---|
[000b090] | 32 | |
---|
| 33 | def init(opt): |
---|
| 34 | pass |
---|
| 35 | |
---|
[46378b3] | 36 | def options(opt): |
---|
[06d30f9] | 37 | opt.add_option('--enable-double', action='store_true', default=False, |
---|
| 38 | help='compile aubio in double precision mode') |
---|
[729a3c0] | 39 | opt.add_option('--disable-fftw', action='store_true', default=False, |
---|
| 40 | help='compile with ooura instead of fftw') |
---|
[000b090] | 41 | opt.add_option('--disable-fftw3f', action='store_true', default=False, |
---|
| 42 | help='compile with fftw3 instead of fftw3f') |
---|
[62b8ab2] | 43 | opt.add_option('--enable-complex', action='store_true', default=False, |
---|
| 44 | help='compile with C99 complex') |
---|
[46378b3] | 45 | opt.add_option('--enable-jack', action='store_true', default=False, |
---|
[2a6e672] | 46 | help='compile with jack support') |
---|
[46378b3] | 47 | opt.add_option('--enable-lash', action='store_true', default=False, |
---|
[2a6e672] | 48 | help='compile with lash support') |
---|
[110ac90] | 49 | opt.add_option('--enable-sndfile', action='store_true', default=False, |
---|
| 50 | help='compile with libsndfile support') |
---|
[ad7c710] | 51 | opt.add_option('--enable-samplerate', action='store_true', default=False, |
---|
[2a6e672] | 52 | help='compile with libsamplerate support') |
---|
[5c411dc] | 53 | opt.add_option('--with-target-platform', type='string', |
---|
| 54 | help='set target platform for cross-compilation', dest='target_platform') |
---|
[46378b3] | 55 | opt.load('compiler_cc') |
---|
| 56 | opt.load('compiler_cxx') |
---|
| 57 | opt.load('gnu_dirs') |
---|
| 58 | opt.load('waf_unit_test') |
---|
[000b090] | 59 | |
---|
| 60 | def configure(conf): |
---|
| 61 | import Options |
---|
| 62 | conf.check_tool('compiler_cc') |
---|
| 63 | conf.check_tool('compiler_cxx') |
---|
| 64 | conf.check_tool('gnu_dirs') # helpful for autotools transition and .pc generation |
---|
[110ac90] | 65 | #conf.check_tool('misc') # needed for subst |
---|
[46378b3] | 66 | conf.load('waf_unit_test') |
---|
[000b090] | 67 | |
---|
[5c411dc] | 68 | if Options.options.target_platform: |
---|
| 69 | Options.platform = Options.options.target_platform |
---|
| 70 | |
---|
| 71 | if Options.platform == 'win32': |
---|
| 72 | conf.env['shlib_PATTERN'] = 'lib%s.dll' |
---|
| 73 | |
---|
[000b090] | 74 | # check for required headers |
---|
| 75 | conf.check(header_name='stdlib.h') |
---|
| 76 | conf.check(header_name='stdio.h') |
---|
| 77 | conf.check(header_name='math.h') |
---|
| 78 | conf.check(header_name='string.h') |
---|
[10a5413] | 79 | conf.check(header_name='limits.h') |
---|
[000b090] | 80 | |
---|
| 81 | # optionally use complex.h |
---|
[62b8ab2] | 82 | if (Options.options.enable_complex == True): |
---|
[000b090] | 83 | conf.check(header_name='complex.h') |
---|
| 84 | |
---|
[2e4fb04] | 85 | # check dependencies |
---|
[110ac90] | 86 | if (Options.options.enable_sndfile == True): |
---|
| 87 | conf.check_cfg(package = 'sndfile', atleast_version = '1.0.4', |
---|
| 88 | args = '--cflags --libs') |
---|
[82335b7] | 89 | if (Options.options.enable_samplerate == True): |
---|
[46378b3] | 90 | conf.check_cfg(package = 'samplerate', atleast_version = '0.0.15', |
---|
[2e4fb04] | 91 | args = '--cflags --libs') |
---|
[000b090] | 92 | |
---|
[06d30f9] | 93 | # double precision mode |
---|
| 94 | if (Options.options.enable_double == True): |
---|
| 95 | conf.define('HAVE_AUBIO_DOUBLE', 1) |
---|
| 96 | else: |
---|
| 97 | conf.define('HAVE_AUBIO_DOUBLE', 0) |
---|
| 98 | |
---|
[110ac90] | 99 | # check if pkg-config is installed, optional |
---|
| 100 | try: |
---|
| 101 | conf.find_program('pkg-config', var='PKGCONFIG') |
---|
| 102 | except conf.errors.ConfigurationError: |
---|
[acb2ac9] | 103 | conf.msg('Could not find pkg-config', 'disabling fftw, jack, and lash') |
---|
| 104 | conf.msg('Could not find fftw', 'using ooura') |
---|
[110ac90] | 105 | |
---|
[36f954a] | 106 | # optional dependancies using pkg-config |
---|
| 107 | if conf.env['PKGCONFIG']: |
---|
| 108 | |
---|
| 109 | if (Options.options.disable_fftw == False): |
---|
| 110 | # one of fftwf or fftw3f |
---|
| 111 | if (Options.options.disable_fftw3f == True): |
---|
[729a3c0] | 112 | conf.check_cfg(package = 'fftw3', atleast_version = '3.0.0', |
---|
| 113 | args = '--cflags --libs') |
---|
| 114 | else: |
---|
[36f954a] | 115 | # fftw3f not disabled, take most sensible one according to enable_double |
---|
| 116 | if (Options.options.enable_double == True): |
---|
| 117 | conf.check_cfg(package = 'fftw3', atleast_version = '3.0.0', |
---|
| 118 | args = '--cflags --libs') |
---|
| 119 | else: |
---|
| 120 | conf.check_cfg(package = 'fftw3f', atleast_version = '3.0.0', |
---|
| 121 | args = '--cflags --libs') |
---|
| 122 | conf.define('HAVE_FFTW3', 1) |
---|
| 123 | else: |
---|
| 124 | # fftw disabled, use ooura |
---|
[acb2ac9] | 125 | conf.msg('Fftw disabled', 'using ooura') |
---|
[36f954a] | 126 | pass |
---|
| 127 | |
---|
| 128 | if (Options.options.enable_jack == True): |
---|
| 129 | conf.check_cfg(package = 'jack', atleast_version = '0.15.0', |
---|
| 130 | args = '--cflags --libs') |
---|
| 131 | |
---|
| 132 | if (Options.options.enable_lash == True): |
---|
| 133 | conf.check_cfg(package = 'lash-1.0', atleast_version = '0.5.0', |
---|
| 134 | args = '--cflags --libs', uselib_store = 'LASH') |
---|
[000b090] | 135 | |
---|
| 136 | # swig |
---|
[110ac90] | 137 | try: |
---|
| 138 | conf.find_program('swig', var='SWIG') |
---|
| 139 | except conf.errors.ConfigurationError: |
---|
| 140 | conf.to_log('swig was not found, not looking for (ignoring)') |
---|
| 141 | if conf.env['SWIG']: |
---|
[000b090] | 142 | conf.check_tool('swig', tooldir='swig') |
---|
| 143 | conf.check_swig_version('1.3.27') |
---|
| 144 | |
---|
| 145 | # python |
---|
[110ac90] | 146 | if conf.find_program('python'): |
---|
[000b090] | 147 | conf.check_tool('python') |
---|
| 148 | conf.check_python_version((2,4,2)) |
---|
| 149 | conf.check_python_headers() |
---|
| 150 | |
---|
| 151 | # check support for C99 __VA_ARGS__ macros |
---|
| 152 | check_c99_varargs = ''' |
---|
| 153 | #include <stdio.h> |
---|
| 154 | #define AUBIO_ERR(...) fprintf(stderr, __VA_ARGS__) |
---|
| 155 | ''' |
---|
[110ac90] | 156 | if conf.check_cc(fragment = check_c99_varargs, |
---|
[46378b3] | 157 | type='cstlib', |
---|
[000b090] | 158 | msg = 'Checking for C99 __VA_ARGS__ macro'): |
---|
| 159 | conf.define('HAVE_C99_VARARGS_MACROS', 1) |
---|
| 160 | |
---|
| 161 | # write configuration header |
---|
| 162 | conf.write_config_header('src/config.h') |
---|
| 163 | |
---|
[110ac90] | 164 | # add some defines used in examples |
---|
[000b090] | 165 | conf.define('AUBIO_PREFIX', conf.env['PREFIX']) |
---|
| 166 | conf.define('PACKAGE', APPNAME) |
---|
| 167 | |
---|
| 168 | # check if docbook-to-man is installed, optional |
---|
[110ac90] | 169 | try: |
---|
| 170 | conf.find_program('docbook-to-man', var='DOCBOOKTOMAN') |
---|
| 171 | except conf.errors.ConfigurationError: |
---|
| 172 | conf.to_log('docbook-to-man was not found (ignoring)') |
---|
[000b090] | 173 | |
---|
| 174 | def build(bld): |
---|
[110ac90] | 175 | bld.env['VERSION'] = VERSION |
---|
| 176 | bld.env['LIB_VERSION'] = LIB_VERSION |
---|
[000b090] | 177 | |
---|
| 178 | # add sub directories |
---|
[e460e60] | 179 | bld.add_subdirs('src examples') |
---|
[000b090] | 180 | if bld.env['SWIG']: |
---|
| 181 | if bld.env['PYTHON']: |
---|
| 182 | bld.add_subdirs('python/aubio python') |
---|
| 183 | |
---|
| 184 | # create the aubio.pc file for pkg-config |
---|
[110ac90] | 185 | if bld.env['TARGET_PLATFORM'] == 'linux': |
---|
| 186 | aubiopc = bld.new_task_gen('subst') |
---|
| 187 | aubiopc.source = 'aubio.pc.in' |
---|
| 188 | aubiopc.target = 'aubio.pc' |
---|
| 189 | aubiopc.install_path = '${PREFIX}/lib/pkgconfig' |
---|
[000b090] | 190 | |
---|
| 191 | # build manpages from sgml files |
---|
| 192 | if bld.env['DOCBOOKTOMAN']: |
---|
| 193 | import TaskGen |
---|
| 194 | TaskGen.declare_chain( |
---|
| 195 | name = 'docbooktoman', |
---|
| 196 | rule = '${DOCBOOKTOMAN} ${SRC} > ${TGT}', |
---|
| 197 | ext_in = '.sgml', |
---|
| 198 | ext_out = '.1', |
---|
| 199 | reentrant = 0, |
---|
| 200 | ) |
---|
[110ac90] | 201 | manpages = bld.new_task_gen(name = 'docbooktoman', |
---|
[000b090] | 202 | source=bld.path.ant_glob('doc/*.sgml')) |
---|
| 203 | bld.install_files('${MANDIR}/man1', bld.path.ant_glob('doc/*.1')) |
---|
| 204 | |
---|
| 205 | # install woodblock sound |
---|
[110ac90] | 206 | bld.install_files('${PREFIX}/share/sounds/aubio/', |
---|
[000b090] | 207 | 'sounds/woodblock.aiff') |
---|
| 208 | |
---|
[f11d78d] | 209 | # build and run the unit tests |
---|
| 210 | build_tests(bld) |
---|
| 211 | |
---|
[000b090] | 212 | def shutdown(bld): |
---|
| 213 | pass |
---|
| 214 | |
---|
[f11d78d] | 215 | # loop over all *.c filenames in tests/src to build them all |
---|
| 216 | # target name is filename.c without the .c |
---|
| 217 | def build_tests(bld): |
---|
[46378b3] | 218 | for target_name in bld.path.ant_glob('tests/src/**/*.c'): |
---|
[110ac90] | 219 | includes = ['src'] |
---|
| 220 | uselib = [] |
---|
| 221 | if not str(target_name).endswith('-jack.c'): |
---|
| 222 | includes = [] |
---|
| 223 | uselib = [] |
---|
| 224 | extra_source = [] |
---|
| 225 | else: |
---|
| 226 | # phasevoc-jack needs jack |
---|
| 227 | if bld.env['JACK']: |
---|
| 228 | includes = ['examples'] |
---|
| 229 | uselib = ['JACK'] |
---|
| 230 | extra_source = ['examples/jackio.c'] |
---|
| 231 | else: |
---|
| 232 | continue |
---|
| 233 | |
---|
[f11d78d] | 234 | this_target = bld.new_task_gen( |
---|
[46378b3] | 235 | features = 'c cprogram test', |
---|
[110ac90] | 236 | uselib = uselib, |
---|
| 237 | source = [target_name] + extra_source, |
---|
[46378b3] | 238 | target = str(target_name).split('.')[0], |
---|
[110ac90] | 239 | includes = ['src'] + includes, |
---|
[740f06b] | 240 | defines = 'AUBIO_UNSTABLE_API=1', |
---|
[46378b3] | 241 | use = 'aubio') |
---|