-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscons_enhancements.py
107 lines (83 loc) · 3.22 KB
/
scons_enhancements.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Make all normal SConstruct calls available
from SCons.Script import *
def MakeEnvironment(packages, configuration):
cfg = configuration.cfg
env = Environment(ENV=os.environ)
if configuration.host:
env['CXX'] = configuration.host + "-g++"
env['AR'] = configuration.host + "-ar"
env['RANLIB'] = configuration.host + "-ranlib"
env['LD'] = configuration.host + "-ld"
for pkg in packages:
# normal packgae name that has to be looked up in the configuration
if type(pkg) == str:
if pkg in cfg:
env.Append(**cfg[pkg])
# FIXME: hack
if 'CXX' in cfg[pkg]:
env['CXX'] = cfg[pkg]['CXX']
if 'AR' in cfg[pkg]:
env['AR'] = cfg[pkg]['AR']
if 'RANLIB' in cfg[pkg]:
env['RANLIB'] = cfg[pkg]['RANLIB']
else:
raise Exception("Unknown package: %s" % pkg)
# 'instant package'
elif type(pkg) == dict:
env.Append(**pkg)
# unknown stuff
else:
raise Exception("Unknown package type: %s" % pkg)
return env
def ParseConfig(cmd):
env = Environment()
env['ENV']['PATH'] = os.environ['PATH']
# env['ENV']['PKG_CONFIG_LIBDIR'] = os.environ['PKG_CONFIG_LIBDIR']
# env['ENV']['PKG_CONFIG_PATH'] = os.environ['PKG_CONFIG_PATH']
env.ParseConfig(cmd)
cfg = {}
for var in [ 'CCFLAGS', 'CPPDEFINES', 'CPPPATH', 'LIBS', 'LIBPATH' ]:
if var in env and env[var] != []:
cfg[var] = env[var]
# if 'CCFLAGS' in cfg:
# cfg['CXXFLAGS'] = cfg['CCFLAGS']
return cfg
def BuildProgram(target, sources, packages = []):
return Configuration.cfg.BuildProgram(target, sources, packages)
def BuildStaticLibrary(target, sources, packages = []):
return Configuration.cfg.BuildStaticLibrary(target, sources, packages)
class Configuration:
cfg = {}
def __init__(self, host = None):
self.cfg = {}
self.host = host
def __getitem__(self, key):
return self.cfg[key]
def __setitem__(self, key, value):
self.cfg[key] = value
def __delitem__(self, key):
del self.cfg[key]
def Package(self, name, **keys):
if name in self.cfg:
raise SCons.Errors.UserError, "package %s already exists" % name
else:
if 'DEPENDS' in keys:
del keys['DEPENDS']
elif 'CMD' in keys:
keys.update(ParseConfig(keys['CMD'])) # FIXME: wrong
del keys['CMD']
self.cfg[name] = keys
def BuildProgram(self, target, sources, packages = []):
env = MakeEnvironment(packages, self)
return env.Program(target, sources)
def BuildStaticLibrary(self, target, sources, packages = []):
env = MakeEnvironment(packages, self)
return env.StaticLibrary(target, sources)
def debug_print(self):
print
print "Current Configuration:"
print "======================"
for k, v in self.cfg.items():
print "cfg['%s'] = %s" % (k, v)
print
# EOF #