root/lv2plugin.py

Revision 45524f93f5fb311d1a0f2f849484aed3c5e742c6, 4.2 KB (checked in by Nedko Arnaudov <nedko@…>, 14 months ago)

waf build system skeleton (LV2)

  • Property mode set to 100644
Line 
1#! /usr/bin/env python
2# encoding: utf-8
3#
4# Copyright (C) 2008,2009 Nedko Arnaudov <nedko@arnaudov.name>
5#
6# waf tool for lv2 plugins
7
8import Object
9from Object import taskgen, after, before, feature
10from Common import install_files
11import os
12import Params
13import shutil
14
15from Configure import g_maxlen
16#g_maxlen = 40
17
18def display_msg(msg, status = None, color = None):
19    sr = msg
20    global g_maxlen
21    g_maxlen = max(g_maxlen, len(msg))
22    if status:
23        print "%s :" % msg.ljust(g_maxlen),
24        Params.pprint(color, status)
25    else:
26        print "%s" % msg.ljust(g_maxlen)
27
28def get_lv2_install_dir():
29    envvar = 'LV2_PATH'
30
31    has_lv2_path = os.environ.has_key(envvar)
32    if has_lv2_path:
33        display_msg("Checking LV2_PATH")
34    else:
35        display_msg("Checking LV2_PATH", "not set", 'YELLOW')
36        return None
37
38    if has_lv2_path:
39        lv2paths = os.environ[envvar].split(':')
40        for lv2path in lv2paths:
41            if not os.path.isdir(lv2path):
42                display_msg('  ' + lv2path, 'not directory!', 'YELLOW')
43                continue
44
45            if not os.access(lv2path, os.W_OK):
46                display_msg('  ' + lv2path, 'not writable', 'YELLOW')
47                continue
48
49            display_msg('  ' + lv2path, 'looks good', 'GREEN')
50            return lv2path
51
52    return None
53
54class lv2plugin_proxy_abstract(Object.task_gen):
55    def __init__(self, tool, hook):
56        Object.task_gen.__init__(self)
57        self.tool = tool
58        self.hook = hook
59
60    def the_hook(self, obj, node):
61        #print "-------------- '%s'" % node
62        #print "tool '%s'" % self.tool
63        #print "tool.target '%s'" % self.tool.target
64        #print "hook '%s'" % self.hook
65        #print "obj '%s'" % obj
66        #print "self '%s'" % self
67        self.hook(self.tool, node)
68
69class lv2plugin_taskgen(Object.task_gen):
70    def __init__(self, type = 'cpp', env=None):
71        Object.task_gen.__init__(self)
72        self.type = type
73        self.tool = Object.task_gen.classes[type]('shlib')
74        if type == 'cpp':
75            self.tool.m_type_initials = 'cpp'
76            self.tool.features.append('cc')
77            self.tool.ccflags = ''
78            self.tool.mappings['.c'] = Object.task_gen.mappings['.cc']
79
80    def apply_core(self):
81        #print "lv2plugin.apply_core() called."
82        #print "sources: " + repr(self.source)
83        #print "target: '%s'" % self.target
84        #print "ttl: '%s'" % self.ttl
85        self.tool.target = self.target
86        self.tool.env['shlib_PATTERN'] = '%s.so'
87        self.tool.uselib = self.uselib
88        self.tool.ttl = self.ttl
89        self.tool.lv2 = True
90        Object.task_gen.apply_core(self)
91
92    def get_hook(self, ext):
93        classes = Object.task_gen.classes
94        for cls in classes.keys():
95            if cls == 'lv2plugin':
96                continue
97
98            if cls != self.type:
99                continue
100
101            map = classes[cls].mappings
102            for x in map:
103                if x == ext:
104                    hook = map[x]
105                    obj = lv2plugin_proxy_abstract(self.tool, hook)
106                    return obj.the_hook
107
108        return None
109
110def set_options(opt):
111    opt.add_option('--lv2-dir', type='string', default='', dest='LV2_INSTALL_DIR', help='Force directory where LV2 plugin(s) will be installed.')
112
113def detect(conf):
114    conf.env['LV2_INSTALL_DIR'] = getattr(Params.g_options, 'LV2_INSTALL_DIR')
115    status = conf.env['LV2_INSTALL_DIR']
116    if not status:
117        status = 'will be deduced from LV2_PATH'
118    display_msg('LV2 installation directory', status, 'GREEN')
119
120@taskgen
121@feature('normal')
122@after('apply_objdeps')
123@before('install_target')
124def install_lv2(self):
125    if not getattr(self, 'lv2', None):
126        return
127
128    self.meths.remove('install_target')
129
130    if not Params.g_install:
131        return
132
133    if not self.env['LV2_INSTALL_DIR']:
134        self.env['LV2_INSTALL_DIR'] = get_lv2_install_dir()
135        if not self.env['LV2_INSTALL_DIR']:
136            Params.fatal('Cannot locate LV2 plugins directory')
137
138    display_msg('LV2 installation directory', self.env['LV2_INSTALL_DIR'], 'GREEN')
139
140    bundle_files = self.ttl
141    bundle_files.append(self.target + '.so')
142    install_files('LV2_INSTALL_DIR', self.target + '.lv2', bundle_files, self.env)
Note: See TracBrowser for help on using the browser.