This repository has been archived by the owner on Aug 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnuttx_dlang_toolchain.patch
146 lines (141 loc) · 5.28 KB
/
nuttx_dlang_toolchain.patch
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
diff --git a/arch/arm/src/common/Toolchain.defs b/arch/arm/src/common/Toolchain.defs
index 6ac51393..b1077d4c 100644
--- a/arch/arm/src/common/Toolchain.defs
+++ b/arch/arm/src/common/Toolchain.defs
@@ -403,3 +403,7 @@ include $(TOPDIR)/tools/Zig.defs
# Rust toolchain
include $(TOPDIR)/tools/Rust.defs
+
+# LDC (LLVM D Compiler) toolchain
+
+include $(TOPDIR)/tools/D.defs
\ No newline at end of file
diff --git a/arch/risc-v/src/common/Toolchain.defs b/arch/risc-v/src/common/Toolchain.defs
index 44852e69..072afd8f 100644
--- a/arch/risc-v/src/common/Toolchain.defs
+++ b/arch/risc-v/src/common/Toolchain.defs
@@ -336,3 +336,7 @@ include $(TOPDIR)/tools/Zig.defs
# Rust toolchain
include $(TOPDIR)/tools/Rust.defs
+
+# LDC (LLVM D Compiler) toolchain
+
+include $(TOPDIR)/tools/D.defs
\ No newline at end of file
diff --git a/boards/sim/sim/sim/scripts/Make.defs b/boards/sim/sim/sim/scripts/Make.defs
index b74ec9a0..2232611b 100644
--- a/boards/sim/sim/sim/scripts/Make.defs
+++ b/boards/sim/sim/sim/scripts/Make.defs
@@ -190,6 +190,10 @@ include $(TOPDIR)/tools/Zig.defs
include $(TOPDIR)/tools/Rust.defs
+# LDC (LLVM D Compiler) toolchain
+
+include $(TOPDIR)/tools/D.defs
+
CFLAGS := $(ARCHOPTIMIZATION) $(ARCHCFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
CXXFLAGS := $(ARCHOPTIMIZATION) $(ARCHCXXFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/tools/Config.mk b/tools/Config.mk
index a49dc6a6..82cc57ce 100644
--- a/tools/Config.mk
+++ b/tools/Config.mk
@@ -362,6 +362,25 @@ define COMPILEZIG
$(ECHO_END)
endef
+# COMPILED - Default macro to compile one D file
+# Example: $(call COMPILED, in-file, out-file)
+#
+# Depends on these settings defined in board-specific Make.defs file
+# installed at $(TOPDIR)/Make.defs:
+#
+# DC - The command to invoke the D compiler
+# DFLAGS - Options to pass to the D compiler
+#
+# '<filename>.d_DFLAGS += <options>' may also be used, as an example, to
+# change the options used with the single file <filename>.d. The same
+# applies mutatis mutandis.
+
+define COMPILED
+ $(ECHO_BEGIN)"DC: $1 "
+ $(Q) $(DC) -c $(DFLAGS) $($(strip $1)_DFLAGS) $1 -of $2
+ $(ECHO_END)
+endef
+
# ASSEMBLE - Default macro to assemble one assembly language file
# Example: $(call ASSEMBLE, in-file, out-file)
#
diff --git a/tools/D.defs b/tools/D.defs
new file mode 100644
index 00000000..a464d058
--- /dev/null
+++ b/tools/D.defs
@@ -0,0 +1,56 @@
+############################################################################
+# tools/D.defs
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+############################################################################
+
+DC := ldmd2
+
+DFLAGS := -i -betterC
+
+ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
+ DFLAGS += -g
+endif
+
+ifeq ($(CONFIG_DEBUG_NOOPT),y)
+ DFLAGS += -O
+endif
+
+# Special handling for the SIM
+
+ifeq ($(CONFIG_ARCH_SIM),y)
+ ifeq ($(CONFIG_HOST_LINUX),y)
+ ifeq ($(LLVM_ARCHTYPE),x86)
+ # Only for x86 based host or x64 but m32 build
+ DFLAGS += -mtriple=i686-unknown-linux-$(LLVM_ABITYPE)
+ else
+ # For other archs, such as aarch64, arm etc
+ DFLAGS += -mtriple=$(LLVM_ARCHTYPE)-unknown-linux-$(LLVM_ABITYPE)
+ endif
+ else ifeq ($(CONFIG_HOST_MACOS),y)
+ DFLAGS += -mtriple=$(LLVM_ARCHTYPE)-apple-$(LLVM_ABITYPE)
+ endif
+else ifeq ($(CONFIG_ARCH_RISCV),y)
+ # Traget triple is riscv[32|64][isa]-unknown-none-elf
+ DFLAGS += -mtriple=$(LLVM_ARCHTYPE)$(ARCHRVISAM)$(ARCHRVISAA)$(ARCHRVISAF)$(ARCHRVISAD)$(ARCHRVISAC)-unknown-none-elf
+ DFLAGS += -mattr=+m,+a,+f,+d,+c -mabi=ilp32d
+ DFLAGS += -mcpu=generic-rv32
+else
+ # For arm, but there are some other archs not support yet,
+ # such as xtensa, x86 bare metal, etc.
+ DFLAGS += -mtriple=$(LLVM_ARCHTYPE)-none-$(LLVM_ABITYPE)
+endif
diff --git a/tools/mkexport.sh b/tools/mkexport.sh
index c3f3353a..7023e5ba 100755
--- a/tools/mkexport.sh
+++ b/tools/mkexport.sh
@@ -245,6 +245,8 @@ echo "OBJCOPY = ${OBJCOPY}" >>"${EXPORTDIR}/scripts/Make.defs"
echo "OBJDUMP = ${OBJDUMP}" >>"${EXPORTDIR}/scripts/Make.defs"
echo "ZIG = ${ZIG}" >>"${EXPORTDIR}/scripts/Make.defs"
echo "ZIGFLAGS = ${ZIGFLAGS}" >>"${EXPORTDIR}/scripts/Make.defs"
+echo "DC = ${DC}" >>"${EXPORTDIR}/scripts/Make.defs"
+echo "DFLAGS = ${DFLAGS}" >>"${EXPORTDIR}/scripts/Make.defs"
echo "NXFLATLDFLAGS1 = ${NXFLATLDFLAGS1}" >>"${EXPORTDIR}/scripts/Make.defs"
echo "NXFLATLDFLAGS2 = ${NXFLATLDFLAGS2}" >>"${EXPORTDIR}/scripts/Make.defs"
echo "OBJEXT = ${OBJEXT}" >>"${EXPORTDIR}/scripts/Make.defs"