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.

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