minor fixes for clang++
[senf.git] / site_scons / site_tools / InstallDir.py
1 import os.path, os
2 import SCons.Action, SCons.Builder, SCons.Node.FS
3
4 def installDirFilter(target, source, env):
5     install = env['INSTALL']
6     suffixes = env.get('FILTER_SUFFIXES',[])
7     
8     for t,s in zip(target,source):
9         for path, dirs, files in os.walk(s.get_path()):
10             sdir = env.Dir(path)
11             tdir = t.Dir(sdir.get_path(s))
12             if not os.path.exists(tdir.get_path()):
13                 os.makedirs(tdir.get_path())
14             for f in files:
15                 sfile = sdir.File(f)
16                 if suffixes and sfile.suffix not in suffixes : continue
17                 tfile = tdir.File(sfile.name)
18                 if install(tfile.get_path(), sfile.get_path(), env):
19                     return 1
20     return 0
21
22 def installDirFilterStr(target, source, env):
23     suffixes = env.get('FILTER_SUFFIXES')
24     if suffixes : suffixes = " (only %s)" % " ".join(suffixes)
25     return 'Install directory: "%s" as "%s"%s' % (str(source[0]), str(target[0]), suffixes)
26     
27 InstallDirAction = SCons.Action.Action(installDirFilter, installDirFilterStr)
28
29 InstallDirBuilder = SCons.Builder.Builder(
30     action = InstallDirAction,
31     target_factory = SCons.Node.FS.Dir,
32     source_factory = SCons.Node.FS.Dir,
33     emitter = [ SCons.Tool.install.add_targets_to_INSTALLED_FILES, ])
34
35 def InstallDirWrapper(env, target=None, source=None, **kw):
36     target = env.arg2nodes(target, env.fs.Dir)
37     source = env.arg2nodes(source, env.fs.Dir)
38     builds = []
39     for t in target:
40         for s in source:
41             builds.extend(InstallDirBuilder(env, t.Dir(s.name), s, **kw))
42     return builds
43
44 def generate(env):
45     env['BUILDERS']['InstallDir'] = InstallDirWrapper
46
47 def exists(env):
48     return True