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.

370 lines
14KB

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