xref: /aosp_15_r20/external/pigweed/pw_toolchain/arm_clang/BUILD.gn (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2021 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15import("//build_overrides/pigweed.gni")
16
17import("clang_config.gni")
18
19declare_args() {
20  pw_toolchain_USE_LLVM_PREBUILT_LIBRARIES = false
21}
22
23cortex_m_common_flags = [
24  "-mabi=aapcs",
25  "-mthumb",
26]
27
28cortex_m_software_fpu_flags = [ "-mfloat-abi=soft" ]
29
30cortex_m_hardware_fpu_flags_common = [
31  "-mfloat-abi=hard",
32
33  # Used by some pigweed tests/targets to correctly handle hardware FPU
34  # behavior.
35  "-DPW_ARMV7M_ENABLE_FPU=1",
36]
37
38cortex_m_hardware_fpu_flags =
39    cortex_m_hardware_fpu_flags_common + [ "-mfpu=fpv4-sp-d16" ]
40
41cortex_m_hardware_fpu_v5_flags =
42    cortex_m_hardware_fpu_flags_common + [ "-mfpu=fpv5-d16" ]
43
44cortex_m_hardware_fpu_v5_sp_flags =
45    cortex_m_hardware_fpu_flags_common + [ "-mfpu=fpv5-sp-d16" ]
46
47# Default config added to all the ARM cortex M targets to link `nosys` library.
48config("nosys") {
49  libs = [ "nosys" ]
50}
51
52config("enable_float_printf") {
53  ldflags = [ "-Wl,-u_printf_float" ]
54}
55
56if (pw_toolchain_USE_LLVM_PREBUILT_LIBRARIES) {
57  cortex_m_common_link_flags = [
58    "-nostartfiles",
59    "-nostdlib++",
60  ]
61  cortex_m_common_defines = [
62    # This macro is used by libc++ headers and normally would expand to std::_libcpp_verbose_abort,
63    # but we don't define that since we don't build with libc++ at the moment. For now, we can
64    # have this lower to a trap instruction.
65    "_LIBCPP_VERBOSE_ABORT(...)=__builtin_trap()",
66  ]
67  config("cortex_m0plus") {
68    cflags = [
69      "-mcpu=cortex-m0plus",
70      "--target=armv6m-none-eabi",
71    ]
72    cflags += cortex_m_common_flags
73    cflags += cortex_m_software_fpu_flags
74    asmflags = cflags
75    ldflags = cflags
76    ldflags += cortex_m_common_link_flags
77    defines = cortex_m_common_defines
78  }
79
80  config("cortex_m4") {
81    cflags = [
82      "-mcpu=cortex-m4",
83      "--target=armv7m-none-eabi",
84    ]
85    cflags += cortex_m_common_flags
86    cflags += cortex_m_software_fpu_flags
87    asmflags = cflags
88    ldflags = cflags
89    ldflags += cortex_m_common_link_flags
90    defines = cortex_m_common_defines
91  }
92} else {
93  pw_clang_arm_config("cortex_m0plus") {
94    cflags = [ "-mcpu=cortex-m0plus" ]
95    cflags += cortex_m_common_flags
96    cflags += cortex_m_software_fpu_flags
97    asmflags = cflags
98    ldflags = cflags
99  }
100
101  pw_clang_arm_config("cortex_m4") {
102    cflags = [ "-mcpu=cortex-m4" ]
103    cflags += cortex_m_common_flags
104    cflags += cortex_m_software_fpu_flags
105    asmflags = cflags
106    ldflags = cflags
107  }
108}
109
110pw_clang_arm_config("cortex_m3") {
111  cflags = [ "-mcpu=cortex-m3" ]
112  cflags += cortex_m_common_flags
113  cflags += cortex_m_software_fpu_flags
114  asmflags = cflags
115  ldflags = cflags
116  rustflags = [ "--target=thumbv7m-none-eabi" ]
117}
118
119pw_clang_arm_config("cortex_m4f") {
120  cflags = [ "-mcpu=cortex-m4" ]
121  cflags += cortex_m_common_flags
122  cflags += cortex_m_hardware_fpu_flags
123  asmflags = cflags
124  ldflags = cflags
125}
126
127pw_clang_arm_config("cortex_m7") {
128  cflags = [ "-mcpu=cortex-m7" ]
129  cflags += cortex_m_common_flags
130  cflags += cortex_m_software_fpu_flags
131  asmflags = cflags
132  ldflags = cflags
133}
134
135pw_clang_arm_config("cortex_m7f") {
136  cflags = [ "-mcpu=cortex-m7" ]
137  cflags += cortex_m_common_flags
138  cflags += cortex_m_hardware_fpu_v5_flags
139  asmflags = cflags
140  ldflags = cflags
141}
142
143pw_clang_arm_config("cortex_m33") {
144  cflags = [ "-mcpu=cortex-m33" ]
145  cflags += cortex_m_common_flags
146  cflags += cortex_m_software_fpu_flags
147  asmflags = cflags
148  ldflags = cflags
149}
150
151pw_clang_arm_config("cortex_m33f") {
152  cflags = [ "-mcpu=cortex-m33" ]
153  cflags += cortex_m_common_flags
154  cflags += cortex_m_hardware_fpu_v5_sp_flags
155  asmflags = cflags
156  ldflags = cflags
157}
158
159pw_clang_arm_config("cortex_m55") {
160  cflags = [ "-mcpu=cortex-m55" ]
161  cflags += cortex_m_common_flags
162  cflags += cortex_m_software_fpu_flags
163  asmflags = cflags
164  ldflags = cflags
165}
166