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.

169 lines
6.2KB

  1. #!/usr/bin/env python
  2. import os
  3. import subprocess
  4. from waflib.extras import autowaf as autowaf
  5. import waflib.Options as Options
  6. # Version of this package (even if built as a child)
  7. SRATOM_VERSION = '0.4.0'
  8. SRATOM_MAJOR_VERSION = '0'
  9. # Library version (UNIX style major, minor, micro)
  10. # major increment <=> incompatible changes
  11. # minor increment <=> compatible changes (additions)
  12. # micro increment <=> no interface changes
  13. # Sratom uses the same version number for both library and package
  14. SRATOM_LIB_VERSION = SRATOM_VERSION
  15. # Variables for 'waf dist'
  16. APPNAME = 'sratom'
  17. VERSION = SRATOM_VERSION
  18. # Mandatory variables
  19. top = '.'
  20. out = 'build'
  21. def options(opt):
  22. opt.load('compiler_c')
  23. autowaf.set_options(opt)
  24. opt.add_option('--test', action='store_true', dest='build_tests',
  25. help="Build unit tests")
  26. opt.add_option('--static', action='store_true', dest='static',
  27. help="Build static library")
  28. opt.add_option('--no-shared', action='store_true', dest='no_shared',
  29. help='Do not build shared library')
  30. def configure(conf):
  31. conf.load('compiler_c')
  32. autowaf.configure(conf)
  33. autowaf.set_c99_mode(conf)
  34. autowaf.display_header('Sratom Configuration')
  35. conf.env.BUILD_TESTS = Options.options.build_tests
  36. conf.env.BUILD_SHARED = not Options.options.no_shared
  37. conf.env.BUILD_STATIC = Options.options.static
  38. if not conf.env.BUILD_SHARED and not conf.env.BUILD_STATIC:
  39. conf.fatal('Neither a shared nor a static build requested')
  40. # Check for gcov library (for test coverage)
  41. if conf.env.BUILD_TESTS:
  42. conf.check_cc(lib='gcov',
  43. define_name='HAVE_GCOV',
  44. mandatory=False)
  45. autowaf.check_pkg(conf, 'lv2', atleast_version='1.0.0', uselib_store='LV2')
  46. autowaf.check_pkg(conf, 'serd-0', uselib_store='SERD',
  47. atleast_version='0.14.0', mandatory=True)
  48. autowaf.check_pkg(conf, 'sord-0', uselib_store='SORD',
  49. atleast_version='0.8.0', mandatory=True)
  50. autowaf.define(conf, 'SRATOM_VERSION', SRATOM_VERSION)
  51. conf.write_config_header('sratom_config.h', remove=False)
  52. autowaf.display_msg(conf, "Unit tests", str(conf.env.BUILD_TESTS))
  53. print('')
  54. lib_source = [ 'src/sratom.c' ]
  55. def build(bld):
  56. # C Headers
  57. includedir = '${INCLUDEDIR}/sratom-%s/sratom' % SRATOM_MAJOR_VERSION
  58. bld.install_files(includedir, bld.path.ant_glob('sratom/*.h'))
  59. # Pkgconfig file
  60. autowaf.build_pc(bld, 'SRATOM', SRATOM_VERSION, SRATOM_MAJOR_VERSION,
  61. ['SERD', 'SORD', 'LV2'],
  62. {'SRATOM_MAJOR_VERSION' : SRATOM_MAJOR_VERSION})
  63. libflags = ['-fvisibility=hidden']
  64. libs = ['m']
  65. defines = []
  66. if bld.env.MSVC_COMPILER:
  67. libflags = []
  68. libs = []
  69. defines = ['snprintf=_snprintf']
  70. # Shared Library
  71. if bld.env.BUILD_SHARED:
  72. obj = bld(features = 'c cshlib',
  73. export_includes = ['.'],
  74. source = lib_source,
  75. includes = ['.', './src'],
  76. lib = libs,
  77. name = 'libsratom',
  78. target = 'sratom-%s' % SRATOM_MAJOR_VERSION,
  79. vnum = SRATOM_LIB_VERSION,
  80. install_path = '${LIBDIR}',
  81. defines = defines + ['SRATOM_SHARED', 'SRATOM_INTERNAL'],
  82. cflags = libflags)
  83. autowaf.use_lib(bld, obj, 'SERD SORD LV2')
  84. # Static library
  85. if bld.env.BUILD_STATIC:
  86. obj = bld(features = 'c cstlib',
  87. export_includes = ['.'],
  88. source = lib_source,
  89. includes = ['.', './src'],
  90. lib = libs,
  91. name = 'libsratom_static',
  92. target = 'sratom-%s' % SRATOM_MAJOR_VERSION,
  93. vnum = SRATOM_LIB_VERSION,
  94. install_path = '${LIBDIR}',
  95. defines = defines + ['SRATOM_INTERNAL'])
  96. autowaf.use_lib(bld, obj, 'SERD SORD LV2')
  97. if bld.env.BUILD_TESTS:
  98. test_libs = libs
  99. test_cflags = ['']
  100. if bld.is_defined('HAVE_GCOV'):
  101. test_libs += ['gcov']
  102. test_cflags += ['-fprofile-arcs', '-ftest-coverage']
  103. # Static library (for unit test code coverage)
  104. obj = bld(features = 'c cstlib',
  105. source = lib_source,
  106. includes = ['.', './src'],
  107. lib = test_libs,
  108. name = 'libsratom_profiled',
  109. target = 'sratom_profiled',
  110. install_path = '',
  111. defines = defines + ['SRATOM_INTERNAL'],
  112. cflags = test_cflags)
  113. autowaf.use_lib(bld, obj, 'SERD SORD LV2')
  114. # Unit test program
  115. obj = bld(features = 'c cprogram',
  116. source = 'tests/sratom_test.c',
  117. includes = ['.', './src'],
  118. use = 'libsratom_profiled',
  119. lib = test_libs,
  120. target = 'sratom_test',
  121. install_path = '',
  122. defines = defines,
  123. cflags = test_cflags)
  124. # Documentation
  125. autowaf.build_dox(bld, 'SRATOM', SRATOM_VERSION, top, out)
  126. bld.add_post_fun(autowaf.run_ldconfig)
  127. if bld.env.DOCS:
  128. bld.add_post_fun(fix_docs)
  129. def test(ctx):
  130. autowaf.pre_test(ctx, APPNAME)
  131. os.environ['PATH'] = '.' + os.pathsep + os.getenv('PATH')
  132. autowaf.run_tests(ctx, APPNAME, ['sratom_test'], dirs=['./src','./tests'])
  133. autowaf.post_test(ctx, APPNAME)
  134. def lint(ctx):
  135. subprocess.call('cpplint.py --filter=+whitespace/comments,-whitespace/tab,-whitespace/braces,-whitespace/labels,-build/header_guard,-readability/casting,-readability/todo,-build/include src/* sratom/*', shell=True)
  136. def fix_docs(ctx):
  137. if ctx.cmd == 'build':
  138. autowaf.make_simple_dox(APPNAME)
  139. def upload_docs(ctx):
  140. os.system("rsync -ravz --delete -e ssh build/doc/html/ drobilla@drobilla.net:~/drobilla.net/docs/sratom/")