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.

309 lines
12KB

  1. #!/usr/bin/env python
  2. import glob
  3. import os
  4. import subprocess
  5. import waflib.Logs as Logs
  6. import waflib.Options as Options
  7. import waflib.extras.autowaf as autowaf
  8. # Library and package version (UNIX style major, minor, micro)
  9. # major increment <=> incompatible changes
  10. # minor increment <=> compatible changes (additions)
  11. # micro increment <=> no interface changes
  12. SORD_VERSION = '0.13.0'
  13. SORD_MAJOR_VERSION = '0'
  14. # Mandatory waf variables
  15. APPNAME = 'sord' # Package name for waf dist
  16. VERSION = SORD_VERSION # Package version for waf dist
  17. top = '.' # Source directory
  18. out = 'build' # Build directory
  19. def options(opt):
  20. opt.load('compiler_c')
  21. opt.load('compiler_cxx')
  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('--test', action='store_true', dest='build_tests',
  26. help='Build unit tests')
  27. opt.add_option('--static', action='store_true', dest='static',
  28. help='Build static library')
  29. opt.add_option('--no-shared', action='store_true', dest='no_shared',
  30. help='Do not build shared library')
  31. opt.add_option('--static-progs', action='store_true', dest='static_progs',
  32. help='Build programs as static binaries')
  33. opt.add_option('--dump', type='string', default='', dest='dump',
  34. help='Dump debugging output (iter, search, write, all)')
  35. def configure(conf):
  36. conf.load('compiler_c')
  37. if Options.options.build_tests:
  38. try:
  39. conf.load('compiler_cxx')
  40. except:
  41. Logs.warn("No C++ compiler, sordmm.hpp compile test skipped")
  42. pass
  43. autowaf.configure(conf)
  44. autowaf.set_c99_mode(conf)
  45. autowaf.display_header('Sord configuration')
  46. conf.env.BUILD_TESTS = Options.options.build_tests
  47. conf.env.BUILD_UTILS = not Options.options.no_utils
  48. conf.env.BUILD_SHARED = not Options.options.no_shared
  49. conf.env.STATIC_PROGS = Options.options.static_progs
  50. conf.env.BUILD_STATIC = (Options.options.static or
  51. Options.options.static_progs)
  52. if conf.env.BUILD_TESTS:
  53. conf.check(lib = 'gcov',
  54. define_name = 'HAVE_GCOV',
  55. mandatory = False)
  56. autowaf.check_pkg(conf, 'serd-0', uselib_store='SERD',
  57. atleast_version='0.18.0', mandatory=True)
  58. autowaf.check_pkg(conf, 'libpcre', uselib_store='PCRE', mandatory=False)
  59. # Parse dump options and define things accordingly
  60. dump = Options.options.dump.split(',')
  61. all = 'all' in dump
  62. if all or 'iter' in dump:
  63. autowaf.define(conf, 'SORD_DEBUG_ITER', 1)
  64. if all or 'search' in dump:
  65. autowaf.define(conf, 'SORD_DEBUG_SEARCH', 1)
  66. if all or 'write' in dump:
  67. autowaf.define(conf, 'SORD_DEBUG_WRITE', 1)
  68. autowaf.define(conf, 'SORD_VERSION', SORD_VERSION)
  69. autowaf.set_lib_env(conf, 'sord', SORD_VERSION)
  70. conf.write_config_header('sord_config.h', remove=False)
  71. autowaf.display_msg(conf, 'Utilities', bool(conf.env.BUILD_UTILS))
  72. autowaf.display_msg(conf, 'Unit tests', bool(conf.env.BUILD_TESTS))
  73. autowaf.display_msg(conf, 'Debug dumping', dump)
  74. print('')
  75. def build(bld):
  76. # C/C++ Headers
  77. includedir = '${INCLUDEDIR}/sord-%s/sord' % SORD_MAJOR_VERSION
  78. bld.install_files(includedir, bld.path.ant_glob('sord/*.h'))
  79. bld.install_files(includedir, bld.path.ant_glob('sord/*.hpp'))
  80. # Pkgconfig file
  81. autowaf.build_pc(bld, 'SORD', SORD_VERSION, SORD_MAJOR_VERSION, 'SERD',
  82. {'SORD_MAJOR_VERSION' : SORD_MAJOR_VERSION})
  83. source = 'src/sord.c src/syntax.c'
  84. libflags = ['-fvisibility=hidden']
  85. libs = ['m']
  86. defines = []
  87. if bld.env.MSVC_COMPILER:
  88. libflags = []
  89. libs = []
  90. defines = ['snprintf=_snprintf']
  91. # Shared Library
  92. if bld.env.BUILD_SHARED:
  93. obj = bld(features = 'c cshlib',
  94. source = source,
  95. includes = ['.', './src'],
  96. export_includes = ['.'],
  97. name = 'libsord',
  98. target = 'sord-%s' % SORD_MAJOR_VERSION,
  99. vnum = SORD_VERSION,
  100. install_path = '${LIBDIR}',
  101. libs = libs,
  102. defines = defines + ['SORD_SHARED', 'SORD_INTERNAL'],
  103. cflags = libflags)
  104. autowaf.use_lib(bld, obj, 'SERD')
  105. # Static Library
  106. if bld.env.BUILD_STATIC:
  107. obj = bld(features = 'c cstlib',
  108. source = source,
  109. includes = ['.', './src'],
  110. export_includes = ['.'],
  111. name = 'libsord_static',
  112. target = 'sord-%s' % SORD_MAJOR_VERSION,
  113. vnum = SORD_VERSION,
  114. install_path = '${LIBDIR}',
  115. libs = libs,
  116. defines = ['SORD_INTERNAL'])
  117. autowaf.use_lib(bld, obj, 'SERD')
  118. if bld.env.BUILD_TESTS:
  119. test_libs = libs
  120. test_cflags = ['']
  121. if bld.is_defined('HAVE_GCOV'):
  122. test_libs += ['gcov']
  123. test_cflags += ['-fprofile-arcs', '-ftest-coverage']
  124. # Profiled static library for test coverage
  125. obj = bld(features = 'c cstlib',
  126. source = source,
  127. includes = ['.', './src'],
  128. name = 'libsord_profiled',
  129. target = 'sord_profiled',
  130. install_path = '',
  131. defines = defines,
  132. cflags = test_cflags,
  133. lib = test_libs)
  134. autowaf.use_lib(bld, obj, 'SERD')
  135. # Unit test program
  136. obj = bld(features = 'c cprogram',
  137. source = 'src/sord_test.c',
  138. includes = ['.', './src'],
  139. use = 'libsord_profiled',
  140. lib = test_libs,
  141. target = 'sord_test',
  142. install_path = '',
  143. defines = defines,
  144. cflags = test_cflags)
  145. autowaf.use_lib(bld, obj, 'SERD')
  146. # Static profiled sordi for tests
  147. obj = bld(features = 'c cprogram',
  148. source = 'src/sordi.c',
  149. includes = ['.', './src'],
  150. use = 'libsord_profiled',
  151. lib = test_libs,
  152. target = 'sordi_static',
  153. install_path = '',
  154. defines = defines,
  155. cflags = test_cflags)
  156. autowaf.use_lib(bld, obj, 'SERD')
  157. # C++ build test
  158. if bld.env.COMPILER_CXX:
  159. obj = bld(features = 'cxx cxxprogram',
  160. source = 'src/sordmm_test.cpp',
  161. includes = ['.', './src'],
  162. use = 'libsord_profiled',
  163. lib = test_libs,
  164. target = 'sordmm_test',
  165. install_path = '',
  166. defines = defines)
  167. autowaf.use_lib(bld, obj, 'SERD')
  168. # Utilities
  169. if bld.env.BUILD_UTILS:
  170. for i in ['sordi', 'sord_validate']:
  171. obj = bld(features = 'c cprogram',
  172. source = 'src/%s.c' % i,
  173. includes = ['.', './src'],
  174. use = 'libsord',
  175. lib = libs,
  176. target = i,
  177. install_path = '${BINDIR}',
  178. defines = defines)
  179. if not bld.env.BUILD_SHARED or bld.env.STATIC_PROGS:
  180. obj.use = 'libsord_static'
  181. if bld.env.STATIC_PROGS:
  182. obj.env.SHLIB_MARKER = obj.env.STLIB_MARKER
  183. obj.linkflags = ['-static', '-Wl,--start-group']
  184. autowaf.use_lib(bld, obj, 'SERD')
  185. if i == 'sord_validate':
  186. autowaf.use_lib(bld, obj, 'PCRE')
  187. obj.cflags = '-pthread'
  188. # Documentation
  189. autowaf.build_dox(bld, 'SORD', SORD_VERSION, top, out)
  190. # Man pages
  191. bld.install_files('${MANDIR}/man1', bld.path.ant_glob('doc/*.1'))
  192. bld.add_post_fun(autowaf.run_ldconfig)
  193. if bld.env.DOCS:
  194. bld.add_post_fun(fix_docs)
  195. def lint(ctx):
  196. subprocess.call('cpplint.py --filter=+whitespace/comments,-whitespace/tab,-whitespace/braces,-whitespace/labels,-build/header_guard,-readability/casting,-readability/todo,-build/include src/*.* sord/* src/zix/*.*', shell=True)
  197. def fix_docs(ctx):
  198. if ctx.cmd == 'build':
  199. autowaf.make_simple_dox(APPNAME)
  200. def upload_docs(ctx):
  201. os.system('rsync -ravz --delete -e ssh build/doc/html/ drobilla@drobilla.net:~/drobilla.net/docs/sord/')
  202. for page in glob.glob('doc/*.[1-8]'):
  203. os.system('soelim %s | pre-grohtml troff -man -wall -Thtml | post-grohtml > build/%s.html' % (page, page))
  204. os.system('rsync -avz --delete -e ssh build/%s.html drobilla@drobilla.net:~/drobilla.net/man/' % page)
  205. def test(ctx):
  206. blddir = autowaf.build_dir(APPNAME, 'tests')
  207. try:
  208. os.makedirs(blddir)
  209. except:
  210. pass
  211. for i in glob.glob(blddir + '/*.*'):
  212. os.remove(i)
  213. srcdir = ctx.path.abspath()
  214. orig_dir = os.path.abspath(os.curdir)
  215. os.chdir(srcdir)
  216. good_tests = glob.glob('tests/test-*.ttl')
  217. good_tests.sort()
  218. os.chdir(orig_dir)
  219. autowaf.pre_test(ctx, APPNAME)
  220. os.environ['PATH'] = '.' + os.pathsep + os.getenv('PATH')
  221. nul = os.devnull
  222. autowaf.run_tests(ctx, APPNAME, [
  223. 'sordi_static file://%s/tests/manifest.ttl > %s' % (srcdir, nul),
  224. 'sordi_static %s/tests/UTF-8.ttl > %s' % (srcdir, nul),
  225. 'sordi_static -v > %s' % nul,
  226. 'sordi_static -h > %s' % nul,
  227. 'sordi_static -s "<foo> a <#Thingie> ." file:///test > %s' % nul,
  228. 'sordi_static %s > %s' % (nul, nul)],
  229. 0, name='sordi-cmd-good')
  230. autowaf.run_tests(ctx, APPNAME, [
  231. 'sordi_static > %s' % nul,
  232. 'sordi_static ftp://example.org/unsupported.ttl > %s' % nul,
  233. 'sordi_static -i > %s' % nul,
  234. 'sordi_static -o > %s' % nul,
  235. 'sordi_static -z > %s' % nul,
  236. 'sordi_static -p > %s' % nul,
  237. 'sordi_static -c > %s' % nul,
  238. 'sordi_static -i illegal > %s' % nul,
  239. 'sordi_static -o illegal > %s' % nul,
  240. 'sordi_static -i turtle > %s' % nul,
  241. 'sordi_static /no/such/file > %s' % nul],
  242. 1, name='sordi-cmd-bad')
  243. autowaf.run_tests(ctx, APPNAME, ['sord_test'])
  244. commands = []
  245. for test in good_tests:
  246. base_uri = 'http://www.w3.org/2001/sw/DataAccess/df1/' + test.replace('\\', '/')
  247. commands += [ 'sordi_static "%s" "%s" > %s.out' % (
  248. os.path.join(srcdir, test), base_uri, test) ]
  249. autowaf.run_tests(ctx, APPNAME, commands, 0, name='good')
  250. Logs.pprint('BOLD', '\nVerifying turtle => ntriples')
  251. for test in good_tests:
  252. out_filename = test + '.out'
  253. cmp_filename = srcdir + '/' + test.replace('.ttl', '.out')
  254. if not os.access(out_filename, os.F_OK):
  255. Logs.pprint('RED', 'FAIL: %s output is missing' % test)
  256. else:
  257. out_lines = sorted(open(out_filename).readlines())
  258. cmp_lines = sorted(open(cmp_filename).readlines())
  259. if out_lines != cmp_lines:
  260. Logs.pprint('RED', 'FAIL: %s is incorrect' % out_filename)
  261. else:
  262. Logs.pprint('GREEN', 'Pass: %s' % test)
  263. autowaf.post_test(ctx, APPNAME)