forked from openwsn-berkeley/openwsn-fw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSConscript
147 lines (114 loc) · 3.74 KB
/
SConscript
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
import os
Import('env')
localEnv = env.Clone()
#===== retrieve the list of apps to build
# apps which should always be built
defaultApps = [
'c6t',
'cinfo',
'cleds',
'cwellknown',
'techo',
'uecho',
'uinject',
'rrt',
]
if localEnv['board']=='python':
defaultApps += [
'cexample',
'cstorm',
]
# apps which should always be present
defaultAppsInit = [
'c6t',
'cinfo',
'cleds',
'cwellknown',
'techo',
'uecho',
'rrt',
]
# additional apps the user wants to build
if localEnv['apps']:
userApps = localEnv['apps'].split(',')
else:
userApps = []
# union of default and additional apps (without duplicates)
apps = sorted(list(set(defaultApps+userApps)))
appsInit = sorted(list(set(defaultAppsInit+userApps)))
#===== rule to create a (temporary) openapps_dyn.c file
def dynify(env,target,source):
assert len(target)==1
assert len(source)==1
target = target[0].abspath
source = source[0].abspath
#=== create file
dynfile = '#include "opendefs.h"\n\n'
dynfile += '{HEADERS_FILES}'.format(HEADERS_FILES = '\n'.join(['#include "{0}.h"'.format(a) for a in apps]))
dynfile += '\n\nvoid openapps_init(void) {\n'
dynfile += '{INIT_FUNCTIONS}'''.format(INIT_FUNCTIONS = '\n'.join([' {0}_init();'.format(a) for a in appsInit]))
dynfile += '\n}'
# this is a workaround for the fact that leds_init() is called leds__init()
# which itself it due to possible confusion in the objecticication process
# between leds_init() and rleds_init()
dynfile = dynfile.replace('leds_init','leds__init')
#=== write
with open(target,'w') as f:
f.write(dynfile)
dynifyBuilder = Builder(
action = Action(dynify,'Dynifying $TARGET')
)
localEnv.Append(BUILDERS = {'Dynify' : dynifyBuilder})
dynapps = localEnv.Dynify(
target = 'openapps_dyn.c',
source = 'openapps.c'
)
localEnv.AlwaysBuild(dynapps)
localEnv.Alias('dynapps', dynapps)
#===== pick the correct source files
target = 'libopenapps'
sources_c = []
sources_h = []
if localEnv['board']=='python':
sources_c += ['openapps.c']
else:
sources_c += ['openapps_dyn.c']
sources_h += ['openapps.h']
for a in apps:
sources_c += [os.path.join(a,a+'.c')]
sources_h += [os.path.join(a,a+'.h')]
#===== build the openapps library
if localEnv['board']=='python':
if userApps:
raise SystemError("Dynamic app creation not yet supported in simulation mode")
for s in sources_c+sources_h:
temp = localEnv.Objectify(
target = localEnv.ObjectifiedFilename(s),
source = s,
)
#localEnv.AlwaysBuild(temp)
libopenapps = localEnv.Library(
target = target,
source = [localEnv.ObjectifiedFilename(s) for s in sources_c],
)
localEnv.Depends(libopenapps,[localEnv.ObjectifiedFilename(s) for s in sources_h])
else:
localEnv.Append(
CPPPATH = [
# inc
os.path.join('#','inc'),
# openstack
os.path.join('#','openstack','04-TRAN'),
os.path.join('#','openstack','cross-layers'),
os.path.join('#','openstack','02a-MAClow'),
os.path.join('#','openstack','02b-MAChigh'),
os.path.join('#','openstack','03b-IPv6'),
# openapps
os.path.join('#','openapps'),
]+[os.path.join('#','openapps',a) for a in apps],
)
libopenapps = localEnv.Library(
target = target,
source = sources_c,
)
Alias('libopenapps', libopenapps)