auth/wscript: fix options use
[samba.git] / third_party / waf / waflib / extras / softlink_libs.py
1 #! /usr/bin/env python
2 # encoding: utf-8
3 # WARNING! Do not edit! https://waf.io/book/index.html#_obtaining_the_waf_file
4
5 #! /usr/bin/env python
6 # per rosengren 2011
7
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
12
13 def options(opt):
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]')
16
17 def configure(cnf):
18         cnf.find_program('ldd')
19         if not cnf.env.SOFTLINK_EXCLUDE:
20                 cnf.env.SOFTLINK_EXCLUDE = cnf.options.exclude.split(',')
21
22 @feature('softlink_libs')
23 @after_method('process_rule')
24 def add_finder(self):
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)
29
30 class sll_finder(Task):
31         ext_out = 'softlink_libs'
32         def run(self):
33                 bld = self.generator.bld
34                 linked=[]
35                 target_paths = []
36                 for g in bld.groups:
37                         for tgen in g:
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']]
44                 lib_list = []
45                 if len(linked):
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)
52                                 result.seek(0)
53                                 for line in result.readlines():
54                                         words = line.split()
55                                         if len(words) < 3 or words[1] != '=>':
56                                                 continue
57                                         lib = words[2]
58                                         if lib == 'not':
59                                                 continue
60                                         if any([lib.startswith(p) for p in
61                                                         [bld.bldnode.abspath(), '('] +
62                                                         self.env.SOFTLINK_EXCLUDE]):
63                                                 continue
64                                         if not isabs(lib):
65                                                 continue
66                                         lib_list.append(lib)
67                         lib_list = sorted(set(lib_list))
68                 self.outputs[0].write(linesep.join(lib_list + self.env.DYNAMIC_LIBS))
69                 return 0
70
71 class sll_installer(Task):
72         ext_in = 'softlink_libs'
73         def run(self):
74                 tgt = self.outputs[0]
75                 self.generator.bld.install_files('${LIBDIR}', tgt, postpone=False)
76                 lib_list=tgt.read().split()
77                 for lib in lib_list:
78                         self.generator.bld.symlink_as('${LIBDIR}/'+basename(lib), lib, postpone=False)
79                 return 0
80