-
Notifications
You must be signed in to change notification settings - Fork 143
/
SConscript.in
218 lines (197 loc) · 6.93 KB
/
SConscript.in
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# Copyright (c) 2017-2023, Niklas Hauser
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#!/usr/bin/env python3
from os.path import join, abspath
Import("env")
profile = ARGUMENTS.get("profile", "release")
%% if is_modm
env["CONFIG_PROFILE"] = profile
env["BUILDPATH"] = join(env["CONFIG_BUILD_BASE"], "scons-" + profile)
env["BASEPATH"] = abspath("..")
%% if core.startswith("avr")
env["COMPILERPREFIX"] = "avr-"
%% elif core.startswith("cortex-m")
env["COMPILERPREFIX"] = "arm-none-eabi-"
%% endif
%% if family == "darwin"
# Using homebrew gcc-13 on macOS instead of clang
env["COMPILERSUFFIX"] = "-13"
%% endif
%% endif
%% if toolpaths
# SCons tools
env.Append(toolpath=[
%% for toolpath in toolpaths | sort
abspath("{{ toolpath | modm.windowsify(escape_level=1) }}"),
%% endfor
])
%% endif
%% for tool in tools | sort
env.Tool("{{tool}}")
%% endfor
%% macro generate_flags_for_profile(name, profile, append=False)
env{% if append %}.Append({{name | upper}}{% else %}["{{name | upper}}"]{% endif %} = [
%% for flag in flags[name][profile] | sort
{{ flag | flags_format | modm.windowsify(escape_level=1) }},
%% endfor
]{% if append %}){% endif -%}
%% endmacro
%% macro generate_flags(name, append=False)
%% if not append or flags[name][""] | length
{{ generate_flags_for_profile(name, "", append) }}
%% endif
%% for profile in flags[name].keys()
%% if profile != "" and flags[name][profile] | length
if profile == "{{ profile }}":
{{ generate_flags_for_profile(name, profile, True) | lbuild.indent(4) }}
%% endif
%% endfor
%% endmacro
# Toolchain configuration
{{ generate_flags("cppdefines", True) }}
{{ generate_flags("ccflags", not is_modm) }}
{{ generate_flags("cflags", not is_modm) }}
{{ generate_flags("cxxflags", not is_modm) }}
{{ generate_flags("asflags", not is_modm) }}
{{ generate_flags("linkflags", not is_modm) }}
{{ generate_flags("archflags", not is_modm) }}
%% if is_modm
# ARCHFLAGS must be known for compiling *and* linking
env.Append(CCFLAGS="$ARCHFLAGS")
env.Append(ASFLAGS="$ARCHFLAGS")
env.Append(LINKFLAGS="$ARCHFLAGS")
%% if family != "darwin"
# Search all linked static libraries multiple times
env["_LIBFLAGS"] = "-Wl,--start-group " + env["_LIBFLAGS"] + " -Wl,--end-group"
%% endif
%% if platform != "hosted"
# We need to link libmodm.a with --whole-archive, so that all weak symbols are
# visible to the linker. Functions placed in a linker section list are typically
# not referenced externally, so the linker will discard them when searching.
# From https://sourceware.org/binutils/docs/ld/Options.html#Options:
# For each archive mentioned on the command line after the --whole-archive option, include every object
# file in the archive in the link, rather than searching the archive for the required object files.
env["_LIBFLAGS"] = "-Wl,--whole-archive " + env["_LIBFLAGS"] + " -Wl,--no-whole-archive"
%# alternative workarounds
%# env["LINKCOM"] = env["LINKCOM"].replace("$_LIBFLAGS", "-Wl,--whole-archive $_LIBFLAGS -Wl,--no-whole-archive")
%# workaround for one individual library
%# whole_archive = env.Command(join(env.Dir("#").path, "-Wl,--whole-archive"), [], "")
%# no_whole_archive = env.Command(join(env.Dir("#").path, "-Wl,--no-whole-archive"), [], "")
%# library = whole_archive + library + no_whole_archive
%% endif
# Device configuration
env["CONFIG_DEVICE_NAME"] = "{{ partname }}"
%% if memories | length
env["CONFIG_DEVICE_MEMORY"] = [
%% for memory in memories
{{ memory }},
%% endfor
]
%% endif
# Programming configuration
%% if core.startswith("avr")
env["CONFIG_AVRDUDE_DEVICE"] = "{{ mcu }}"
%% if avrdude_programmer
env["CONFIG_AVRDUDE_PROGRAMMER"] = "{{ avrdude_programmer }}"
%% endif
%% if avrdude_port
env["CONFIG_AVRDUDE_PORT"] = "{{ avrdude_port }}"
%% endif
%% if avrdude_options
env["CONFIG_AVRDUDE_OPTIONS"] = "{{ avrdude_options }}"
%% endif
%% if avrdude_baudrate
env["CONFIG_AVRDUDE_BAUDRATE"] = "{{ avrdude_baudrate }}"
%% endif
%% elif core.startswith("cortex-m")
env.Append(MODM_OPENOCD_CONFIGFILES = "$BASEPATH/modm/openocd.cfg")
env.Append(MODM_JLINK_DEVICE = "{{ jlink_partname }}")
env.Append(MODM_GDBINIT = "$BASEPATH/modm/gdbinit")
env.Append(MODM_GDBINIT_OPENOCD = "$BASEPATH/modm/gdbinit_openocd")
env.Append(MODM_GDBINIT_JLINK = "$BASEPATH/modm/gdbinit_jlink")
env.Append(MODM_GDBINIT_BMP = "$BASEPATH/modm/gdbinit_bmp")
env.Append(MODM_GDB_COMMANDS = ["dir $GCC_PATH", "modm_setup_tui"])
%% if core.startswith("cortex-m")
env["CONFIG_FLASH_OFFSET"] = {{ flash_offset }}
env["CONFIG_FLASH_ADDRESS"] = {{ flash_address }}
%% endif
%% if platform == "sam"
%% if bossac_offset
env.Append(MODM_BOSSAC_OFFSET = {{ bossac_offset }})
%% endif
%% if bossac_options
env.Append(MODM_BOSSAC_OPTIONS = "{{ bossac_options }}")
%% endif
%% endif
%% endif
# XPCC generator tool path
env["XPCC_SYSTEM_DESIGN"] = "$BASEPATH/modm/tools/xpcc_generator"
%% endif
%% if is_modm and family == "darwin"
env.AppendUnique(CPPFLAGS=[
"-isystem", "/usr/local/include",
])
%% endif
env.AppendUnique(CPPPATH=[
%% for path in include_paths | sort
abspath("{{ path | relocate | modm.windowsify(escape_level=1) }}"),
%% endfor
])
files = [
%% for file, flags in sources if not flags | length
env.File("{{ file | relocate | modm.windowsify(escape_level=1) }}"),
%% endfor
]
%% for file, flags in sources
%% if flags | length
flags = { {%- for key, profiles in flags.items() if "" in profiles %}"{{ key | upper }}": {{profiles[""]}}, {% endfor -%} }
%% for key, profiles in flags.items()
%% for profile, flags in profiles.items() if "" != profile
if profile == "{{profile}}": flags["{{ key | upper }}"].extend({{flags}});
%% endfor
%% endfor
files.append(env.Object("{{ file | relocate | modm.windowsify(escape_level=1) }}", **flags))
%% endif
%% endfor
library = env.StaticLibrary(target="{{ repo }}", source=files)
env.AppendUnique(LIBS=[
library,
%% for library in libraries | sort
"{{ library }}",
%% endfor
])
env.AppendUnique(LIBPATH=[
%% if is_modm and family == "darwin"
"/usr/local/lib",
%% endif
abspath(str(library[0].get_dir())),
%% for library in library_paths | sort
abspath("{{ library | relocate | modm.windowsify(escape_level=1) }}"),
%% endfor
])
%% if packages | length
env.ParseConfig("pkg-config --cflags --libs {{ packages | sort | join(" ") }}")
%% endif
%% if is_modm
for flags in ["CCFLAGS", "CFLAGS", "CXXFLAGS", "ASFLAGS", "ARCHFLAGS", "LINKFLAGS"]:
flags_str = ARGUMENTS.get(flags)
if flags_str is not None:
flags_list = flags_str.split(",")
for flag in flags_list:
if len(flag) > 1 and flag[0] == "~":
try:
env[flags].remove(flag[1:])
except ValueError:
print("'" + flag[1:] + "' does not exist in " + flags +
" and therefore can not be removed.")
print("Info: " + flags + ": " + ", ".join(env[flags]))
exit(1)
else:
env[flags].append(flag)
%% endif
Return("library")