| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | import Object |
|---|
| 9 | from Object import taskgen, after, before, feature |
|---|
| 10 | from Common import install_files |
|---|
| 11 | import os |
|---|
| 12 | import Params |
|---|
| 13 | import shutil |
|---|
| 14 | |
|---|
| 15 | from Configure import g_maxlen |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | def 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 | |
|---|
| 28 | def 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 | |
|---|
| 54 | class 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 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | self.hook(self.tool, node) |
|---|
| 68 | |
|---|
| 69 | class 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 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 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 | |
|---|
| 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.') |
|---|
| 112 | |
|---|
| 113 | def 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') |
|---|
| 124 | def 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) |
|---|