-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.d
106 lines (91 loc) · 2.68 KB
/
build.d
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
#!/usr/bin/rdmd
import std.algorithm;
import std.array;
import std.file;
import std.path;
import std.process;
import std.stdio;
import std.getopt;
void run(string cmd)
{
writeln(cmd);
auto result = executeShell(cmd);
writeln(result.output);
}
void main(string[] args)
{
string compiler;
auto result = getopt
(
args,
"compiler|c", "The compiler to use (gdc or ldc)", &compiler
);
if (result.helpWanted || args.length < 1 || (compiler != "gdc" && compiler != "ldc"))
{
writefln("USAGE: -c=gdc|ldc", args[0]);
writeln();
write("options:");
defaultGetoptPrinter("", result.options);
return;
}
auto sourceDir = "source";
auto binaryDir = "binary";
auto objectFile = buildPath(binaryDir, "firmware.o");
auto outputFile = buildPath(binaryDir, "firmware");
// Create any directories that may not exist
if (!binaryDir.exists())
{
mkdir(binaryDir);
}
// remove any intermediate files
auto cmd = "rm -f " ~ binaryDir ~ "/*";
run(cmd);
auto sourceFiles = sourceDir
.dirEntries("*.d", SpanMode.depth)
.filter!(a => a.name == "source/runtime/exception.d" || !a.name.startsWith("source/runtime"))
.map!"a.name"
.join(" ");
if (compiler == "gdc")
{
cmd = "arm-none-eabi-gdc -c -O1 -nophoboslib -nostdinc -nodefaultlibs -nostdlib"
~ " -mthumb -mcpu=cortex-m4 -mtune=cortex-m4 -mfloat-abi=hard"
~ " -Isource/runtime" // to import runtime automatically
~ " -fno-bounds-check"
~ " -ffunction-sections"
~ " -fdata-sections"
~ " -fno-weak"
~ " -fno-tree-loop-distribute-patterns"
~ " -funroll-loops"
~ " -ftransition=dip1000"
// ~ " -S"
~ " " ~ sourceFiles
~ " -o " ~ objectFile;
}
else if (compiler == "ldc")
{
cmd = "ldc2 -conf= -disable-simplify-libcalls -c -Os"
~ " -mtriple=thumb-none-eabi -float-abi=hard"
~ " -mcpu=cortex-m4"
~ " -Isource/runtime" // to import runtime automatically
~ " -boundscheck=off"
~ " -linkonce-templates"
~ " -dip1000"
// ~ " -output-s"
~ " " ~ sourceFiles
~ " -of=" ~ objectFile;
}
else
{
assert(false);
}
run(cmd);
// link, creating executable
cmd = "arm-none-eabi-ld"
~ " -Tlinker/linker.ld"
~ " --gc-sections"
~ " " ~ objectFile
~ " -o " ~ outputFile;
run(cmd);
// display the size
run("arm-none-eabi-size " ~ outputFile);
}