Audio plugin host https://kx.studio/carla
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.

379 lines
14KB

  1. #!/usr/bin/env python
  2. import os
  3. import sys
  4. import subprocess
  5. from waflib.extras import autowaf as autowaf
  6. import waflib.Options as Options
  7. # Version of this package (even if built as a child)
  8. LILV_VERSION = '0.14.4'
  9. LILV_MAJOR_VERSION = '0'
  10. # Library version (UNIX style major, minor, micro)
  11. # major increment <=> incompatible changes
  12. # minor increment <=> compatible changes (additions)
  13. # micro increment <=> no interface changes
  14. # Lilv uses the same version number for both library and package
  15. LILV_LIB_VERSION = LILV_VERSION
  16. # Variables for 'waf dist'
  17. APPNAME = 'lilv'
  18. VERSION = LILV_VERSION
  19. # Mandatory variables
  20. top = '.'
  21. out = 'build'
  22. def options(opt):
  23. opt.load('compiler_c')
  24. opt.load('compiler_cxx')
  25. opt.load('python')
  26. autowaf.set_options(opt)
  27. opt.add_option('--no-utils', action='store_true', dest='no_utils',
  28. help='Do not build command line utilities')
  29. opt.add_option('--bindings', action='store_true', dest='bindings',
  30. help='Build python bindings')
  31. opt.add_option('--dyn-manifest', action='store_true', dest='dyn_manifest',
  32. help='Build support for dynamic manifests')
  33. opt.add_option('--test', action='store_true', dest='build_tests',
  34. help='Build unit tests')
  35. opt.add_option('--no-bash-completion', action='store_true',
  36. dest='no_bash_completion',
  37. help='Do not install bash completion script in CONFIGDIR')
  38. opt.add_option('--static', action='store_true', dest='static',
  39. help='Build static library')
  40. opt.add_option('--no-shared', action='store_true', dest='no_shared',
  41. help='Do not build shared library')
  42. opt.add_option('--static-progs', action='store_true', dest='static_progs',
  43. help='Build programs as static binaries')
  44. opt.add_option('--default-lv2-path', type='string', default='',
  45. dest='default_lv2_path',
  46. help='Default LV2 path to use if LV2_PATH is unset')
  47. def configure(conf):
  48. conf.load('compiler_c')
  49. if Options.options.bindings:
  50. try:
  51. conf.load('swig')
  52. conf.load('python')
  53. conf.load('compiler_cxx')
  54. conf.check_python_headers()
  55. autowaf.define(conf, 'LILV_PYTHON', 1);
  56. except:
  57. pass
  58. autowaf.configure(conf)
  59. autowaf.set_c99_mode(conf)
  60. autowaf.display_header('Lilv Configuration')
  61. conf.env.BASH_COMPLETION = not Options.options.no_bash_completion
  62. conf.env.BUILD_TESTS = Options.options.build_tests
  63. conf.env.BUILD_UTILS = not Options.options.no_utils
  64. conf.env.BUILD_SHARED = not Options.options.no_shared
  65. conf.env.STATIC_PROGS = Options.options.static_progs
  66. conf.env.BUILD_STATIC = (Options.options.static or
  67. Options.options.static_progs)
  68. if not conf.env.BUILD_SHARED and not conf.env.BUILD_STATIC:
  69. conf.fatal('Neither a shared nor a static build requested')
  70. autowaf.check_pkg(conf, 'lv2', uselib_store='LV2',
  71. atleast_version='1.0.0', mandatory=True)
  72. autowaf.check_pkg(conf, 'serd-0', uselib_store='SERD',
  73. atleast_version='0.14.0', mandatory=True)
  74. autowaf.check_pkg(conf, 'sord-0', uselib_store='SORD',
  75. atleast_version='0.8.0', mandatory=True)
  76. autowaf.check_pkg(conf, 'sratom-0', uselib_store='SRATOM',
  77. atleast_version='0.2.0', mandatory=True)
  78. autowaf.define(conf, 'LILV_NEW_LV2', 1) # New LV2 discovery API
  79. defines = ['_POSIX_C_SOURCE', '_BSD_SOURCE']
  80. if Options.platform == 'darwin':
  81. defines += ['_DARWIN_C_SOURCE']
  82. # Check for gcov library (for test coverage)
  83. if conf.env.BUILD_TESTS:
  84. conf.check_cc(lib='gcov',
  85. define_name='HAVE_GCOV',
  86. mandatory=False)
  87. conf.check_cc(function_name='flock',
  88. header_name='sys/file.h',
  89. defines=defines,
  90. define_name='HAVE_FLOCK',
  91. mandatory=False)
  92. conf.check_cc(function_name='fileno',
  93. header_name='stdio.h',
  94. defines=defines,
  95. define_name='HAVE_FILENO',
  96. mandatory=False)
  97. conf.check_cc(function_name='clock_gettime',
  98. header_name=['sys/time.h','time.h'],
  99. defines=['_POSIX_C_SOURCE=199309L'],
  100. define_name='HAVE_CLOCK_GETTIME',
  101. uselib_store='CLOCK_GETTIME',
  102. lib=['rt'],
  103. mandatory=False)
  104. autowaf.define(conf, 'LILV_VERSION', LILV_VERSION)
  105. if Options.options.dyn_manifest:
  106. autowaf.define(conf, 'LILV_DYN_MANIFEST', 1)
  107. lilv_path_sep = ':'
  108. lilv_dir_sep = '/'
  109. if sys.platform == 'win32':
  110. lilv_path_sep = ';'
  111. lilv_dir_sep = '\\\\'
  112. autowaf.define(conf, 'LILV_PATH_SEP', lilv_path_sep)
  113. autowaf.define(conf, 'LILV_DIR_SEP', lilv_dir_sep)
  114. # Set default LV2 path
  115. lv2_path = Options.options.default_lv2_path
  116. if lv2_path == '':
  117. if Options.platform == 'darwin':
  118. lv2_path = lilv_path_sep.join(['~/Library/Audio/Plug-Ins/LV2',
  119. '~/.lv2',
  120. '/usr/local/lib/lv2',
  121. '/usr/lib/lv2',
  122. '/Library/Audio/Plug-Ins/LV2'])
  123. elif Options.platform == 'haiku':
  124. lv2_path = lilv_path_sep.join(['~/.lv2',
  125. '/boot/common/add-ons/lv2'])
  126. elif Options.platform == 'win32':
  127. lv2_path = lilv_path_sep.join(['%APPDATA%\\\\LV2',
  128. '%COMMONPROGRAMFILES%\\\\LV2'])
  129. else:
  130. libdirname = os.path.basename(conf.env.LIBDIR)
  131. lv2_path = lilv_path_sep.join(['~/.lv2',
  132. '/usr/%s/lv2' % libdirname,
  133. '/usr/local/%s/lv2' % libdirname])
  134. autowaf.define(conf, 'LILV_DEFAULT_LV2_PATH', lv2_path)
  135. conf.env.LIB_LILV = ['lilv-%s' % LILV_MAJOR_VERSION]
  136. conf.write_config_header('lilv_config.h', remove=False)
  137. autowaf.display_msg(conf, 'Default LV2_PATH',
  138. conf.env.LILV_DEFAULT_LV2_PATH)
  139. autowaf.display_msg(conf, 'Utilities',
  140. bool(conf.env.BUILD_UTILS))
  141. autowaf.display_msg(conf, 'Unit tests',
  142. bool(conf.env.BUILD_TESTS))
  143. autowaf.display_msg(conf, 'Dynamic manifest support',
  144. bool(conf.env.LILV_DYN_MANIFEST))
  145. autowaf.display_msg(conf, 'Python bindings',
  146. conf.is_defined('LILV_PYTHON'))
  147. conf.undefine('LILV_DEFAULT_LV2_PATH') # Cmd line errors with VC++
  148. print('')
  149. def build_util(bld, name, defines):
  150. obj = bld(features = 'c cprogram',
  151. source = name + '.c',
  152. includes = ['.', './src', './utils'],
  153. use = 'liblilv',
  154. target = name,
  155. defines = defines,
  156. install_path = '${BINDIR}')
  157. if not bld.env.BUILD_SHARED or bld.env.STATIC_PROGS:
  158. obj.use = 'liblilv_static'
  159. if bld.env.STATIC_PROGS:
  160. if not bld.env.MSVC_COMPILER:
  161. obj.lib = ['m']
  162. obj.env.SHLIB_MARKER = obj.env.STLIB_MARKER
  163. obj.linkflags = ['-static', '-Wl,--start-group']
  164. return obj
  165. def build(bld):
  166. # C/C++ Headers
  167. includedir = '${INCLUDEDIR}/lilv-%s/lilv' % LILV_MAJOR_VERSION
  168. bld.install_files(includedir, bld.path.ant_glob('lilv/*.h'))
  169. bld.install_files(includedir, bld.path.ant_glob('lilv/*.hpp'))
  170. # Pkgconfig file
  171. autowaf.build_pc(bld, 'LILV', LILV_VERSION, LILV_MAJOR_VERSION, [],
  172. {'LILV_MAJOR_VERSION' : LILV_MAJOR_VERSION,
  173. 'LILV_PKG_DEPS' : 'lv2 serd-0 sord-0 sratom-0'})
  174. lib_source = '''
  175. src/collections.c
  176. src/instance.c
  177. src/lib.c
  178. src/node.c
  179. src/plugin.c
  180. src/pluginclass.c
  181. src/port.c
  182. src/query.c
  183. src/scalepoint.c
  184. src/state.c
  185. src/ui.c
  186. src/util.c
  187. src/world.c
  188. src/zix/tree.c
  189. '''.split()
  190. lib = ['dl']
  191. libflags = ['-fvisibility=hidden']
  192. defines = []
  193. if sys.platform == 'win32':
  194. lib = []
  195. if bld.env.MSVC_COMPILER:
  196. libflags = []
  197. defines = ['snprintf=_snprintf']
  198. elif sys.platform.find('bsd') > 0:
  199. lib = []
  200. # Shared Library
  201. if bld.env.BUILD_SHARED:
  202. obj = bld(features = 'c cshlib',
  203. export_includes = ['.'],
  204. source = lib_source,
  205. includes = ['.', './src'],
  206. name = 'liblilv',
  207. target = 'lilv-%s' % LILV_MAJOR_VERSION,
  208. vnum = LILV_LIB_VERSION,
  209. install_path = '${LIBDIR}',
  210. defines = ['LILV_SHARED', 'LILV_INTERNAL'],
  211. cflags = libflags,
  212. lib = lib)
  213. autowaf.use_lib(bld, obj, 'SORD SRATOM LV2')
  214. # Static library
  215. if bld.env.BUILD_STATIC:
  216. obj = bld(features = 'c cstlib',
  217. export_includes = ['.'],
  218. source = lib_source,
  219. includes = ['.', './src'],
  220. name = 'liblilv_static',
  221. target = 'lilv-%s' % LILV_MAJOR_VERSION,
  222. vnum = LILV_LIB_VERSION,
  223. install_path = '${LIBDIR}',
  224. defines = defines + ['LILV_INTERNAL'])
  225. autowaf.use_lib(bld, obj, 'SORD SRATOM LV2')
  226. if bld.env.BUILD_TESTS:
  227. test_libs = lib
  228. test_cflags = ['']
  229. if bld.is_defined('HAVE_GCOV'):
  230. test_libs += ['gcov']
  231. test_cflags += ['-fprofile-arcs', '-ftest-coverage']
  232. # Test plugin library
  233. penv = bld.env.derive()
  234. shlib_pattern = penv.cshlib_PATTERN
  235. if shlib_pattern.startswith('lib'):
  236. shlib_pattern = shlib_pattern[3:]
  237. penv.cshlib_PATTERN = shlib_pattern
  238. shlib_ext = shlib_pattern[shlib_pattern.rfind('.'):]
  239. obj = bld(features = 'c cshlib',
  240. env = penv,
  241. source = 'test/test_plugin.c',
  242. name = 'test_plugin',
  243. target = 'test/test_plugin.lv2/test_plugin',
  244. install_path = None,
  245. defines = defines,
  246. cflags = test_cflags,
  247. lib = test_libs,
  248. uselib = 'LV2')
  249. # Test plugin data files
  250. for i in [ 'manifest.ttl.in', 'test_plugin.ttl.in' ]:
  251. bld(features = 'subst',
  252. source = 'test/' + i,
  253. target = 'test/test_plugin.lv2/' + i.replace('.in', ''),
  254. install_path = None,
  255. SHLIB_EXT = shlib_ext)
  256. # Static profiled library (for unit test code coverage)
  257. obj = bld(features = 'c cstlib',
  258. source = lib_source,
  259. includes = ['.', './src'],
  260. name = 'liblilv_profiled',
  261. target = 'lilv_profiled',
  262. install_path = None,
  263. defines = defines + ['LILV_INTERNAL'],
  264. cflags = test_cflags,
  265. lib = test_libs)
  266. autowaf.use_lib(bld, obj, 'SORD SRATOM LV2')
  267. # Unit test program
  268. bpath = os.path.abspath(os.path.join(out, 'test', 'test_plugin.lv2'))
  269. bpath = bpath.replace('\\', '/')
  270. obj = bld(features = 'c cprogram',
  271. source = 'test/lilv_test.c',
  272. includes = ['.', './src'],
  273. use = 'liblilv_profiled',
  274. uselib = 'SORD LV2',
  275. lib = test_libs,
  276. target = 'test/lilv_test',
  277. install_path = None,
  278. defines = defines + ['LILV_TEST_BUNDLE=\"%s/\"' % bpath],
  279. cflags = test_cflags)
  280. autowaf.use_lib(bld, obj, 'SORD SRATOM LV2')
  281. # Utilities
  282. if bld.env.BUILD_UTILS:
  283. utils = '''
  284. utils/lilv-bench
  285. utils/lv2info
  286. utils/lv2ls
  287. '''
  288. for i in utils.split():
  289. build_util(bld, i, defines)
  290. # lv2bench (less portable than other utilities)
  291. if bld.is_defined('HAVE_CLOCK_GETTIME'):
  292. obj = build_util(bld, 'utils/lv2bench', defines)
  293. if not bld.env.MSVC_COMPILER:
  294. obj.lib = ['rt']
  295. # Documentation
  296. autowaf.build_dox(bld, 'LILV', LILV_VERSION, top, out)
  297. # Man pages
  298. bld.install_files('${MANDIR}/man1', bld.path.ant_glob('doc/*.1'))
  299. # Bash completion
  300. if bld.env.BASH_COMPLETION:
  301. bld.install_as(
  302. '${SYSCONFDIR}/bash_completion.d/lilv', 'utils/lilv.bash_completion')
  303. if bld.is_defined('LILV_PYTHON'):
  304. # Python Wrapper
  305. obj = bld(features = 'cxx cxxshlib pyext',
  306. source = 'bindings/lilv.i',
  307. target = 'bindings/_lilv',
  308. includes = ['..'],
  309. swig_flags = '-c++ -python -Wall -I.. -llilv -features autodoc=1',
  310. use = 'liblilv')
  311. autowaf.use_lib(bld, obj, 'LILV')
  312. bld.install_files('${PYTHONDIR}', 'bindings/lilv.py')
  313. bld.add_post_fun(autowaf.run_ldconfig)
  314. if bld.env.DOCS:
  315. bld.add_post_fun(fix_docs)
  316. def fix_docs(ctx):
  317. if ctx.cmd == 'build':
  318. autowaf.make_simple_dox(APPNAME)
  319. def upload_docs(ctx):
  320. os.system('rsync -ravz --delete -e ssh build/doc/html/ drobilla@drobilla.net:~/drobilla.net/docs/lilv/')
  321. def test(ctx):
  322. autowaf.pre_test(ctx, APPNAME)
  323. os.environ['PATH'] = 'test' + os.pathsep + os.getenv('PATH')
  324. autowaf.run_tests(ctx, APPNAME, ['lilv_test'], dirs=['./src','./test'])
  325. autowaf.post_test(ctx, APPNAME)
  326. def lint(ctx):
  327. subprocess.call('cpplint.py --filter=+whitespace/comments,-whitespace/tab,-whitespace/braces,-whitespace/labels,-build/header_guard,-readability/casting,-readability/todo,-build/include,-runtime/sizeof src/* lilv/*', shell=True)