• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)] + 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      # TODO(tonymd): Determine if libs are needed.
81      #   Teensy4 core recipe uses: '-larm_cortexM7lfsp_math -lm -lstdc++'
82      libs = filter_exclude(
83              exec_script(arduino_builder_script,
84                          arduino_show_command_args + [ "--ld-lib-names" ],
85                          "list lines"),
86              # Exclude stdc++ which causes linking errors for teensy cores.
87              [ "\bstdc++\b" ])
88    }
89
90    pw_source_set("pre_init") {
91      sources = [ "init.cc" ]
92      public_deps = [
93        "$dir_pw_sys_io_arduino",
94        "$dir_pw_third_party/arduino:arduino_core_sources",
95      ]
96      deps = [
97        "$dir_pw_arduino_build:arduino_init.facade",
98        "$dir_pw_preprocessor",
99      ]
100    }
101
102    pw_source_set("system_rpc_server") {
103      deps = [
104        "$dir_pw_hdlc:pw_rpc",
105        "$dir_pw_hdlc:rpc_channel_output",
106        "$dir_pw_rpc/system_server:facade",
107        "$dir_pw_stream:sys_io_stream",
108        dir_pw_log,
109      ]
110      sources = [ "system_rpc_server.cc" ]
111    }
112  }
113} else {
114  config("arduino_build") {
115  }
116  group("pre_init") {
117  }
118}
119