4 # Copyright (C) 2008,2009 Nedko Arnaudov <nedko@arnaudov.name>
6 # waf tool for lv2 plugins
9 from Object
import taskgen
, after
, before
, feature
10 from Common
import install_files
15 from Configure
import g_maxlen
18 def display_msg(msg
, status
= None, color
= None):
21 g_maxlen
= max(g_maxlen
, len(msg
))
23 print "%s :" % msg
.ljust(g_maxlen
),
24 Params
.pprint(color
, status
)
26 print "%s" % msg
.ljust(g_maxlen
)
28 def get_lv2_install_dir():
31 has_lv2_path
= os
.environ
.has_key(envvar
)
33 display_msg("Checking LV2_PATH")
35 display_msg("Checking LV2_PATH", "not set", 'YELLOW')
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')
45 if not os
.access(lv2path
, os
.W_OK
):
46 display_msg(' ' + lv2path
, 'not writable', 'YELLOW')
49 display_msg(' ' + lv2path
, 'looks good', 'GREEN')
54 class lv2plugin_proxy_abstract(Object
.task_gen
):
55 def __init__(self
, tool
, hook
):
56 Object
.task_gen
.__init
__(self
)
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
)
69 class lv2plugin_taskgen(Object
.task_gen
):
70 def __init__(self
, type = 'cpp', env
=None):
71 Object
.task_gen
.__init
__(self
)
73 self
.tool
= Object
.task_gen
.classes
[type]('shlib')
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']
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
90 Object
.task_gen
.apply_core(self
)
92 def get_hook(self
, ext
):
93 classes
= Object
.task_gen
.classes
94 for cls
in classes
.keys():
95 if cls
== 'lv2plugin':
101 map = classes
[cls
].mappings
105 obj
= lv2plugin_proxy_abstract(self
.tool
, hook
)
110 def 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.')
114 conf
.env
['LV2_INSTALL_DIR'] = getattr(Params
.g_options
, 'LV2_INSTALL_DIR')
115 status
= conf
.env
['LV2_INSTALL_DIR']
117 status
= 'will be deduced from LV2_PATH'
118 display_msg('LV2 installation directory', status
, 'GREEN')
122 @after('apply_objdeps')
123 @before('install_target')
124 def install_lv2(self
):
125 if not getattr(self
, 'lv2', None):
128 self
.meths
.remove('install_target')
130 if not Params
.g_install
:
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')
138 display_msg('LV2 installation directory', self
.env
['LV2_INSTALL_DIR'], 'GREEN')
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
)