blob: 466201f81ad858cfa07cca1b6482c14ebda707d3 [file] [log] [blame]
# Copyright 2019 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("$zx/public/gn/toolchain/environment.gni")
import("$zx/public/gn/toolchain/environment_redirect.gni")
# Gigaboot gets its own toolchains to build EFI code.
# TODO(mcgrathr): Put efi into standard.gni? That would require moving
# the referenced configs (efi_config + kernel:standalone) int public/gn.
# Maybe only worthwhile if lib+include gets turned into an efi-libc
# library() that could theoretically be exported.
if (current_toolchain == default_toolchain) {
foreach(cpu, standard_fuchsia_cpus) {
environment("efi") {
cpu = cpu
os = "win"
globals = {
is_kernel = true
}
configs += standard_fuchsia_configs + [ ":efi_config" ]
# TODO: harmless, but just to match build.mk
configs -= [ "$zx/public/gn/config:default_frame_pointers" ]
# TODO: strip = true
# There isn't a GCC toolchain that supports the Windows target directly
# the way we use it.
exclude_variant_tags = [ "gcc" ]
tags = [ "standalone" ]
}
}
} else if (toolchain.environment == "efi") {
# This is the top config for all code in the efi_toolchain.
config("efi_config") {
configs = [
"$zx/kernel:standalone",
"$zx/public/gn/config:no_sanitizers",
# TODO: "$zx/kernel:warnings",
]
include_dirs = [ "include" ]
cflags = [
"-std=c99",
"-fshort-wchar",
]
# The compiler predefines _MSC_VER for compatibility with the Windows
# compiler. But then some compiler-provided headers like <stddef.h>
# test _MSC_VER and except some Windows API headers to exist if it's
# set. We use the "windows-msvc" compiler target for EFI because it's
# right wrt calling conventions and object file format, but this EFI
# compilation environment does not use a Windows-style API.
cflags += [ "-U_MSC_VER" ]
}
executable("bootloader") {
output_dir = root_out_dir
if (current_cpu == "arm64") {
output_name = "bootaa64"
} else {
output_name = "boot${current_cpu}"
}
output_extension = "efi"
deps = [
"lib",
"src",
]
ldflags = [
"-Wl,/subsystem:efi_application",
"-Wl,/entry:efi_main",
]
# For the //:images build_api_module().
metadata = {
images = [
{
label = get_label_info(":$target_name", "label_with_toolchain")
name = "bootloader"
type = "efi"
path = rebase_path("$root_out_dir/$output_name.$output_extension",
root_build_dir)
cpu = current_cpu
},
]
}
}
} else {
# In any other toolchain, just redirect to the proper toolchain.
environment_redirect("bootloader") {
environment_label = ":efi"
direct = true
deps = [
":bootloader",
]
}
}