-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSConstruct
More file actions
79 lines (68 loc) · 2.41 KB
/
Copy pathSConstruct
File metadata and controls
79 lines (68 loc) · 2.41 KB
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
# SConstruct - AutoTitrator-Firmware
# Bare-metal STM32F103C8T6, C++23, SCons build
import os
PROJECT = 'AutoTitrator-Firmware'
MCU = 'cortex-m3'
CROSS = ARGUMENTS.get('CROSS', 'arm-none-eabi-')
env = Environment(
tools = ['gcc', 'g++', 'gnulink', 'ar', 'as'],
CC = CROSS + 'gcc',
CXX = CROSS + 'g++',
AS = CROSS + 'gcc',
AR = CROSS + 'ar',
LINK = CROSS + 'g++',
OBJCOPY = CROSS + 'objcopy',
SIZE = CROSS + 'size',
OBJDUMP = CROSS + 'objdump',
PROGSUFFIX = '.elf', # override Windows default .exe
)
# Propagate the user's full environment into the build environment so
# cross-compiler toolchains are found even on Windows.
# Override TMP/TEMP/TMPDIR with a simple project-local path to avoid
# issues with extended-length path prefixes (\\?\...).
env['ENV'] = dict(os.environ)
env['ENV']['TMP'] = 'build/tmp'
env['ENV']['TEMP'] = 'build/tmp'
env['ENV']['TMPDIR'] = 'build/tmp'
# Ensure the temp directory exists (SCons cleans it on -c)
try:
os.makedirs('build/tmp', exist_ok=True)
except OSError:
pass
env.Append(
CCFLAGS=[
'-mcpu=%s' % MCU, '-mthumb',
'-ffunction-sections', '-fdata-sections',
'-Os', '-g3', '-Wall', '-Wextra',
],
CXXFLAGS=[
'-std=c++23',
'-fno-exceptions', '-fno-rtti',
'-fno-use-cxa-atexit',
'-fcheck-new', # bare-metal operator new may return null
],
LINKFLAGS=[
'-mcpu=%s' % MCU, '-mthumb',
'-T', 'Startup/linker.ld',
'-nostdlib',
'-Wl,--gc-sections',
'-Wl,-Map=build/%s.map' % PROJECT,
'-Wl,--print-memory-usage',
],
CPPPATH=['include'],
)
# ---- Variant build dirs (keeps .o out of source tree) ----
VariantDir('build/obj/src', 'src', duplicate=0)
VariantDir('build/obj/Startup', 'Startup', duplicate=0)
# ---- Source files (from variant dirs) ----
sources = Glob('build/obj/src/*.cpp')
sources += Glob('build/obj/src/**/*.cpp')
sources += Glob('build/obj/Startup/*.cpp')
# ---- Build targets ----
elf = env.Program('build/%s' % PROJECT, sources)
hex = env.Command('build/%s.hex' % PROJECT, elf, '$OBJCOPY -O ihex $SOURCE $TARGET')
lst = env.Command('build/%s.lst' % PROJECT, elf, '$OBJDUMP -S $SOURCE > $TARGET')
env.Alias('hex', hex)
env.Alias('lst', lst)
Default([elf, hex])
Clean(elf, ['build'])