Fix integer conversion for poll_timeout_ms
[jack2.git] / wscript
blob14e561a365b220fc158e94dd9307292c29ea08f0
1 #! /usr/bin/python3
2 # encoding: utf-8
3 from __future__ import print_function
5 import os
6 import subprocess
7 import shutil
8 import re
9 import sys
11 from waflib import Logs, Options, Task, Utils
12 from waflib.Build import BuildContext, CleanContext, InstallContext, UninstallContext
14 VERSION='1.9.14'
15 APPNAME='jack'
16 JACK_API_VERSION = '0.1.0'
18 # these variables are mandatory ('/' are converted automatically)
19 top = '.'
20 out = 'build'
22 # lib32 variant name used when building in mixed mode
23 lib32 = 'lib32'
25 def display_feature(conf, msg, build):
26     if build:
27         conf.msg(msg, 'yes', color='GREEN')
28     else:
29         conf.msg(msg, 'no', color='YELLOW')
31 def check_for_celt(conf):
32     found = False
33     for version in ['11', '8', '7', '5']:
34         define = 'HAVE_CELT_API_0_' + version
35         if not found:
36             try:
37                 conf.check_cfg(
38                         package='celt >= 0.%s.0' % version,
39                         args='--cflags --libs')
40                 found = True
41                 conf.define(define, 1)
42                 continue
43             except conf.errors.ConfigurationError:
44                 pass
45         conf.define(define, 0)
47     if not found:
48         raise conf.errors.ConfigurationError
50 def options(opt):
51     # options provided by the modules
52     opt.load('compiler_cxx')
53     opt.load('compiler_c')
54     opt.load('autooptions');
56     opt.load('xcode6')
58     opt.recurse('compat')
60     # install directories
61     opt.add_option('--htmldir', type='string', default=None, help='HTML documentation directory [Default: <prefix>/share/jack-audio-connection-kit/reference/html/')
62     opt.add_option('--libdir', type='string', help='Library directory [Default: <prefix>/lib]')
63     opt.add_option('--libdir32', type='string', help='32bit Library directory [Default: <prefix>/lib32]')
64     opt.add_option('--pkgconfigdir', type='string', help='pkg-config file directory [Default: <libdir>/pkgconfig]')
65     opt.add_option('--mandir', type='string', help='Manpage directory [Default: <prefix>/share/man/man1]')
67     # options affecting binaries
68     opt.add_option('--platform', type='string', default=sys.platform, help='Target platform for cross-compiling, e.g. cygwin or win32')
69     opt.add_option('--mixed', action='store_true', default=False, help='Build with 32/64 bits mixed mode')
70     opt.add_option('--debug', action='store_true', default=False, dest='debug', help='Build debuggable binaries')
72     # options affecting general jack functionality
73     opt.add_option('--classic', action='store_true', default=False, help='Force enable standard JACK (jackd) even if D-Bus JACK (jackdbus) is enabled too')
74     opt.add_option('--dbus', action='store_true', default=False, help='Enable D-Bus JACK (jackdbus)')
75     opt.add_option('--autostart', type='string', default='default', help='Autostart method. Possible values: "default", "classic", "dbus", "none"')
76     opt.add_option('--profile', action='store_true', default=False, help='Build with engine profiling')
77     opt.add_option('--clients', default=256, type='int', dest='clients', help='Maximum number of JACK clients')
78     opt.add_option('--ports-per-application', default=2048, type='int', dest='application_ports', help='Maximum number of ports per application')
79     opt.add_option('--systemd-unit', action='store_true', default=False, help='Install systemd units.')
81     opt.set_auto_options_define('HAVE_%s')
82     opt.set_auto_options_style('yesno_and_hack')
84     # options with third party dependencies
85     doxygen = opt.add_auto_option(
86             'doxygen',
87             help='Build doxygen documentation',
88             conf_dest='BUILD_DOXYGEN_DOCS',
89             default=False)
90     doxygen.find_program('doxygen')
91     alsa = opt.add_auto_option(
92             'alsa',
93             help='Enable ALSA driver',
94             conf_dest='BUILD_DRIVER_ALSA')
95     alsa.check_cfg(
96             package='alsa >= 1.0.18',
97             args='--cflags --libs')
98     firewire = opt.add_auto_option(
99             'firewire',
100             help='Enable FireWire driver (FFADO)',
101             conf_dest='BUILD_DRIVER_FFADO')
102     firewire.check_cfg(
103             package='libffado >= 1.999.17',
104             args='--cflags --libs')
105     iio = opt.add_auto_option(
106             'iio',
107             help='Enable IIO driver',
108             conf_dest='BUILD_DRIVER_IIO')
109     iio.check_cfg(
110             package='gtkIOStream >= 1.4.0',
111             args='--cflags --libs')
112     iio.check_cfg(
113             package='eigen3 >= 3.1.2',
114             args='--cflags --libs')
115     portaudio = opt.add_auto_option(
116             'portaudio',
117             help='Enable Portaudio driver',
118             conf_dest='BUILD_DRIVER_PORTAUDIO')
119     portaudio.check(header_name='windows.h') # only build portaudio on windows
120     portaudio.check_cfg(
121             package='portaudio-2.0 >= 19',
122             uselib_store='PORTAUDIO',
123             args='--cflags --libs')
124     winmme = opt.add_auto_option(
125             'winmme',
126             help='Enable WinMME driver',
127             conf_dest='BUILD_DRIVER_WINMME')
128     winmme.check(
129             header_name=['windows.h', 'mmsystem.h'],
130             msg='Checking for header mmsystem.h')
132     celt = opt.add_auto_option(
133             'celt',
134             help='Build with CELT')
135     celt.add_function(check_for_celt)
137     # Suffix _PKG to not collide with HAVE_OPUS defined by the option.
138     opus = opt.add_auto_option(
139             'opus',
140             help='Build Opus netjack2')
141     opus.check(header_name='opus/opus_custom.h')
142     opus.check_cfg(
143             package='opus >= 0.9.0',
144             args='--cflags --libs',
145             define_name='HAVE_OPUS_PKG')
147     samplerate = opt.add_auto_option(
148             'samplerate',
149             help='Build with libsamplerate')
150     samplerate.check_cfg(
151             package='samplerate',
152             args='--cflags --libs')
153     sndfile = opt.add_auto_option(
154             'sndfile',
155             help='Build with libsndfile')
156     sndfile.check_cfg(
157             package='sndfile',
158             args='--cflags --libs')
159     readline = opt.add_auto_option(
160             'readline',
161             help='Build with readline')
162     readline.check(lib='readline')
163     readline.check(
164             header_name=['stdio.h', 'readline/readline.h'],
165             msg='Checking for header readline/readline.h')
166     sd = opt.add_auto_option(
167             'systemd',
168             help='Use systemd notify')
169     sd.check(header_name='systemd/sd-daemon.h')
170     sd.check(lib='systemd')
171     db = opt.add_auto_option(
172             'db',
173             help='Use Berkeley DB (metadata)')
174     db.check(header_name='db.h')
175     db.check(lib='db')
177     # dbus options
178     opt.recurse('dbus')
180     # this must be called before the configure phase
181     opt.apply_auto_options_hack()
183 def detect_platform(conf):
184     # GNU/kFreeBSD and GNU/Hurd are treated as Linux
185     platforms = [
186         # ('KEY, 'Human readable name', ['strings', 'to', 'check', 'for'])
187         ('IS_LINUX',   'Linux',   ['gnu0', 'gnukfreebsd', 'linux', 'posix']),
188         ('IS_MACOSX',  'MacOS X', ['darwin']),
189         ('IS_SUN',     'SunOS',   ['sunos']),
190         ('IS_WINDOWS', 'Windows', ['cygwin', 'msys', 'win32'])
191     ]
193     for key,name,strings in platforms:
194         conf.env[key] = False
196     conf.start_msg('Checking platform')
197     platform = Options.options.platform
198     for key,name,strings in platforms:
199         for s in strings:
200             if platform.startswith(s):
201                 conf.env[key] = True
202                 conf.end_msg(name, color='CYAN')
203                 break
206 def configure(conf):
207     conf.load('compiler_cxx')
208     conf.load('compiler_c')
210     detect_platform(conf)
212     if conf.env['IS_WINDOWS']:
213         conf.env.append_unique('CCDEFINES', '_POSIX')
214         conf.env.append_unique('CXXDEFINES', '_POSIX')
215         if Options.options.platform == 'msys':
216             conf.env.append_value('INCLUDES', ['/mingw64/include'])
217             conf.check(
218                 header_name='asio.h',
219                 includes='/opt/asiosdk/common',
220                 msg='Checking for ASIO SDK',
221                 define_name='HAVE_ASIO',
222                 mandatory=False)
224     conf.env.append_unique('CFLAGS', '-Wall')
225     conf.env.append_unique('CXXFLAGS', '-Wall')
226     conf.env.append_unique('CXXFLAGS', '-std=gnu++11')
228     if not conf.env['IS_MACOSX']:
229         conf.env.append_unique('LDFLAGS', '-Wl,--no-undefined')
230     else:
231         conf.check(lib='aften', uselib='AFTEN', define_name='AFTEN')
232         conf.check_cxx(
233             fragment=''
234                 + '#include <aften/aften.h>\n'
235                 + 'int\n'
236                 + 'main(void)\n'
237                 + '{\n'
238                 + 'AftenContext fAftenContext;\n'
239                 + 'aften_set_defaults(&fAftenContext);\n'
240                 + 'unsigned char *fb;\n'
241                 + 'float *buf=new float[10];\n'
242                 + 'int res = aften_encode_frame(&fAftenContext, fb, buf, 1);\n'
243                 + '}\n',
244             lib='aften',
245             msg='Checking for aften_encode_frame()',
246             define_name='HAVE_AFTEN_NEW_API',
247             mandatory=False)
249         # TODO
250         conf.env.append_unique('CXXFLAGS', '-Wno-deprecated-register')
252     conf.load('autooptions')
254     conf.recurse('compat')
256     # Check for functions.
257     conf.check(
258             fragment=''
259                 + '#define _GNU_SOURCE\n'
260                 + '#include <poll.h>\n'
261                 + '#include <signal.h>\n'
262                 + '#include <stddef.h>\n'
263                 + 'int\n'
264                 + 'main(void)\n'
265                 + '{\n'
266                 + '   ppoll(NULL, 0, NULL, NULL);\n'
267                 + '}\n',
268             msg='Checking for ppoll',
269             define_name='HAVE_PPOLL',
270             mandatory=False)
272     # Check for backtrace support
273     conf.check(
274         header_name='execinfo.h',
275         define_name='HAVE_EXECINFO_H',
276         mandatory=False)
278     conf.recurse('common')
279     if Options.options.dbus:
280         conf.recurse('dbus')
281         if conf.env['BUILD_JACKDBUS'] != True:
282             conf.fatal('jackdbus was explicitly requested but cannot be built')
283     if conf.env['IS_LINUX']:
284         if Options.options.systemd_unit:
285             conf.recurse('systemd')
286         else:
287             conf.env['SYSTEMD_USER_UNIT_DIR'] = None
290     conf.recurse('example-clients')
292     # test for the availability of ucontext, and how it should be used
293     for t in ['gp_regs', 'uc_regs', 'mc_gregs', 'gregs']:
294         fragment = '#include <ucontext.h>\n'
295         fragment += 'int main() { ucontext_t *ucontext; return (int) ucontext->uc_mcontext.%s[0]; }' % t
296         confvar = 'HAVE_UCONTEXT_%s' % t.upper()
297         conf.check_cc(fragment=fragment, define_name=confvar, mandatory=False,
298                       msg='Checking for ucontext->uc_mcontext.%s' % t)
299         if conf.is_defined(confvar):
300             conf.define('HAVE_UCONTEXT', 1)
302     fragment = '#include <ucontext.h>\n'
303     fragment += 'int main() { return NGREG; }'
304     conf.check_cc(fragment=fragment, define_name='HAVE_NGREG', mandatory=False,
305                   msg='Checking for NGREG')
307     conf.env['LIB_PTHREAD'] = ['pthread']
308     conf.env['LIB_DL'] = ['dl']
309     conf.env['LIB_RT'] = ['rt']
310     conf.env['LIB_M'] = ['m']
311     conf.env['LIB_STDC++'] = ['stdc++']
312     conf.env['JACK_API_VERSION'] = JACK_API_VERSION
313     conf.env['JACK_VERSION'] = VERSION
315     conf.env['BUILD_WITH_PROFILE'] = Options.options.profile
316     conf.env['BUILD_WITH_32_64'] = Options.options.mixed
317     conf.env['BUILD_CLASSIC'] = Options.options.classic
318     conf.env['BUILD_DEBUG'] = Options.options.debug
320     if conf.env['BUILD_JACKDBUS']:
321         conf.env['BUILD_JACKD'] = conf.env['BUILD_CLASSIC']
322     else:
323         conf.env['BUILD_JACKD'] = True
325     conf.env['BINDIR'] = conf.env['PREFIX'] + '/bin'
327     if Options.options.htmldir:
328         conf.env['HTMLDIR'] = Options.options.htmldir
329     else:
330         # set to None here so that the doxygen code can find out the highest
331         # directory to remove upon install
332         conf.env['HTMLDIR'] = None
334     if Options.options.libdir:
335         conf.env['LIBDIR'] = Options.options.libdir
336     else:
337         conf.env['LIBDIR'] = conf.env['PREFIX'] + '/lib'
339     if Options.options.pkgconfigdir:
340         conf.env['PKGCONFDIR'] = Options.options.pkgconfigdir
341     else:
342         conf.env['PKGCONFDIR'] = conf.env['LIBDIR'] + '/pkgconfig'
344     if Options.options.mandir:
345         conf.env['MANDIR'] = Options.options.mandir
346     else:
347         conf.env['MANDIR'] = conf.env['PREFIX'] + '/share/man/man1'
349     if conf.env['BUILD_DEBUG']:
350         conf.env.append_unique('CXXFLAGS', '-g')
351         conf.env.append_unique('CFLAGS', '-g')
352         conf.env.append_unique('LINKFLAGS', '-g')
354     if not Options.options.autostart in ['default', 'classic', 'dbus', 'none']:
355         conf.fatal('Invalid autostart value "' + Options.options.autostart + '"')
357     if Options.options.autostart == 'default':
358         if conf.env['BUILD_JACKD']:
359             conf.env['AUTOSTART_METHOD'] = 'classic'
360         else:
361             conf.env['AUTOSTART_METHOD'] = 'dbus'
362     else:
363         conf.env['AUTOSTART_METHOD'] = Options.options.autostart
365     if conf.env['AUTOSTART_METHOD'] == 'dbus' and not conf.env['BUILD_JACKDBUS']:
366         conf.fatal('D-Bus autostart mode was specified but jackdbus will not be built')
367     if conf.env['AUTOSTART_METHOD'] == 'classic' and not conf.env['BUILD_JACKD']:
368         conf.fatal('Classic autostart mode was specified but jackd will not be built')
370     if conf.env['AUTOSTART_METHOD'] == 'dbus':
371         conf.define('USE_LIBDBUS_AUTOLAUNCH', 1)
372     elif conf.env['AUTOSTART_METHOD'] == 'classic':
373         conf.define('USE_CLASSIC_AUTOLAUNCH', 1)
375     conf.define('CLIENT_NUM', Options.options.clients)
376     conf.define('PORT_NUM_FOR_CLIENT', Options.options.application_ports)
378     if conf.env['IS_WINDOWS']:
379         # we define this in the environment to maintain compatibility with
380         # existing install paths that use ADDON_DIR rather than have to
381         # have special cases for windows each time.
382         conf.env['ADDON_DIR'] = conf.env['LIBDIR'] + '/jack'
383         if Options.options.platform == 'msys':
384             conf.define('ADDON_DIR', 'jack')
385             conf.define('__STDC_FORMAT_MACROS', 1) # for PRIu64
386         else:
387             # don't define ADDON_DIR in config.h, use the default 'jack' defined in
388             # windows/JackPlatformPlug_os.h
389             pass
390     else:
391         conf.env['ADDON_DIR'] = os.path.normpath(os.path.join(conf.env['LIBDIR'], 'jack'))
392         conf.define('ADDON_DIR', conf.env['ADDON_DIR'])
393         conf.define('JACK_LOCATION', os.path.normpath(os.path.join(conf.env['PREFIX'], 'bin')))
395     if not conf.env['IS_WINDOWS']:
396         conf.define('USE_POSIX_SHM', 1)
397     conf.define('JACKMP', 1)
398     if conf.env['BUILD_JACKDBUS']:
399         conf.define('JACK_DBUS', 1)
400     if conf.env['BUILD_WITH_PROFILE']:
401         conf.define('JACK_MONITOR', 1)
402     conf.write_config_header('config.h', remove=False)
404     svnrev = None
405     try:
406         f = open('svnversion.h')
407         data = f.read()
408         m = re.match(r'^#define SVN_VERSION "([^"]*)"$', data)
409         if m != None:
410             svnrev = m.group(1)
411         f.close()
412     except IOError:
413         pass
415     if Options.options.mixed:
416         conf.setenv(lib32, env=conf.env.derive())
417         conf.env.append_unique('CFLAGS', '-m32')
418         conf.env.append_unique('CXXFLAGS', '-m32')
419         conf.env.append_unique('CXXFLAGS', '-DBUILD_WITH_32_64')
420         conf.env.append_unique('LINKFLAGS', '-m32')
421         if Options.options.libdir32:
422             conf.env['LIBDIR'] = Options.options.libdir32
423         else:
424             conf.env['LIBDIR'] = conf.env['PREFIX'] + '/lib32'
425         # libdb does not work in mixed mode
426         conf.all_envs[lib32]['HAVE_DB'] = 0
427         conf.all_envs[lib32]['HAVE_DB_H'] = 0
428         conf.all_envs[lib32]['LIB_DB'] = []
429         # no need for opus in 32bit mixed mode clients
430         conf.all_envs[lib32]['LIB_OPUS'] = []
431         # someone tell me where this file gets written please..
432         conf.write_config_header('config.h')
434     print()
435     print('==================')
436     version_msg = 'JACK ' + VERSION
437     if svnrev:
438         version_msg += ' exported from r' + svnrev
439     else:
440         version_msg += ' svn revision will checked and eventually updated during build'
441     print(version_msg)
443     conf.msg('Maximum JACK clients', Options.options.clients, color='NORMAL')
444     conf.msg('Maximum ports per application', Options.options.application_ports, color='NORMAL')
446     conf.msg('Install prefix', conf.env['PREFIX'], color='CYAN')
447     conf.msg('Library directory', conf.all_envs['']['LIBDIR'], color='CYAN')
448     if conf.env['BUILD_WITH_32_64']:
449         conf.msg('32-bit library directory', conf.all_envs[lib32]['LIBDIR'], color='CYAN')
450     conf.msg('Drivers directory', conf.env['ADDON_DIR'], color='CYAN')
451     display_feature(conf, 'Build debuggable binaries', conf.env['BUILD_DEBUG'])
453     tool_flags = [
454         ('C compiler flags',   ['CFLAGS', 'CPPFLAGS']),
455         ('C++ compiler flags', ['CXXFLAGS', 'CPPFLAGS']),
456         ('Linker flags',       ['LINKFLAGS', 'LDFLAGS'])
457     ]
458     for name,vars in tool_flags:
459         flags = []
460         for var in vars:
461             flags += conf.all_envs[''][var]
462         conf.msg(name, repr(flags), color='NORMAL')
464     if conf.env['BUILD_WITH_32_64']:
465         conf.msg('32-bit C compiler flags', repr(conf.all_envs[lib32]['CFLAGS']))
466         conf.msg('32-bit C++ compiler flags', repr(conf.all_envs[lib32]['CXXFLAGS']))
467         conf.msg('32-bit linker flags', repr(conf.all_envs[lib32]['LINKFLAGS']))
468     display_feature(conf, 'Build with engine profiling', conf.env['BUILD_WITH_PROFILE'])
469     display_feature(conf, 'Build with 32/64 bits mixed mode', conf.env['BUILD_WITH_32_64'])
471     display_feature(conf, 'Build standard JACK (jackd)', conf.env['BUILD_JACKD'])
472     display_feature(conf, 'Build D-Bus JACK (jackdbus)', conf.env['BUILD_JACKDBUS'])
473     conf.msg('Autostart method', conf.env['AUTOSTART_METHOD'])
475     if conf.env['BUILD_JACKDBUS'] and conf.env['BUILD_JACKD']:
476         print(Logs.colors.RED + 'WARNING !! mixing both jackd and jackdbus may cause issues:' + Logs.colors.NORMAL)
477         print(Logs.colors.RED + 'WARNING !! jackdbus does not use .jackdrc nor qjackctl settings' + Logs.colors.NORMAL)
479     conf.summarize_auto_options()
481     if conf.env['BUILD_JACKDBUS']:
482         conf.msg('D-Bus service install directory', conf.env['DBUS_SERVICES_DIR'], color='CYAN')
484         if conf.env['DBUS_SERVICES_DIR'] != conf.env['DBUS_SERVICES_DIR_REAL']:
485             print()
486             print(Logs.colors.RED + 'WARNING: D-Bus session services directory as reported by pkg-config is')
487             print(Logs.colors.RED + 'WARNING:', end=' ')
488             print(Logs.colors.CYAN + conf.env['DBUS_SERVICES_DIR_REAL'])
489             print(Logs.colors.RED + 'WARNING: but service file will be installed in')
490             print(Logs.colors.RED + 'WARNING:', end=' ')
491             print(Logs.colors.CYAN + conf.env['DBUS_SERVICES_DIR'])
492             print(Logs.colors.RED + 'WARNING: You may need to adjust your D-Bus configuration after installing jackdbus')
493             print('WARNING: You can override dbus service install directory')
494             print('WARNING: with --enable-pkg-config-dbus-service-dir option to this script')
495             print(Logs.colors.NORMAL, end=' ')
496     print()
498 def init(ctx):
499     for y in (BuildContext, CleanContext, InstallContext, UninstallContext):
500         name = y.__name__.replace('Context','').lower()
501         class tmp(y):
502             cmd = name + '_' + lib32
503             variant = lib32
505 def obj_add_includes(bld, obj):
506     if bld.env['BUILD_JACKDBUS']:
507         obj.includes += ['dbus']
509     if bld.env['IS_LINUX']:
510         obj.includes += ['linux', 'posix']
512     if bld.env['IS_MACOSX']:
513         obj.includes += ['macosx', 'posix']
515     if bld.env['IS_SUN']:
516         obj.includes += ['posix', 'solaris']
518     if bld.env['IS_WINDOWS']:
519         obj.includes += ['windows']
521 # FIXME: Is SERVER_SIDE needed?
522 def build_jackd(bld):
523     jackd = bld(
524         features = ['cxx', 'cxxprogram'],
525         defines = ['HAVE_CONFIG_H','SERVER_SIDE'],
526         includes = ['.', 'common', 'common/jack'],
527         target = 'jackd',
528         source = ['common/Jackdmp.cpp'],
529         use = ['serverlib', 'SYSTEMD']
530     )
532     if bld.env['BUILD_JACKDBUS']:
533         jackd.source += ['dbus/audio_reserve.c', 'dbus/reserve.c']
534         jackd.use += ['DBUS-1']
536     if bld.env['IS_LINUX']:
537         jackd.use += ['DL', 'M', 'PTHREAD', 'RT', 'STDC++']
539     if bld.env['IS_MACOSX']:
540         jackd.use += ['DL', 'PTHREAD']
541         jackd.framework = ['CoreFoundation']
543     if bld.env['IS_SUN']:
544         jackd.use += ['DL', 'PTHREAD']
546     obj_add_includes(bld, jackd)
548     return jackd
550 # FIXME: Is SERVER_SIDE needed?
551 def create_driver_obj(bld, **kw):
552     if 'use' in kw:
553         kw['use'] += ['serverlib']
554     else:
555         kw['use'] = ['serverlib']
557     driver = bld(
558         features = ['c', 'cxx', 'cshlib', 'cxxshlib'],
559         defines = ['HAVE_CONFIG_H', 'SERVER_SIDE'],
560         includes = ['.', 'common', 'common/jack'],
561         install_path = '${ADDON_DIR}/',
562         **kw)
564     if bld.env['IS_WINDOWS']:
565         driver.env['cxxshlib_PATTERN'] = 'jack_%s.dll'
566     else:
567         driver.env['cxxshlib_PATTERN'] = 'jack_%s.so'
569     obj_add_includes(bld, driver)
571     return driver
573 def build_drivers(bld):
574     # Non-hardware driver sources. Lexically sorted.
575     dummy_src = [
576         'common/JackDummyDriver.cpp'
577     ]
579     loopback_src = [
580         'common/JackLoopbackDriver.cpp'
581     ]
583     net_src = [
584         'common/JackNetDriver.cpp'
585     ]
587     netone_src = [
588         'common/JackNetOneDriver.cpp',
589         'common/netjack.c',
590         'common/netjack_packet.c'
591     ]
593     proxy_src = [
594         'common/JackProxyDriver.cpp'
595     ]
597     # Hardware driver sources. Lexically sorted.
598     alsa_src = [
599         'common/memops.c',
600         'linux/alsa/JackAlsaDriver.cpp',
601         'linux/alsa/alsa_rawmidi.c',
602         'linux/alsa/alsa_seqmidi.c',
603         'linux/alsa/alsa_midi_jackmp.cpp',
604         'linux/alsa/generic_hw.c',
605         'linux/alsa/hdsp.c',
606         'linux/alsa/alsa_driver.c',
607         'linux/alsa/hammerfall.c',
608         'linux/alsa/ice1712.c'
609     ]
611     alsarawmidi_src = [
612         'linux/alsarawmidi/JackALSARawMidiDriver.cpp',
613         'linux/alsarawmidi/JackALSARawMidiInputPort.cpp',
614         'linux/alsarawmidi/JackALSARawMidiOutputPort.cpp',
615         'linux/alsarawmidi/JackALSARawMidiPort.cpp',
616         'linux/alsarawmidi/JackALSARawMidiReceiveQueue.cpp',
617         'linux/alsarawmidi/JackALSARawMidiSendQueue.cpp',
618         'linux/alsarawmidi/JackALSARawMidiUtil.cpp'
619     ]
621     boomer_src = [
622         'common/memops.c',
623         'solaris/oss/JackBoomerDriver.cpp'
624     ]
626     coreaudio_src = [
627         'macosx/coreaudio/JackCoreAudioDriver.mm',
628         'common/JackAC3Encoder.cpp'
629     ]
631     coremidi_src = [
632         'macosx/coremidi/JackCoreMidiInputPort.mm',
633         'macosx/coremidi/JackCoreMidiOutputPort.mm',
634         'macosx/coremidi/JackCoreMidiPhysicalInputPort.mm',
635         'macosx/coremidi/JackCoreMidiPhysicalOutputPort.mm',
636         'macosx/coremidi/JackCoreMidiVirtualInputPort.mm',
637         'macosx/coremidi/JackCoreMidiVirtualOutputPort.mm',
638         'macosx/coremidi/JackCoreMidiPort.mm',
639         'macosx/coremidi/JackCoreMidiUtil.mm',
640         'macosx/coremidi/JackCoreMidiDriver.mm'
641     ]
643     ffado_src = [
644         'linux/firewire/JackFFADODriver.cpp',
645         'linux/firewire/JackFFADOMidiInputPort.cpp',
646         'linux/firewire/JackFFADOMidiOutputPort.cpp',
647         'linux/firewire/JackFFADOMidiReceiveQueue.cpp',
648         'linux/firewire/JackFFADOMidiSendQueue.cpp'
649     ]
651     iio_driver_src = [
652         'linux/iio/JackIIODriver.cpp'
653     ]
655     oss_src = [
656         'common/memops.c',
657         'solaris/oss/JackOSSDriver.cpp'
658     ]
660     portaudio_src = [
661         'windows/portaudio/JackPortAudioDevices.cpp',
662         'windows/portaudio/JackPortAudioDriver.cpp',
663     ]
665     winmme_src = [
666         'windows/winmme/JackWinMMEDriver.cpp',
667         'windows/winmme/JackWinMMEInputPort.cpp',
668         'windows/winmme/JackWinMMEOutputPort.cpp',
669         'windows/winmme/JackWinMMEPort.cpp',
670     ]
672     # Create non-hardware driver objects. Lexically sorted.
673     create_driver_obj(
674         bld,
675         target = 'dummy',
676         source = dummy_src)
678     create_driver_obj(
679         bld,
680         target = 'loopback',
681         source = loopback_src)
683     create_driver_obj(
684         bld,
685         target = 'net',
686         source = net_src)
688     create_driver_obj(
689         bld,
690         target = 'netone',
691         source = netone_src,
692         use = ['SAMPLERATE', 'CELT'])
694     create_driver_obj(
695         bld,
696         target = 'proxy',
697         source = proxy_src)
699     # Create hardware driver objects. Lexically sorted after the conditional,
700     # e.g. BUILD_DRIVER_ALSA.
701     if bld.env['BUILD_DRIVER_ALSA']:
702         create_driver_obj(
703             bld,
704             target = 'alsa',
705             source = alsa_src,
706             use = ['ALSA'])
707         create_driver_obj(
708             bld,
709             target = 'alsarawmidi',
710             source = alsarawmidi_src,
711             use = ['ALSA'])
713     if bld.env['BUILD_DRIVER_FFADO']:
714         create_driver_obj(
715             bld,
716             target = 'firewire',
717             source = ffado_src,
718             use = ['LIBFFADO'])
720     if bld.env['BUILD_DRIVER_IIO']:
721         create_driver_obj(
722             bld,
723             target = 'iio',
724             source = iio_src,
725             use = ['GTKIOSTREAM', 'EIGEN3'])
727     if bld.env['BUILD_DRIVER_PORTAUDIO']:
728         create_driver_obj(
729             bld,
730             target = 'portaudio',
731             source = portaudio_src,
732             use = ['PORTAUDIO'])
734     if bld.env['BUILD_DRIVER_WINMME']:
735         create_driver_obj(
736             bld,
737             target = 'winmme',
738             source = winmme_src,
739             use = ['WINMME'])
741     if bld.env['IS_MACOSX']:
742         create_driver_obj(
743             bld,
744             target = 'coreaudio',
745             source = coreaudio_src,
746             use = ['AFTEN'],
747             framework = ['AudioUnit', 'CoreAudio', 'CoreServices'])
749         create_driver_obj(
750             bld,
751             target = 'coremidi',
752             source = coremidi_src,
753             use = ['serverlib'], # FIXME: Is this needed?
754             framework = ['AudioUnit', 'CoreMIDI', 'CoreServices', 'Foundation'])
756     if bld.env['IS_SUN']:
757         create_driver_obj(
758             bld,
759             target = 'boomer',
760             source = boomer_src)
761         create_driver_obj(
762             bld,
763             target = 'oss',
764             source = oss_src)
766 def build(bld):
767     if not bld.variant and bld.env['BUILD_WITH_32_64']:
768         Options.commands.append(bld.cmd + '_' + lib32)
770     # process subfolders from here
771     bld.recurse('common')
773     if bld.variant:
774         # only the wscript in common/ knows how to handle variants
775         return
777     bld.recurse('compat')
779     if not os.access('svnversion.h', os.R_OK):
780         def post_run(self):
781             sg = Utils.h_file(self.outputs[0].abspath(self.env))
782             #print sg.encode('hex')
783             Build.bld.node_sigs[self.env.variant()][self.outputs[0].id] = sg
785         script = bld.path.find_resource('svnversion_regenerate.sh')
786         script = script.abspath()
788         bld(
789                 rule = '%s ${TGT}' % script,
790                 name = 'svnversion',
791                 runnable_status = Task.RUN_ME,
792                 before = 'c cxx',
793                 color = 'BLUE',
794                 post_run = post_run,
795                 source = ['svnversion_regenerate.sh'],
796                 target = [bld.path.find_or_declare('svnversion.h')]
797         )
799     if bld.env['BUILD_JACKD']:
800         build_jackd(bld)
802     build_drivers(bld)
804     bld.recurse('example-clients')
805     if bld.env['IS_LINUX']:
806         bld.recurse('man')
807         bld.recurse('systemd')
808     if not bld.env['IS_WINDOWS']:
809         bld.recurse('tests')
810     if bld.env['BUILD_JACKDBUS']:
811         bld.recurse('dbus')
813     if bld.env['BUILD_DOXYGEN_DOCS']:
814         html_build_dir = bld.path.find_or_declare('html').abspath()
816         bld(
817             features = 'subst',
818             source = 'doxyfile.in',
819             target = 'doxyfile',
820             HTML_BUILD_DIR = html_build_dir,
821             SRCDIR = bld.srcnode.abspath(),
822             VERSION = VERSION
823         )
825         # There are two reasons for logging to doxygen.log and using it as
826         # target in the build rule (rather than html_build_dir):
827         # (1) reduce the noise when running the build
828         # (2) waf has a regular file to check for a timestamp. If the directory
829         #     is used instead waf will rebuild the doxygen target (even upon
830         #     install).
831         def doxygen(task):
832             doxyfile = task.inputs[0].abspath()
833             logfile = task.outputs[0].abspath()
834             cmd = '%s %s &> %s' % (task.env['DOXYGEN'][0], doxyfile, logfile)
835             return task.exec_command(cmd)
837         bld(
838             rule = doxygen,
839             source = 'doxyfile',
840             target = 'doxygen.log'
841         )
843         # Determine where to install HTML documentation. Since share_dir is the
844         # highest directory the uninstall routine should remove, there is no
845         # better candidate for share_dir, but the requested HTML directory if
846         # --htmldir is given.
847         if bld.env['HTMLDIR']:
848             html_install_dir = bld.options.destdir + bld.env['HTMLDIR']
849             share_dir = html_install_dir
850         else:
851             share_dir = bld.options.destdir + bld.env['PREFIX'] + '/share/jack-audio-connection-kit'
852             html_install_dir = share_dir + '/reference/html/'
854         if bld.cmd == 'install':
855             if os.path.isdir(html_install_dir):
856                 Logs.pprint('CYAN', 'Removing old doxygen documentation installation...')
857                 shutil.rmtree(html_install_dir)
858                 Logs.pprint('CYAN', 'Removing old doxygen documentation installation done.')
859             Logs.pprint('CYAN', 'Installing doxygen documentation...')
860             shutil.copytree(html_build_dir, html_install_dir)
861             Logs.pprint('CYAN', 'Installing doxygen documentation done.')
862         elif bld.cmd =='uninstall':
863             Logs.pprint('CYAN', 'Uninstalling doxygen documentation...')
864             if os.path.isdir(share_dir):
865                 shutil.rmtree(share_dir)
866             Logs.pprint('CYAN', 'Uninstalling doxygen documentation done.')
867         elif bld.cmd =='clean':
868             if os.access(html_build_dir, os.R_OK):
869                 Logs.pprint('CYAN', 'Removing doxygen generated documentation...')
870                 shutil.rmtree(html_build_dir)
871                 Logs.pprint('CYAN', 'Removing doxygen generated documentation done.')
873 def dist(ctx):
874     # This code blindly assumes it is working in the toplevel source directory.
875     if not os.path.exists('svnversion.h'):
876         os.system('./svnversion_regenerate.sh svnversion.h')
878 from waflib import TaskGen
879 @TaskGen.extension('.mm')
880 def mm_hook(self, node):
881     """Alias .mm files to be compiled the same as .cpp files, gcc will do the right thing."""
882     return self.create_compiled_task('cxx', node)