wscript: Make CELT optional
[jack2.git] / wscript
blobe18bd3df383a8081865a9c23887f650188553952
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 platform = sys.platform
83 conf.env['IS_MACOSX'] = platform == 'darwin'
84 conf.env['IS_LINUX'] = platform == 'linux' or platform == 'linux2' or platform == 'posix'
85 conf.env['IS_SUN'] = platform == 'sunos'
87 if conf.env['IS_LINUX']:
88 Logs.pprint('CYAN', "Linux detected")
90 if conf.env['IS_MACOSX']:
91 Logs.pprint('CYAN', "MacOS X detected")
93 if conf.env['IS_SUN']:
94 Logs.pprint('CYAN', "SunOS detected")
96 if conf.env['IS_LINUX']:
97 conf.check_tool('compiler_cxx')
98 conf.check_tool('compiler_cc')
100 if conf.env['IS_MACOSX']:
101 conf.check_tool('compiler_cxx')
102 conf.check_tool('compiler_cc')
104 # waf 1.5 : check_tool('compiler_cxx') and check_tool('compiler_cc') do not work correctly, so explicit use of gcc and g++
105 if conf.env['IS_SUN']:
106 conf.check_tool('g++')
107 conf.check_tool('gcc')
109 #if conf.env['IS_SUN']:
110 # conf.check_tool('compiler_cxx')
111 # conf.check_tool('compiler_cc')
113 conf.env.append_unique('CXXFLAGS', '-Wall')
114 conf.env.append_unique('CCFLAGS', '-Wall')
116 conf.sub_config('common')
117 if conf.env['IS_LINUX']:
118 conf.sub_config('linux')
119 if Options.options.alsa and not conf.env['BUILD_DRIVER_ALSA']:
120 conf.fatal('ALSA driver was explicitly requested but cannot be built')
121 if Options.options.freebob and not conf.env['BUILD_DRIVER_FREEBOB']:
122 conf.fatal('FreeBob driver was explicitly requested but cannot be built')
123 if Options.options.firewire and not conf.env['BUILD_DRIVER_FFADO']:
124 conf.fatal('FFADO driver was explicitly requested but cannot be built')
125 conf.env['BUILD_DRIVER_ALSA'] = Options.options.alsa
126 conf.env['BUILD_DRIVER_FFADO'] = Options.options.firewire
127 conf.env['BUILD_DRIVER_FREEBOB'] = Options.options.freebob
128 if Options.options.dbus:
129 conf.sub_config('dbus')
130 if conf.env['BUILD_JACKDBUS'] != True:
131 conf.fatal('jackdbus was explicitly requested but cannot be built')
133 conf.check_cc(header_name='samplerate.h', define_name="HAVE_SAMPLERATE")
135 if conf.is_defined('HAVE_SAMPLERATE'):
136 conf.env['LIB_SAMPLERATE'] = ['samplerate']
138 conf.sub_config('example-clients')
140 if conf.check_cfg(package='celt', atleast_version='0.11.0', args='--cflags --libs', mandatory=False):
141 conf.define('HAVE_CELT', 1)
142 conf.define('HAVE_CELT_API_0_11', 1)
143 conf.define('HAVE_CELT_API_0_8', 0)
144 conf.define('HAVE_CELT_API_0_7', 0)
145 conf.define('HAVE_CELT_API_0_5', 0)
146 elif conf.check_cfg(package='celt', atleast_version='0.8.0', args='--cflags --libs', mandatory=False):
147 conf.define('HAVE_CELT', 1)
148 conf.define('HAVE_CELT_API_0_11', 0)
149 conf.define('HAVE_CELT_API_0_8', 1)
150 conf.define('HAVE_CELT_API_0_7', 0)
151 conf.define('HAVE_CELT_API_0_5', 0)
152 elif conf.check_cfg(package='celt', atleast_version='0.7.0', args='--cflags --libs', mandatory=False):
153 conf.define('HAVE_CELT', 1)
154 conf.define('HAVE_CELT_API_0_11', 0)
155 conf.define('HAVE_CELT_API_0_8', 0)
156 conf.define('HAVE_CELT_API_0_7', 1)
157 conf.define('HAVE_CELT_API_0_5', 0)
158 elif conf.check_cfg(package='celt', atleast_version='0.5.0', args='--cflags --libs', mandatory=False):
159 conf.define('HAVE_CELT', 1)
160 conf.define('HAVE_CELT_API_0_11', 0)
161 conf.define('HAVE_CELT_API_0_8', 0)
162 conf.define('HAVE_CELT_API_0_7', 0)
163 conf.define('HAVE_CELT_API_0_5', 1)
164 else:
165 conf.define('HAVE_CELT', 0)
166 conf.define('HAVE_CELT_API_0_11', 0)
167 conf.define('HAVE_CELT_API_0_8', 0)
168 conf.define('HAVE_CELT_API_0_7', 0)
169 conf.define('HAVE_CELT_API_0_5', 0)
171 conf.env['LIB_PTHREAD'] = ['pthread']
172 conf.env['LIB_DL'] = ['dl']
173 conf.env['LIB_RT'] = ['rt']
174 conf.env['JACK_API_VERSION'] = JACK_API_VERSION
175 conf.env['JACK_VERSION'] = VERSION
177 conf.env['BUILD_DOXYGEN_DOCS'] = Options.options.doxygen
178 conf.env['BUILD_WITH_PROFILE'] = Options.options.profile
179 conf.env['BUILD_WITH_32_64'] = Options.options.mixed
180 conf.env['BUILD_CLASSIC'] = Options.options.classic
181 conf.env['BUILD_DEBUG'] = Options.options.debug
183 if conf.env['BUILD_JACKDBUS']:
184 conf.env['BUILD_JACKD'] = conf.env['BUILD_CLASSIC']
185 else:
186 conf.env['BUILD_JACKD'] = True
188 if Options.options.libdir:
189 conf.env['LIBDIR'] = conf.env['PREFIX'] + Options.options.libdir
190 else:
191 conf.env['LIBDIR'] = conf.env['PREFIX'] + '/lib'
193 if Options.options.mandir:
194 conf.env['MANDIR'] = conf.env['PREFIX'] + Options.options.mandir
195 else:
196 conf.env['MANDIR'] = conf.env['PREFIX'] + '/share/man/man1'
198 if conf.env['BUILD_DEBUG']:
199 conf.env.append_unique('CXXFLAGS', '-g')
200 conf.env.append_unique('CCFLAGS', '-g')
201 conf.env.append_unique('LINKFLAGS', '-g')
203 conf.define('CLIENT_NUM', Options.options.clients)
204 conf.define('PORT_NUM_FOR_CLIENT', Options.options.application_ports)
206 conf.define('ADDON_DIR', os.path.normpath(os.path.join(conf.env['LIBDIR'], 'jack')))
207 conf.define('JACK_LOCATION', os.path.normpath(os.path.join(conf.env['PREFIX'], 'bin')))
208 conf.define('USE_POSIX_SHM', 1)
209 conf.define('JACKMP', 1)
210 if conf.env['BUILD_JACKDBUS'] == True:
211 conf.define('JACK_DBUS', 1)
212 if conf.env['BUILD_JACKD'] == False:
213 conf.define('USE_LIBDBUS_AUTOLAUNCH', 1)
214 if conf.env['BUILD_WITH_PROFILE'] == True:
215 conf.define('JACK_MONITOR', 1)
216 if conf.env['BUILD_WITH_32_64'] == True:
217 conf.define('JACK_32_64', 1)
218 conf.write_config_header('config.h')
220 svnrev = None
221 if os.access('svnversion.h', os.R_OK):
222 data = file('svnversion.h').read()
223 m = re.match(r'^#define SVN_VERSION "([^"]*)"$', data)
224 if m != None:
225 svnrev = m.group(1)
227 conf.env.append_unique('LINKFLAGS', ['-lm', '-lstdc++'])
229 if Options.options.mixed == True:
230 env_variant2 = conf.env.copy()
231 conf.set_env_name('lib32', env_variant2)
232 env_variant2.set_variant('lib32')
233 conf.setenv('lib32')
234 conf.env.append_unique('CXXFLAGS', '-m32')
235 conf.env.append_unique('CCFLAGS', '-m32')
236 conf.env.append_unique('LINKFLAGS', '-m32')
237 if Options.options.libdir32:
238 conf.env['LIBDIR'] = conf.env['PREFIX'] + Options.options.libdir32
239 else:
240 conf.env['LIBDIR'] = conf.env['PREFIX'] + '/lib32'
241 conf.write_config_header('config.h')
243 print()
244 display_msg("==================")
245 version_msg = "JACK " + VERSION
246 if svnrev:
247 version_msg += " exported from r" + svnrev
248 else:
249 version_msg += " svn revision will checked and eventually updated during build"
250 print(version_msg)
252 print("Build with a maximum of %d JACK clients" % Options.options.clients)
253 print("Build with a maximum of %d ports per application" % Options.options.application_ports)
255 display_msg("Install prefix", conf.env['PREFIX'], 'CYAN')
256 display_msg("Library directory", conf.env['LIBDIR'], 'CYAN')
257 display_msg("Drivers directory", conf.env['ADDON_DIR'], 'CYAN')
258 display_feature('Build debuggable binaries', conf.env['BUILD_DEBUG'])
259 display_msg('C compiler flags', repr(conf.env['CCFLAGS']))
260 display_msg('C++ compiler flags', repr(conf.env['CXXFLAGS']))
261 display_msg('Linker flags', repr(conf.env['LINKFLAGS']))
262 display_feature('Build doxygen documentation', conf.env['BUILD_DOXYGEN_DOCS'])
263 display_feature('Build with engine profiling', conf.env['BUILD_WITH_PROFILE'])
264 display_feature('Build with 32/64 bits mixed mode', conf.env['BUILD_WITH_32_64'])
266 display_feature('Build standard JACK (jackd)', conf.env['BUILD_JACKD'])
267 display_feature('Build D-Bus JACK (jackdbus)', conf.env['BUILD_JACKDBUS'])
269 if conf.env['BUILD_JACKDBUS'] and conf.env['BUILD_JACKD']:
270 print(Logs.colors.RED + 'WARNING !! mixing both jackd and jackdbus may cause issues:' + Logs.colors.NORMAL)
271 print(Logs.colors.RED + 'WARNING !! jackdbus does not use .jackdrc nor qjackctl settings' + Logs.colors.NORMAL)
273 if conf.env['IS_LINUX']:
274 display_feature('Build with ALSA support', conf.env['BUILD_DRIVER_ALSA'] == True)
275 display_feature('Build with FireWire (FreeBob) support', conf.env['BUILD_DRIVER_FREEBOB'] == True)
276 display_feature('Build with FireWire (FFADO) support', conf.env['BUILD_DRIVER_FFADO'] == True)
278 if conf.env['BUILD_JACKDBUS'] == True:
279 display_msg('D-Bus service install directory', conf.env['DBUS_SERVICES_DIR'], 'CYAN')
280 #display_msg('Settings persistence', xxx)
282 if conf.env['DBUS_SERVICES_DIR'] != conf.env['DBUS_SERVICES_DIR_REAL']:
283 print()
284 print(Logs.colors.RED + "WARNING: D-Bus session services directory as reported by pkg-config is")
285 print(Logs.colors.RED + "WARNING:", end=' ')
286 print(Logs.colors.CYAN + conf.env['DBUS_SERVICES_DIR_REAL'])
287 print(Logs.colors.RED + 'WARNING: but service file will be installed in')
288 print(Logs.colors.RED + "WARNING:", end=' ')
289 print(Logs.colors.CYAN + conf.env['DBUS_SERVICES_DIR'])
290 print(Logs.colors.RED + 'WARNING: You may need to adjust your D-Bus configuration after installing jackdbus')
291 print('WARNING: You can override dbus service install directory')
292 print('WARNING: with --enable-pkg-config-dbus-service-dir option to this script')
293 print(Logs.colors.NORMAL, end=' ')
294 print()
296 def build(bld):
297 print(("make[1]: Entering directory `" + os.getcwd() + "/" + out + "'" ))
298 if not os.access('svnversion.h', os.R_OK):
299 create_svnversion_task(bld)
301 # process subfolders from here
302 bld.add_subdirs('common')
303 if bld.env['IS_LINUX']:
304 bld.add_subdirs('linux')
305 bld.add_subdirs('example-clients')
306 bld.add_subdirs('tests')
307 bld.add_subdirs('man')
308 if bld.env['BUILD_JACKDBUS'] == True:
309 bld.add_subdirs('dbus')
311 if bld.env['IS_MACOSX']:
312 bld.add_subdirs('macosx')
313 bld.add_subdirs('example-clients')
314 bld.add_subdirs('tests')
315 if bld.env['BUILD_JACKDBUS'] == True:
316 bld.add_subdirs('dbus')
318 if bld.env['IS_SUN']:
319 bld.add_subdirs('solaris')
320 bld.add_subdirs('example-clients')
321 bld.add_subdirs('tests')
322 if bld.env['BUILD_JACKDBUS'] == True:
323 bld.add_subdirs('dbus')
325 if bld.env['BUILD_DOXYGEN_DOCS'] == True:
326 share_dir = bld.env.get_destdir() + bld.env['PREFIX'] + '/share/jack-audio-connection-kit'
327 html_docs_source_dir = "build/default/html"
328 html_docs_install_dir = share_dir + '/reference/html/'
329 if Options.commands['install']:
330 if os.path.isdir(html_docs_install_dir):
331 Logs.pprint('CYAN', "Removing old doxygen documentation installation...")
332 shutil.rmtree(html_docs_install_dir)
333 Logs.pprint('CYAN', "Removing old doxygen documentation installation done.")
334 Logs.pprint('CYAN', "Installing doxygen documentation...")
335 shutil.copytree(html_docs_source_dir, html_docs_install_dir)
336 Logs.pprint('CYAN', "Installing doxygen documentation done.")
337 elif Options.commands['uninstall']:
338 Logs.pprint('CYAN', "Uninstalling doxygen documentation...")
339 if os.path.isdir(share_dir):
340 shutil.rmtree(share_dir)
341 Logs.pprint('CYAN', "Uninstalling doxygen documentation done.")
342 elif Options.commands['clean']:
343 if os.access(html_docs_source_dir, os.R_OK):
344 Logs.pprint('CYAN', "Removing doxygen generated documentation...")
345 shutil.rmtree(html_docs_source_dir)
346 Logs.pprint('CYAN', "Removing doxygen generated documentation done.")
347 elif Options.commands['build']:
348 if not os.access(html_docs_source_dir, os.R_OK):
349 os.popen("doxygen").read()
350 else:
351 Logs.pprint('CYAN', "doxygen documentation already built.")
353 def dist_hook():
354 os.remove('svnversion_regenerate.sh')
355 os.system('../svnversion_regenerate.sh svnversion.h')