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.

1114 lines
41KB

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