Correct JackPortAudioDriver::Open : special case for ASIO drivers.
[jack2.git] / wscript
blobc2fb95cf209c668d342a4f74d4a444d01a0a1380
1 #! /usr/bin/env python
2 # encoding: utf-8
3 from __future__ import print_function
5 import os
6 import Utils
7 import Options
8 import subprocess
9 g_maxlen = 40
10 import shutil
11 import Task
12 import re
13 import Logs
14 import sys
16 VERSION='1.9.9'
17 APPNAME='jack'
18 JACK_API_VERSION = '0.1.0'
20 # these variables are mandatory ('/' are converted automatically)
21 top = '.'
22 out = 'build'
24 def display_msg(msg, status = None, color = None):
25 sr = msg
26 global g_maxlen
27 g_maxlen = max(g_maxlen, len(msg))
28 if status:
29 Logs.pprint('NORMAL', "%s :" % msg.ljust(g_maxlen), sep=' ')
30 Logs.pprint(color, status)
31 else:
32 print("%s" % msg.ljust(g_maxlen))
34 def display_feature(msg, build):
35 if build:
36 display_msg(msg, "yes", 'GREEN')
37 else:
38 display_msg(msg, "no", 'YELLOW')
40 def create_svnversion_task(bld, header='svnversion.h', define=None):
41 cmd = '../svnversion_regenerate.sh ${TGT}'
42 if define:
43 cmd += " " + define
45 def post_run(self):
46 sg = Utils.h_file(self.outputs[0].abspath(self.env))
47 #print sg.encode('hex')
48 Build.bld.node_sigs[self.env.variant()][self.outputs[0].id] = sg
50 bld(
51 rule = cmd,
52 name = 'svnversion',
53 runnable_status = Task.RUN_ME,
54 before = 'c',
55 color = 'BLUE',
56 post_run = post_run,
57 target = [bld.path.find_or_declare(header)]
60 def options(opt):
61 # options provided by the modules
62 opt.tool_options('compiler_cxx')
63 opt.tool_options('compiler_cc')
65 opt.add_option('--libdir', type='string', help="Library directory [Default: <prefix>/lib]")
66 opt.add_option('--libdir32', type='string', help="32bit Library directory [Default: <prefix>/lib32]")
67 opt.add_option('--mandir', type='string', help="Manpage directory [Default: <prefix>/share/man/man1]")
68 opt.add_option('--dbus', action='store_true', default=False, help='Enable D-Bus JACK (jackdbus)')
69 opt.add_option('--classic', action='store_true', default=False, help='Force enable standard JACK (jackd) even if D-Bus JACK (jackdbus) is enabled too')
70 opt.add_option('--doxygen', action='store_true', default=False, help='Enable build of doxygen documentation')
71 opt.add_option('--profile', action='store_true', default=False, help='Build with engine profiling')
72 opt.add_option('--mixed', action='store_true', default=False, help='Build with 32/64 bits mixed mode')
73 opt.add_option('--clients', default=64, type="int", dest="clients", help='Maximum number of JACK clients')
74 opt.add_option('--ports-per-application', default=768, type="int", dest="application_ports", help='Maximum number of ports per application')
75 opt.add_option('--debug', action='store_true', default=False, dest='debug', help='Build debuggable binaries')
76 opt.add_option('--firewire', action='store_true', default=False, help='Enable FireWire driver (FFADO)')
77 opt.add_option('--freebob', action='store_true', default=False, help='Enable FreeBob driver')
78 opt.add_option('--alsa', action='store_true', default=False, help='Enable ALSA driver')
79 opt.sub_options('dbus')
81 def configure(conf):
82 conf.load('compiler_cxx')
83 conf.load('compiler_cc')
84 platform = sys.platform
85 conf.env['IS_MACOSX'] = platform == 'darwin'
86 conf.env['IS_LINUX'] = platform == 'linux' or platform == 'linux2' or platform == 'posix'
87 conf.env['IS_SUN'] = platform == 'sunos'
88 # GNU/kFreeBSD and GNU/Hurd are treated as Linux
89 if platform.startswith('gnu0') or platform.startswith('gnukfreebsd'):
90 conf.env['IS_LINUX'] = True
92 if conf.env['IS_LINUX']:
93 Logs.pprint('CYAN', "Linux detected")
95 if conf.env['IS_MACOSX']:
96 Logs.pprint('CYAN', "MacOS X detected")
98 if conf.env['IS_SUN']:
99 Logs.pprint('CYAN', "SunOS detected")
101 if conf.env['IS_LINUX']:
102 conf.check_tool('compiler_cxx')
103 conf.check_tool('compiler_cc')
105 if conf.env['IS_MACOSX']:
106 conf.check_tool('compiler_cxx')
107 conf.check_tool('compiler_cc')
109 # waf 1.5 : check_tool('compiler_cxx') and check_tool('compiler_cc') do not work correctly, so explicit use of gcc and g++
110 if conf.env['IS_SUN']:
111 conf.check_tool('g++')
112 conf.check_tool('gcc')
114 #if conf.env['IS_SUN']:
115 # conf.check_tool('compiler_cxx')
116 # conf.check_tool('compiler_cc')
118 conf.env.append_unique('CXXFLAGS', '-Wall')
119 conf.env.append_unique('CFLAGS', '-Wall')
121 conf.sub_config('common')
122 if conf.env['IS_LINUX']:
123 conf.sub_config('linux')
124 if Options.options.alsa and not conf.env['BUILD_DRIVER_ALSA']:
125 conf.fatal('ALSA driver was explicitly requested but cannot be built')
126 if Options.options.freebob and not conf.env['BUILD_DRIVER_FREEBOB']:
127 conf.fatal('FreeBob driver was explicitly requested but cannot be built')
128 if Options.options.firewire and not conf.env['BUILD_DRIVER_FFADO']:
129 conf.fatal('FFADO driver was explicitly requested but cannot be built')
130 conf.env['BUILD_DRIVER_ALSA'] = Options.options.alsa
131 conf.env['BUILD_DRIVER_FFADO'] = Options.options.firewire
132 conf.env['BUILD_DRIVER_FREEBOB'] = Options.options.freebob
133 if Options.options.dbus:
134 conf.sub_config('dbus')
135 if conf.env['BUILD_JACKDBUS'] != True:
136 conf.fatal('jackdbus was explicitly requested but cannot be built')
138 conf.check_cc(header_name='samplerate.h', define_name="HAVE_SAMPLERATE")
140 if conf.is_defined('HAVE_SAMPLERATE'):
141 conf.env['LIB_SAMPLERATE'] = ['samplerate']
143 conf.sub_config('example-clients')
145 if conf.check_cfg(package='celt', atleast_version='0.11.0', args='--cflags --libs', mandatory=False):
146 conf.define('HAVE_CELT', 1)
147 conf.define('HAVE_CELT_API_0_11', 1)
148 conf.define('HAVE_CELT_API_0_8', 0)
149 conf.define('HAVE_CELT_API_0_7', 0)
150 conf.define('HAVE_CELT_API_0_5', 0)
151 elif conf.check_cfg(package='celt', atleast_version='0.8.0', args='--cflags --libs', mandatory=False):
152 conf.define('HAVE_CELT', 1)
153 conf.define('HAVE_CELT_API_0_11', 0)
154 conf.define('HAVE_CELT_API_0_8', 1)
155 conf.define('HAVE_CELT_API_0_7', 0)
156 conf.define('HAVE_CELT_API_0_5', 0)
157 elif conf.check_cfg(package='celt', atleast_version='0.7.0', args='--cflags --libs', mandatory=False):
158 conf.define('HAVE_CELT', 1)
159 conf.define('HAVE_CELT_API_0_11', 0)
160 conf.define('HAVE_CELT_API_0_8', 0)
161 conf.define('HAVE_CELT_API_0_7', 1)
162 conf.define('HAVE_CELT_API_0_5', 0)
163 elif conf.check_cfg(package='celt', atleast_version='0.5.0', args='--cflags --libs', mandatory=False):
164 conf.define('HAVE_CELT', 1)
165 conf.define('HAVE_CELT_API_0_11', 0)
166 conf.define('HAVE_CELT_API_0_8', 0)
167 conf.define('HAVE_CELT_API_0_7', 0)
168 conf.define('HAVE_CELT_API_0_5', 1)
169 else:
170 conf.define('HAVE_CELT', 0)
171 conf.define('HAVE_CELT_API_0_11', 0)
172 conf.define('HAVE_CELT_API_0_8', 0)
173 conf.define('HAVE_CELT_API_0_7', 0)
174 conf.define('HAVE_CELT_API_0_5', 0)
176 conf.env['WITH_OPUS'] = False
177 if conf.check_cfg(package='opus', atleast_version='0.9.0' , args='--cflags --libs', mandatory=False):
178 if conf.check_cc(header_name='opus/opus_custom.h', mandatory=False):
179 conf.define('HAVE_OPUS', 1)
180 conf.env['WITH_OPUS'] = True
183 conf.env['LIB_PTHREAD'] = ['pthread']
184 conf.env['LIB_DL'] = ['dl']
185 conf.env['LIB_RT'] = ['rt']
186 conf.env['LIB_M'] = ['m']
187 conf.env['LIB_STDC++'] = ['stdc++']
188 conf.env['JACK_API_VERSION'] = JACK_API_VERSION
189 conf.env['JACK_VERSION'] = VERSION
191 conf.env['BUILD_DOXYGEN_DOCS'] = Options.options.doxygen
192 conf.env['BUILD_WITH_PROFILE'] = Options.options.profile
193 conf.env['BUILD_WITH_32_64'] = Options.options.mixed
194 conf.env['BUILD_CLASSIC'] = Options.options.classic
195 conf.env['BUILD_DEBUG'] = Options.options.debug
197 if conf.env['BUILD_JACKDBUS']:
198 conf.env['BUILD_JACKD'] = conf.env['BUILD_CLASSIC']
199 else:
200 conf.env['BUILD_JACKD'] = True
202 if Options.options.libdir:
203 conf.env['LIBDIR'] = Options.options.libdir
204 else:
205 conf.env['LIBDIR'] = conf.env['PREFIX'] + '/lib'
207 if Options.options.mandir:
208 conf.env['MANDIR'] = Options.options.mandir
209 else:
210 conf.env['MANDIR'] = conf.env['PREFIX'] + '/share/man/man1'
212 if conf.env['BUILD_DEBUG']:
213 conf.env.append_unique('CXXFLAGS', '-g')
214 conf.env.append_unique('CFLAGS', '-g')
215 conf.env.append_unique('LINKFLAGS', '-g')
217 conf.define('CLIENT_NUM', Options.options.clients)
218 conf.define('PORT_NUM_FOR_CLIENT', Options.options.application_ports)
220 conf.env['ADDON_DIR'] = os.path.normpath(os.path.join(conf.env['LIBDIR'], 'jack'))
221 conf.define('ADDON_DIR', conf.env['ADDON_DIR'])
222 conf.define('JACK_LOCATION', os.path.normpath(os.path.join(conf.env['PREFIX'], 'bin')))
223 conf.define('USE_POSIX_SHM', 1)
224 conf.define('JACKMP', 1)
225 if conf.env['BUILD_JACKDBUS'] == True:
226 conf.define('JACK_DBUS', 1)
227 if conf.env['BUILD_JACKD'] == False:
228 conf.define('USE_LIBDBUS_AUTOLAUNCH', 1)
229 if conf.env['BUILD_WITH_PROFILE'] == True:
230 conf.define('JACK_MONITOR', 1)
231 conf.write_config_header('config.h', remove=False)
233 svnrev = None
234 if os.access('svnversion.h', os.R_OK):
235 data = file('svnversion.h').read()
236 m = re.match(r'^#define SVN_VERSION "([^"]*)"$', data)
237 if m != None:
238 svnrev = m.group(1)
240 if Options.options.mixed == True:
241 env_variant2 = conf.env.copy()
242 conf.set_env_name('lib32', env_variant2)
243 env_variant2.set_variant('lib32')
244 conf.setenv('lib32')
245 conf.env.append_unique('CXXFLAGS', '-m32')
246 conf.env.append_unique('CFLAGS', '-m32')
247 conf.env.append_unique('LINKFLAGS', '-m32')
248 if Options.options.libdir32:
249 conf.env['LIBDIR'] = Options.options.libdir32
250 else:
251 conf.env['LIBDIR'] = conf.env['PREFIX'] + '/lib32'
252 conf.write_config_header('config.h')
254 print()
255 display_msg("==================")
256 version_msg = "JACK " + VERSION
257 if svnrev:
258 version_msg += " exported from r" + svnrev
259 else:
260 version_msg += " svn revision will checked and eventually updated during build"
261 print(version_msg)
263 print("Build with a maximum of %d JACK clients" % Options.options.clients)
264 print("Build with a maximum of %d ports per application" % Options.options.application_ports)
266 display_msg("Install prefix", conf.env['PREFIX'], 'CYAN')
267 display_msg("Library directory", conf.env['LIBDIR'], 'CYAN')
268 display_msg("Drivers directory", conf.env['ADDON_DIR'], 'CYAN')
269 display_feature('Build debuggable binaries', conf.env['BUILD_DEBUG'])
270 display_msg('C compiler flags', repr(conf.env['CFLAGS']))
271 display_msg('C++ compiler flags', repr(conf.env['CXXFLAGS']))
272 display_msg('Linker flags', repr(conf.env['LINKFLAGS']))
273 display_feature('Build doxygen documentation', conf.env['BUILD_DOXYGEN_DOCS'])
274 display_feature('Build Opus netjack2', conf.env['WITH_OPUS'])
275 display_feature('Build with engine profiling', conf.env['BUILD_WITH_PROFILE'])
276 display_feature('Build with 32/64 bits mixed mode', conf.env['BUILD_WITH_32_64'])
278 display_feature('Build standard JACK (jackd)', conf.env['BUILD_JACKD'])
279 display_feature('Build D-Bus JACK (jackdbus)', conf.env['BUILD_JACKDBUS'])
281 if conf.env['BUILD_JACKDBUS'] and conf.env['BUILD_JACKD']:
282 print(Logs.colors.RED + 'WARNING !! mixing both jackd and jackdbus may cause issues:' + Logs.colors.NORMAL)
283 print(Logs.colors.RED + 'WARNING !! jackdbus does not use .jackdrc nor qjackctl settings' + Logs.colors.NORMAL)
285 if conf.env['IS_LINUX']:
286 display_feature('Build with ALSA support', conf.env['BUILD_DRIVER_ALSA'] == True)
287 display_feature('Build with FireWire (FreeBob) support', conf.env['BUILD_DRIVER_FREEBOB'] == True)
288 display_feature('Build with FireWire (FFADO) support', conf.env['BUILD_DRIVER_FFADO'] == True)
290 if conf.env['BUILD_JACKDBUS'] == True:
291 display_msg('D-Bus service install directory', conf.env['DBUS_SERVICES_DIR'], 'CYAN')
292 #display_msg('Settings persistence', xxx)
294 if conf.env['DBUS_SERVICES_DIR'] != conf.env['DBUS_SERVICES_DIR_REAL']:
295 print()
296 print(Logs.colors.RED + "WARNING: D-Bus session services directory as reported by pkg-config is")
297 print(Logs.colors.RED + "WARNING:", end=' ')
298 print(Logs.colors.CYAN + conf.env['DBUS_SERVICES_DIR_REAL'])
299 print(Logs.colors.RED + 'WARNING: but service file will be installed in')
300 print(Logs.colors.RED + "WARNING:", end=' ')
301 print(Logs.colors.CYAN + conf.env['DBUS_SERVICES_DIR'])
302 print(Logs.colors.RED + 'WARNING: You may need to adjust your D-Bus configuration after installing jackdbus')
303 print('WARNING: You can override dbus service install directory')
304 print('WARNING: with --enable-pkg-config-dbus-service-dir option to this script')
305 print(Logs.colors.NORMAL, end=' ')
306 print()
308 def build(bld):
309 print("make[1]: Entering directory `" + os.getcwd() + "/" + out + "'")
310 if not os.access('svnversion.h', os.R_OK):
311 create_svnversion_task(bld)
313 # process subfolders from here
314 bld.add_subdirs('common')
315 if bld.env['IS_LINUX']:
316 bld.add_subdirs('linux')
317 bld.add_subdirs('example-clients')
318 bld.add_subdirs('tests')
319 bld.add_subdirs('man')
320 if bld.env['BUILD_JACKDBUS'] == True:
321 bld.add_subdirs('dbus')
323 if bld.env['IS_MACOSX']:
324 bld.add_subdirs('macosx')
325 bld.add_subdirs('example-clients')
326 bld.add_subdirs('tests')
327 if bld.env['BUILD_JACKDBUS'] == True:
328 bld.add_subdirs('dbus')
330 if bld.env['IS_SUN']:
331 bld.add_subdirs('solaris')
332 bld.add_subdirs('example-clients')
333 bld.add_subdirs('tests')
334 if bld.env['BUILD_JACKDBUS'] == True:
335 bld.add_subdirs('dbus')
337 if bld.env['BUILD_DOXYGEN_DOCS'] == True:
338 share_dir = bld.env.get_destdir() + bld.env['PREFIX'] + '/share/jack-audio-connection-kit'
339 html_docs_source_dir = "build/default/html"
340 html_docs_install_dir = share_dir + '/reference/html/'
341 if Options.commands['install']:
342 if os.path.isdir(html_docs_install_dir):
343 Logs.pprint('CYAN', "Removing old doxygen documentation installation...")
344 shutil.rmtree(html_docs_install_dir)
345 Logs.pprint('CYAN', "Removing old doxygen documentation installation done.")
346 Logs.pprint('CYAN', "Installing doxygen documentation...")
347 shutil.copytree(html_docs_source_dir, html_docs_install_dir)
348 Logs.pprint('CYAN', "Installing doxygen documentation done.")
349 elif Options.commands['uninstall']:
350 Logs.pprint('CYAN', "Uninstalling doxygen documentation...")
351 if os.path.isdir(share_dir):
352 shutil.rmtree(share_dir)
353 Logs.pprint('CYAN', "Uninstalling doxygen documentation done.")
354 elif Options.commands['clean']:
355 if os.access(html_docs_source_dir, os.R_OK):
356 Logs.pprint('CYAN', "Removing doxygen generated documentation...")
357 shutil.rmtree(html_docs_source_dir)
358 Logs.pprint('CYAN', "Removing doxygen generated documentation done.")
359 elif Options.commands['build']:
360 if not os.access(html_docs_source_dir, os.R_OK):
361 os.popen("doxygen").read()
362 else:
363 Logs.pprint('CYAN', "doxygen documentation already built.")
365 def dist_hook():
366 os.remove('svnversion_regenerate.sh')
367 os.system('../svnversion_regenerate.sh svnversion.h')