blob: fac66b6c21eb1d52eed1cc7180de7e2c80ada9f5 [file] [log] [blame]
# Copyright 2017 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.
assert(current_os == "fuchsia")
# Declare a driver module target.
#
# This target allows you to create an object file that can be used as a driver
# that is loaded at runtime.
#
# Parameters
#
# test (optional)
# [boolean] Whether this driver is a test driver. Defaults to false.
# Note: this only makes sense for drivers migrated from the Zircon build.
# Safe to ignore in other cases.
#
# Flags: cflags, cflags_c, cflags_cc, asmflags, defines, include_dirs,
# ldflags, lib_dirs, libs,
# Deps: data_deps, deps, public_deps
# Dependent configs: all_dependent_configs, public_configs
# General: check_includes, configs, data, inputs, output_name,
# output_extension, public, sources, testonly, visibility
template("driver_module") {
loadable_module(target_name) {
_target_type = "driver_module"
# Save the target name as forward_variables_from below might override it.
_target_name = target_name
# Explicitly forward visibility, implicitly forward everything else.
# See comment in //build/config/BUILDCONFIG.gn for details on this pattern.
forward_variables_from(invoker, [ "visibility" ])
forward_variables_from(invoker,
"*",
[
"test",
"visibility",
])
# Restore the target name.
target_name = _target_name
if (!defined(output_dir)) {
output_dir = root_out_dir
}
if (!defined(output_name)) {
output_name = target_name
}
if (!defined(output_extension)) {
output_extension = "so"
}
_output_file_name = output_name
if (output_extension != "") {
_output_file_name += ".$output_extension"
}
_output_file = "$output_dir/$_output_file_name"
_rebased_output_file = rebase_path(_output_file, root_build_dir)
_dest_dir = "driver"
if (defined(invoker.test) && invoker.test) {
_dest_dir += "/test"
}
metadata = {
migrated_manifest_lines =
[ "$_dest_dir/$_output_file_name=$_rebased_output_file" ]
}
}
}
set_defaults("driver_module") {
# Sets the default configs for driver_module, which can be modified later
# by the invoker. This overrides the loadable_module default.
configs = default_shared_library_configs
# In general, drivers should not use the C++ standard library, and drivers
# cannot dynamically link against it. This config tells the linker to not
# link against the C++ standard library.
# Drivers that do require standard library functionality should remove this
# config line and add "//build/config/fuchsia:static_cpp_standard_library" to
# statically link it into the driver.
configs += [ "//build/config/fuchsia:no_cpp_standard_library" ]
}