aboutsummaryrefslogtreecommitdiffstats
path: root/ext.wscript
blob: 197f82ed9c0dcf0a0fd72ea0d302bc8bd30c29d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
import glob
import os
import shutil

from waflib.extras import autowaf as autowaf

# A rule for making a link in the build directory to a source file
def link(task):
    if hasattr(os, 'symlink'):
        func = os.symlink
    else:
        func = shutil.copy  # Symlinks unavailable, make a copy

    try:
        os.remove(task.outputs[0].abspath())  # Remove old target
    except:
        pass  # No old target, whatever

    func(task.inputs[0].abspath(), task.outputs[0].abspath())

def configure(conf):
    pass

def options(opt):
    opt.load('compiler_c')
    autowaf.set_options(opt)
    opt.add_option('--test', action='store_true', default=False, dest='build_tests',
                   help="Build unit tests")
    opt.add_option('--copy-headers', action='store_true', default=False,
                   dest='copy_headers',
                   help='Copy headers instead of linking to bundle')

def build(bld):
    path        = bld.path.srcpath()[len('lv2/'):]
    name        = os.path.basename(path)
    bundle_dir  = os.path.join(bld.env['LV2DIR'], name + '.lv2')
    include_dir = os.path.join(bld.env['INCLUDEDIR'], 'lv2', path)

    # Copy headers to URI-style include paths in build directory
    for i in bld.path.ant_glob('*.h'):
        bld(rule   = link,
            name   = 'link',
            cwd    = 'build/lv2/%s' % path,
            source = '%s' % i,
            target = 'lv2/%s/%s' % (path, i))

    if bld.env['BUILD_TESTS'] and bld.path.find_node('%s-test.c' % name):
        test_lib    = []
        test_cflags = ['']
        if bld.is_defined('HAVE_GCOV'):
            test_lib    += ['gcov']
            test_cflags += ['-fprofile-arcs', '-ftest-coverage']

        # Unit test program
        bld(features     = 'c cprogram',
            source       = '%s-test.c' % name,
            lib          = test_lib,
            target       = '%s-test' % name,
            install_path = '',
            cflags       = test_cflags)
            
    # Install bundle
    bld.install_files(bundle_dir,
                      bld.path.ant_glob('?*.*', excl='*.in'))

    # Install URI-like includes
    if bld.path.ant_glob('*.h'):
        if bld.env['COPY_HEADERS']:
            bld.install_files(include_dir, bld.path.ant_glob('*.h'))
        else:
            bld.symlink_as(include_dir,
                           os.path.relpath(bundle_dir,
                                           os.path.dirname(include_dir)))

def test(ctx):
    name = os.path.basename(ctx.path.srcpath()[len('lv2/'):])
    autowaf.pre_test(ctx, name, dirs=['.'])
    os.environ['PATH'] = '.' + os.pathsep + os.getenv('PATH')
    autowaf.run_tests(ctx, name, ['%s-test' % name], dirs=['.'])
    autowaf.post_test(ctx, name, dirs=['.'])

def news(ctx):
    path = ctx.path.abspath()
    autowaf.write_news(os.path.basename(path),
                       glob.glob(os.path.join(path, '*.ttl')),
                       os.path.join(path, 'NEWS'))

def pre_dist(ctx):
    # Write NEWS file in source directory
    news(ctx)

def post_dist(ctx):
    # Delete generated NEWS file from source directory
    try:
        os.remove(os.path.join(ctx.path.abspath(), 'NEWS'))
    except:
        pass