Add FreeBSD support
[jack2.git] / wscript
blob451ca7e0b1f14612d3033ae1ed19a37265a0adab
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.20'
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')
71     opt.add_option('--static', action='store_true', default=False, dest='static', help='Build static binaries (Windows only)')
73     # options affecting general jack functionality
74     opt.add_option('--classic', action='store_true', default=False, help='Force enable standard JACK (jackd) even if D-Bus JACK (jackdbus) is enabled too')
75     opt.add_option('--dbus', action='store_true', default=False, help='Enable D-Bus JACK (jackdbus)')
76     opt.add_option('--autostart', type='string', default='default', help='Autostart method. Possible values: "default", "classic", "dbus", "none"')
77     opt.add_option('--profile', action='store_true', default=False, help='Build with engine profiling')
78     opt.add_option('--clients', default=256, type='int', dest='clients', help='Maximum number of JACK clients')
79     opt.add_option('--ports-per-application', default=2048, type='int', dest='application_ports', help='Maximum number of ports per application')
80     opt.add_option('--systemd-unit', action='store_true', default=False, help='Install systemd units.')
82     opt.set_auto_options_define('HAVE_%s')
83     opt.set_auto_options_style('yesno_and_hack')
85     # options with third party dependencies
86     doxygen = opt.add_auto_option(
87             'doxygen',
88             help='Build doxygen documentation',
89             conf_dest='BUILD_DOXYGEN_DOCS',
90             default=False)
91     doxygen.find_program('doxygen')
92     alsa = opt.add_auto_option(
93             'alsa',
94             help='Enable ALSA driver',
95             conf_dest='BUILD_DRIVER_ALSA')
96     alsa.check_cfg(
97             package='alsa >= 1.0.18',
98             args='--cflags --libs')
99     firewire = opt.add_auto_option(
100             'firewire',
101             help='Enable FireWire driver (FFADO)',
102             conf_dest='BUILD_DRIVER_FFADO')
103     firewire.check_cfg(
104             package='libffado >= 1.999.17',
105             args='--cflags --libs')
106     iio = opt.add_auto_option(
107             'iio',
108             help='Enable IIO driver',
109             conf_dest='BUILD_DRIVER_IIO')
110     iio.check_cfg(
111             package='gtkIOStream >= 1.4.0',
112             args='--cflags --libs')
113     iio.check_cfg(
114             package='eigen3 >= 3.1.2',
115             args='--cflags --libs')
116     portaudio = opt.add_auto_option(
117             'portaudio',
118             help='Enable Portaudio driver',
119             conf_dest='BUILD_DRIVER_PORTAUDIO')
120     portaudio.check(header_name='windows.h') # only build portaudio on windows
121     portaudio.check_cfg(
122             package='portaudio-2.0 >= 19',
123             uselib_store='PORTAUDIO',
124             args='--cflags --libs')
125     winmme = opt.add_auto_option(
126             'winmme',
127             help='Enable WinMME driver',
128             conf_dest='BUILD_DRIVER_WINMME')
129     winmme.check(
130             header_name=['windows.h', 'mmsystem.h'],
131             msg='Checking for header mmsystem.h')
133     celt = opt.add_auto_option(
134             'celt',
135             help='Build with CELT')
136     celt.add_function(check_for_celt)
138     # Suffix _PKG to not collide with HAVE_OPUS defined by the option.
139     opus = opt.add_auto_option(
140             'opus',
141             help='Build Opus netjack2')
142     opus.check(header_name='opus/opus_custom.h')
143     opus.check_cfg(
144             package='opus >= 0.9.0',
145             args='--cflags --libs',
146             define_name='HAVE_OPUS_PKG')
148     samplerate = opt.add_auto_option(
149             'samplerate',
150             help='Build with libsamplerate')
151     samplerate.check_cfg(
152             package='samplerate',
153             args='--cflags --libs')
154     sndfile = opt.add_auto_option(
155             'sndfile',
156             help='Build with libsndfile')
157     sndfile.check_cfg(
158             package='sndfile',
159             args='--cflags --libs')
160     readline = opt.add_auto_option(
161             'readline',
162             help='Build with readline')
163     readline.check(lib='readline')
164     readline.check(
165             header_name=['stdio.h', 'readline/readline.h'],
166             msg='Checking for header readline/readline.h')
167     sd = opt.add_auto_option(
168             'systemd',
169             help='Use systemd notify')
170     sd.check(header_name='systemd/sd-daemon.h')
171     sd.check(lib='systemd')
172     db = opt.add_auto_option(
173             'db',
174             help='Use Berkeley DB (metadata)')
175     db.check(header_name='db.h')
176     db.check(lib='db')
177     zalsa = opt.add_auto_option(
178             'zalsa',
179             help='Build internal zita-a2j/j2a client')
180     zalsa.check(lib='zita-alsa-pcmi')
181     zalsa.check(lib='zita-resampler')
183     # dbus options
184     opt.recurse('dbus')
186     # this must be called before the configure phase
187     opt.apply_auto_options_hack()
189 def detect_platform(conf):
190     # GNU/kFreeBSD and GNU/Hurd are treated as Linux
191     platforms = [
192         # ('KEY, 'Human readable name', ['strings', 'to', 'check', 'for'])
193         ('IS_LINUX',   'Linux',   ['gnu0', 'gnukfreebsd', 'linux', 'posix']),
194         ('IS_FREEBSD', 'FreeBSD', ['freebsd']),
195         ('IS_MACOSX',  'MacOS X', ['darwin']),
196         ('IS_SUN',     'SunOS',   ['sunos']),
197         ('IS_WINDOWS', 'Windows', ['cygwin', 'msys', 'win32'])
198     ]
200     for key,name,strings in platforms:
201         conf.env[key] = False
203     conf.start_msg('Checking platform')
204     platform = Options.options.platform
205     for key,name,strings in platforms:
206         for s in strings:
207             if platform.startswith(s):
208                 conf.env[key] = True
209                 conf.end_msg(name, color='CYAN')
210                 break
213 def configure(conf):
214     conf.load('compiler_cxx')
215     conf.load('compiler_c')
217     detect_platform(conf)
219     if conf.env['IS_WINDOWS']:
220         conf.env.append_unique('CCDEFINES', '_POSIX')
221         conf.env.append_unique('CXXDEFINES', '_POSIX')
222         if Options.options.platform in ('msys', 'win32'):
223             conf.env.append_value('INCLUDES', ['/mingw64/include'])
224             conf.check(
225                 header_name='pa_asio.h',
226                 msg='Checking for PortAudio ASIO support',
227                 define_name='HAVE_ASIO',
228                 mandatory=False)
230     conf.env.append_unique('CFLAGS', '-Wall')
231     conf.env.append_unique('CXXFLAGS', ['-Wall', '-Wno-invalid-offsetof'])
232     conf.env.append_unique('CXXFLAGS', '-std=gnu++11')
234     if conf.env['IS_FREEBSD']:
235         conf.check(lib='execinfo', uselib='EXECINFO', define_name='EXECINFO')
236         conf.check_cfg(package='libsysinfo', args='--cflags --libs')
238     if not conf.env['IS_MACOSX']:
239         conf.env.append_unique('LDFLAGS', '-Wl,--no-undefined')
240     else:
241         conf.check(lib='aften', uselib='AFTEN', define_name='AFTEN')
242         conf.check_cxx(
243             fragment=''
244                 + '#include <aften/aften.h>\n'
245                 + 'int\n'
246                 + 'main(void)\n'
247                 + '{\n'
248                 + 'AftenContext fAftenContext;\n'
249                 + 'aften_set_defaults(&fAftenContext);\n'
250                 + 'unsigned char *fb;\n'
251                 + 'float *buf=new float[10];\n'
252                 + 'int res = aften_encode_frame(&fAftenContext, fb, buf, 1);\n'
253                 + '}\n',
254             lib='aften',
255             msg='Checking for aften_encode_frame()',
256             define_name='HAVE_AFTEN_NEW_API',
257             mandatory=False)
259         # TODO
260         conf.env.append_unique('CXXFLAGS', '-Wno-deprecated-register')
262     conf.load('autooptions')
264     conf.recurse('compat')
266     # Check for functions.
267     conf.check(
268             fragment=''
269                 + '#define _GNU_SOURCE\n'
270                 + '#include <poll.h>\n'
271                 + '#include <signal.h>\n'
272                 + '#include <stddef.h>\n'
273                 + 'int\n'
274                 + 'main(void)\n'
275                 + '{\n'
276                 + '   ppoll(NULL, 0, NULL, NULL);\n'
277                 + '}\n',
278             msg='Checking for ppoll',
279             define_name='HAVE_PPOLL',
280             mandatory=False)
282     # Check for backtrace support
283     conf.check(
284         header_name='execinfo.h',
285         define_name='HAVE_EXECINFO_H',
286         mandatory=False)
288     conf.recurse('common')
289     if Options.options.dbus:
290         conf.recurse('dbus')
291         if conf.env['BUILD_JACKDBUS'] != True:
292             conf.fatal('jackdbus was explicitly requested but cannot be built')
293     if conf.env['IS_LINUX']:
294         if Options.options.systemd_unit:
295             conf.recurse('systemd')
296         else:
297             conf.env['SYSTEMD_USER_UNIT_DIR'] = None
300     conf.recurse('example-clients')
301     conf.recurse('tools')
303     # test for the availability of ucontext, and how it should be used
304     for t in ['gp_regs', 'uc_regs', 'mc_gregs', 'gregs']:
305         fragment = '#include <ucontext.h>\n'
306         fragment += 'int main() { ucontext_t *ucontext; return (int) ucontext->uc_mcontext.%s[0]; }' % t
307         confvar = 'HAVE_UCONTEXT_%s' % t.upper()
308         conf.check_cc(fragment=fragment, define_name=confvar, mandatory=False,
309                       msg='Checking for ucontext->uc_mcontext.%s' % t)
310         if conf.is_defined(confvar):
311             conf.define('HAVE_UCONTEXT', 1)
313     fragment = '#include <ucontext.h>\n'
314     fragment += 'int main() { return NGREG; }'
315     conf.check_cc(fragment=fragment, define_name='HAVE_NGREG', mandatory=False,
316                   msg='Checking for NGREG')
318     conf.env['LIB_PTHREAD'] = ['pthread']
319     conf.env['LIB_DL'] = ['dl']
320     conf.env['LIB_RT'] = ['rt']
321     conf.env['LIB_M'] = ['m']
322     conf.env['LIB_STDC++'] = ['stdc++']
323     conf.env['JACK_API_VERSION'] = JACK_API_VERSION
324     conf.env['JACK_VERSION'] = VERSION
326     conf.env['BUILD_WITH_PROFILE'] = Options.options.profile
327     conf.env['BUILD_WITH_32_64'] = Options.options.mixed
328     conf.env['BUILD_CLASSIC'] = Options.options.classic
329     conf.env['BUILD_DEBUG'] = Options.options.debug
330     conf.env['BUILD_STATIC'] = Options.options.static
332     if conf.env['BUILD_JACKDBUS']:
333         conf.env['BUILD_JACKD'] = conf.env['BUILD_CLASSIC']
334     else:
335         conf.env['BUILD_JACKD'] = True
337     conf.env['BINDIR'] = conf.env['PREFIX'] + '/bin'
339     if Options.options.htmldir:
340         conf.env['HTMLDIR'] = Options.options.htmldir
341     else:
342         # set to None here so that the doxygen code can find out the highest
343         # directory to remove upon install
344         conf.env['HTMLDIR'] = None
346     if Options.options.libdir:
347         conf.env['LIBDIR'] = Options.options.libdir
348     else:
349         conf.env['LIBDIR'] = conf.env['PREFIX'] + '/lib'
351     if Options.options.pkgconfigdir:
352         conf.env['PKGCONFDIR'] = Options.options.pkgconfigdir
353     else:
354         conf.env['PKGCONFDIR'] = conf.env['LIBDIR'] + '/pkgconfig'
356     if Options.options.mandir:
357         conf.env['MANDIR'] = Options.options.mandir
358     else:
359         conf.env['MANDIR'] = conf.env['PREFIX'] + '/share/man/man1'
361     if conf.env['BUILD_DEBUG']:
362         conf.env.append_unique('CXXFLAGS', '-g')
363         conf.env.append_unique('CFLAGS', '-g')
364         conf.env.append_unique('LINKFLAGS', '-g')
366     if not Options.options.autostart in ['default', 'classic', 'dbus', 'none']:
367         conf.fatal('Invalid autostart value "' + Options.options.autostart + '"')
369     if Options.options.autostart == 'default':
370         if conf.env['BUILD_JACKD']:
371             conf.env['AUTOSTART_METHOD'] = 'classic'
372         else:
373             conf.env['AUTOSTART_METHOD'] = 'dbus'
374     else:
375         conf.env['AUTOSTART_METHOD'] = Options.options.autostart
377     if conf.env['AUTOSTART_METHOD'] == 'dbus' and not conf.env['BUILD_JACKDBUS']:
378         conf.fatal('D-Bus autostart mode was specified but jackdbus will not be built')
379     if conf.env['AUTOSTART_METHOD'] == 'classic' and not conf.env['BUILD_JACKD']:
380         conf.fatal('Classic autostart mode was specified but jackd will not be built')
382     if conf.env['AUTOSTART_METHOD'] == 'dbus':
383         conf.define('USE_LIBDBUS_AUTOLAUNCH', 1)
384     elif conf.env['AUTOSTART_METHOD'] == 'classic':
385         conf.define('USE_CLASSIC_AUTOLAUNCH', 1)
387     conf.define('CLIENT_NUM', Options.options.clients)
388     conf.define('PORT_NUM_FOR_CLIENT', Options.options.application_ports)
390     if conf.env['IS_WINDOWS']:
391         # we define this in the environment to maintain compatibility with
392         # existing install paths that use ADDON_DIR rather than have to
393         # have special cases for windows each time.
394         conf.env['ADDON_DIR'] = conf.env['LIBDIR'] + '/jack'
395         if Options.options.platform in ('msys', 'win32'):
396             conf.define('ADDON_DIR', 'jack')
397             conf.define('__STDC_FORMAT_MACROS', 1) # for PRIu64
398         else:
399             # don't define ADDON_DIR in config.h, use the default 'jack' defined in
400             # windows/JackPlatformPlug_os.h
401             pass
402     else:
403         conf.env['ADDON_DIR'] = os.path.normpath(os.path.join(conf.env['LIBDIR'], 'jack'))
404         conf.define('ADDON_DIR', conf.env['ADDON_DIR'])
405         conf.define('JACK_LOCATION', os.path.normpath(os.path.join(conf.env['PREFIX'], 'bin')))
407     if not conf.env['IS_WINDOWS']:
408         conf.define('USE_POSIX_SHM', 1)
409     conf.define('JACKMP', 1)
410     if conf.env['BUILD_JACKDBUS']:
411         conf.define('JACK_DBUS', 1)
412     if conf.env['BUILD_WITH_PROFILE']:
413         conf.define('JACK_MONITOR', 1)
414     conf.write_config_header('config.h', remove=False)
416     svnrev = None
417     try:
418         f = open('svnversion.h')
419         data = f.read()
420         m = re.match(r'^#define SVN_VERSION "([^"]*)"$', data)
421         if m != None:
422             svnrev = m.group(1)
423         f.close()
424     except IOError:
425         pass
427     if Options.options.mixed:
428         conf.setenv(lib32, env=conf.env.derive())
429         conf.env.append_unique('CFLAGS', '-m32')
430         conf.env.append_unique('CXXFLAGS', '-m32')
431         conf.env.append_unique('CXXFLAGS', '-DBUILD_WITH_32_64')
432         conf.env.append_unique('LINKFLAGS', '-m32')
433         if Options.options.libdir32:
434             conf.env['LIBDIR'] = Options.options.libdir32
435         else:
436             conf.env['LIBDIR'] = conf.env['PREFIX'] + '/lib32'
438         if conf.env['IS_WINDOWS'] and conf.env['BUILD_STATIC']:
439             def replaceFor32bit(env):
440                 for e in env: yield e.replace('x86_64', 'i686', 1)
441             for env in ('AR', 'CC', 'CXX', 'LINK_CC', 'LINK_CXX'):
442                 conf.all_envs[lib32][env] = list(replaceFor32bit(conf.all_envs[lib32][env]))
443             conf.all_envs[lib32]['LIB_REGEX'] = ['tre32']
445         # libdb does not work in mixed mode
446         conf.all_envs[lib32]['HAVE_DB'] = 0
447         conf.all_envs[lib32]['HAVE_DB_H'] = 0
448         conf.all_envs[lib32]['LIB_DB'] = []
449         # no need for opus in 32bit mixed mode clients
450         conf.all_envs[lib32]['LIB_OPUS'] = []
451         # someone tell me where this file gets written please..
452         conf.write_config_header('config.h')
454     print()
455     print('==================')
456     version_msg = 'JACK ' + VERSION
457     if svnrev:
458         version_msg += ' exported from r' + svnrev
459     else:
460         version_msg += ' svn revision will checked and eventually updated during build'
461     print(version_msg)
463     conf.msg('Maximum JACK clients', Options.options.clients, color='NORMAL')
464     conf.msg('Maximum ports per application', Options.options.application_ports, color='NORMAL')
466     conf.msg('Install prefix', conf.env['PREFIX'], color='CYAN')
467     conf.msg('Library directory', conf.all_envs['']['LIBDIR'], color='CYAN')
468     if conf.env['BUILD_WITH_32_64']:
469         conf.msg('32-bit library directory', conf.all_envs[lib32]['LIBDIR'], color='CYAN')
470     conf.msg('Drivers directory', conf.env['ADDON_DIR'], color='CYAN')
471     display_feature(conf, 'Build debuggable binaries', conf.env['BUILD_DEBUG'])
473     tool_flags = [
474         ('C compiler flags',   ['CFLAGS', 'CPPFLAGS']),
475         ('C++ compiler flags', ['CXXFLAGS', 'CPPFLAGS']),
476         ('Linker flags',       ['LINKFLAGS', 'LDFLAGS'])
477     ]
478     for name,vars in tool_flags:
479         flags = []
480         for var in vars:
481             flags += conf.all_envs[''][var]
482         conf.msg(name, repr(flags), color='NORMAL')
484     if conf.env['BUILD_WITH_32_64']:
485         conf.msg('32-bit C compiler flags', repr(conf.all_envs[lib32]['CFLAGS']))
486         conf.msg('32-bit C++ compiler flags', repr(conf.all_envs[lib32]['CXXFLAGS']))
487         conf.msg('32-bit linker flags', repr(conf.all_envs[lib32]['LINKFLAGS']))
488     display_feature(conf, 'Build with engine profiling', conf.env['BUILD_WITH_PROFILE'])
489     display_feature(conf, 'Build with 32/64 bits mixed mode', conf.env['BUILD_WITH_32_64'])
491     display_feature(conf, 'Build standard JACK (jackd)', conf.env['BUILD_JACKD'])
492     display_feature(conf, 'Build D-Bus JACK (jackdbus)', conf.env['BUILD_JACKDBUS'])
493     conf.msg('Autostart method', conf.env['AUTOSTART_METHOD'])
495     if conf.env['BUILD_JACKDBUS'] and conf.env['BUILD_JACKD']:
496         print(Logs.colors.RED + 'WARNING !! mixing both jackd and jackdbus may cause issues:' + Logs.colors.NORMAL)
497         print(Logs.colors.RED + 'WARNING !! jackdbus does not use .jackdrc nor qjackctl settings' + Logs.colors.NORMAL)
499     conf.summarize_auto_options()
501     if conf.env['BUILD_JACKDBUS']:
502         conf.msg('D-Bus service install directory', conf.env['DBUS_SERVICES_DIR'], color='CYAN')
504         if conf.env['DBUS_SERVICES_DIR'] != conf.env['DBUS_SERVICES_DIR_REAL']:
505             print()
506             print(Logs.colors.RED + 'WARNING: D-Bus session services directory as reported by pkg-config is')
507             print(Logs.colors.RED + 'WARNING:', end=' ')
508             print(Logs.colors.CYAN + conf.env['DBUS_SERVICES_DIR_REAL'])
509             print(Logs.colors.RED + 'WARNING: but service file will be installed in')
510             print(Logs.colors.RED + 'WARNING:', end=' ')
511             print(Logs.colors.CYAN + conf.env['DBUS_SERVICES_DIR'])
512             print(Logs.colors.RED + 'WARNING: You may need to adjust your D-Bus configuration after installing jackdbus')
513             print('WARNING: You can override dbus service install directory')
514             print('WARNING: with --enable-pkg-config-dbus-service-dir option to this script')
515             print(Logs.colors.NORMAL, end=' ')
516     print()
518 def init(ctx):
519     for y in (BuildContext, CleanContext, InstallContext, UninstallContext):
520         name = y.__name__.replace('Context','').lower()
521         class tmp(y):
522             cmd = name + '_' + lib32
523             variant = lib32
525 def obj_add_includes(bld, obj):
526     if bld.env['BUILD_JACKDBUS']:
527         obj.includes += ['dbus']
529     if bld.env['IS_LINUX']:
530         obj.includes += ['linux', 'posix']
532     if bld.env['IS_FREEBSD']:
533         obj.includes += ['freebsd', 'posix']
535     if bld.env['IS_MACOSX']:
536         obj.includes += ['macosx', 'posix']
538     if bld.env['IS_SUN']:
539         obj.includes += ['posix', 'solaris']
541     if bld.env['IS_WINDOWS']:
542         obj.includes += ['windows']
544 # FIXME: Is SERVER_SIDE needed?
545 def build_jackd(bld):
546     jackd = bld(
547         features = ['cxx', 'cxxprogram'],
548         defines = ['HAVE_CONFIG_H','SERVER_SIDE'],
549         includes = ['.', 'common', 'common/jack'],
550         target = 'jackd',
551         source = ['common/Jackdmp.cpp'],
552         use = ['serverlib', 'SYSTEMD']
553     )
555     if bld.env['BUILD_JACKDBUS']:
556         jackd.source += ['dbus/audio_reserve.c', 'dbus/reserve.c']
557         jackd.use += ['DBUS-1']
559     if bld.env['IS_LINUX']:
560         jackd.use += ['DL', 'M', 'PTHREAD', 'RT', 'STDC++']
562     if bld.env['IS_FREEBSD']:
563         jackd.use += ['M', 'PTHREAD']
565     if bld.env['IS_MACOSX']:
566         jackd.use += ['DL', 'PTHREAD']
567         jackd.framework = ['CoreFoundation']
569     if bld.env['IS_SUN']:
570         jackd.use += ['DL', 'PTHREAD']
572     obj_add_includes(bld, jackd)
574     return jackd
576 # FIXME: Is SERVER_SIDE needed?
577 def create_driver_obj(bld, **kw):
578     if 'use' in kw:
579         kw['use'] += ['serverlib']
580     else:
581         kw['use'] = ['serverlib']
583     driver = bld(
584         features = ['c', 'cxx', 'cshlib', 'cxxshlib'],
585         defines = ['HAVE_CONFIG_H', 'SERVER_SIDE'],
586         includes = ['.', 'common', 'common/jack'],
587         install_path = '${ADDON_DIR}/',
588         **kw)
590     if bld.env['IS_WINDOWS']:
591         driver.env['cxxshlib_PATTERN'] = 'jack_%s.dll'
592     else:
593         driver.env['cxxshlib_PATTERN'] = 'jack_%s.so'
595     obj_add_includes(bld, driver)
597     return driver
599 def build_drivers(bld):
600     # Non-hardware driver sources. Lexically sorted.
601     dummy_src = [
602         'common/JackDummyDriver.cpp'
603     ]
605     loopback_src = [
606         'common/JackLoopbackDriver.cpp'
607     ]
609     net_src = [
610         'common/JackNetDriver.cpp'
611     ]
613     netone_src = [
614         'common/JackNetOneDriver.cpp',
615         'common/netjack.c',
616         'common/netjack_packet.c'
617     ]
619     proxy_src = [
620         'common/JackProxyDriver.cpp'
621     ]
623     # Hardware driver sources. Lexically sorted.
624     alsa_src = [
625         'common/memops.c',
626         'linux/alsa/JackAlsaDriver.cpp',
627         'linux/alsa/alsa_rawmidi.c',
628         'linux/alsa/alsa_seqmidi.c',
629         'linux/alsa/alsa_midi_jackmp.cpp',
630         'linux/alsa/generic_hw.c',
631         'linux/alsa/hdsp.c',
632         'linux/alsa/alsa_driver.c',
633         'linux/alsa/hammerfall.c',
634         'linux/alsa/ice1712.c'
635     ]
637     alsarawmidi_src = [
638         'linux/alsarawmidi/JackALSARawMidiDriver.cpp',
639         'linux/alsarawmidi/JackALSARawMidiInputPort.cpp',
640         'linux/alsarawmidi/JackALSARawMidiOutputPort.cpp',
641         'linux/alsarawmidi/JackALSARawMidiPort.cpp',
642         'linux/alsarawmidi/JackALSARawMidiReceiveQueue.cpp',
643         'linux/alsarawmidi/JackALSARawMidiSendQueue.cpp',
644         'linux/alsarawmidi/JackALSARawMidiUtil.cpp'
645     ]
647     boomer_src = [
648         'common/memops.c',
649         'solaris/oss/JackBoomerDriver.cpp'
650     ]
652     coreaudio_src = [
653         'macosx/coreaudio/JackCoreAudioDriver.mm',
654         'common/JackAC3Encoder.cpp'
655     ]
657     coremidi_src = [
658         'macosx/coremidi/JackCoreMidiInputPort.mm',
659         'macosx/coremidi/JackCoreMidiOutputPort.mm',
660         'macosx/coremidi/JackCoreMidiPhysicalInputPort.mm',
661         'macosx/coremidi/JackCoreMidiPhysicalOutputPort.mm',
662         'macosx/coremidi/JackCoreMidiVirtualInputPort.mm',
663         'macosx/coremidi/JackCoreMidiVirtualOutputPort.mm',
664         'macosx/coremidi/JackCoreMidiPort.mm',
665         'macosx/coremidi/JackCoreMidiUtil.mm',
666         'macosx/coremidi/JackCoreMidiDriver.mm'
667     ]
669     ffado_src = [
670         'linux/firewire/JackFFADODriver.cpp',
671         'linux/firewire/JackFFADOMidiInputPort.cpp',
672         'linux/firewire/JackFFADOMidiOutputPort.cpp',
673         'linux/firewire/JackFFADOMidiReceiveQueue.cpp',
674         'linux/firewire/JackFFADOMidiSendQueue.cpp'
675     ]
677     iio_driver_src = [
678         'linux/iio/JackIIODriver.cpp'
679     ]
681     oss_src = [
682         'common/memops.c',
683         'solaris/oss/JackOSSDriver.cpp'
684     ]
686     portaudio_src = [
687         'windows/portaudio/JackPortAudioDevices.cpp',
688         'windows/portaudio/JackPortAudioDriver.cpp',
689     ]
691     winmme_src = [
692         'windows/winmme/JackWinMMEDriver.cpp',
693         'windows/winmme/JackWinMMEInputPort.cpp',
694         'windows/winmme/JackWinMMEOutputPort.cpp',
695         'windows/winmme/JackWinMMEPort.cpp',
696     ]
698     # Create non-hardware driver objects. Lexically sorted.
699     create_driver_obj(
700         bld,
701         target = 'dummy',
702         source = dummy_src)
704     create_driver_obj(
705         bld,
706         target = 'loopback',
707         source = loopback_src)
709     create_driver_obj(
710         bld,
711         target = 'net',
712         source = net_src)
714     create_driver_obj(
715         bld,
716         target = 'netone',
717         source = netone_src,
718         use = ['SAMPLERATE', 'CELT'])
720     create_driver_obj(
721         bld,
722         target = 'proxy',
723         source = proxy_src)
725     # Create hardware driver objects. Lexically sorted after the conditional,
726     # e.g. BUILD_DRIVER_ALSA.
727     if bld.env['BUILD_DRIVER_ALSA']:
728         create_driver_obj(
729             bld,
730             target = 'alsa',
731             source = alsa_src,
732             use = ['ALSA'])
733         create_driver_obj(
734             bld,
735             target = 'alsarawmidi',
736             source = alsarawmidi_src,
737             use = ['ALSA'])
739     if bld.env['BUILD_DRIVER_FFADO']:
740         create_driver_obj(
741             bld,
742             target = 'firewire',
743             source = ffado_src,
744             use = ['LIBFFADO'])
746     if bld.env['BUILD_DRIVER_IIO']:
747         create_driver_obj(
748             bld,
749             target = 'iio',
750             source = iio_src,
751             use = ['GTKIOSTREAM', 'EIGEN3'])
753     if bld.env['BUILD_DRIVER_PORTAUDIO']:
754         create_driver_obj(
755             bld,
756             target = 'portaudio',
757             source = portaudio_src,
758             use = ['PORTAUDIO'])
760     if bld.env['BUILD_DRIVER_WINMME']:
761         create_driver_obj(
762             bld,
763             target = 'winmme',
764             source = winmme_src,
765             use = ['WINMME'])
767     if bld.env['IS_MACOSX']:
768         create_driver_obj(
769             bld,
770             target = 'coreaudio',
771             source = coreaudio_src,
772             use = ['AFTEN'],
773             framework = ['AudioUnit', 'CoreAudio', 'CoreServices'])
775         create_driver_obj(
776             bld,
777             target = 'coremidi',
778             source = coremidi_src,
779             use = ['serverlib'], # FIXME: Is this needed?
780             framework = ['AudioUnit', 'CoreMIDI', 'CoreServices', 'Foundation'])
782     if bld.env['IS_SUN'] or bld.env['IS_FREEBSD']:
783         create_driver_obj(
784             bld,
785             target = 'boomer',
786             source = boomer_src)
787         create_driver_obj(
788             bld,
789             target = 'oss',
790             source = oss_src)
792 def build(bld):
793     if not bld.variant and bld.env['BUILD_WITH_32_64']:
794         Options.commands.append(bld.cmd + '_' + lib32)
796     # process subfolders from here
797     bld.recurse('common')
799     if bld.variant:
800         # only the wscript in common/ knows how to handle variants
801         return
803     bld.recurse('compat')
805     if not os.access('svnversion.h', os.R_OK):
806         def post_run(self):
807             sg = Utils.h_file(self.outputs[0].abspath(self.env))
808             #print sg.encode('hex')
809             Build.bld.node_sigs[self.env.variant()][self.outputs[0].id] = sg
811         script = bld.path.find_resource('svnversion_regenerate.sh')
812         script = script.abspath()
814         bld(
815                 rule = '%s ${TGT}' % script,
816                 name = 'svnversion',
817                 runnable_status = Task.RUN_ME,
818                 before = 'c cxx',
819                 color = 'BLUE',
820                 post_run = post_run,
821                 source = ['svnversion_regenerate.sh'],
822                 target = [bld.path.find_or_declare('svnversion.h')]
823         )
825     if bld.env['BUILD_JACKD']:
826         build_jackd(bld)
828     build_drivers(bld)
830     bld.recurse('example-clients')
831     bld.recurse('tools')
833     if bld.env['IS_LINUX'] or bld.env['IS_FREEBSD']:
834         bld.recurse('man')
835         bld.recurse('systemd')
836     if not bld.env['IS_WINDOWS']:
837         bld.recurse('tests')
838     if bld.env['BUILD_JACKDBUS']:
839         bld.recurse('dbus')
841     if bld.env['BUILD_DOXYGEN_DOCS']:
842         html_build_dir = bld.path.find_or_declare('html').abspath()
844         bld(
845             features = 'subst',
846             source = 'doxyfile.in',
847             target = 'doxyfile',
848             HTML_BUILD_DIR = html_build_dir,
849             SRCDIR = bld.srcnode.abspath(),
850             VERSION = VERSION
851         )
853         # There are two reasons for logging to doxygen.log and using it as
854         # target in the build rule (rather than html_build_dir):
855         # (1) reduce the noise when running the build
856         # (2) waf has a regular file to check for a timestamp. If the directory
857         #     is used instead waf will rebuild the doxygen target (even upon
858         #     install).
859         def doxygen(task):
860             doxyfile = task.inputs[0].abspath()
861             logfile = task.outputs[0].abspath()
862             cmd = '%s %s &> %s' % (task.env['DOXYGEN'][0], doxyfile, logfile)
863             return task.exec_command(cmd)
865         bld(
866             rule = doxygen,
867             source = 'doxyfile',
868             target = 'doxygen.log'
869         )
871         # Determine where to install HTML documentation. Since share_dir is the
872         # highest directory the uninstall routine should remove, there is no
873         # better candidate for share_dir, but the requested HTML directory if
874         # --htmldir is given.
875         if bld.env['HTMLDIR']:
876             html_install_dir = bld.options.destdir + bld.env['HTMLDIR']
877             share_dir = html_install_dir
878         else:
879             share_dir = bld.options.destdir + bld.env['PREFIX'] + '/share/jack-audio-connection-kit'
880             html_install_dir = share_dir + '/reference/html/'
882         if bld.cmd == 'install':
883             if os.path.isdir(html_install_dir):
884                 Logs.pprint('CYAN', 'Removing old doxygen documentation installation...')
885                 shutil.rmtree(html_install_dir)
886                 Logs.pprint('CYAN', 'Removing old doxygen documentation installation done.')
887             Logs.pprint('CYAN', 'Installing doxygen documentation...')
888             shutil.copytree(html_build_dir, html_install_dir)
889             Logs.pprint('CYAN', 'Installing doxygen documentation done.')
890         elif bld.cmd =='uninstall':
891             Logs.pprint('CYAN', 'Uninstalling doxygen documentation...')
892             if os.path.isdir(share_dir):
893                 shutil.rmtree(share_dir)
894             Logs.pprint('CYAN', 'Uninstalling doxygen documentation done.')
895         elif bld.cmd =='clean':
896             if os.access(html_build_dir, os.R_OK):
897                 Logs.pprint('CYAN', 'Removing doxygen generated documentation...')
898                 shutil.rmtree(html_build_dir)
899                 Logs.pprint('CYAN', 'Removing doxygen generated documentation done.')
901 def dist(ctx):
902     # This code blindly assumes it is working in the toplevel source directory.
903     if not os.path.exists('svnversion.h'):
904         os.system('./svnversion_regenerate.sh svnversion.h')
906 from waflib import TaskGen
907 @TaskGen.extension('.mm')
908 def mm_hook(self, node):
909     """Alias .mm files to be compiled the same as .cpp files, gcc will do the right thing."""
910     return self.create_compiled_task('cxx', node)