intf_libs = # Interface dependencies.
impl_libs = # Implementation dependencies.

import libbuild2 = build2%lib{build2}

import impl_libs += $libbuild2 # Implied interface dependency.

# Include the lexer and parser source files for reference (see README-DEV for
# details).
#
define y: file
y{*}: extension = y

define l: file
l{*}: extension = l

getopt = ($c.target.class == 'windows' && $c.target.system != 'mingw32')

lib{build2-kconfig}: {hxx ixx txx cxx}{**} $impl_libs $intf_libs

lib{build2-kconfig}: {h c}{* -conf} y{parser} l{lexer}
lib{build2-kconfig}: c{conf}: include = adhoc # Included by confapi.c.
lib{build2-kconfig}: getopt/h{getopt}: include = $getopt

# Build options.
#
cc.poptions =+ "-I$out_root" "-I$src_root" "-I$src_base"

if $getopt
  c.poptions =+ "-I($src_base/getopt)"

# Disable autoconfig support.
#
cc.poptions += -DKCONFIG_AUTOCONFIG=NULL -DKCONFIG_REGEX=0

obja{*}: cc.poptions += -DLIBBUILD2_KCONFIG_STATIC_BUILD
objs{*}: cc.poptions += -DLIBBUILD2_KCONFIG_SHARED_BUILD

# Disable warnings in Kconfig code.
#
switch $c.class
{
  case 'gcc'
  {
    c.coptions += -Wno-extra -Wno-error

    if ($c.target.class == 'windows')
      c.coptions += -Wno-deprecated-declarations

    obj{lexer.lex...}: c.coptions += -Wno-unused-function -Wno-unused-label
  }

  case 'msvc'
    c.coptions += /w
}

# Export options.
#
lib{build2-kconfig}:
{
  cxx.export.poptions = "-I$out_root" "-I$src_root"
  cxx.export.libs = $intf_libs
}

liba{build2-kconfig}: cxx.export.poptions += -DLIBBUILD2_KCONFIG_STATIC
libs{build2-kconfig}: cxx.export.poptions += -DLIBBUILD2_KCONFIG_SHARED

# 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.
#
if $version.pre_release
  lib{build2-kconfig}: bin.lib.version = "-$version.project_id"
else
  lib{build2-kconfig}: bin.lib.version = "-$version.major.$version.minor"

# Embed the build system core version as our load suffix.
#
# Get the version as exported by the lib{build2} target falling back to the
# running build system version if unable to (installed lib{build2}).
#
iv = ($project($libbuild2) == [null]     \
      ? $($libbuild2: interface_version) \
      : [null])

ifn $iv
  iv = $build.version.interface

libs{build2-kconfig}: bin.lib.load_suffix = "-$iv"

# Install into the libbuild2/kconfig/ subdirectory of, say, /usr/include/
# recreating subdirectories.
#
# And don't install kconfig C headers (implementation details).
#
h{*}: install = false

{hxx ixx txx}{*}:
{
  install         = include/libbuild2/kconfig/
  install.subdirs = true
}
