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.

1097 lines
41KB

  1. #! /usr/bin/env python
  2. # encoding: utf-8
  3. from __future__ import print_function
  4. import os
  5. import subprocess
  6. import shutil
  7. import re
  8. import sys
  9. from waflib import Logs, Options, Task, Utils
  10. from waflib.Build import BuildContext, CleanContext, InstallContext, UninstallContext
  11. VERSION='1.9.11-RC1'
  12. APPNAME='jack'
  13. JACK_API_VERSION = '0.1.0'
  14. # these variables are mandatory ('/' are converted automatically)
  15. top = '.'
  16. out = 'build'
  17. # lib32 variant name used when building in mixed mode
  18. lib32 = 'lib32'
  19. auto_options = []
  20. def display_feature(conf, msg, build):
  21. if build:
  22. conf.msg(msg, 'yes', color='GREEN')
  23. else:
  24. conf.msg(msg, 'no', color='YELLOW')
  25. # This function prints an error without stopping waf. The reason waf should not
  26. # be stopped is to be able to list all missing dependencies in one chunk.
  27. def print_error(msg):
  28. print(Logs.colors.RED + msg + Logs.colors.NORMAL)
  29. class AutoOption:
  30. """
  31. This class is the foundation for the auto options. It adds an option
  32. --foo=no|yes to the list of options and deals with all logic and checks for
  33. these options.
  34. Each option can have different dependencies that will be checked. If all
  35. dependencies are available and the user has not done any request the option
  36. will be enabled. If the user has requested to enable the option the class
  37. ensures that all dependencies are available and prints an error message
  38. otherwise. If the user disables the option, i.e. --foo=no, no checks are
  39. made.
  40. For each option it is possible to add packages that are required for the
  41. option using the add_package function. For dependency programs add_program
  42. should be used. For libraries (without pkg-config support) the add_library
  43. function should be used. For headers the add_header function exists. If
  44. there is another type of requirement or dependency the check hook (an
  45. external function called when configuring) can be used.
  46. When all checks have been made and the class has made a decision the result
  47. is saved in conf.env['NAME'] where 'NAME' by default is the uppercase of the
  48. name argument to __init__, but it can be changed with the conf_dest argument
  49. to __init__.
  50. The class will define a preprocessor symbol with the result. The default
  51. name is HAVE_NAME, but it can be changed using the define argument to
  52. __init__.
  53. """
  54. def __init__(self, opt, name, help, conf_dest=None, define=None):
  55. # check hook to call upon configuration
  56. self.check_hook = None
  57. self.check_hook_error = None
  58. self.check_hook_found = True
  59. # required libraries
  60. self.libs = [] # elements on the form [lib,uselib_store]
  61. self.libs_not_found = [] # elements on the form lib
  62. # required headers
  63. self.headers = []
  64. self.headers_not_found = []
  65. # required packages (checked with pkg-config)
  66. self.packages = [] # elements on the form [package,uselib_store,atleast_version]
  67. self.packages_not_found = [] # elements on the form [package,atleast_version]
  68. # required programs
  69. self.programs = [] # elements on the form [program,var]
  70. self.programs_not_found = [] # elements on the form program
  71. # the result of the configuration (should the option be enabled or not?)
  72. self.result = False
  73. self.help = help
  74. self.option = '--' + name
  75. self.dest = 'auto_option_' + name
  76. if conf_dest:
  77. self.conf_dest = conf_dest
  78. else:
  79. self.conf_dest = name.upper()
  80. if not define:
  81. self.define = 'HAVE_' + name.upper()
  82. else:
  83. self.define = define
  84. opt.add_option(self.option, type='string', default='auto', dest=self.dest, help=self.help+' (enabled by default if possible)', metavar='no|yes')
  85. def add_library(self, library, uselib_store=None):
  86. """
  87. Add a required library that should be checked during configuration. The
  88. library will be checked using the conf.check function. If the
  89. uselib_store arugment is not given it defaults to LIBRARY (the uppercase
  90. of the library argument). The uselib_store argument will be passed to
  91. check which means LIB_LIBRARY, CFLAGS_LIBRARY and DEFINES_LIBRARY, etc.
  92. will be defined if the option is enabled.
  93. """
  94. if not uselib_store:
  95. uselib_store = library.upper().replace('-', '_')
  96. self.libs.append([library, uselib_store])
  97. def add_header(self, header):
  98. """
  99. Add a required header that should be checked during configuration. The
  100. header will be checked using the conf.check function which means
  101. HAVE_HEADER_H will be defined if found.
  102. """
  103. self.headers.append(header)
  104. def add_package(self, package, uselib_store=None, atleast_version=None):
  105. """
  106. Add a required package that should be checked using pkg-config during
  107. configuration. The package will be checked using the conf.check_cfg
  108. function and the uselib_store and atleast_version will be passed to
  109. check_cfg. If uselib_store is None it defaults to PACKAGE (uppercase of
  110. the package argument) with hyphens and dots replaced with underscores.
  111. If atleast_version is None it defaults to '0'.
  112. """
  113. if not uselib_store:
  114. uselib_store = package.upper().replace('-', '_').replace('.', '_')
  115. if not atleast_version:
  116. atleast_version = '0'
  117. self.packages.append([package, uselib_store, atleast_version])
  118. def add_program(self, program, var=None):
  119. """
  120. Add a required program that should be checked during configuration. If
  121. var is not given it defaults to PROGRAM (the uppercase of the program
  122. argument). If the option is enabled the program is saved as a list (?!)
  123. in conf.env['PROGRAM'].
  124. """
  125. if not var:
  126. var = program.upper().replace('-', '_')
  127. self.programs.append([program, var])
  128. def set_check_hook(self, check_hook, check_hook_error):
  129. """
  130. Set the check hook and the corresponding error printing function to the
  131. configure step. The check_hook argument is a function that should return
  132. True if the extra prerequisites were found and False if not. The
  133. check_hook_error argument is an error printing function that should
  134. print an error message telling the user that --foo was explicitly
  135. requested but cannot be built since the extra prerequisites were not
  136. found. Both function should take a single argument that is the waf
  137. configuration context.
  138. """
  139. self.check_hook = check_hook
  140. self.check_hook_error = check_hook_error
  141. def _check(self, conf):
  142. """
  143. This is an internal function that runs all necessary configure checks.
  144. It checks all dependencies (even if some dependency was not found) so
  145. that the user can install all missing dependencies in one go, instead
  146. of playing the infamous hit-configure-hit-configure game.
  147. This function returns True if all dependencies were found and False if
  148. not.
  149. """
  150. all_found = True
  151. # Use-variables that should be used when checking libraries, headers and
  152. # programs. The list will be populated when looking for packages.
  153. use = []
  154. # check for packages
  155. for package,uselib_store,atleast_version in self.packages:
  156. try:
  157. conf.check_cfg(package=package, uselib_store=uselib_store, atleast_version=atleast_version, args='--cflags --libs')
  158. use.append(uselib_store)
  159. except conf.errors.ConfigurationError:
  160. all_found = False
  161. self.packages_not_found.append([package,atleast_version])
  162. # check for libraries
  163. for lib,uselib_store in self.libs:
  164. try:
  165. conf.check(lib=lib, uselib_store=uselib_store, use=use)
  166. except conf.errors.ConfigurationError:
  167. all_found = False
  168. self.libs_not_found.append(lib)
  169. # check for headers
  170. for header in self.headers:
  171. try:
  172. conf.check(header_name=header, use=use)
  173. except conf.errors.ConfigurationError:
  174. all_found = False
  175. self.headers_not_found.append(header)
  176. # check for programs
  177. for program,var in self.programs:
  178. try:
  179. conf.find_program(program, var=var, use=use)
  180. except conf.errors.ConfigurationError:
  181. all_found = False
  182. self.programs_not_found.append(program)
  183. # call hook (if specified)
  184. if self.check_hook:
  185. self.check_hook_found = self.check_hook(conf)
  186. if not self.check_hook_found:
  187. all_found = False
  188. return all_found
  189. def _configure_error(self, conf):
  190. """
  191. This is an internal function that prints errors for each missing
  192. dependency. The error messages tell the user that this option required
  193. some dependency, but it cannot be found.
  194. """
  195. for lib in self.libs_not_found:
  196. print_error('%s requires the %s library, but it cannot be found.' % (self.option, lib))
  197. for header in self.headers_not_found:
  198. print_error('%s requires the %s header, but it cannot be found.' % (self.option, header))
  199. for package,atleast_version in self.packages_not_found:
  200. string = package
  201. if atleast_version:
  202. string += ' >= ' + atleast_version
  203. print_error('%s requires the package %s, but it cannot be found.' % (self.option, string))
  204. for program in self.programs_not_found:
  205. print_error('%s requires the %s program, but it cannot be found.' % (self.option, program))
  206. if not self.check_hook_found:
  207. self.check_hook_error(conf)
  208. def configure(self, conf):
  209. """
  210. This function configures the option examining the argument given too
  211. --foo (where foo is this option). This function sets self.result to the
  212. result of the configuration; True if the option should be enabled or
  213. False if not. If not all dependencies were found self.result will shall
  214. be False. conf.env['NAME'] will be set to the same value aswell as a
  215. preprocessor symbol will be defined according to the result.
  216. If --foo[=yes] was given, but some dependency was not found an error
  217. message is printed (foreach missing dependency).
  218. This function returns True on success and False on error.
  219. """
  220. argument = getattr(Options.options, self.dest)
  221. if argument == 'no':
  222. self.result = False
  223. retvalue = True
  224. elif argument == 'yes':
  225. if self._check(conf):
  226. self.result = True
  227. retvalue = True
  228. else:
  229. self.result = False
  230. retvalue = False
  231. self._configure_error(conf)
  232. elif argument == 'auto':
  233. self.result = self._check(conf)
  234. retvalue = True
  235. else:
  236. print_error('Invalid argument "' + argument + '" to ' + self.option)
  237. self.result = False
  238. retvalue = False
  239. conf.env[self.conf_dest] = self.result
  240. if self.result:
  241. conf.define(self.define, 1)
  242. else:
  243. conf.define(self.define, 0)
  244. return retvalue
  245. def display_message(self, conf):
  246. """
  247. This function displays a result message with the help text and the
  248. result of the configuration.
  249. """
  250. display_feature(conf, self.help, self.result)
  251. # This function adds an option to the list of auto options and returns the newly
  252. # created option.
  253. def add_auto_option(opt, name, help, conf_dest=None, define=None):
  254. option = AutoOption(opt, name, help, conf_dest=conf_dest, define=define)
  255. auto_options.append(option)
  256. return option
  257. # This function applies a hack that for each auto option --foo=no|yes replaces
  258. # any occurence --foo in argv with --foo=yes, in effect interpreting --foo as
  259. # --foo=yes. The function has to be called before waf issues the option parser,
  260. # i.e. before the configure phase.
  261. def auto_options_argv_hack():
  262. for option in auto_options:
  263. for x in range(1, len(sys.argv)):
  264. if sys.argv[x] == option.option:
  265. sys.argv[x] += '=yes'
  266. # This function configures all auto options. It stops waf and prints an error
  267. # message if there were unsatisfied requirements.
  268. def configure_auto_options(conf):
  269. ok = True
  270. for option in auto_options:
  271. if not option.configure(conf):
  272. ok = False
  273. if not ok:
  274. conf.fatal('There were unsatisfied requirements.')
  275. # This function displays all options and the configuration results.
  276. def display_auto_options_messages(conf):
  277. for option in auto_options:
  278. option.display_message(conf)
  279. def check_for_celt(conf):
  280. found = False
  281. for version in ['11', '8', '7', '5']:
  282. define = 'HAVE_CELT_API_0_' + version
  283. if not found:
  284. try:
  285. conf.check_cfg(package='celt', atleast_version='0.' + version + '.0', args='--cflags --libs')
  286. found = True
  287. conf.define(define, 1)
  288. continue
  289. except conf.errors.ConfigurationError:
  290. pass
  291. conf.define(define, 0)
  292. return found
  293. def check_for_celt_error(conf):
  294. print_error('--celt requires the package celt, but it could not be found.')
  295. # The readline/readline.h header does not work if stdio.h is not included
  296. # before. Thus a fragment with both stdio.h and readline/readline.h need to be
  297. # test-compiled to find out whether readline is available.
  298. def check_for_readline(conf):
  299. # FIXME: This check can be incorporated into the AutoOptions class by
  300. # passing header_name=['stdio.h', 'readline/readline.h'] to check.
  301. try:
  302. conf.check(fragment='''
  303. #include <stdio.h>
  304. #include <readline/readline.h>
  305. int main(void) { return 0; }''',
  306. execute=False,
  307. msg='Checking for header readline/readline.h',
  308. errmsg='not found')
  309. return True
  310. except conf.errors.ConfigurationError:
  311. return False
  312. def check_for_readline_error(conf):
  313. print_error('--readline requires the readline/readline.h header, but it cannot be found.')
  314. def check_for_mmsystem(conf):
  315. # FIXME: See comment in check_for_readline.
  316. try:
  317. conf.check(fragment='''
  318. #include <windows.h>
  319. #include <mmsystem.h>
  320. int main(void) { return 0; }''',
  321. execute=False,
  322. msg='Checking for header mmsystem.h',
  323. errmsg='not found')
  324. return True
  325. except conf.errors.ConfigurationError:
  326. return False
  327. def check_for_mmsystem_error(conf):
  328. print_error('--winmme requires the mmsystem.h header, but it cannot be found.')
  329. def options(opt):
  330. # options provided by the modules
  331. opt.load('compiler_cxx')
  332. opt.load('compiler_c')
  333. opt.load('xcode')
  334. opt.load('xcode6')
  335. # install directories
  336. opt.add_option('--htmldir', type='string', default=None, help='HTML documentation directory [Default: <prefix>/share/jack-audio-connection-kit/reference/html/')
  337. opt.add_option('--libdir', type='string', help='Library directory [Default: <prefix>/lib]')
  338. opt.add_option('--libdir32', type='string', help='32bit Library directory [Default: <prefix>/lib32]')
  339. opt.add_option('--mandir', type='string', help='Manpage directory [Default: <prefix>/share/man/man1]')
  340. # options affecting binaries
  341. opt.add_option('--platform', type='string', default=sys.platform, help='Target platform for cross-compiling, e.g. cygwin or win32')
  342. opt.add_option('--mixed', action='store_true', default=False, help='Build with 32/64 bits mixed mode')
  343. opt.add_option('--debug', action='store_true', default=False, dest='debug', help='Build debuggable binaries')
  344. # options affecting general jack functionality
  345. opt.add_option('--classic', action='store_true', default=False, help='Force enable standard JACK (jackd) even if D-Bus JACK (jackdbus) is enabled too')
  346. opt.add_option('--dbus', action='store_true', default=False, help='Enable D-Bus JACK (jackdbus)')
  347. opt.add_option('--autostart', type='string', default='default', help='Autostart method. Possible values: "default", "classic", "dbus", "none"')
  348. opt.add_option('--profile', action='store_true', default=False, help='Build with engine profiling')
  349. opt.add_option('--clients', default=64, type='int', dest='clients', help='Maximum number of JACK clients')
  350. opt.add_option('--ports-per-application', default=768, type='int', dest='application_ports', help='Maximum number of ports per application')
  351. # options with third party dependencies
  352. doxygen = add_auto_option(opt, 'doxygen', help='Build doxygen documentation', conf_dest='BUILD_DOXYGEN_DOCS')
  353. doxygen.add_program('doxygen')
  354. alsa = add_auto_option(opt, 'alsa', help='Enable ALSA driver', conf_dest='BUILD_DRIVER_ALSA')
  355. alsa.add_package('alsa', atleast_version='1.0.18')
  356. firewire = add_auto_option(opt, 'firewire', help='Enable FireWire driver (FFADO)', conf_dest='BUILD_DRIVER_FFADO')
  357. firewire.add_package('libffado', atleast_version='1.999.17')
  358. freebob = add_auto_option(opt, 'freebob', help='Enable FreeBob driver')
  359. freebob.add_package('libfreebob', atleast_version='1.0.0')
  360. iio = add_auto_option(opt, 'iio', help='Enable IIO driver', conf_dest='BUILD_DRIVER_IIO')
  361. iio.add_package('gtkIOStream', atleast_version='1.4.0')
  362. iio.add_package('eigen3', atleast_version='3.1.2')
  363. portaudio = add_auto_option(opt, 'portaudio', help='Enable Portaudio driver', conf_dest='BUILD_DRIVER_PORTAUDIO')
  364. portaudio.add_header('windows.h') # only build portaudio on windows
  365. portaudio.add_package('portaudio-2.0', uselib_store='PORTAUDIO', atleast_version='19')
  366. winmme = add_auto_option(opt, 'winmme', help='Enable WinMME driver', conf_dest='BUILD_DRIVER_WINMME')
  367. winmme.set_check_hook(check_for_mmsystem, check_for_mmsystem_error)
  368. celt = add_auto_option(opt, 'celt', help='Build with CELT')
  369. celt.set_check_hook(check_for_celt, check_for_celt_error)
  370. opus = add_auto_option(opt, 'opus', help='Build Opus netjack2')
  371. opus.add_header('opus/opus_custom.h')
  372. opus.add_package('opus', atleast_version='0.9.0')
  373. samplerate = add_auto_option(opt, 'samplerate', help='Build with libsamplerate')
  374. samplerate.add_package('samplerate')
  375. sndfile = add_auto_option(opt, 'sndfile', help='Build with libsndfile')
  376. sndfile.add_package('sndfile')
  377. readline = add_auto_option(opt, 'readline', help='Build with readline')
  378. readline.add_library('readline')
  379. readline.set_check_hook(check_for_readline, check_for_readline_error)
  380. # dbus options
  381. opt.recurse('dbus')
  382. # this must be called before the configure phase
  383. auto_options_argv_hack()
  384. def detect_platform(conf):
  385. # GNU/kFreeBSD and GNU/Hurd are treated as Linux
  386. platforms = [
  387. # ('KEY, 'Human readable name', ['strings', 'to', 'check', 'for'])
  388. ('IS_LINUX', 'Linux', ['gnu0', 'gnukfreebsd', 'linux', 'posix']),
  389. ('IS_MACOSX', 'MacOS X', ['darwin']),
  390. ('IS_SUN', 'SunOS', ['sunos']),
  391. ('IS_WINDOWS', 'Windows', ['cygwin', 'msys', 'win32'])
  392. ]
  393. for key,name,strings in platforms:
  394. conf.env[key] = False
  395. conf.start_msg('Checking platform')
  396. platform = Options.options.platform
  397. for key,name,strings in platforms:
  398. for s in strings:
  399. if platform.startswith(s):
  400. conf.env[key] = True
  401. conf.end_msg(name, color='CYAN')
  402. break
  403. def configure(conf):
  404. conf.load('compiler_cxx')
  405. conf.load('compiler_c')
  406. detect_platform(conf)
  407. if conf.env['IS_WINDOWS']:
  408. conf.env.append_unique('CCDEFINES', '_POSIX')
  409. conf.env.append_unique('CXXDEFINES', '_POSIX')
  410. conf.env.append_unique('CXXFLAGS', '-Wall')
  411. conf.env.append_unique('CFLAGS', '-Wall')
  412. if conf.env['IS_MACOSX']:
  413. conf.check(lib='aften', uselib='AFTEN', define_name='AFTEN')
  414. # configure all auto options
  415. configure_auto_options(conf)
  416. # Check for functions.
  417. conf.check(
  418. function_name='ppoll',
  419. header_name=['poll.h', 'signal.h'],
  420. defines=['_GNU_SOURCE'],
  421. mandatory=False)
  422. # Check for backtrace support
  423. conf.check(
  424. header_name='execinfo.h',
  425. define_name='HAVE_EXECINFO_H',
  426. mandatory=False)
  427. conf.recurse('common')
  428. if Options.options.dbus:
  429. conf.recurse('dbus')
  430. if conf.env['BUILD_JACKDBUS'] != True:
  431. conf.fatal('jackdbus was explicitly requested but cannot be built')
  432. conf.recurse('example-clients')
  433. # test for the availability of ucontext, and how it should be used
  434. for t in ['gp_regs', 'uc_regs', 'mc_gregs', 'gregs']:
  435. fragment = '#include <ucontext.h>\n'
  436. fragment += 'int main() { ucontext_t *ucontext; return (int) ucontext->uc_mcontext.%s[0]; }' % t
  437. confvar = 'HAVE_UCONTEXT_%s' % t.upper()
  438. conf.check_cc(fragment=fragment, define_name=confvar, mandatory=False,
  439. msg='Checking for ucontext->uc_mcontext.%s' % t)
  440. if conf.is_defined(confvar):
  441. conf.define('HAVE_UCONTEXT', 1)
  442. fragment = '#include <ucontext.h>\n'
  443. fragment += 'int main() { return NGREG; }'
  444. conf.check_cc(fragment=fragment, define_name='HAVE_NGREG', mandatory=False,
  445. msg='Checking for NGREG')
  446. conf.env['LIB_PTHREAD'] = ['pthread']
  447. conf.env['LIB_DL'] = ['dl']
  448. conf.env['LIB_RT'] = ['rt']
  449. conf.env['LIB_M'] = ['m']
  450. conf.env['LIB_STDC++'] = ['stdc++']
  451. conf.env['JACK_API_VERSION'] = JACK_API_VERSION
  452. conf.env['JACK_VERSION'] = VERSION
  453. conf.env['BUILD_WITH_PROFILE'] = Options.options.profile
  454. conf.env['BUILD_WITH_32_64'] = Options.options.mixed
  455. conf.env['BUILD_CLASSIC'] = Options.options.classic
  456. conf.env['BUILD_DEBUG'] = Options.options.debug
  457. if conf.env['BUILD_JACKDBUS']:
  458. conf.env['BUILD_JACKD'] = conf.env['BUILD_CLASSIC']
  459. else:
  460. conf.env['BUILD_JACKD'] = True
  461. conf.env['BINDIR'] = conf.env['PREFIX'] + '/bin'
  462. if Options.options.htmldir:
  463. conf.env['HTMLDIR'] = Options.options.htmldir
  464. else:
  465. # set to None here so that the doxygen code can find out the highest
  466. # directory to remove upon install
  467. conf.env['HTMLDIR'] = None
  468. if Options.options.libdir:
  469. conf.env['LIBDIR'] = Options.options.libdir
  470. else:
  471. conf.env['LIBDIR'] = conf.env['PREFIX'] + '/lib'
  472. if Options.options.mandir:
  473. conf.env['MANDIR'] = Options.options.mandir
  474. else:
  475. conf.env['MANDIR'] = conf.env['PREFIX'] + '/share/man/man1'
  476. if conf.env['BUILD_DEBUG']:
  477. conf.env.append_unique('CXXFLAGS', '-g')
  478. conf.env.append_unique('CFLAGS', '-g')
  479. conf.env.append_unique('LINKFLAGS', '-g')
  480. if not Options.options.autostart in ['default', 'classic', 'dbus' 'none']:
  481. conf.fatal('Invalid autostart value "' + Options.options.autostart + '"')
  482. if Options.options.autostart == 'default':
  483. if conf.env['BUILD_JACKD']:
  484. conf.env['AUTOSTART_METHOD'] = 'classic'
  485. else:
  486. conf.env['AUTOSTART_METHOD'] = 'dbus'
  487. else:
  488. conf.env['AUTOSTART_METHOD'] = Options.options.autostart
  489. if conf.env['AUTOSTART_METHOD'] == 'dbus' and not conf.env['BUILD_JACKDBUS']:
  490. conf.fatal('D-Bus autostart mode was specified but jackdbus will not be built')
  491. if conf.env['AUTOSTART_METHOD'] == 'classic' and not conf.env['BUILD_JACKD']:
  492. conf.fatal('Classic autostart mode was specified but jackd will not be built')
  493. if conf.env['AUTOSTART_METHOD'] == 'dbus':
  494. conf.define('USE_LIBDBUS_AUTOLAUNCH', 1)
  495. elif conf.env['AUTOSTART_METHOD'] == 'classic':
  496. conf.define('USE_CLASSIC_AUTOLAUNCH', 1)
  497. conf.define('CLIENT_NUM', Options.options.clients)
  498. conf.define('PORT_NUM_FOR_CLIENT', Options.options.application_ports)
  499. if conf.env['IS_WINDOWS']:
  500. # we define this in the environment to maintain compatability with
  501. # existing install paths that use ADDON_DIR rather than have to
  502. # have special cases for windows each time.
  503. conf.env['ADDON_DIR'] = conf.env['BINDIR'] + '/jack'
  504. # don't define ADDON_DIR in config.h, use the default 'jack' defined in
  505. # windows/JackPlatformPlug_os.h
  506. else:
  507. conf.env['ADDON_DIR'] = os.path.normpath(os.path.join(conf.env['LIBDIR'], 'jack'))
  508. conf.define('ADDON_DIR', conf.env['ADDON_DIR'])
  509. conf.define('JACK_LOCATION', os.path.normpath(os.path.join(conf.env['PREFIX'], 'bin')))
  510. if not conf.env['IS_WINDOWS']:
  511. conf.define('USE_POSIX_SHM', 1)
  512. conf.define('JACKMP', 1)
  513. if conf.env['BUILD_JACKDBUS']:
  514. conf.define('JACK_DBUS', 1)
  515. if conf.env['BUILD_WITH_PROFILE']:
  516. conf.define('JACK_MONITOR', 1)
  517. conf.write_config_header('config.h', remove=False)
  518. svnrev = None
  519. try:
  520. f = open('svnversion.h')
  521. data = f.read()
  522. m = re.match(r'^#define SVN_VERSION "([^"]*)"$', data)
  523. if m != None:
  524. svnrev = m.group(1)
  525. f.close()
  526. except IOError:
  527. pass
  528. if Options.options.mixed:
  529. conf.setenv(lib32, env=conf.env.derive())
  530. conf.env.append_unique('CXXFLAGS', '-m32')
  531. conf.env.append_unique('CFLAGS', '-m32')
  532. conf.env.append_unique('LINKFLAGS', '-m32')
  533. if Options.options.libdir32:
  534. conf.env['LIBDIR'] = Options.options.libdir32
  535. else:
  536. conf.env['LIBDIR'] = conf.env['PREFIX'] + '/lib32'
  537. conf.write_config_header('config.h')
  538. print()
  539. print('==================')
  540. version_msg = 'JACK ' + VERSION
  541. if svnrev:
  542. version_msg += ' exported from r' + svnrev
  543. else:
  544. version_msg += ' svn revision will checked and eventually updated during build'
  545. print(version_msg)
  546. conf.msg('Maximum JACK clients', Options.options.clients, color='NORMAL')
  547. conf.msg('Maximum ports per application', Options.options.application_ports, color='NORMAL')
  548. conf.msg('Install prefix', conf.env['PREFIX'], color='CYAN')
  549. conf.msg('Library directory', conf.all_envs['']['LIBDIR'], color='CYAN')
  550. if conf.env['BUILD_WITH_32_64']:
  551. conf.msg('32-bit library directory', conf.all_envs[lib32]['LIBDIR'], color='CYAN')
  552. conf.msg('Drivers directory', conf.env['ADDON_DIR'], color='CYAN')
  553. display_feature(conf, 'Build debuggable binaries', conf.env['BUILD_DEBUG'])
  554. tool_flags = [
  555. ('C compiler flags', ['CFLAGS', 'CPPFLAGS']),
  556. ('C++ compiler flags', ['CXXFLAGS', 'CPPFLAGS']),
  557. ('Linker flags', ['LINKFLAGS', 'LDFLAGS'])
  558. ]
  559. for name,vars in tool_flags:
  560. flags = []
  561. for var in vars:
  562. flags += conf.all_envs[''][var]
  563. conf.msg(name, repr(flags), color='NORMAL')
  564. if conf.env['BUILD_WITH_32_64']:
  565. conf.msg('32-bit C compiler flags', repr(conf.all_envs[lib32]['CFLAGS']))
  566. conf.msg('32-bit C++ compiler flags', repr(conf.all_envs[lib32]['CXXFLAGS']))
  567. conf.msg('32-bit linker flags', repr(conf.all_envs[lib32]['LINKFLAGS']))
  568. display_feature(conf, 'Build with engine profiling', conf.env['BUILD_WITH_PROFILE'])
  569. display_feature(conf, 'Build with 32/64 bits mixed mode', conf.env['BUILD_WITH_32_64'])
  570. display_feature(conf, 'Build standard JACK (jackd)', conf.env['BUILD_JACKD'])
  571. display_feature(conf, 'Build D-Bus JACK (jackdbus)', conf.env['BUILD_JACKDBUS'])
  572. conf.msg('Autostart method', conf.env['AUTOSTART_METHOD'])
  573. if conf.env['BUILD_JACKDBUS'] and conf.env['BUILD_JACKD']:
  574. print(Logs.colors.RED + 'WARNING !! mixing both jackd and jackdbus may cause issues:' + Logs.colors.NORMAL)
  575. print(Logs.colors.RED + 'WARNING !! jackdbus does not use .jackdrc nor qjackctl settings' + Logs.colors.NORMAL)
  576. # display configuration result messages for auto options
  577. display_auto_options_messages(conf)
  578. if conf.env['BUILD_JACKDBUS']:
  579. conf.msg('D-Bus service install directory', conf.env['DBUS_SERVICES_DIR'], color='CYAN')
  580. if conf.env['DBUS_SERVICES_DIR'] != conf.env['DBUS_SERVICES_DIR_REAL']:
  581. print()
  582. print(Logs.colors.RED + 'WARNING: D-Bus session services directory as reported by pkg-config is')
  583. print(Logs.colors.RED + 'WARNING:', end=' ')
  584. print(Logs.colors.CYAN + conf.env['DBUS_SERVICES_DIR_REAL'])
  585. print(Logs.colors.RED + 'WARNING: but service file will be installed in')
  586. print(Logs.colors.RED + 'WARNING:', end=' ')
  587. print(Logs.colors.CYAN + conf.env['DBUS_SERVICES_DIR'])
  588. print(Logs.colors.RED + 'WARNING: You may need to adjust your D-Bus configuration after installing jackdbus')
  589. print('WARNING: You can override dbus service install directory')
  590. print('WARNING: with --enable-pkg-config-dbus-service-dir option to this script')
  591. print(Logs.colors.NORMAL, end=' ')
  592. print()
  593. def init(ctx):
  594. for y in (BuildContext, CleanContext, InstallContext, UninstallContext):
  595. name = y.__name__.replace('Context','').lower()
  596. class tmp(y):
  597. cmd = name + '_' + lib32
  598. variant = lib32
  599. def obj_add_includes(bld, obj):
  600. if bld.env['BUILD_JACKDBUS']:
  601. obj.includes += ['dbus']
  602. if bld.env['IS_LINUX']:
  603. obj.includes += ['linux', 'posix']
  604. if bld.env['IS_MACOSX']:
  605. obj.includes += ['macosx', 'posix']
  606. if bld.env['IS_SUN']:
  607. obj.includes += ['posix', 'solaris']
  608. if bld.env['IS_WINDOWS']:
  609. obj.includes += ['windows']
  610. # FIXME: Is SERVER_SIDE needed?
  611. def build_jackd(bld):
  612. jackd = bld(
  613. features = ['cxx', 'cxxprogram'],
  614. defines = ['HAVE_CONFIG_H','SERVER_SIDE'],
  615. includes = ['.', 'common', 'common/jack'],
  616. target = 'jackd',
  617. source = ['common/Jackdmp.cpp'],
  618. use = ['serverlib']
  619. )
  620. if bld.env['BUILD_JACKDBUS']:
  621. jackd.source += ['dbus/audio_reserve.c', 'dbus/reserve.c']
  622. jackd.use += ['DBUS-1']
  623. if bld.env['IS_LINUX']:
  624. jackd.use += ['DL', 'M', 'PTHREAD', 'RT', 'STDC++']
  625. if bld.env['IS_MACOSX']:
  626. jackd.use += ['DL', 'PTHREAD']
  627. jackd.framework = ['CoreFoundation']
  628. if bld.env['IS_SUN']:
  629. jackd.use += ['DL', 'PTHREAD']
  630. obj_add_includes(bld, jackd)
  631. return jackd
  632. # FIXME: Is SERVER_SIDE needed?
  633. def create_driver_obj(bld, **kw):
  634. if bld.env['IS_MACOSX'] or bld.env['IS_WINDOWS']:
  635. # On MacOSX this is necessary.
  636. # I do not know if this is necessary on Windows.
  637. # Note added on 2015-12-13 by lilrc.
  638. if 'use' in kw:
  639. kw['use'] += ['serverlib']
  640. else:
  641. kw['use'] = ['serverlib']
  642. driver = bld(
  643. features = ['c', 'cxx', 'cshlib', 'cxxshlib'],
  644. defines = ['HAVE_CONFIG_H', 'SERVER_SIDE'],
  645. includes = ['.', 'common', 'common/jack'],
  646. install_path = '${ADDON_DIR}/',
  647. **kw)
  648. if bld.env['IS_WINDOWS']:
  649. driver.env['cxxshlib_PATTERN'] = 'jack_%s.dll'
  650. else:
  651. driver.env['cxxshlib_PATTERN'] = 'jack_%s.so'
  652. obj_add_includes(bld, driver)
  653. return driver
  654. def build_drivers(bld):
  655. # Non-hardware driver sources. Lexically sorted.
  656. dummy_src = [
  657. 'common/JackDummyDriver.cpp'
  658. ]
  659. loopback_src = [
  660. 'common/JackLoopbackDriver.cpp'
  661. ]
  662. net_src = [
  663. 'common/JackNetDriver.cpp'
  664. ]
  665. netone_src = [
  666. 'common/JackNetOneDriver.cpp',
  667. 'common/netjack.c',
  668. 'common/netjack_packet.c'
  669. ]
  670. proxy_src = [
  671. 'common/JackProxyDriver.cpp'
  672. ]
  673. # Hardware driver sources. Lexically sorted.
  674. alsa_src = [
  675. 'common/memops.c',
  676. 'linux/alsa/JackAlsaDriver.cpp',
  677. 'linux/alsa/alsa_rawmidi.c',
  678. 'linux/alsa/alsa_seqmidi.c',
  679. 'linux/alsa/alsa_midi_jackmp.cpp',
  680. 'linux/alsa/generic_hw.c',
  681. 'linux/alsa/hdsp.c',
  682. 'linux/alsa/alsa_driver.c',
  683. 'linux/alsa/hammerfall.c',
  684. 'linux/alsa/ice1712.c'
  685. ]
  686. alsarawmidi_src = [
  687. 'linux/alsarawmidi/JackALSARawMidiDriver.cpp',
  688. 'linux/alsarawmidi/JackALSARawMidiInputPort.cpp',
  689. 'linux/alsarawmidi/JackALSARawMidiOutputPort.cpp',
  690. 'linux/alsarawmidi/JackALSARawMidiPort.cpp',
  691. 'linux/alsarawmidi/JackALSARawMidiReceiveQueue.cpp',
  692. 'linux/alsarawmidi/JackALSARawMidiSendQueue.cpp',
  693. 'linux/alsarawmidi/JackALSARawMidiUtil.cpp'
  694. ]
  695. boomer_src = [
  696. 'common/memops.c',
  697. 'solaris/oss/JackBoomerDriver.cpp'
  698. ]
  699. coreaudio_src = [
  700. 'macosx/coreaudio/JackCoreAudioDriver.mm',
  701. 'common/JackAC3Encoder.cpp'
  702. ]
  703. coremidi_src = [
  704. 'macosx/coremidi/JackCoreMidiInputPort.mm',
  705. 'macosx/coremidi/JackCoreMidiOutputPort.mm',
  706. 'macosx/coremidi/JackCoreMidiPhysicalInputPort.mm',
  707. 'macosx/coremidi/JackCoreMidiPhysicalOutputPort.mm',
  708. 'macosx/coremidi/JackCoreMidiVirtualInputPort.mm',
  709. 'macosx/coremidi/JackCoreMidiVirtualOutputPort.mm',
  710. 'macosx/coremidi/JackCoreMidiPort.mm',
  711. 'macosx/coremidi/JackCoreMidiUtil.mm',
  712. 'macosx/coremidi/JackCoreMidiDriver.mm'
  713. ]
  714. ffado_src = [
  715. 'linux/firewire/JackFFADODriver.cpp',
  716. 'linux/firewire/JackFFADOMidiInputPort.cpp',
  717. 'linux/firewire/JackFFADOMidiOutputPort.cpp',
  718. 'linux/firewire/JackFFADOMidiReceiveQueue.cpp',
  719. 'linux/firewire/JackFFADOMidiSendQueue.cpp'
  720. ]
  721. freebob_src = [
  722. 'linux/freebob/JackFreebobDriver.cpp'
  723. ]
  724. iio_driver_src = [
  725. 'linux/iio/JackIIODriver.cpp'
  726. ]
  727. oss_src = [
  728. 'common/memops.c',
  729. 'solaris/oss/JackOSSDriver.cpp'
  730. ]
  731. portaudio_src = [
  732. 'windows/portaudio/JackPortAudioDevices.cpp',
  733. 'windows/portaudio/JackPortAudioDriver.cpp',
  734. ]
  735. winmme_src = [
  736. 'windows/winmme/JackWinMMEDriver.cpp',
  737. 'windows/winmme/JackWinMMEInputPort.cpp',
  738. 'windows/winmme/JackWinMMEOutputPort.cpp',
  739. 'windows/winmme/JackWinMMEPort.cpp',
  740. ]
  741. # Create non-hardware driver objects. Lexically sorted.
  742. create_driver_obj(
  743. bld,
  744. target = 'dummy',
  745. source = dummy_src)
  746. create_driver_obj(
  747. bld,
  748. target = 'loopback',
  749. source = loopback_src)
  750. create_driver_obj(
  751. bld,
  752. target = 'net',
  753. source = net_src)
  754. create_driver_obj(
  755. bld,
  756. target = 'netone',
  757. source = netone_src,
  758. use = ['SAMPLERATE', 'CELT'])
  759. create_driver_obj(
  760. bld,
  761. target = 'proxy',
  762. source = proxy_src)
  763. # Create hardware driver objects. Lexically sorted after the conditional,
  764. # e.g. BUILD_DRIVER_ALSA.
  765. if bld.env['BUILD_DRIVER_ALSA']:
  766. create_driver_obj(
  767. bld,
  768. target = 'alsa',
  769. source = alsa_src,
  770. use = ['ALSA'])
  771. create_driver_obj(
  772. bld,
  773. target = 'alsarawmidi',
  774. source = alsarawmidi_src,
  775. use = ['ALSA'])
  776. if bld.env['BUILD_DRIVER_FREEBOB']:
  777. create_driver_obj(
  778. bld,
  779. target = 'freebob',
  780. source = freebob_src,
  781. use = ['LIBFREEBOB'])
  782. if bld.env['BUILD_DRIVER_FFADO']:
  783. create_driver_obj(
  784. bld,
  785. target = 'firewire',
  786. source = ffado_src,
  787. use = ['LIBFFADO'])
  788. if bld.env['BUILD_DRIVER_IIO']:
  789. create_driver_obj(
  790. bld,
  791. target = 'iio',
  792. source = iio_src,
  793. use = ['GTKIOSTREAM', 'EIGEN3'])
  794. if bld.env['BUILD_DRIVER_PORTAUDIO']:
  795. create_driver_obj(
  796. bld,
  797. target = 'portaudio',
  798. source = portaudio_src,
  799. use = ['PORTAUDIO'])
  800. if bld.env['BUILD_DRIVER_WINMME']:
  801. create_driver_obj(
  802. bld,
  803. target = 'winmme',
  804. source = winmme_src,
  805. use = ['WINMME'])
  806. if bld.env['IS_MACOSX']:
  807. create_driver_obj(
  808. bld,
  809. target = 'coreaudio',
  810. source = coreaudio_src,
  811. use = ['AFTEN'],
  812. framework = ['AudioUnit', 'CoreAudio', 'CoreServices'])
  813. create_driver_obj(
  814. bld,
  815. target = 'coremidi',
  816. source = coremidi_src,
  817. use = ['serverlib'], # FIXME: Is this needed?
  818. framework = ['AudioUnit', 'CoreMIDI', 'CoreServices', 'Foundation'])
  819. if bld.env['IS_SUN']:
  820. create_driver_obj(
  821. bld,
  822. target = 'boomer',
  823. source = boomer_src)
  824. create_driver_obj(
  825. bld,
  826. target = 'oss',
  827. source = oss_src)
  828. def build(bld):
  829. if not bld.variant and bld.env['BUILD_WITH_32_64']:
  830. Options.commands.append(bld.cmd + '_' + lib32)
  831. # process subfolders from here
  832. bld.recurse('common')
  833. if bld.variant:
  834. # only the wscript in common/ knows how to handle variants
  835. return
  836. if not os.access('svnversion.h', os.R_OK):
  837. def post_run(self):
  838. sg = Utils.h_file(self.outputs[0].abspath(self.env))
  839. #print sg.encode('hex')
  840. Build.bld.node_sigs[self.env.variant()][self.outputs[0].id] = sg
  841. script = bld.path.find_resource('svnversion_regenerate.sh')
  842. script = script.abspath()
  843. bld(
  844. rule = '%s ${TGT}' % script,
  845. name = 'svnversion',
  846. runnable_status = Task.RUN_ME,
  847. before = 'c cxx',
  848. color = 'BLUE',
  849. post_run = post_run,
  850. source = ['svnversion_regenerate.sh'],
  851. target = [bld.path.find_or_declare('svnversion.h')]
  852. )
  853. if bld.env['BUILD_JACKD']:
  854. build_jackd(bld)
  855. build_drivers(bld)
  856. bld.recurse('example-clients')
  857. if bld.env['IS_LINUX']:
  858. bld.recurse('man')
  859. if not bld.env['IS_WINDOWS']:
  860. bld.recurse('tests')
  861. if bld.env['BUILD_JACKDBUS']:
  862. bld.recurse('dbus')
  863. if bld.env['BUILD_DOXYGEN_DOCS']:
  864. html_build_dir = bld.path.find_or_declare('html').abspath()
  865. bld(
  866. features = 'subst',
  867. source = 'doxyfile.in',
  868. target = 'doxyfile',
  869. HTML_BUILD_DIR = html_build_dir,
  870. SRCDIR = bld.srcnode.abspath(),
  871. VERSION = VERSION
  872. )
  873. # There are two reasons for logging to doxygen.log and using it as
  874. # target in the build rule (rather than html_build_dir):
  875. # (1) reduce the noise when running the build
  876. # (2) waf has a regular file to check for a timestamp. If the directory
  877. # is used instead waf will rebuild the doxygen target (even upon
  878. # install).
  879. def doxygen(task):
  880. doxyfile = task.inputs[0].abspath()
  881. logfile = task.outputs[0].abspath()
  882. cmd = '%s %s &> %s' % (task.env['DOXYGEN'][0], doxyfile, logfile)
  883. return task.exec_command(cmd)
  884. bld(
  885. rule = doxygen,
  886. source = 'doxyfile',
  887. target = 'doxygen.log'
  888. )
  889. # Determine where to install HTML documentation. Since share_dir is the
  890. # highest directory the uninstall routine should remove, there is no
  891. # better candidate for share_dir, but the requested HTML directory if
  892. # --htmldir is given.
  893. if bld.env['HTMLDIR']:
  894. html_install_dir = bld.options.destdir + bld.env['HTMLDIR']
  895. share_dir = html_install_dir
  896. else:
  897. share_dir = bld.options.destdir + bld.env['PREFIX'] + '/share/jack-audio-connection-kit'
  898. html_install_dir = share_dir + '/reference/html/'
  899. if bld.cmd == 'install':
  900. if os.path.isdir(html_install_dir):
  901. Logs.pprint('CYAN', 'Removing old doxygen documentation installation...')
  902. shutil.rmtree(html_install_dir)
  903. Logs.pprint('CYAN', 'Removing old doxygen documentation installation done.')
  904. Logs.pprint('CYAN', 'Installing doxygen documentation...')
  905. shutil.copytree(html_build_dir, html_install_dir)
  906. Logs.pprint('CYAN', 'Installing doxygen documentation done.')
  907. elif bld.cmd =='uninstall':
  908. Logs.pprint('CYAN', 'Uninstalling doxygen documentation...')
  909. if os.path.isdir(share_dir):
  910. shutil.rmtree(share_dir)
  911. Logs.pprint('CYAN', 'Uninstalling doxygen documentation done.')
  912. elif bld.cmd =='clean':
  913. if os.access(html_build_dir, os.R_OK):
  914. Logs.pprint('CYAN', 'Removing doxygen generated documentation...')
  915. shutil.rmtree(html_build_dir)
  916. Logs.pprint('CYAN', 'Removing doxygen generated documentation done.')
  917. def dist(ctx):
  918. # This code blindly assumes it is working in the toplevel source directory.
  919. if not os.path.exists('svnversion.h'):
  920. os.system('./svnversion_regenerate.sh svnversion.h')
  921. from waflib import TaskGen
  922. @TaskGen.extension('.mm')
  923. def mm_hook(self, node):
  924. """Alias .mm files to be compiled the same as .cpp files, gcc will do the right thing."""
  925. return self.create_compiled_task('cxx', node)