jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

391 lines
17KB

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