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.

358 lines
15KB

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