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.

432 lines
19KB

  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('--dist-target', type='string', default='auto', help='Specify the target for cross-compiling [auto,mingw]')
  60. opt.add_option('--classic', action='store_true', default=False, help='Force enable standard JACK (jackd) even if D-Bus JACK (jackdbus) is enabled too')
  61. opt.add_option('--doxygen', action='store_true', default=False, help='Enable build of doxygen documentation')
  62. opt.add_option('--profile', action='store_true', default=False, help='Build with engine profiling')
  63. opt.add_option('--mixed', action='store_true', default=False, help='Build with 32/64 bits mixed mode')
  64. opt.add_option('--clients', default=64, type="int", dest="clients", help='Maximum number of JACK clients')
  65. opt.add_option('--ports-per-application', default=768, type="int", dest="application_ports", help='Maximum number of ports per application')
  66. opt.add_option('--debug', action='store_true', default=False, dest='debug', help='Build debuggable binaries')
  67. opt.add_option('--firewire', action='store_true', default=False, help='Enable FireWire driver (FFADO)')
  68. opt.add_option('--freebob', action='store_true', default=False, help='Enable FreeBob driver')
  69. opt.add_option('--alsa', action='store_true', default=False, help='Enable ALSA driver')
  70. opt.add_option('--autostart', type='string', default="default", help='Autostart method. Possible values: "default", "classic", "dbus", "none"')
  71. opt.add_option('--portaudio', action='store_true', default=False, help='Enable Portaudio driver')
  72. opt.add_option('--winmme', action='store_true', default=False, help='Enable WinMME driver')
  73. opt.sub_options('dbus')
  74. def configure(conf):
  75. conf.load('compiler_cxx')
  76. conf.load('compiler_cc')
  77. if Options.options.dist_target == 'auto':
  78. platform = sys.platform
  79. conf.env['IS_MACOSX'] = platform == 'darwin'
  80. conf.env['IS_LINUX'] = platform == 'linux' or platform == 'linux2' or platform == 'linux3' or platform == 'posix'
  81. conf.env['IS_SUN'] = platform == 'sunos'
  82. # GNU/kFreeBSD and GNU/Hurd are treated as Linux
  83. if platform.startswith('gnu0') or platform.startswith('gnukfreebsd'):
  84. conf.env['IS_LINUX'] = True
  85. elif Options.options.dist_target == 'mingw':
  86. conf.env['IS_WINDOWS'] = True
  87. if conf.env['IS_LINUX']:
  88. Logs.pprint('CYAN', "Linux detected")
  89. if conf.env['IS_MACOSX']:
  90. Logs.pprint('CYAN', "MacOS X detected")
  91. if conf.env['IS_SUN']:
  92. Logs.pprint('CYAN', "SunOS detected")
  93. if conf.env['IS_WINDOWS']:
  94. Logs.pprint('CYAN', "Windows detected")
  95. if conf.env['IS_LINUX']:
  96. conf.check_tool('compiler_cxx')
  97. conf.check_tool('compiler_cc')
  98. if conf.env['IS_MACOSX']:
  99. conf.check_tool('compiler_cxx')
  100. conf.check_tool('compiler_cc')
  101. # waf 1.5 : check_tool('compiler_cxx') and check_tool('compiler_cc') do not work correctly, so explicit use of gcc and g++
  102. if conf.env['IS_SUN']:
  103. conf.check_tool('g++')
  104. conf.check_tool('gcc')
  105. #if conf.env['IS_SUN']:
  106. # conf.check_tool('compiler_cxx')
  107. # conf.check_tool('compiler_cc')
  108. if conf.env['IS_WINDOWS']:
  109. conf.check_tool('compiler_cxx')
  110. conf.check_tool('compiler_cc')
  111. conf.env.append_unique('CCDEFINES', '_POSIX')
  112. conf.env.append_unique('CXXDEFINES', '_POSIX')
  113. conf.env.append_unique('CXXFLAGS', '-Wall')
  114. conf.env.append_unique('CFLAGS', '-Wall')
  115. conf.sub_config('common')
  116. if conf.env['IS_LINUX']:
  117. conf.sub_config('linux')
  118. if Options.options.alsa and not conf.env['BUILD_DRIVER_ALSA']:
  119. conf.fatal('ALSA driver was explicitly requested but cannot be built')
  120. if Options.options.freebob and not conf.env['BUILD_DRIVER_FREEBOB']:
  121. conf.fatal('FreeBob driver was explicitly requested but cannot be built')
  122. if Options.options.firewire and not conf.env['BUILD_DRIVER_FFADO']:
  123. conf.fatal('FFADO driver was explicitly requested but cannot be built')
  124. conf.env['BUILD_DRIVER_ALSA'] = Options.options.alsa
  125. conf.env['BUILD_DRIVER_FFADO'] = Options.options.firewire
  126. conf.env['BUILD_DRIVER_FREEBOB'] = Options.options.freebob
  127. if conf.env['IS_WINDOWS']:
  128. conf.sub_config('windows')
  129. if Options.options.portaudio and not conf.env['BUILD_DRIVER_PORTAUDIO']:
  130. conf.fatal('Portaudio driver was explicitly requested but cannot be built')
  131. conf.env['BUILD_DRIVER_WINMME'] = Options.options.winmme
  132. if Options.options.dbus:
  133. conf.sub_config('dbus')
  134. if conf.env['BUILD_JACKDBUS'] != True:
  135. conf.fatal('jackdbus was explicitly requested but cannot be built')
  136. conf.check_cc(header_name='samplerate.h', define_name="HAVE_SAMPLERATE")
  137. if conf.is_defined('HAVE_SAMPLERATE'):
  138. conf.env['LIB_SAMPLERATE'] = ['samplerate']
  139. 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)
  170. conf.env['WITH_OPUS'] = False
  171. if conf.check_cfg(package='opus', atleast_version='0.9.0' , args='--cflags --libs', mandatory=False):
  172. if conf.check_cc(header_name='opus/opus_custom.h', mandatory=False):
  173. conf.define('HAVE_OPUS', 1)
  174. conf.env['WITH_OPUS'] = True
  175. else:
  176. conf.define('HAVE_OPUS', 0)
  177. conf.env['LIB_PTHREAD'] = ['pthread']
  178. conf.env['LIB_DL'] = ['dl']
  179. conf.env['LIB_RT'] = ['rt']
  180. conf.env['LIB_M'] = ['m']
  181. conf.env['LIB_STDC++'] = ['stdc++']
  182. conf.env['JACK_API_VERSION'] = JACK_API_VERSION
  183. conf.env['JACK_VERSION'] = VERSION
  184. conf.env['BUILD_DOXYGEN_DOCS'] = Options.options.doxygen
  185. conf.env['BUILD_WITH_PROFILE'] = Options.options.profile
  186. conf.env['BUILD_WITH_32_64'] = Options.options.mixed
  187. conf.env['BUILD_CLASSIC'] = Options.options.classic
  188. conf.env['BUILD_DEBUG'] = Options.options.debug
  189. if conf.env['BUILD_JACKDBUS']:
  190. conf.env['BUILD_JACKD'] = conf.env['BUILD_CLASSIC']
  191. else:
  192. conf.env['BUILD_JACKD'] = True
  193. conf.env['BINDIR'] = conf.env['PREFIX'] + '/bin'
  194. if Options.options.libdir:
  195. conf.env['LIBDIR'] = Options.options.libdir
  196. else:
  197. 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'
  202. if conf.env['BUILD_DEBUG']:
  203. conf.env.append_unique('CXXFLAGS', '-g')
  204. conf.env.append_unique('CFLAGS', '-g')
  205. conf.env.append_unique('LINKFLAGS', '-g')
  206. if not Options.options.autostart in ["default", "classic", "dbus", "none"]:
  207. conf.fatal("Invalid autostart value \"" + Options.options.autostart + "\"")
  208. if Options.options.autostart == "default":
  209. if conf.env['BUILD_JACKDBUS'] == True and conf.env['BUILD_JACKD'] == False:
  210. conf.env['AUTOSTART_METHOD'] = "dbus"
  211. else:
  212. conf.env['AUTOSTART_METHOD'] = "classic"
  213. else:
  214. conf.env['AUTOSTART_METHOD'] = Options.options.autostart
  215. if conf.env['AUTOSTART_METHOD'] == "dbus" and not conf.env['BUILD_JACKDBUS']:
  216. conf.fatal("D-Bus autostart mode was specified but jackdbus will not be built")
  217. if conf.env['AUTOSTART_METHOD'] == "classic" and not conf.env['BUILD_JACKD']:
  218. conf.fatal("Classic autostart mode was specified but jackd will not be built")
  219. if conf.env['AUTOSTART_METHOD'] == "dbus":
  220. conf.define('USE_LIBDBUS_AUTOLAUNCH', 1)
  221. elif conf.env['AUTOSTART_METHOD'] == "classic":
  222. conf.define('USE_CLASSIC_AUTOLAUNCH', 1)
  223. conf.define('CLIENT_NUM', Options.options.clients)
  224. conf.define('PORT_NUM_FOR_CLIENT', Options.options.application_ports)
  225. if conf.env['IS_WINDOWS']:
  226. # we define this in the environment to maintain compatability with
  227. # existing install paths that use ADDON_DIR rather than have to
  228. # have special cases for windows each time.
  229. conf.env['ADDON_DIR'] = conf.env['BINDIR'] + '/jack'
  230. # don't define ADDON_DIR in config.h, use the default 'jack' defined in
  231. # windows/JackPlatformPlug_os.h
  232. else:
  233. conf.env['ADDON_DIR'] = os.path.normpath(os.path.join(conf.env['LIBDIR'], 'jack'))
  234. conf.define('ADDON_DIR', conf.env['ADDON_DIR'])
  235. conf.define('JACK_LOCATION', os.path.normpath(os.path.join(conf.env['PREFIX'], 'bin')))
  236. if not conf.env['IS_WINDOWS']:
  237. conf.define('USE_POSIX_SHM', 1)
  238. conf.define('JACKMP', 1)
  239. if conf.env['BUILD_JACKDBUS'] == True:
  240. conf.define('JACK_DBUS', 1)
  241. if conf.env['BUILD_WITH_PROFILE'] == True:
  242. conf.define('JACK_MONITOR', 1)
  243. conf.write_config_header('config.h', remove=False)
  244. svnrev = None
  245. if os.access('svnversion.h', os.R_OK):
  246. data = file('svnversion.h').read()
  247. m = re.match(r'^#define SVN_VERSION "([^"]*)"$', data)
  248. if m != None:
  249. svnrev = m.group(1)
  250. if Options.options.mixed == True:
  251. env_variant2 = conf.env.copy()
  252. conf.set_env_name('lib32', env_variant2)
  253. env_variant2.set_variant('lib32')
  254. conf.setenv('lib32')
  255. conf.env.append_unique('CXXFLAGS', '-m32')
  256. conf.env.append_unique('CFLAGS', '-m32')
  257. conf.env.append_unique('LINKFLAGS', '-m32')
  258. if Options.options.libdir32:
  259. conf.env['LIBDIR'] = Options.options.libdir32
  260. else:
  261. conf.env['LIBDIR'] = conf.env['PREFIX'] + '/lib32'
  262. conf.write_config_header('config.h')
  263. print()
  264. display_msg("==================")
  265. version_msg = "JACK " + VERSION
  266. if svnrev:
  267. version_msg += " exported from r" + svnrev
  268. else:
  269. version_msg += " svn revision will checked and eventually updated during build"
  270. print(version_msg)
  271. print("Build with a maximum of %d JACK clients" % Options.options.clients)
  272. print("Build with a maximum of %d ports per application" % Options.options.application_ports)
  273. display_msg("Install prefix", conf.env['PREFIX'], 'CYAN')
  274. display_msg("Library directory", conf.env['LIBDIR'], 'CYAN')
  275. display_msg("Drivers directory", conf.env['ADDON_DIR'], 'CYAN')
  276. display_feature('Build debuggable binaries', conf.env['BUILD_DEBUG'])
  277. display_msg('C compiler flags', repr(conf.env['CFLAGS']))
  278. display_msg('C++ compiler flags', repr(conf.env['CXXFLAGS']))
  279. display_msg('Linker flags', repr(conf.env['LINKFLAGS']))
  280. display_feature('Build doxygen documentation', conf.env['BUILD_DOXYGEN_DOCS'])
  281. display_feature('Build Opus netjack2', conf.env['WITH_OPUS'])
  282. display_feature('Build with engine profiling', conf.env['BUILD_WITH_PROFILE'])
  283. display_feature('Build with 32/64 bits mixed mode', conf.env['BUILD_WITH_32_64'])
  284. display_feature('Build standard JACK (jackd)', conf.env['BUILD_JACKD'])
  285. display_feature('Build D-Bus JACK (jackdbus)', conf.env['BUILD_JACKDBUS'])
  286. display_msg('Autostart method', conf.env['AUTOSTART_METHOD'])
  287. if conf.env['BUILD_JACKDBUS'] and conf.env['BUILD_JACKD']:
  288. print(Logs.colors.RED + 'WARNING !! mixing both jackd and jackdbus may cause issues:' + Logs.colors.NORMAL)
  289. print(Logs.colors.RED + 'WARNING !! jackdbus does not use .jackdrc nor qjackctl settings' + Logs.colors.NORMAL)
  290. if conf.env['IS_LINUX']:
  291. display_feature('Build with ALSA support', conf.env['BUILD_DRIVER_ALSA'] == True)
  292. display_feature('Build with FireWire (FreeBob) support', conf.env['BUILD_DRIVER_FREEBOB'] == True)
  293. display_feature('Build with FireWire (FFADO) support', conf.env['BUILD_DRIVER_FFADO'] == True)
  294. if conf.env['IS_WINDOWS']:
  295. display_feature('Build with WinMME support', conf.env['BUILD_DRIVER_WINMME'] == True)
  296. display_feature('Build with Portaudio support', conf.env['BUILD_DRIVER_PORTAUDIO'] == True)
  297. if conf.env['BUILD_JACKDBUS'] == True:
  298. display_msg('D-Bus service install directory', conf.env['DBUS_SERVICES_DIR'], 'CYAN')
  299. #display_msg('Settings persistence', xxx)
  300. if conf.env['DBUS_SERVICES_DIR'] != conf.env['DBUS_SERVICES_DIR_REAL']:
  301. print()
  302. print(Logs.colors.RED + "WARNING: D-Bus session services directory as reported by pkg-config is")
  303. print(Logs.colors.RED + "WARNING:", end=' ')
  304. print(Logs.colors.CYAN + conf.env['DBUS_SERVICES_DIR_REAL'])
  305. print(Logs.colors.RED + 'WARNING: but service file will be installed in')
  306. print(Logs.colors.RED + "WARNING:", end=' ')
  307. print(Logs.colors.CYAN + conf.env['DBUS_SERVICES_DIR'])
  308. print(Logs.colors.RED + 'WARNING: You may need to adjust your D-Bus configuration after installing jackdbus')
  309. print('WARNING: You can override dbus service install directory')
  310. print('WARNING: with --enable-pkg-config-dbus-service-dir option to this script')
  311. print(Logs.colors.NORMAL, end=' ')
  312. print()
  313. def build(bld):
  314. print("make[1]: Entering directory `" + os.getcwd() + "/" + out + "'")
  315. if not os.access('svnversion.h', os.R_OK):
  316. create_svnversion_task(bld)
  317. # process subfolders from here
  318. bld.add_subdirs('common')
  319. if bld.env['IS_LINUX']:
  320. bld.add_subdirs('linux')
  321. bld.add_subdirs('example-clients')
  322. bld.add_subdirs('tests')
  323. bld.add_subdirs('man')
  324. if bld.env['BUILD_JACKDBUS'] == True:
  325. bld.add_subdirs('dbus')
  326. if bld.env['IS_MACOSX']:
  327. bld.add_subdirs('macosx')
  328. bld.add_subdirs('example-clients')
  329. bld.add_subdirs('tests')
  330. if bld.env['BUILD_JACKDBUS'] == True:
  331. bld.add_subdirs('dbus')
  332. if bld.env['IS_SUN']:
  333. bld.add_subdirs('solaris')
  334. bld.add_subdirs('example-clients')
  335. bld.add_subdirs('tests')
  336. if bld.env['BUILD_JACKDBUS'] == True:
  337. bld.add_subdirs('dbus')
  338. if bld.env['IS_WINDOWS']:
  339. bld.add_subdirs('windows')
  340. bld.add_subdirs('example-clients')
  341. #bld.add_subdirs('tests')
  342. if bld.env['BUILD_DOXYGEN_DOCS'] == True:
  343. html_docs_source_dir = "build/default/html"
  344. if bld.cmd == 'install':
  345. share_dir = bld.options.destdir + bld.env['PREFIX'] + '/share/jack-audio-connection-kit'
  346. html_docs_install_dir = share_dir + '/reference/html/'
  347. if os.path.isdir(html_docs_install_dir):
  348. Logs.pprint('CYAN', "Removing old doxygen documentation installation...")
  349. shutil.rmtree(html_docs_install_dir)
  350. Logs.pprint('CYAN', "Removing old doxygen documentation installation done.")
  351. Logs.pprint('CYAN', "Installing doxygen documentation...")
  352. shutil.copytree(html_docs_source_dir, html_docs_install_dir)
  353. Logs.pprint('CYAN', "Installing doxygen documentation done.")
  354. elif bld.cmd =='uninstall':
  355. Logs.pprint('CYAN', "Uninstalling doxygen documentation...")
  356. if os.path.isdir(share_dir):
  357. shutil.rmtree(share_dir)
  358. Logs.pprint('CYAN', "Uninstalling doxygen documentation done.")
  359. elif bld.cmd =='clean':
  360. if os.access(html_docs_source_dir, os.R_OK):
  361. Logs.pprint('CYAN', "Removing doxygen generated documentation...")
  362. shutil.rmtree(html_docs_source_dir)
  363. Logs.pprint('CYAN', "Removing doxygen generated documentation done.")
  364. elif bld.cmd =='build':
  365. if not os.access(html_docs_source_dir, os.R_OK):
  366. os.popen("doxygen").read()
  367. else:
  368. Logs.pprint('CYAN', "doxygen documentation already built.")
  369. def dist_hook():
  370. os.remove('svnversion_regenerate.sh')
  371. os.system('../svnversion_regenerate.sh svnversion.h')