xref: /aosp_15_r20/external/pigweed/targets/arduino/BUILD.gn (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2020 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("$dir_pw_arduino_build/arduino.gni")
18import("$dir_pw_build/target_types.gni")
19import("$dir_pw_docgen/docs.gni")
20import("$dir_pw_toolchain/generate_toolchain.gni")
21pw_doc_group("target_docs") {
22  sources = [ "target_docs.rst" ]
23}
24
25if (pw_arduino_build_CORE_PATH != "") {
26  import("target_toolchains.gni")
27
28  generate_toolchains("target_toolchains") {
29    toolchains = pw_target_toolchain_arduino_list
30  }
31
32  if (current_toolchain != default_toolchain) {
33    config("arduino_build") {
34      # Debug: Print out arduinobuilder.py args
35      # print(string_join(" ", [rebase_path(arduino_builder_script, root_build_dir)] + arduino_show_command_args))
36
37      # Run prebuilds
38      # TODO(tonymd) This only needs to be run once but it's happening multiple times.
39      exec_script(arduino_builder_script,
40                  filter_exclude(arduino_run_command_args,
41                                 [ "--save-config" ]) + [ "--run-prebuilds" ],
42                  "string")
43
44      _exclude_flags = [ "-std=gnu++14" ]
45
46      _cflags = exec_script(arduino_builder_script,
47                            arduino_show_command_args + [ "--c-flags" ],
48                            "list lines")
49      cflags = filter_exclude(_cflags, _exclude_flags)
50
51      asmflags = exec_script(arduino_builder_script,
52                             arduino_show_command_args + [ "--s-only-flags" ],
53                             "list lines")
54
55      _cflags_cc =
56          exec_script(arduino_builder_script,
57                      arduino_show_command_args + [ "--cpp-only-flags" ],
58                      "list lines")
59      cflags_cc = filter_exclude(_cflags_cc, _exclude_flags)
60
61      _ldflags = exec_script(arduino_builder_script,
62                             arduino_show_command_args + [ "--ld-flags" ],
63                             "list lines")
64      ldflags =
65          filter_exclude(_ldflags,
66                         [
67                           # Remove arguments ending in 'core.a', for example:
68                           # C:/Users/username/pigweed/out/core.a
69                           "*core.a\b",
70
71                           # Remove .elf output file, for example:
72                           # -o C:/Users/username/pigweed/out/pigweed.elf
73                           "\b-o\b",
74                           "*.elf\b",
75
76                           # Remove the Arduino {object_files} variable
77                           "{object_files}",
78                         ])
79
80      # Teensy4 core recipe uses: '-larm_cortexM7lfsp_math -lm -lstdc++'
81      libs = filter_exclude(
82              exec_script(arduino_builder_script,
83                          arduino_show_command_args + [ "--ld-lib-names" ],
84                          "list lines"),
85              [
86                # Exclude stdc++ and precompiled math libraries which causes
87                # linking errors for teensy cores.
88                "\bstdc++\b",
89                "\barm_cortexM0l_math\b",
90                "\barm_cortexM4lf_math\b",
91                "\barm_cortexM4l_math\b",
92                "\barm_cortexM7lfsp_math\b",
93              ])
94    }
95
96    pw_source_set("pre_init") {
97      sources = [ "init.cc" ]
98      public_deps = [
99        "$dir_pw_sys_io_arduino",
100        "$dir_pw_third_party/arduino:arduino_core_sources",
101      ]
102      deps = [
103        "$dir_pw_arduino_build:arduino_init.facade",
104        "$dir_pw_preprocessor",
105      ]
106    }
107  }
108} else {
109  config("arduino_build") {
110  }
111  group("pre_init") {
112  }
113}
114