import intf_libs  = libboost-assert%lib{boost_assert}
import intf_libs += libboost-config%lib{boost_config}
import intf_libs += libboost-context%lib{boost_context}
import intf_libs += libboost-core%lib{boost_core}
import intf_libs += libboost-intrusive%lib{boost_intrusive}
import intf_libs += libboost-predef%lib{boost_predef}
import intf_libs += libboost-smart-ptr%lib{boost_smart_ptr}
import impl_libs  = libboost-algorithm%lib{boost_algorithm}
import impl_libs += libboost-filesystem%lib{boost_filesystem}
import impl_libs += libboost-format%lib{boost_format}

intf_libs = $cxx.deduplicate_export_libs($intf_libs)

# Public headers.
#
pub = [dir_path] ../include/boost/

include $pub

pub_hdrs = $($pub/ pub_hdrs)

# BEGIN MANUAL CUSTOMIZATION
#

tclass = $cxx.target.class
tsys   = $cxx.target.system

windows = ($tclass == 'windows')
mingw32 = ($tsys   == 'mingw32')
linux   = ($tclass == 'linux')
freebsd = ($tsys   == 'freebsd')

libs = boost_fiber boost_fiber_numa

# Splitting the library headers feels a bit hairy. Let's keep it simple and
# consider both libraries sharing the same full set of public headers under
# the boost/fiber/ subdirectory.
#
# Note that the NUMA sources and headers both include non-NUMA headers so in
# Fiber's case the headers are also too entwined to separate.
#
./: lib{$libs}: $pub/{$pub_hdrs}

# Sources as well as dependencies.
#
lib{boost_fiber}:      cxx{*} algo/cxx{**}
lib{boost_fiber_numa}: numa/algo/cxx{**}

lib{boost_fiber_numa}: numa/windows/cxx{**}: include = ($windows && ! $mingw32)
lib{boost_fiber_numa}: numa/linux/cxx{**}:   include = $linux
lib{boost_fiber_numa}: numa/freebsd/cxx{**}: include = $freebsd
lib{boost_fiber_numa}: numa/cxx{*}:          include = \
  ((! $windows || $mingw32) && ! $linux && ! $freebsd)

lib{boost_fiber_numa}: lib{boost_fiber}

# While these libraries have potentially different dependency sets we are
# unable to easily deduce them, since `boostdep` is not of much help here. We
# also don't want to maintain these sets manually. Thus, let's assume that
# both libraries require the full set of dependencies.
#
# Note also that because fiber is an interface dependency of fiber_numa, we
# omit $intf_libs from its dependency list (in a sense, this is the manual
# version of $cxx.deduplicate_export_libs() above).
#
lib{boost_fiber}: $intf_libs
lib{$libs}:       $impl_libs

#
# END MANUAL CUSTOMIZATION

# Build options.
#
out_pfx_inc = [dir_path] $out_root/include/
src_pfx_inc = [dir_path] $src_root/include/
out_pfx_src = [dir_path] $out_root/src/
src_pfx_src = [dir_path] $src_root/src/

# BEGIN MANUAL CUSTOMIZATION
#

cxx.poptions =+ "-I$out_pfx_src" "-I$src_pfx_src" \
                "-I$out_pfx_inc" "-I$src_pfx_inc" \
                -DBOOST_USE_NUMA

if $windows
{
  cxx.poptions += -D_WIN32_WINNT=0x0601 # Windows 7 and later.
}
else
{
  # Currently lib{boost_fiber} doesn't actually need pthread but it's simpler
  # this way and it's also how Upstream does it.
  #
  cxx.poptions += -D_REENTRANT
  cxx.libs     += -lpthread
}

# Note that Boost.Fiber breaks convention by using "FIBERS", with an S,
# instead of "FIBER", the library name. Therefore we need to override all of
# the changes the `generate` script would usually do automatically.
#
{hbmi  obj }{*}: cxx.poptions += -DBOOST_FIBERS_SOURCE
{hbmia obja}{*}: cxx.poptions += -DBOOST_FIBERS_STATIC_LINK
{hbmis objs}{*}: cxx.poptions += -DBOOST_FIBERS_DYN_LINK

# Export options.
#
lib{boost_fiber}:
{
  cxx.export.poptions = "-I$out_pfx_inc" "-I$src_pfx_inc" \
                        -DBOOST_FIBERS_NO_LIB
  cxx.export.libs     = $intf_libs
}

lib{boost_fiber_numa}:
{
  cxx.export.poptions = "-I$out_pfx_inc" "-I$src_pfx_inc" \
                        -DBOOST_FIBERS_NO_LIB
  cxx.export.libs     = lib{boost_fiber}
}

liba{$libs}: cxx.export.poptions += -DBOOST_FIBERS_STATIC_LINK
libs{$libs}: cxx.export.poptions += -DBOOST_FIBERS_DYN_LINK

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

#
# END MANUAL CUSTOMIZATION

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