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

12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. #!/usr/bin/env python
  2. import glob
  3. import os
  4. import shutil
  5. import subprocess
  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. SERD_VERSION = '0.18.2'
  14. SERD_MAJOR_VERSION = '0'
  15. # Mandatory waf variables
  16. APPNAME = 'serd' # Package name for waf dist
  17. VERSION = SERD_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. 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('--stack-check', action='store_true', dest='stack_check',
  28. help='Include runtime stack sanity checks')
  29. opt.add_option('--static', action='store_true', dest='static',
  30. help='Build static library')
  31. opt.add_option('--no-shared', action='store_true', dest='no_shared',
  32. help='Do not build shared library')
  33. opt.add_option('--static-progs', action='store_true', dest='static_progs',
  34. help='Build programs as static binaries')
  35. opt.add_option('--largefile', action='store_true', dest='largefile',
  36. help='Build with large file support on 32-bit systems')
  37. def configure(conf):
  38. conf.load('compiler_c')
  39. autowaf.configure(conf)
  40. autowaf.set_c99_mode(conf)
  41. autowaf.display_header('Serd Configuration')
  42. conf.env.BUILD_TESTS = Options.options.build_tests
  43. conf.env.BUILD_UTILS = not Options.options.no_utils
  44. conf.env.BUILD_SHARED = not Options.options.no_shared
  45. conf.env.STATIC_PROGS = Options.options.static_progs
  46. conf.env.BUILD_STATIC = (Options.options.static or
  47. Options.options.static_progs)
  48. if not conf.env.BUILD_SHARED and not conf.env.BUILD_STATIC:
  49. conf.fatal('Neither a shared nor a static build requested')
  50. if Options.options.stack_check:
  51. autowaf.define(conf, 'SERD_STACK_CHECK', SERD_VERSION)
  52. if Options.options.largefile:
  53. conf.env.append_unique('DEFINES', ['_FILE_OFFSET_BITS=64'])
  54. if conf.env.BUILD_TESTS:
  55. conf.check(lib = 'gcov',
  56. define_name = 'HAVE_GCOV',
  57. mandatory = False)
  58. conf.check(function_name = 'fmax',
  59. header_name = 'math.h',
  60. define_name = 'HAVE_FMAX',
  61. lib = ['m'],
  62. mandatory = False)
  63. conf.check(function_name = 'posix_memalign',
  64. header_name = 'stdlib.h',
  65. define_name = 'HAVE_POSIX_MEMALIGN',
  66. defines = ['_POSIX_C_SOURCE=201112L'],
  67. mandatory = False)
  68. conf.check(function_name = 'posix_fadvise',
  69. header_name = 'fcntl.h',
  70. define_name = 'HAVE_POSIX_FADVISE',
  71. defines = ['_POSIX_C_SOURCE=201112L'],
  72. mandatory = False)
  73. conf.check(function_name = 'fileno',
  74. header_name = 'stdio.h',
  75. define_name = 'HAVE_FILENO',
  76. defines = ['_POSIX_C_SOURCE=201112L'],
  77. mandatory = False)
  78. autowaf.define(conf, 'SERD_VERSION', SERD_VERSION)
  79. autowaf.set_lib_env(conf, 'serd', SERD_VERSION)
  80. conf.write_config_header('serd_config.h', remove=False)
  81. autowaf.display_msg(conf, 'Utilities', str(conf.env.BUILD_UTILS))
  82. autowaf.display_msg(conf, 'Unit tests', str(conf.env.BUILD_TESTS))
  83. print('')
  84. lib_source = [
  85. 'src/env.c',
  86. 'src/node.c',
  87. 'src/reader.c',
  88. 'src/string.c',
  89. 'src/uri.c',
  90. 'src/writer.c',
  91. ]
  92. def build(bld):
  93. # C Headers
  94. includedir = '${INCLUDEDIR}/serd-%s/serd' % SERD_MAJOR_VERSION
  95. bld.install_files(includedir, bld.path.ant_glob('serd/*.h'))
  96. # Pkgconfig file
  97. autowaf.build_pc(bld, 'SERD', SERD_VERSION, SERD_MAJOR_VERSION, [],
  98. {'SERD_MAJOR_VERSION' : SERD_MAJOR_VERSION})
  99. libflags = ['-fvisibility=hidden']
  100. libs = ['m']
  101. defines = []
  102. if bld.env.MSVC_COMPILER:
  103. libflags = []
  104. libs = []
  105. defines = ['snprintf=_snprintf']
  106. # Shared Library
  107. if bld.env.BUILD_SHARED:
  108. bld(features = 'c cshlib',
  109. export_includes = ['.'],
  110. source = lib_source,
  111. includes = ['.', './src'],
  112. lib = libs,
  113. name = 'libserd',
  114. target = 'serd-%s' % SERD_MAJOR_VERSION,
  115. vnum = SERD_VERSION,
  116. install_path = '${LIBDIR}',
  117. defines = defines + ['SERD_SHARED', 'SERD_INTERNAL'],
  118. cflags = libflags)
  119. # Static library
  120. if bld.env.BUILD_STATIC:
  121. bld(features = 'c cstlib',
  122. export_includes = ['.'],
  123. source = lib_source,
  124. includes = ['.', './src'],
  125. lib = libs,
  126. name = 'libserd_static',
  127. target = 'serd-%s' % SERD_MAJOR_VERSION,
  128. vnum = SERD_VERSION,
  129. install_path = '${LIBDIR}',
  130. defines = defines + ['SERD_INTERNAL'])
  131. if bld.env.BUILD_TESTS:
  132. test_libs = libs
  133. test_cflags = ['']
  134. if bld.is_defined('HAVE_GCOV'):
  135. test_libs += ['gcov']
  136. test_cflags += ['-fprofile-arcs', '-ftest-coverage']
  137. # Profiled static library for test coverage
  138. bld(features = 'c cstlib',
  139. source = lib_source,
  140. includes = ['.', './src'],
  141. lib = test_libs,
  142. name = 'libserd_profiled',
  143. target = 'serd_profiled',
  144. install_path = '',
  145. defines = defines + ['SERD_INTERNAL'],
  146. cflags = test_cflags)
  147. # Static profiled serdi for tests
  148. bld(features = 'c cprogram',
  149. source = 'src/serdi.c',
  150. includes = ['.', './src'],
  151. use = 'libserd_profiled',
  152. lib = test_libs,
  153. target = 'serdi_static',
  154. install_path = '',
  155. defines = defines,
  156. cflags = test_cflags)
  157. # Unit test program
  158. bld(features = 'c cprogram',
  159. source = 'tests/serd_test.c',
  160. includes = ['.', './src'],
  161. use = 'libserd_profiled',
  162. lib = test_libs,
  163. target = 'serd_test',
  164. install_path = '',
  165. defines = defines,
  166. cflags = test_cflags)
  167. # Utilities
  168. if bld.env.BUILD_UTILS:
  169. obj = bld(features = 'c cprogram',
  170. source = 'src/serdi.c',
  171. target = 'serdi',
  172. includes = ['.', './src'],
  173. use = 'libserd',
  174. lib = libs,
  175. install_path = '${BINDIR}')
  176. if not bld.env.BUILD_SHARED or bld.env.STATIC_PROGS:
  177. obj.use = 'libserd_static'
  178. if bld.env.STATIC_PROGS:
  179. obj.env.SHLIB_MARKER = obj.env.STLIB_MARKER
  180. obj.linkflags = ['-static']
  181. # Documentation
  182. autowaf.build_dox(bld, 'SERD', SERD_VERSION, top, out)
  183. # Man page
  184. bld.install_files('${MANDIR}/man1', 'doc/serdi.1')
  185. bld.add_post_fun(autowaf.run_ldconfig)
  186. if bld.env.DOCS:
  187. bld.add_post_fun(fix_docs)
  188. def lint(ctx):
  189. subprocess.call('cpplint.py --filter=+whitespace/comments,-whitespace/tab,-whitespace/braces,-whitespace/labels,-build/header_guard,-readability/casting,-readability/todo,-build/include src/* serd/*', shell=True)
  190. def amalgamate(ctx):
  191. shutil.copy('serd/serd.h', 'build/serd.h')
  192. amalgamation = open('build/serd.c', 'w')
  193. serd_internal_h = open('src/serd_internal.h')
  194. for l in serd_internal_h:
  195. if l == '#include "serd/serd.h"\n':
  196. amalgamation.write('#include "serd.h"\n')
  197. else:
  198. amalgamation.write(l)
  199. serd_internal_h.close()
  200. for f in lib_source:
  201. fd = open(f)
  202. amalgamation.write('\n/**\n @file %s\n*/' % f)
  203. header = True
  204. for l in fd:
  205. if header:
  206. if l == '*/\n':
  207. header = False
  208. else:
  209. if l != '#include "serd_internal.h"\n':
  210. amalgamation.write(l)
  211. fd.close()
  212. amalgamation.close()
  213. for i in ['c', 'h']:
  214. Logs.info('Wrote build/serd.%s' % i)
  215. def fix_docs(ctx):
  216. if ctx.cmd == 'build':
  217. autowaf.make_simple_dox(APPNAME)
  218. def upload_docs(ctx):
  219. os.system('rsync -ravz --delete -e ssh build/doc/html/ drobilla@drobilla.net:~/drobilla.net/docs/serd/')
  220. def file_equals(patha, pathb, subst_from='', subst_to=''):
  221. fa = open(patha, 'rU')
  222. fb = open(pathb, 'rU')
  223. for line in fa:
  224. if line.replace(subst_from, subst_to) != fb.readline().replace(subst_from, subst_to):
  225. return False
  226. fa.close()
  227. fb.close()
  228. return True
  229. def test(ctx):
  230. blddir = autowaf.build_dir(APPNAME, 'tests')
  231. try:
  232. os.makedirs(blddir)
  233. except:
  234. pass
  235. for i in glob.glob(blddir + '/*.*'):
  236. os.remove(i)
  237. srcdir = ctx.path.abspath()
  238. orig_dir = os.path.abspath(os.curdir)
  239. os.chdir(srcdir)
  240. good_tests = glob.glob('tests/test-*.ttl')
  241. good_tests.sort()
  242. bad_tests = glob.glob('tests/bad-*.ttl')
  243. bad_tests.sort()
  244. os.chdir(orig_dir)
  245. autowaf.pre_test(ctx, APPNAME)
  246. os.environ['PATH'] = '.' + os.pathsep + os.getenv('PATH')
  247. autowaf.run_tests(ctx, APPNAME, ['serd_test'], dirs=['.'])
  248. autowaf.run_tests(ctx, APPNAME, [
  249. 'serdi_static -o turtle %s/tests/base.ttl "base.ttl" > tests/base.ttl.out' % srcdir],
  250. 0, name='base')
  251. if not file_equals('%s/tests/base.ttl' % srcdir, 'tests/base.ttl.out'):
  252. Logs.pprint('RED', 'FAIL: build/tests/base.ttl.out is incorrect')
  253. nul = os.devnull
  254. autowaf.run_tests(ctx, APPNAME, [
  255. 'serdi_static file://%s/tests/manifest.ttl > %s' % (srcdir, nul),
  256. 'serdi_static %s/tests/UTF-8.ttl > %s' % (srcdir, nul),
  257. 'serdi_static -v > %s' % nul,
  258. 'serdi_static -h > %s' % nul,
  259. 'serdi_static -s "<foo> a <#Thingie> ." > %s' % nul,
  260. 'serdi_static %s > %s' % (nul, nul)],
  261. 0, name='serdi-cmd-good')
  262. autowaf.run_tests(ctx, APPNAME, [
  263. 'serdi_static -q file://%s/tests/bad-id-clash.ttl > %s' % (srcdir, nul),
  264. 'serdi_static > %s' % nul,
  265. 'serdi_static ftp://example.org/unsupported.ttl > %s' % nul,
  266. 'serdi_static -i > %s' % nul,
  267. 'serdi_static -o > %s' % nul,
  268. 'serdi_static -z > %s' % nul,
  269. 'serdi_static -p > %s' % nul,
  270. 'serdi_static -c > %s' % nul,
  271. 'serdi_static -r > %s' % nul,
  272. 'serdi_static -i illegal > %s' % nul,
  273. 'serdi_static -o illegal > %s' % nul,
  274. 'serdi_static -i turtle > %s' % nul,
  275. 'serdi_static /no/such/file > %s' % nul],
  276. 1, name='serdi-cmd-bad')
  277. commands = []
  278. for test in good_tests:
  279. base_uri = 'http://www.w3.org/2001/sw/DataAccess/df1/' + test.replace('\\', '/')
  280. commands += [ 'serdi_static -f "%s" "%s" > %s.out' % (
  281. os.path.join(srcdir, test), base_uri, test) ]
  282. autowaf.run_tests(ctx, APPNAME, commands, 0, name='good')
  283. Logs.pprint('BOLD', '\nVerifying turtle => ntriples')
  284. for test in good_tests:
  285. out_filename = test + '.out'
  286. if not os.access(out_filename, os.F_OK):
  287. Logs.pprint('RED', 'FAIL: %s output is missing' % test)
  288. elif not file_equals(srcdir + '/' + test.replace('.ttl', '.out'),
  289. test + '.out'):
  290. Logs.pprint('RED', 'FAIL: %s is incorrect' % out_filename)
  291. else:
  292. Logs.pprint('GREEN', 'Pass: %s' % test)
  293. commands = []
  294. for test in bad_tests:
  295. commands += [ 'serdi_static "%s" "http://www.w3.org/2001/sw/DataAccess/df1/%s" > %s.out' % (os.path.join(srcdir, test), test.replace('\\', '/'), test) ]
  296. autowaf.run_tests(ctx, APPNAME, commands, 1, name='bad')
  297. thru_tests = good_tests
  298. thru_tests.remove(os.path.join('tests', 'test-id.ttl')) # IDs are mapped so files won't be identical
  299. commands = []
  300. num = 0
  301. for test in thru_tests:
  302. num += 1
  303. flags = ''
  304. if (num % 2 == 0):
  305. flags += '-b'
  306. if (num % 5 == 0):
  307. flags += ' -f'
  308. if (num % 3 == 0):
  309. flags += ' -r http://www.w3.org/'
  310. if (num % 7 == 0):
  311. flags += ' -e'
  312. base_uri = 'http://www.w3.org/2001/sw/DataAccess/df1/' + test.replace('\\', '/')
  313. out_filename = test + '.thru'
  314. commands += [
  315. '%s %s -i ntriples -o turtle -p foo "%s" "%s" | %s -i turtle -o ntriples -c foo - "%s" > %s.thru' % (
  316. 'serdi_static', flags.ljust(5),
  317. os.path.join(srcdir, test), base_uri,
  318. 'serdi_static', base_uri, test) ]
  319. autowaf.run_tests(ctx, APPNAME, commands, 0, name='turtle-round-trip')
  320. Logs.pprint('BOLD', '\nVerifying ntriples => turtle => ntriples')
  321. for test in thru_tests:
  322. out_filename = test + '.thru'
  323. if not os.access(out_filename, os.F_OK):
  324. Logs.pprint('RED', 'FAIL: %s output is missing' % test)
  325. elif not file_equals(srcdir + '/' + test.replace('.ttl', '.out'),
  326. test + '.thru',
  327. '_:docid', '_:genid'):
  328. Logs.pprint('RED', 'FAIL: %s is incorrect' % out_filename)
  329. else:
  330. Logs.pprint('GREEN', 'Pass: %s' % test)
  331. autowaf.post_test(ctx, APPNAME)