Fix last commit
[jack2.git] / wscript
blobaef4bd89ef85c87dd676e158369a64cbd3161388
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 import waflib.Options
17 from waflib.Build import BuildContext, CleanContext, InstallContext, UninstallContext
19 VERSION='1.9.10'
20 APPNAME='jack'
21 JACK_API_VERSION = '0.1.0'
23 # these variables are mandatory ('/' are converted automatically)
24 top = '.'
25 out = 'build'
27 # lib32 variant name used when building in mixed mode
28 lib32 = 'lib32'
30 def display_msg(msg, status = None, color = None):
31 sr = msg
32 global g_maxlen
33 g_maxlen = max(g_maxlen, len(msg))
34 if status:
35 Logs.pprint('NORMAL', "%s :" % msg.ljust(g_maxlen), sep=' ')
36 Logs.pprint(color, status)
37 else:
38 print("%s" % msg.ljust(g_maxlen))
40 def display_feature(msg, build):
41 if build:
42 display_msg(msg, "yes", 'GREEN')
43 else:
44 display_msg(msg, "no", 'YELLOW')
46 def create_svnversion_task(bld, header='svnversion.h', define=None):
47 cmd = '../svnversion_regenerate.sh ${TGT}'
48 if define:
49 cmd += " " + define
51 def post_run(self):
52 sg = Utils.h_file(self.outputs[0].abspath(self.env))
53 #print sg.encode('hex')
54 Build.bld.node_sigs[self.env.variant()][self.outputs[0].id] = sg
56 bld(
57 rule = cmd,
58 name = 'svnversion',
59 runnable_status = Task.RUN_ME,
60 before = 'c',
61 color = 'BLUE',
62 post_run = post_run,
63 target = [bld.path.find_or_declare(header)]
66 def options(opt):
67 # options provided by the modules
68 opt.tool_options('compiler_cxx')
69 opt.tool_options('compiler_cc')
71 opt.add_option('--libdir', type='string', help="Library directory [Default: <prefix>/lib]")
72 opt.add_option('--libdir32', type='string', help="32bit Library directory [Default: <prefix>/lib32]")
73 opt.add_option('--mandir', type='string', help="Manpage directory [Default: <prefix>/share/man/man1]")
74 opt.add_option('--dbus', action='store_true', default=False, help='Enable D-Bus JACK (jackdbus)')
75 opt.add_option('--dist-target', type='string', default='auto', help='Specify the target for cross-compiling [auto,mingw]')
76 opt.add_option('--classic', action='store_true', default=False, help='Force enable standard JACK (jackd) even if D-Bus JACK (jackdbus) is enabled too')
77 opt.add_option('--doxygen', action='store_true', default=False, help='Enable build of doxygen documentation')
78 opt.add_option('--profile', action='store_true', default=False, help='Build with engine profiling')
79 opt.add_option('--mixed', action='store_true', default=False, help='Build with 32/64 bits mixed mode')
80 opt.add_option('--clients', default=64, type="int", dest="clients", help='Maximum number of JACK clients')
81 opt.add_option('--ports-per-application', default=768, type="int", dest="application_ports", help='Maximum number of ports per application')
82 opt.add_option('--debug', action='store_true', default=False, dest='debug', help='Build debuggable binaries')
83 opt.add_option('--firewire', action='store_true', default=False, help='Enable FireWire driver (FFADO)')
84 opt.add_option('--freebob', action='store_true', default=False, help='Enable FreeBob driver')
85 opt.add_option('--alsa', action='store_true', default=False, help='Enable ALSA driver')
86 opt.add_option('--iio', action='store_true', default=False, help='Enable IIO driver')
87 opt.add_option('--autostart', type='string', default="default", help='Autostart method. Possible values: "default", "classic", "dbus", "none"')
88 opt.add_option('--portaudio', action='store_true', default=False, help='Enable Portaudio driver')
89 opt.add_option('--winmme', action='store_true', default=False, help='Enable WinMME driver')
90 opt.sub_options('dbus')
92 def configure(conf):
93 conf.load('compiler_cxx')
94 conf.load('compiler_cc')
95 if Options.options.dist_target == 'auto':
96 platform = sys.platform
97 conf.env['IS_MACOSX'] = platform == 'darwin'
98 conf.env['IS_LINUX'] = platform == 'linux' or platform == 'linux2' or platform == 'linux3' or platform == 'posix'
99 conf.env['IS_SUN'] = platform == 'sunos'
100 # GNU/kFreeBSD and GNU/Hurd are treated as Linux
101 if platform.startswith('gnu0') or platform.startswith('gnukfreebsd'):
102 conf.env['IS_LINUX'] = True
103 elif Options.options.dist_target == 'mingw':
104 conf.env['IS_WINDOWS'] = True
106 if conf.env['IS_LINUX']:
107 Logs.pprint('CYAN', "Linux detected")
109 if conf.env['IS_MACOSX']:
110 Logs.pprint('CYAN', "MacOS X detected")
112 if conf.env['IS_SUN']:
113 Logs.pprint('CYAN', "SunOS detected")
115 if conf.env['IS_WINDOWS']:
116 Logs.pprint('CYAN', "Windows detected")
118 if conf.env['IS_LINUX']:
119 conf.check_tool('compiler_cxx')
120 conf.check_tool('compiler_cc')
122 if conf.env['IS_MACOSX']:
123 conf.check_tool('compiler_cxx')
124 conf.check_tool('compiler_cc')
126 # waf 1.5 : check_tool('compiler_cxx') and check_tool('compiler_cc') do not work correctly, so explicit use of gcc and g++
127 if conf.env['IS_SUN']:
128 conf.check_tool('g++')
129 conf.check_tool('gcc')
131 #if conf.env['IS_SUN']:
132 # conf.check_tool('compiler_cxx')
133 # conf.check_tool('compiler_cc')
135 if conf.env['IS_WINDOWS']:
136 conf.check_tool('compiler_cxx')
137 conf.check_tool('compiler_cc')
138 conf.env.append_unique('CCDEFINES', '_POSIX')
139 conf.env.append_unique('CXXDEFINES', '_POSIX')
141 conf.env.append_unique('CXXFLAGS', '-Wall')
142 conf.env.append_unique('CFLAGS', '-Wall')
144 conf.sub_config('common')
145 if conf.env['IS_LINUX']:
146 conf.sub_config('linux')
147 if Options.options.alsa and not conf.env['BUILD_DRIVER_ALSA']:
148 conf.fatal('ALSA driver was explicitly requested but cannot be built')
149 if Options.options.freebob and not conf.env['BUILD_DRIVER_FREEBOB']:
150 conf.fatal('FreeBob driver was explicitly requested but cannot be built')
151 if Options.options.firewire and not conf.env['BUILD_DRIVER_FFADO']:
152 conf.fatal('FFADO driver was explicitly requested but cannot be built')
153 if Options.options.iio and not conf.env['BUILD_DRIVER_IIO']:
154 conf.fatal('IIO driver was explicitly requested but cannot be built')
155 conf.env['BUILD_DRIVER_ALSA'] = Options.options.alsa
156 conf.env['BUILD_DRIVER_FFADO'] = Options.options.firewire
157 conf.env['BUILD_DRIVER_FREEBOB'] = Options.options.freebob
158 conf.env['BUILD_DRIVER_IIO'] = Options.options.iio
159 if conf.env['IS_WINDOWS']:
160 conf.sub_config('windows')
161 if Options.options.portaudio and not conf.env['BUILD_DRIVER_PORTAUDIO']:
162 conf.fatal('Portaudio driver was explicitly requested but cannot be built')
163 conf.env['BUILD_DRIVER_WINMME'] = Options.options.winmme
164 if Options.options.dbus:
165 conf.sub_config('dbus')
166 if conf.env['BUILD_JACKDBUS'] != True:
167 conf.fatal('jackdbus was explicitly requested but cannot be built')
169 conf.check_cc(header_name='samplerate.h', define_name="HAVE_SAMPLERATE")
171 if conf.is_defined('HAVE_SAMPLERATE'):
172 conf.env['LIB_SAMPLERATE'] = ['samplerate']
174 conf.sub_config('example-clients')
176 if conf.check_cfg(package='celt', atleast_version='0.11.0', args='--cflags --libs', mandatory=False):
177 conf.define('HAVE_CELT', 1)
178 conf.define('HAVE_CELT_API_0_11', 1)
179 conf.define('HAVE_CELT_API_0_8', 0)
180 conf.define('HAVE_CELT_API_0_7', 0)
181 conf.define('HAVE_CELT_API_0_5', 0)
182 elif conf.check_cfg(package='celt', atleast_version='0.8.0', args='--cflags --libs', mandatory=False):
183 conf.define('HAVE_CELT', 1)
184 conf.define('HAVE_CELT_API_0_11', 0)
185 conf.define('HAVE_CELT_API_0_8', 1)
186 conf.define('HAVE_CELT_API_0_7', 0)
187 conf.define('HAVE_CELT_API_0_5', 0)
188 elif conf.check_cfg(package='celt', atleast_version='0.7.0', args='--cflags --libs', mandatory=False):
189 conf.define('HAVE_CELT', 1)
190 conf.define('HAVE_CELT_API_0_11', 0)
191 conf.define('HAVE_CELT_API_0_8', 0)
192 conf.define('HAVE_CELT_API_0_7', 1)
193 conf.define('HAVE_CELT_API_0_5', 0)
194 elif conf.check_cfg(package='celt', atleast_version='0.5.0', args='--cflags --libs', mandatory=False):
195 conf.define('HAVE_CELT', 1)
196 conf.define('HAVE_CELT_API_0_11', 0)
197 conf.define('HAVE_CELT_API_0_8', 0)
198 conf.define('HAVE_CELT_API_0_7', 0)
199 conf.define('HAVE_CELT_API_0_5', 1)
200 else:
201 conf.define('HAVE_CELT', 0)
202 conf.define('HAVE_CELT_API_0_11', 0)
203 conf.define('HAVE_CELT_API_0_8', 0)
204 conf.define('HAVE_CELT_API_0_7', 0)
205 conf.define('HAVE_CELT_API_0_5', 0)
207 conf.env['WITH_OPUS'] = False
208 if conf.check_cfg(package='opus', atleast_version='0.9.0' , args='--cflags --libs', mandatory=False):
209 if conf.check_cc(header_name='opus/opus_custom.h', mandatory=False):
210 conf.define('HAVE_OPUS', 1)
211 conf.env['WITH_OPUS'] = True
212 else:
213 conf.define('HAVE_OPUS', 0)
216 conf.env['LIB_PTHREAD'] = ['pthread']
217 conf.env['LIB_DL'] = ['dl']
218 conf.env['LIB_RT'] = ['rt']
219 conf.env['LIB_M'] = ['m']
220 conf.env['LIB_STDC++'] = ['stdc++']
221 conf.env['JACK_API_VERSION'] = JACK_API_VERSION
222 conf.env['JACK_VERSION'] = VERSION
224 conf.env['BUILD_DOXYGEN_DOCS'] = Options.options.doxygen
225 conf.env['BUILD_WITH_PROFILE'] = Options.options.profile
226 conf.env['BUILD_WITH_32_64'] = Options.options.mixed
227 conf.env['BUILD_CLASSIC'] = Options.options.classic
228 conf.env['BUILD_DEBUG'] = Options.options.debug
230 if conf.env['BUILD_JACKDBUS']:
231 conf.env['BUILD_JACKD'] = conf.env['BUILD_CLASSIC']
232 else:
233 conf.env['BUILD_JACKD'] = True
235 conf.env['BINDIR'] = conf.env['PREFIX'] + '/bin'
237 if Options.options.libdir:
238 conf.env['LIBDIR'] = Options.options.libdir
239 else:
240 conf.env['LIBDIR'] = conf.env['PREFIX'] + '/lib'
242 if Options.options.mandir:
243 conf.env['MANDIR'] = Options.options.mandir
244 else:
245 conf.env['MANDIR'] = conf.env['PREFIX'] + '/share/man/man1'
247 if conf.env['BUILD_DEBUG']:
248 conf.env.append_unique('CXXFLAGS', '-g')
249 conf.env.append_unique('CFLAGS', '-g')
250 conf.env.append_unique('LINKFLAGS', '-g')
252 if not Options.options.autostart in ["default", "classic", "dbus", "none"]:
253 conf.fatal("Invalid autostart value \"" + Options.options.autostart + "\"")
255 if Options.options.autostart == "default":
256 if conf.env['BUILD_JACKDBUS'] == True and conf.env['BUILD_JACKD'] == False:
257 conf.env['AUTOSTART_METHOD'] = "dbus"
258 else:
259 conf.env['AUTOSTART_METHOD'] = "classic"
260 else:
261 conf.env['AUTOSTART_METHOD'] = Options.options.autostart
263 if conf.env['AUTOSTART_METHOD'] == "dbus" and not conf.env['BUILD_JACKDBUS']:
264 conf.fatal("D-Bus autostart mode was specified but jackdbus will not be built")
265 if conf.env['AUTOSTART_METHOD'] == "classic" and not conf.env['BUILD_JACKD']:
266 conf.fatal("Classic autostart mode was specified but jackd will not be built")
268 if conf.env['AUTOSTART_METHOD'] == "dbus":
269 conf.define('USE_LIBDBUS_AUTOLAUNCH', 1)
270 elif conf.env['AUTOSTART_METHOD'] == "classic":
271 conf.define('USE_CLASSIC_AUTOLAUNCH', 1)
273 conf.define('CLIENT_NUM', Options.options.clients)
274 conf.define('PORT_NUM_FOR_CLIENT', Options.options.application_ports)
276 if conf.env['IS_WINDOWS']:
277 # we define this in the environment to maintain compatability with
278 # existing install paths that use ADDON_DIR rather than have to
279 # have special cases for windows each time.
280 conf.env['ADDON_DIR'] = conf.env['BINDIR'] + '/jack'
281 # don't define ADDON_DIR in config.h, use the default 'jack' defined in
282 # windows/JackPlatformPlug_os.h
283 else:
284 conf.env['ADDON_DIR'] = os.path.normpath(os.path.join(conf.env['LIBDIR'], 'jack'))
285 conf.define('ADDON_DIR', conf.env['ADDON_DIR'])
286 conf.define('JACK_LOCATION', os.path.normpath(os.path.join(conf.env['PREFIX'], 'bin')))
288 if not conf.env['IS_WINDOWS']:
289 conf.define('USE_POSIX_SHM', 1)
290 conf.define('JACKMP', 1)
291 if conf.env['BUILD_JACKDBUS'] == True:
292 conf.define('JACK_DBUS', 1)
293 if conf.env['BUILD_WITH_PROFILE'] == True:
294 conf.define('JACK_MONITOR', 1)
295 conf.write_config_header('config.h', remove=False)
297 svnrev = None
298 if os.access('svnversion.h', os.R_OK):
299 data = file('svnversion.h').read()
300 m = re.match(r'^#define SVN_VERSION "([^"]*)"$', data)
301 if m != None:
302 svnrev = m.group(1)
304 if Options.options.mixed == True:
305 conf.setenv(lib32, env=conf.env.derive())
306 conf.env.append_unique('CXXFLAGS', '-m32')
307 conf.env.append_unique('CFLAGS', '-m32')
308 conf.env.append_unique('LINKFLAGS', '-m32')
309 if Options.options.libdir32:
310 conf.env['LIBDIR'] = Options.options.libdir32
311 else:
312 conf.env['LIBDIR'] = conf.env['PREFIX'] + '/lib32'
313 conf.write_config_header('config.h')
315 print()
316 display_msg("==================")
317 version_msg = "JACK " + VERSION
318 if svnrev:
319 version_msg += " exported from r" + svnrev
320 else:
321 version_msg += " svn revision will checked and eventually updated during build"
322 print(version_msg)
324 print("Build with a maximum of %d JACK clients" % Options.options.clients)
325 print("Build with a maximum of %d ports per application" % Options.options.application_ports)
327 display_msg("Install prefix", conf.env['PREFIX'], 'CYAN')
328 display_msg("Library directory", conf.all_envs[""]['LIBDIR'], 'CYAN')
329 if conf.env['BUILD_WITH_32_64'] == True:
330 display_msg("32-bit library directory", conf.all_envs[lib32]['LIBDIR'], 'CYAN')
331 display_msg("Drivers directory", conf.env['ADDON_DIR'], 'CYAN')
332 display_feature('Build debuggable binaries', conf.env['BUILD_DEBUG'])
333 display_msg('C compiler flags', repr(conf.all_envs[""]['CFLAGS']))
334 display_msg('C++ compiler flags', repr(conf.all_envs[""]['CXXFLAGS']))
335 display_msg('Linker flags', repr(conf.all_envs[""]['LINKFLAGS']))
336 if conf.env['BUILD_WITH_32_64'] == True:
337 display_msg('32-bit C compiler flags', repr(conf.all_envs[lib32]['CFLAGS']))
338 display_msg('32-bit C++ compiler flags', repr(conf.all_envs[lib32]['CXXFLAGS']))
339 display_msg('32-bit linker flags', repr(conf.all_envs[lib32]['LINKFLAGS']))
340 display_feature('Build doxygen documentation', conf.env['BUILD_DOXYGEN_DOCS'])
341 display_feature('Build Opus netjack2', conf.env['WITH_OPUS'])
342 display_feature('Build with engine profiling', conf.env['BUILD_WITH_PROFILE'])
343 display_feature('Build with 32/64 bits mixed mode', conf.env['BUILD_WITH_32_64'])
345 display_feature('Build standard JACK (jackd)', conf.env['BUILD_JACKD'])
346 display_feature('Build D-Bus JACK (jackdbus)', conf.env['BUILD_JACKDBUS'])
347 display_msg('Autostart method', conf.env['AUTOSTART_METHOD'])
349 if conf.env['BUILD_JACKDBUS'] and conf.env['BUILD_JACKD']:
350 print(Logs.colors.RED + 'WARNING !! mixing both jackd and jackdbus may cause issues:' + Logs.colors.NORMAL)
351 print(Logs.colors.RED + 'WARNING !! jackdbus does not use .jackdrc nor qjackctl settings' + Logs.colors.NORMAL)
353 if conf.env['IS_LINUX']:
354 display_feature('Build with ALSA support', conf.env['BUILD_DRIVER_ALSA'] == True)
355 display_feature('Build with FireWire (FreeBob) support', conf.env['BUILD_DRIVER_FREEBOB'] == True)
356 display_feature('Build with FireWire (FFADO) support', conf.env['BUILD_DRIVER_FFADO'] == True)
357 display_feature('Build with IIO support', conf.env['BUILD_DRIVER_IIO'] == True)
359 if conf.env['IS_WINDOWS']:
360 display_feature('Build with WinMME support', conf.env['BUILD_DRIVER_WINMME'] == True)
361 display_feature('Build with Portaudio support', conf.env['BUILD_DRIVER_PORTAUDIO'] == True)
363 if conf.env['BUILD_JACKDBUS'] == True:
364 display_msg('D-Bus service install directory', conf.env['DBUS_SERVICES_DIR'], 'CYAN')
365 #display_msg('Settings persistence', xxx)
367 if conf.env['DBUS_SERVICES_DIR'] != conf.env['DBUS_SERVICES_DIR_REAL']:
368 print()
369 print(Logs.colors.RED + "WARNING: D-Bus session services directory as reported by pkg-config is")
370 print(Logs.colors.RED + "WARNING:", end=' ')
371 print(Logs.colors.CYAN + conf.env['DBUS_SERVICES_DIR_REAL'])
372 print(Logs.colors.RED + 'WARNING: but service file will be installed in')
373 print(Logs.colors.RED + "WARNING:", end=' ')
374 print(Logs.colors.CYAN + conf.env['DBUS_SERVICES_DIR'])
375 print(Logs.colors.RED + 'WARNING: You may need to adjust your D-Bus configuration after installing jackdbus')
376 print('WARNING: You can override dbus service install directory')
377 print('WARNING: with --enable-pkg-config-dbus-service-dir option to this script')
378 print(Logs.colors.NORMAL, end=' ')
379 print()
381 def init(ctx):
382 for y in (BuildContext, CleanContext, InstallContext, UninstallContext):
383 name = y.__name__.replace('Context','').lower()
384 class tmp(y):
385 cmd = name + '_' + lib32
386 variant = lib32
388 def build(bld):
389 if not bld.variant:
390 out2 = out
391 else:
392 out2 = out + "/" + bld.variant
393 print("make[1]: Entering directory `" + os.getcwd() + "/" + out2 + "'")
395 if not bld.variant:
396 if not os.access('svnversion.h', os.R_OK):
397 create_svnversion_task(bld)
398 if bld.env['BUILD_WITH_32_64'] == True:
399 waflib.Options.commands.append(bld.cmd + '_' + lib32)
401 # process subfolders from here
402 bld.add_subdirs('common')
404 if bld.variant:
405 # only the wscript in common/ knows how to handle variants
406 return
408 if bld.env['IS_LINUX']:
409 bld.add_subdirs('linux')
410 bld.add_subdirs('example-clients')
411 bld.add_subdirs('tests')
412 bld.add_subdirs('man')
413 if bld.env['BUILD_JACKDBUS'] == True:
414 bld.add_subdirs('dbus')
416 if bld.env['IS_MACOSX']:
417 bld.add_subdirs('macosx')
418 bld.add_subdirs('example-clients')
419 bld.add_subdirs('tests')
420 if bld.env['BUILD_JACKDBUS'] == True:
421 bld.add_subdirs('dbus')
423 if bld.env['IS_SUN']:
424 bld.add_subdirs('solaris')
425 bld.add_subdirs('example-clients')
426 bld.add_subdirs('tests')
427 if bld.env['BUILD_JACKDBUS'] == True:
428 bld.add_subdirs('dbus')
430 if bld.env['IS_WINDOWS']:
431 bld.add_subdirs('windows')
432 bld.add_subdirs('example-clients')
433 #bld.add_subdirs('tests')
435 if bld.env['BUILD_DOXYGEN_DOCS'] == True:
436 html_docs_source_dir = "build/default/html"
437 if bld.cmd == 'install':
438 share_dir = bld.options.destdir + bld.env['PREFIX'] + '/share/jack-audio-connection-kit'
439 html_docs_install_dir = share_dir + '/reference/html/'
440 if os.path.isdir(html_docs_install_dir):
441 Logs.pprint('CYAN', "Removing old doxygen documentation installation...")
442 shutil.rmtree(html_docs_install_dir)
443 Logs.pprint('CYAN', "Removing old doxygen documentation installation done.")
444 Logs.pprint('CYAN', "Installing doxygen documentation...")
445 shutil.copytree(html_docs_source_dir, html_docs_install_dir)
446 Logs.pprint('CYAN', "Installing doxygen documentation done.")
447 elif bld.cmd =='uninstall':
448 Logs.pprint('CYAN', "Uninstalling doxygen documentation...")
449 if os.path.isdir(share_dir):
450 shutil.rmtree(share_dir)
451 Logs.pprint('CYAN', "Uninstalling doxygen documentation done.")
452 elif bld.cmd =='clean':
453 if os.access(html_docs_source_dir, os.R_OK):
454 Logs.pprint('CYAN', "Removing doxygen generated documentation...")
455 shutil.rmtree(html_docs_source_dir)
456 Logs.pprint('CYAN', "Removing doxygen generated documentation done.")
457 elif bld.cmd =='build':
458 if not os.access(html_docs_source_dir, os.R_OK):
459 os.popen("doxygen").read()
460 else:
461 Logs.pprint('CYAN', "doxygen documentation already built.")
463 def dist_hook():
464 os.remove('svnversion_regenerate.sh')
465 os.system('../svnversion_regenerate.sh svnversion.h')