3 # WARNING! Do not edit! https://waf.io/book/index.html#_obtaining_the_waf_file
8 from waflib.TaskGen import feature, after_method
9 from waflib.Task import Task, always_run
10 from os.path import basename, isabs
11 from os import tmpfile, linesep
14 grp = opt.add_option_group('Softlink Libraries Options')
15 grp.add_option('--exclude', default='/usr/lib,/lib', help='No symbolic links are created for libs within [%default]')
18 cnf.find_program('ldd')
19 if not cnf.env.SOFTLINK_EXCLUDE:
20 cnf.env.SOFTLINK_EXCLUDE = cnf.options.exclude.split(',')
22 @feature('softlink_libs')
23 @after_method('process_rule')
25 tgt = self.path.find_or_declare(self.target)
26 self.create_task('sll_finder', tgt=tgt)
27 self.create_task('sll_installer', tgt=tgt)
28 always_run(sll_installer)
30 class sll_finder(Task):
31 ext_out = 'softlink_libs'
33 bld = self.generator.bld
38 # FIXME it might be better to check if there is a link_task (getattr?)
39 target_paths += [tgen.path.get_bld().bldpath()]
40 linked += [t.outputs[0].bldpath()
41 for t in getattr(tgen, 'tasks', [])
42 if t.__class__.__name__ in
43 ['cprogram', 'cshlib', 'cxxprogram', 'cxxshlib']]
46 cmd = [self.env.LDD] + linked
47 # FIXME add DYLD_LIBRARY_PATH+PATH for osx+win32
48 ldd_env = {'LD_LIBRARY_PATH': ':'.join(target_paths + self.env.LIBPATH)}
49 # FIXME the with syntax will not work in python 2
50 with tmpfile() as result:
51 self.exec_command(cmd, env=ldd_env, stdout=result)
53 for line in result.readlines():
55 if len(words) < 3 or words[1] != '=>':
60 if any([lib.startswith(p) for p in
61 [bld.bldnode.abspath(), '('] +
62 self.env.SOFTLINK_EXCLUDE]):
67 lib_list = sorted(set(lib_list))
68 self.outputs[0].write(linesep.join(lib_list + self.env.DYNAMIC_LIBS))
71 class sll_installer(Task):
72 ext_in = 'softlink_libs'
75 self.generator.bld.install_files('${LIBDIR}', tgt, postpone=False)
76 lib_list=tgt.read().split()
78 self.generator.bld.symlink_as('${LIBDIR}/'+basename(lib), lib, postpone=False)