-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathconfigure.py
132 lines (93 loc) · 3.01 KB
/
configure.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
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
#!/usr/bin/env python3
import argparse
import pathlib
from wintertools import buildgen
from wintertools.third_party import ninja_syntax
# Check the python version before doing anything else.
buildgen.check_python_version()
# Make sure we're in the right directory.
buildgen.ensure_directory()
# Gemini/test-specific sources, includes, and defines.
PROGRAM = "gemini-firmware-test"
SRCS = [
"../tests/**/*.c",
"../src/gem_oscillator.c",
"../src/generated/gem_ramp_table_data.c",
"../src/gem_ramp_table_lookup.c",
"../third_party/libwinter/wntr_assert.c",
"../third_party/libwinter/wntr_bezier.c",
"../third_party/libwinter/wntr_error_correction.c",
"../third_party/libfixmath/fix16.c",
"../third_party/libfixmath/fix16_str.c",
"../third_party/libfixmath/fix16_exp.c",
"../third_party/munit/munit.c",
]
INCLUDES = [
"../tests/stubs",
"../src/hw",
"../src/drivers",
"../src/lib",
"../third_party/libwinter/samd",
"../third_party/libwinter/samd/samd21",
"../third_party/samd21/include",
"../third_party/cmsis/include",
"../third_party/tinyusb/src",
]
DEFINES = buildgen.Desktop.defines()
DEFINES.update(
dict(
DEBUG=1,
SAMD21=1,
__SAMD21G18A__=1,
)
)
# Toolchain configuration. Wintertools does most of the work here.
# Switch to clang since buildgen defaults to ARM gcc.
buildgen.GCC = "clang"
COMMON_FLAGS = buildgen.Desktop.common_flags()
COMPILE_FLAGS = buildgen.Desktop.cc_flags()
COMPILE_FLAGS += [
"-ggdb3 -Og",
]
LINK_FLAGS = buildgen.Desktop.ld_flags()
# Buildfile generation
def generate_build():
srcs = buildgen.expand_srcs(SRCS)
INCLUDES.extend(buildgen.includes_from_srcs(srcs))
compiler_flags = COMMON_FLAGS + COMPILE_FLAGS
linker_flags = COMMON_FLAGS + LINK_FLAGS
buildfile_path = pathlib.Path("./build.ninja")
buildfile = buildfile_path.open("w")
writer = ninja_syntax.Writer(buildfile)
# Global variables
writer.comment("This is generated by configure.py- don't edit it directly!")
writer.newline()
buildgen.toolchain_variables(
writer,
cc_flags=compiler_flags,
linker_flags=linker_flags,
includes=INCLUDES,
defines=DEFINES,
)
# Use wintertools' common rules for compiling and such.
buildgen.common_rules(writer)
# Builds for compiling, linking, and outputting the program
objects = buildgen.compile_build(writer, srcs)
buildgen.link_build(writer, PROGRAM, objects, ext="")
# Builds for generated files
# Formatting and linting
format_files = list(pathlib.Path(".").glob("tests/**/*.[c,h]"))
buildgen.clang_format_build(writer, format_files)
# Special reconfigure build
buildgen.reconfigure_build(writer)
# All done. :)
writer.close()
def main():
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
args = parser.parse_args()
generate_build()
print("Created build.ninja")
if __name__ == "__main__":
main()