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.

461 lines
20KB

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