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.

wscript 13KB

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