blob: 7b1bf016d54fe090d7f1ef858bce4f1777e11d18 [file] [log] [blame]
# Copyright 2020 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("//build/compiled_action.gni")
# Generate a header file for assembly files to #include from hwreg types.
#
# This defines a target that provides a generated header file.
# The generator program is expected to be defined using <hwreg/asm.h>.
#
# Parameters
#
# * output_name
# - Required: The include file name as it appears in `#include "name"`.
# - Type: string
#
# * sources
# - Required: Source files for the generator program.
# - Type: list(file)
#
# Other parameters are passed on to host_tool(), e.g. `cflags`, `defines`, etc.
#
template("hwreg_asm_header") {
main_target = target_name
tool_target = "_hwreg_header.tool.$target_name"
gen_target = "_hwreg_header.gen.$target_name"
config_target = "_hwreg_header.config.$target_name"
header_dir = get_label_info(":$main_target($default_toolchain)",
"target_gen_dir") + "/$target_name.include"
not_needed([ "tool_target" ])
if (is_host) {
executable(tool_target) {
visibility = [ ":*" ]
output_dir = target_out_dir
deps = []
forward_variables_from(invoker,
"*",
[
"output_dir",
"output_name",
"testonly",
"visibility",
])
forward_variables_from(invoker, [ "testonly" ])
deps += [ "//zircon/system/ulib/hwreg" ]
}
} else {
not_needed(invoker, "*")
}
if (current_toolchain == default_toolchain) {
compiled_action(gen_target) {
forward_variables_from(invoker, [ "testonly" ])
tool = ":$tool_target"
tool_output_dir =
get_label_info(":$tool_target($host_toolchain)", "target_out_dir")
outputs = [ "$header_dir/${invoker.output_name}" ]
args = rebase_path(outputs, root_build_dir) + [ invoker.output_name ]
# Disable the use of a previously built instance of the tool because the
# tool's binary location and name depends on the target cpu architecture
# (e.g. host_x64/obj/zircon/kernel/lib/arch/arm64/_hwreg_header.tool.gen-arm64-system-asm).
can_use_previously_built_tool = false
}
} else {
not_needed(invoker, [ "output_name" ])
}
config(config_target) {
visibility = [ ":$main_target" ]
include_dirs = [ header_dir ]
}
group(main_target) {
forward_variables_from(invoker,
[
"visibility",
"testonly",
])
public_deps = [ ":$gen_target($default_toolchain)" ]
public_configs = [ ":$config_target" ]
}
}