blob: b2c58845d46c9d90aa9efbdfe686a14dadde0fcb [file] [log] [blame]
# Copyright 2018 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Defines a config specifying the result of running pkg-config for the given
# packages. Put the package names you want to query in the "pkg_deps" variable
# inside the template invocation.
template("pkg_config") {
config(target_name) {
forward_variables_from(invoker, "*")
assert(defined(pkg_deps), "pkg_deps must be set")
_pkg_config_result = exec_script("//common-mk/pkg-config_wrapper.py",
[ pkg_config ] + pkg_deps,
"json")
if (_pkg_config_result.cflags != []) {
if (!defined(cflags)) {
cflags = []
}
cflags += _pkg_config_result.cflags
}
if (_pkg_config_result.libs != []) {
if (!defined(libs)) {
libs = []
}
libs += _pkg_config_result.libs
}
if (_pkg_config_result.lib_dirs != []) {
if (!defined(lib_dirs)) {
lib_dirs = []
}
lib_dirs += _pkg_config_result.lib_dirs
}
if (_pkg_config_result.ldflags != []) {
if (!defined(ldflags)) {
ldflags = []
}
ldflags += _pkg_config_result.ldflags
}
}
}
# Generates a .pc file with given parameters.
# All parameters are optional. If missing, empty value is used unless there is
# explicit documentation.
#
# Parameters:
# deps: Dependency of the generated action.
# name: The name of library set in .pc file. If missing
# |target_name| is used.
# output_name: The stem (file name excluding the .pc extension)
# of the generated .pc file. If missing, |name| is used.
# descritption: Description to be embedded.
# version: Version to be embedded.
# requires: Package name list to be embedded into "Requires:".
# requires_private: Similar to requires, but into "Requires.private:".
# libs: Flags passed to ld to be embedded into "Libs:" E.g. [ "-lpthread" ].
# libs_private: Similar to libs, butinto "Libs.private:".
# cflags: Compile flag list to be embedded into "Cflags:".
template("generate_pkg_config") {
action(target_name) {
forward_variables_from(invoker,
[
"deps",
"testonly",
"name",
"output_name",
"description",
"version",
"requires",
"requires_private",
"libs",
"libs_private",
"cflags",
"defines",
])
if (!defined(name)) {
name = target_name
}
if (!defined(output_name)) {
output_name = name
}
outputs = [ "${target_out_dir}/${output_name}.pc" ]
script = "//common-mk/generate-pc.py"
args = [ "--output" ] + rebase_path(outputs) + [ "--name=" + name ]
if (defined(description)) {
args += [ "--description=" + description ]
}
if (defined(version)) {
args += [ "--version=" + version ]
}
if (defined(requires)) {
foreach(pkg, requires) {
args += [ "--requires=" + pkg ]
}
}
if (defined(requires_private)) {
foreach(pkg, requires_private) {
args += [ "--requires-private=" + pkg ]
}
}
if (defined(libs)) {
foreach(lib, libs) {
args += [ "--libs=" + lib ]
}
}
if (defined(libs_private)) {
foreach(lib, libs_private) {
args += [ "--libs-private=" + lib ]
}
}
if (defined(cflags)) {
foreach(cflag, cflags) {
args += [ "--cflags=" + cflag ]
}
}
if (defined(defines)) {
foreach(define, defines) {
args += [ "--cflags=-D" + define ]
}
}
}
}