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 11KB

12 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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.12.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 PCRE')
  185. # Documentation
  186. autowaf.build_dox(bld, 'SORD', SORD_VERSION, top, out)
  187. # Man pages
  188. bld.install_files('${MANDIR}/man1', bld.path.ant_glob('doc/*.1'))
  189. bld.add_post_fun(autowaf.run_ldconfig)
  190. if bld.env.DOCS:
  191. bld.add_post_fun(fix_docs)
  192. def lint(ctx):
  193. 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)
  194. def fix_docs(ctx):
  195. if ctx.cmd == 'build':
  196. autowaf.make_simple_dox(APPNAME)
  197. def upload_docs(ctx):
  198. os.system('rsync -ravz --delete -e ssh build/doc/html/ drobilla@drobilla.net:~/drobilla.net/docs/sord/')
  199. def test(ctx):
  200. blddir = autowaf.build_dir(APPNAME, 'tests')
  201. try:
  202. os.makedirs(blddir)
  203. except:
  204. pass
  205. for i in glob.glob(blddir + '/*.*'):
  206. os.remove(i)
  207. srcdir = ctx.path.abspath()
  208. orig_dir = os.path.abspath(os.curdir)
  209. os.chdir(srcdir)
  210. good_tests = glob.glob('tests/test-*.ttl')
  211. good_tests.sort()
  212. os.chdir(orig_dir)
  213. autowaf.pre_test(ctx, APPNAME)
  214. os.environ['PATH'] = '.' + os.pathsep + os.getenv('PATH')
  215. nul = os.devnull
  216. autowaf.run_tests(ctx, APPNAME, [
  217. 'sordi_static file://%s/tests/manifest.ttl > %s' % (srcdir, nul),
  218. 'sordi_static %s/tests/UTF-8.ttl > %s' % (srcdir, nul),
  219. 'sordi_static -v > %s' % nul,
  220. 'sordi_static -h > %s' % nul,
  221. 'sordi_static -s "<foo> a <#Thingie> ." file:///test > %s' % nul,
  222. 'sordi_static %s > %s' % (nul, nul)],
  223. 0, name='sordi-cmd-good')
  224. autowaf.run_tests(ctx, APPNAME, [
  225. 'sordi_static > %s' % nul,
  226. 'sordi_static ftp://example.org/unsupported.ttl > %s' % nul,
  227. 'sordi_static -i > %s' % nul,
  228. 'sordi_static -o > %s' % nul,
  229. 'sordi_static -z > %s' % nul,
  230. 'sordi_static -p > %s' % nul,
  231. 'sordi_static -c > %s' % nul,
  232. 'sordi_static -i illegal > %s' % nul,
  233. 'sordi_static -o illegal > %s' % nul,
  234. 'sordi_static -i turtle > %s' % nul,
  235. 'sordi_static /no/such/file > %s' % nul],
  236. 1, name='sordi-cmd-bad')
  237. autowaf.run_tests(ctx, APPNAME, ['sord_test'])
  238. commands = []
  239. for test in good_tests:
  240. base_uri = 'http://www.w3.org/2001/sw/DataAccess/df1/' + test.replace('\\', '/')
  241. commands += [ 'sordi_static "%s" "%s" > %s.out' % (
  242. os.path.join(srcdir, test), base_uri, test) ]
  243. autowaf.run_tests(ctx, APPNAME, commands, 0, name='good')
  244. Logs.pprint('BOLD', '\nVerifying turtle => ntriples')
  245. for test in good_tests:
  246. out_filename = test + '.out'
  247. cmp_filename = srcdir + '/' + test.replace('.ttl', '.out')
  248. if not os.access(out_filename, os.F_OK):
  249. Logs.pprint('RED', 'FAIL: %s output is missing' % test)
  250. else:
  251. out_lines = sorted(open(out_filename).readlines())
  252. cmp_lines = sorted(open(cmp_filename).readlines())
  253. if out_lines != cmp_lines:
  254. Logs.pprint('RED', 'FAIL: %s is incorrect' % out_filename)
  255. else:
  256. Logs.pprint('GREEN', 'Pass: %s' % test)
  257. autowaf.post_test(ctx, APPNAME)