Fix OSX scripts.
[jack2.git] / wscript
blobe8d9a8bd86813d34f997a04563dc751ad4ee6b53
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('CCFLAGS', '-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['LIB_PTHREAD'] = ['pthread']
177 conf.env['LIB_DL'] = ['dl']
178 conf.env['LIB_RT'] = ['rt']
179 conf.env['JACK_API_VERSION'] = JACK_API_VERSION
180 conf.env['JACK_VERSION'] = VERSION
182 conf.env['BUILD_DOXYGEN_DOCS'] = Options.options.doxygen
183 conf.env['BUILD_WITH_PROFILE'] = Options.options.profile
184 conf.env['BUILD_WITH_32_64'] = Options.options.mixed
185 conf.env['BUILD_CLASSIC'] = Options.options.classic
186 conf.env['BUILD_DEBUG'] = Options.options.debug
188 if conf.env['BUILD_JACKDBUS']:
189 conf.env['BUILD_JACKD'] = conf.env['BUILD_CLASSIC']
190 else:
191 conf.env['BUILD_JACKD'] = True
193 if Options.options.libdir:
194 conf.env['LIBDIR'] = Options.options.libdir
195 else:
196 conf.env['LIBDIR'] = conf.env['PREFIX'] + '/lib'
198 if Options.options.mandir:
199 conf.env['MANDIR'] = Options.options.mandir
200 else:
201 conf.env['MANDIR'] = conf.env['PREFIX'] + '/share/man/man1'
203 if conf.env['BUILD_DEBUG']:
204 conf.env.append_unique('CXXFLAGS', '-g')
205 conf.env.append_unique('CCFLAGS', '-g')
206 conf.env.append_unique('LINKFLAGS', '-g')
208 conf.define('CLIENT_NUM', Options.options.clients)
209 conf.define('PORT_NUM_FOR_CLIENT', Options.options.application_ports)
211 conf.env['ADDON_DIR'] = os.path.normpath(os.path.join(conf.env['LIBDIR'], 'jack'))
212 conf.define('ADDON_DIR', conf.env['ADDON_DIR'])
213 conf.define('JACK_LOCATION', os.path.normpath(os.path.join(conf.env['PREFIX'], 'bin')))
214 conf.define('USE_POSIX_SHM', 1)
215 conf.define('JACKMP', 1)
216 if conf.env['BUILD_JACKDBUS'] == True:
217 conf.define('JACK_DBUS', 1)
218 if conf.env['BUILD_JACKD'] == False:
219 conf.define('USE_LIBDBUS_AUTOLAUNCH', 1)
220 if conf.env['BUILD_WITH_PROFILE'] == True:
221 conf.define('JACK_MONITOR', 1)
222 conf.write_config_header('config.h')
224 svnrev = None
225 if os.access('svnversion.h', os.R_OK):
226 data = file('svnversion.h').read()
227 m = re.match(r'^#define SVN_VERSION "([^"]*)"$', data)
228 if m != None:
229 svnrev = m.group(1)
231 conf.env.append_unique('LINKFLAGS', ['-lm', '-lstdc++'])
233 if Options.options.mixed == True:
234 env_variant2 = conf.env.copy()
235 conf.set_env_name('lib32', env_variant2)
236 env_variant2.set_variant('lib32')
237 conf.setenv('lib32')
238 conf.env.append_unique('CXXFLAGS', '-m32')
239 conf.env.append_unique('CCFLAGS', '-m32')
240 conf.env.append_unique('LINKFLAGS', '-m32')
241 if Options.options.libdir32:
242 conf.env['LIBDIR'] = Options.options.libdir32
243 else:
244 conf.env['LIBDIR'] = conf.env['PREFIX'] + '/lib32'
245 conf.write_config_header('config.h')
247 print()
248 display_msg("==================")
249 version_msg = "JACK " + VERSION
250 if svnrev:
251 version_msg += " exported from r" + svnrev
252 else:
253 version_msg += " svn revision will checked and eventually updated during build"
254 print(version_msg)
256 print("Build with a maximum of %d JACK clients" % Options.options.clients)
257 print("Build with a maximum of %d ports per application" % Options.options.application_ports)
259 display_msg("Install prefix", conf.env['PREFIX'], 'CYAN')
260 display_msg("Library directory", conf.env['LIBDIR'], 'CYAN')
261 display_msg("Drivers directory", conf.env['ADDON_DIR'], 'CYAN')
262 display_feature('Build debuggable binaries', conf.env['BUILD_DEBUG'])
263 display_msg('C compiler flags', repr(conf.env['CCFLAGS']))
264 display_msg('C++ compiler flags', repr(conf.env['CXXFLAGS']))
265 display_msg('Linker flags', repr(conf.env['LINKFLAGS']))
266 display_feature('Build doxygen documentation', conf.env['BUILD_DOXYGEN_DOCS'])
267 display_feature('Build with engine profiling', conf.env['BUILD_WITH_PROFILE'])
268 display_feature('Build with 32/64 bits mixed mode', conf.env['BUILD_WITH_32_64'])
270 display_feature('Build standard JACK (jackd)', conf.env['BUILD_JACKD'])
271 display_feature('Build D-Bus JACK (jackdbus)', conf.env['BUILD_JACKDBUS'])
273 if conf.env['BUILD_JACKDBUS'] and conf.env['BUILD_JACKD']:
274 print(Logs.colors.RED + 'WARNING !! mixing both jackd and jackdbus may cause issues:' + Logs.colors.NORMAL)
275 print(Logs.colors.RED + 'WARNING !! jackdbus does not use .jackdrc nor qjackctl settings' + Logs.colors.NORMAL)
277 if conf.env['IS_LINUX']:
278 display_feature('Build with ALSA support', conf.env['BUILD_DRIVER_ALSA'] == True)
279 display_feature('Build with FireWire (FreeBob) support', conf.env['BUILD_DRIVER_FREEBOB'] == True)
280 display_feature('Build with FireWire (FFADO) support', conf.env['BUILD_DRIVER_FFADO'] == True)
282 if conf.env['BUILD_JACKDBUS'] == True:
283 display_msg('D-Bus service install directory', conf.env['DBUS_SERVICES_DIR'], 'CYAN')
284 #display_msg('Settings persistence', xxx)
286 if conf.env['DBUS_SERVICES_DIR'] != conf.env['DBUS_SERVICES_DIR_REAL']:
287 print()
288 print(Logs.colors.RED + "WARNING: D-Bus session services directory as reported by pkg-config is")
289 print(Logs.colors.RED + "WARNING:", end=' ')
290 print(Logs.colors.CYAN + conf.env['DBUS_SERVICES_DIR_REAL'])
291 print(Logs.colors.RED + 'WARNING: but service file will be installed in')
292 print(Logs.colors.RED + "WARNING:", end=' ')
293 print(Logs.colors.CYAN + conf.env['DBUS_SERVICES_DIR'])
294 print(Logs.colors.RED + 'WARNING: You may need to adjust your D-Bus configuration after installing jackdbus')
295 print('WARNING: You can override dbus service install directory')
296 print('WARNING: with --enable-pkg-config-dbus-service-dir option to this script')
297 print(Logs.colors.NORMAL, end=' ')
298 print()
300 def build(bld):
301 print("make[1]: Entering directory `" + os.getcwd() + "/" + out + "'")
302 if not os.access('svnversion.h', os.R_OK):
303 create_svnversion_task(bld)
305 # process subfolders from here
306 bld.add_subdirs('common')
307 if bld.env['IS_LINUX']:
308 bld.add_subdirs('linux')
309 bld.add_subdirs('example-clients')
310 bld.add_subdirs('tests')
311 bld.add_subdirs('man')
312 if bld.env['BUILD_JACKDBUS'] == True:
313 bld.add_subdirs('dbus')
315 if bld.env['IS_MACOSX']:
316 bld.add_subdirs('macosx')
317 bld.add_subdirs('example-clients')
318 bld.add_subdirs('tests')
319 if bld.env['BUILD_JACKDBUS'] == True:
320 bld.add_subdirs('dbus')
322 if bld.env['IS_SUN']:
323 bld.add_subdirs('solaris')
324 bld.add_subdirs('example-clients')
325 bld.add_subdirs('tests')
326 if bld.env['BUILD_JACKDBUS'] == True:
327 bld.add_subdirs('dbus')
329 if bld.env['BUILD_DOXYGEN_DOCS'] == True:
330 share_dir = bld.env.get_destdir() + bld.env['PREFIX'] + '/share/jack-audio-connection-kit'
331 html_docs_source_dir = "build/default/html"
332 html_docs_install_dir = share_dir + '/reference/html/'
333 if Options.commands['install']:
334 if os.path.isdir(html_docs_install_dir):
335 Logs.pprint('CYAN', "Removing old doxygen documentation installation...")
336 shutil.rmtree(html_docs_install_dir)
337 Logs.pprint('CYAN', "Removing old doxygen documentation installation done.")
338 Logs.pprint('CYAN', "Installing doxygen documentation...")
339 shutil.copytree(html_docs_source_dir, html_docs_install_dir)
340 Logs.pprint('CYAN', "Installing doxygen documentation done.")
341 elif Options.commands['uninstall']:
342 Logs.pprint('CYAN', "Uninstalling doxygen documentation...")
343 if os.path.isdir(share_dir):
344 shutil.rmtree(share_dir)
345 Logs.pprint('CYAN', "Uninstalling doxygen documentation done.")
346 elif Options.commands['clean']:
347 if os.access(html_docs_source_dir, os.R_OK):
348 Logs.pprint('CYAN', "Removing doxygen generated documentation...")
349 shutil.rmtree(html_docs_source_dir)
350 Logs.pprint('CYAN', "Removing doxygen generated documentation done.")
351 elif Options.commands['build']:
352 if not os.access(html_docs_source_dir, os.R_OK):
353 os.popen("doxygen").read()
354 else:
355 Logs.pprint('CYAN', "doxygen documentation already built.")
357 def dist_hook():
358 os.remove('svnversion_regenerate.sh')
359 os.system('../svnversion_regenerate.sh svnversion.h')