intf_libs = # Interface dependencies.
impl_libs = # Implementation dependencies.
import intf_libs += libmetrics-discovery-headers%lib{metrics-discovery-headers}
import impl_libs += libdrm-uapi-helper%lib{drm-uapi-helper}

# Note that the C and C++ headers share the .h extension, so list them once.
#
lib{igdmd}: {hxx cxx c}{** -xe_drm_config} hxx{xe_drm_config} \
            $impl_libs $intf_libs

# Detect the system kernel xe uAPI that the xe kernel mode driver interface
# can use (see build/autoconf/checks/ for details).
#
using autoconf

hxx{xe_drm_config}: in{xe_drm_config}

# Build options.
#
out_pfx = [dir_path] $out_root/src/
src_pfx = [dir_path] $src_root/src/

cc.poptions =+ "-I$out_pfx" "-I$src_pfx"

# Header search paths, as in upstream. Note that external/drm/ redirects the
# DRM uAPI headers that upstream bundles to drm-uapi-helper and the system
# kernel uAPI headers.
#
md = instrumentation/metrics_discovery
iu = instrumentation/utils

cc.poptions += "-I$src_pfx/$md/common/inc"                            \
               "-I$src_pfx/$md/common/inc/internal"                   \
               "-I$src_pfx/$md/common/inc/internal/concurrent_groups" \
               "-I$src_pfx/$md/codegen"                               \
               "-I$src_pfx/external/drm"                              \
               "-I$src_pfx/$md/linux/inc"                             \
               "-I$src_pfx/$iu/common/inc"                            \
               "-I$src_pfx/$iu/linux/inc"                             \
               "-I$src_pfx/inc/common"                                \
               "-I$src_pfx/inc/common/instrumentation"                \
               "-I$src_pfx/inc/common/instrumentation/api"

# Export only the functions that md_exports.h marks with DllExport, as in
# upstream.
#
cc.coptions += -fvisibility=hidden

# Silence warnings about the upstream sources: multi-line comments (disabled
# in upstream as well), anonymous structs, nested anonymous types, and
# flexible array members (GCC has no narrower option for these than
# -Wno-pedantic), and C function declarations without a prototype.
#
switch $cxx.id
{
  case 'gcc'
  {
    cc.coptions += -Wno-comment
    cxx.coptions += -Wno-pedantic
  }
  case 'clang'
  {
    cxx.coptions += -Wno-gnu-anonymous-struct -Wno-nested-anon-types \
                    -Wno-c99-extensions
    c.coptions += -Wno-strict-prototypes
  }
}

cxx.libs += -ldrm -pthread

# Export options.
#
lib{igdmd}:
{
  cc.export.libs = $intf_libs
}

# For pre-releases use the complete version to make sure they cannot
# be used in place of another pre-release or the final version. See
# the version module for details on the version.* variable values.
#
# Otherwise match the upstream library name (libigdmd.so.MAJOR.MINOR.PATCH
# with the libigdmd.so.MAJOR SONAME).
#
if $version.pre_release
  lib{igdmd}: bin.lib.version = "-$version.project_id"
else
  lib{igdmd}: bin.lib.version = "-$version.major.$version.minor" \
    linux@"$version.major.$version.minor.$version.patch"

# Don't install private headers.
#
{hxx h}{*}: install = false
