-
Notifications
You must be signed in to change notification settings - Fork 6
/
Sconstruct
158 lines (134 loc) · 5.1 KB
/
Sconstruct
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!python
# Overview of the build system
# - All global configurations goes in this file,
# - Each platforms created contains configurations and environment
# - Each project is called passing platforms.
# - For each platform one build will run, always in the 'build' folder.
# - Projects are expected to append data to platform enviroments when
# necessary, such as includes, defines, libraries, etc.
#
# First we add our custom Functions to a default enviroment and configure it
import os
import fnmatch
default_env = Environment()
# Enable color terminal if available
if 'TERM' in os.environ.keys():
default_env['ENV']['TERM'] = os.environ['TERM']
# Add a FindFiles function to help Programs to search for code
def FindFiles(self, path, glob):
matches = []
matches.extend(Glob(path + '/' + glob))
matches.extend(Glob(path + '/*/' + glob))
matches.extend(Glob(path + '/*/*/' + glob))
matches.extend(Glob(path + '/*/*/*/' + glob))
matches.extend(Glob(path + '/*/*/*/*/' + glob))
matches.extend(Glob(path + '/*/*/*/*/*/' + glob))
return matches
default_env.AddMethod(FindFiles)
# Transform a multiline string into a list of Files
def MultiLineStringToFiles(self, multiline_string):
r = []
for f in multiline_string.split('\n'):
if len(f) > 0:
r.append(File('./' + f))
return r
default_env.AddMethod(MultiLineStringToFiles)
# Transform a list of C source into Objects
def SourceToObjects(self, source_list):
r = []
for s in source_list:
s_path = s.path
o_path = s_path.replace('.CPP', '.o').replace('.C', '.o').replace('.cpp', '.o').replace('.c', '.o')
o = File('#' + o_path)
r.append(o)
return r
default_env.AddMethod(SourceToObjects)
# Transform a list of Objects into GCDA and GDNO
def ObjectsToGcov(self, source_list):
r = []
for s in source_list:
s_path = s.path
da_path = s_path.replace('.o', '.gcda')
da = File('#' + da_path)
no_path = s_path.replace('.o', '.gcno')
no = File('#' + no_path)
r.append(da)
r.append(no)
return r
default_env.AddMethod(ObjectsToGcov)
# Create -include flags
def UpdateIncludes(self):
env = {
'CXXFLAGS': sum([['-include', i] for i in self['CXXINCLUDES']], []),
'CFLAGS' : sum([['-include', i] for i in self['CINCLUDES']], [])
}
self.Prepend(**env)
default_env.AddMethod(UpdateIncludes)
def EnablePlatformsFor(build_name, available_platforms):
r = []
for plat in available_platforms:
if build_name in plat.BuildList():
r.append(plat);
return r
def FindAvailablePlatforms():
r = []
for f in Glob('build_platforms/*.sconscript'):
plat = SConscript(f, exports = 'default_env')
r.append(plat)
return r;
available_platforms = FindAvailablePlatforms()
# Build CppUTest libraries for each platforms
platforms = EnablePlatformsFor('cpputest', available_platforms)
cpputest = SConscript('dependencies/cpputest/Sconscript', exports ='platforms')
# Enable GNU Coverage for the next builds
for plat in available_platforms:
if plat.ProfileEnabled():
plat.Env().Append(
CFLAGS = ['-fprofile-arcs', '-ftest-coverage'],
CXXFLAGS = ['-fprofile-arcs', '-ftest-coverage'],
LIBS = ['gcov']
)
# Build reacto as library
platforms = EnablePlatformsFor('reacto', available_platforms)
SConscript('reacto/Sconscript', exports ='platforms')
# Build reacto_tests executable
platforms = EnablePlatformsFor('reacto_tests', available_platforms)
SConscript('reacto_tests/Sconscript', exports ='platforms')
# Build examples
platforms = EnablePlatformsFor('rot13_factory', available_platforms)
SConscript('examples/rot13_factory/Sconscript', exports ='platforms')
# Build examples
platforms = EnablePlatformsFor('msp430_blink', available_platforms)
SConscript('examples/msp430_blink/Sconscript', exports ='platforms')
# Build examples
platforms = EnablePlatformsFor('msp430_timed_blink', available_platforms)
SConscript('examples/msp430_timed_blink/Sconscript', exports ='platforms')
# Build examples
platforms = EnablePlatformsFor('msp430_realtime_blink', available_platforms)
SConscript('examples/msp430_realtime_blink/Sconscript', exports ='platforms')
# Create extra targets for each platform
for p in available_platforms:
p.PostBuildTargets()
# Creating root target for each platform
for plat in available_platforms:
t = Command (target=plat.Name(), source='', action='@echo Built default targets for $TARGET')
for target in plat.TargetNameList():
if isinstance(target, plat.Default):
Depends(t, str(target))
# printing targets
def PrintHelp(target, source, env):
print
print "Usage:"
print " scons -Q <target name> "
print
print "Available targets ([d]efault targets for platform)"
for plat in available_platforms:
print '\t' + plat.Name() + ':'
for target in plat.TargetNameList():
if isinstance(target, plat.Default):
d = '[d] '
else:
d = ' '
print '\t\t' + d + str(target)
none = Command ('none', '', PrintHelp)
Default(none)