| # Copyright 2022 The Fuchsia Authors |
| # |
| # Use of this source code is governed by a MIT-style |
| # license that can be found in the LICENSE file or at |
| # https://opensource.org/licenses/MIT |
| |
| import("toolchain.gni") |
| |
| # Build an executable for the kernel.efi environment. |
| # |
| # This just defines an executable() target, but it's always in the toolchain |
| # for the kernel.efi environment for $current_cpu. |
| # |
| # Parameters |
| # |
| # * install_path |
| # - Optional: If set, this specifies in the destination in FAT filesystem |
| # when aggregated as a dependency of `fat_filesystem()` - at which this |
| # executable should be installed |
| # - Type: relative path |
| # |
| # * output_extension |
| # - Optional: See executable(), but defaults to "efi". |
| # - Type: string |
| # - Default: "efi" |
| # |
| # * emulator_support_aib |
| # - Optional: If true, will generate an `emulator_support_aib_input` metadata entry and barrier |
| # making this image findable as a QEMU Kernel by `assembled_system`. |
| # See `//build/assembly/assembled_system.gni` "Metadata Protocol" for more details. |
| # - Type: boolean |
| # - Default: false |
| # |
| # See executable() for other parameters. |
| template("efi_executable") { |
| if (!is_efi) { |
| group(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| ]) |
| public_deps = [ ":$target_name($efi_toolchain)" ] |
| } |
| not_needed(invoker, "*") |
| } else { |
| executable(target_name) { |
| forward_variables_from(invoker, |
| "*", |
| [ |
| "install_path", |
| "metadata", |
| ]) |
| if (defined(visibility)) { |
| # Make sure it's visible to the redirector group above. |
| visibility += [ ":$target_name" ] |
| } |
| if (!defined(output_extension)) { |
| output_extension = "efi" |
| } |
| if (!defined(output_name)) { |
| output_name = target_name |
| } |
| emulator_support_aib = false |
| if (defined(invoker.emulator_support_aib)) { |
| emulator_support_aib = invoker.emulator_support_aib |
| } |
| |
| output_path = |
| rebase_path("${root_out_dir}/${output_name}.${output_extension}", |
| root_build_dir) |
| if (!defined(invoker.install_path) && !emulator_support_aib) { |
| not_needed([ "output_path" ]) |
| } |
| target_label = get_label_info(":$target_name", "label_with_toolchain") |
| metadata = { |
| if (defined(invoker.metadata)) { |
| forward_variables_from(invoker.metadata, "*") |
| } |
| |
| if (defined(invoker.install_path)) { |
| if (!defined(distribution_entries)) { |
| distribution_entries = [] |
| } |
| distribution_entries += [ |
| { |
| source = output_path |
| destination = invoker.install_path |
| label = target_label |
| }, |
| ] |
| } |
| |
| if (emulator_support_aib) { |
| emulator_support_aib_input_barrier = [] |
| emulator_support_aib_input = [ |
| { |
| path = output_path |
| label = target_label |
| }, |
| ] |
| } |
| } |
| } |
| } |
| } |
| |
| if (is_efi) { |
| set_defaults("efi_executable") { |
| configs = default_executable_configs |
| } |
| } |
| |
| # TODO(mcgrathr): EFI compilation not there yet on RISC-V |
| have_efi = current_cpu != "riscv64" |