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.

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