xref: /aosp_15_r20/external/pigweed/targets/rp2040/pico_executable.gni (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2022 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_build/exec.gni")
18
19# Executable wrapper that allows the 2nd stage bootloader to strip link deps.
20template("pico_executable") {
21  if (defined(invoker.is_boot_stage2) && invoker.is_boot_stage2) {
22    executable(target_name) {
23      forward_variables_from(invoker, "*")
24
25      # Link deps pulls in Pigweed things that don't fit in the 2nd stage
26      # bootloader.
27      deps -= [ "$dir_pw_build:link_deps" ]
28    }
29  } else {
30    _uf2_name = "${target_name}.uf2"
31    _elf_name = "${target_name}.elf"
32    executable(_elf_name) {
33      forward_variables_from(invoker, "*")
34    }
35
36    pw_exec(target_name) {
37      _elf2uf2_target = "$dir_pw_third_party/pico_sdk/src:elf2uf2($dir_pigweed/targets/host:host_clang_debug)"
38      if (host_os == "win") {
39        _elf2uf2_target = "$dir_pw_third_party/pico_sdk/src:elf2uf2($dir_pigweed/targets/host:host_gcc_debug)"
40      }
41      _uf2_out_path = "${target_out_dir}/${_uf2_name}"
42      deps = [
43        ":${_elf_name}",
44        _elf2uf2_target,
45      ]
46      program = "<TARGET_FILE(${_elf2uf2_target})>"
47      args = [
48        "<TARGET_FILE(:${_elf_name})>",
49        rebase_path(_uf2_out_path, root_build_dir),
50      ]
51      outputs = [ _uf2_out_path ]
52    }
53  }
54}
55