intf_libs = # Interface dependencies.
impl_libs = # Implementation dependencies.
#import xxxx_libs += libhello%lib{hello}

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

include $pub

pub_hdrs = $($pub/ pub_hdrs)

lib{etcpak}: libul{etcpak}: $pub/{$pub_hdrs}

# Private headers and sources as well as dependencies.
#
libul{etcpak}: {hxx h ixx txx cxx c}{**} $impl_libs $intf_libs

libs{etcpak}: def{etcpak}: include = ($cxx.target.system == 'win32-msvc')
def{etcpak}: libul{etcpak}

# 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/
out_pfx_inc_unq = [dir_path] $out_root/include/etcpak/
src_pfx_inc_unq = [dir_path] $src_root/include/etcpak/

# _unq lets this package's own TUs keep #include "ProcessRGB.hpp".
# Do not export those paths. Consumers use <etcpak/ProcessRGB.hpp>.
#
cxx.poptions =+ "-I$out_pfx_src" "-I$src_pfx_src" \
                "-I$out_pfx_inc" "-I$src_pfx_inc" \
                "-I$out_pfx_inc_unq" "-I$src_pfx_inc_unq"

if ($cxx.target.class == 'windows')
  cxx.poptions += -DNOMINMAX -DWIN32_LEAN_AND_MEAN

if ($cxx.target.system == 'mingw32')
  cxx.loptions += -Wl,--export-all-symbols

# Silence warnings from vendored bc7enc/bcdec/ProcessRGB/ProcessDxtc code
# that we don't patch (see upstream). Each was checked to be benign at
# its actual call sites, not blanket-suppressed on the warning name alone.
# ProcessDxtc.cpp's and ProcessRGB.cpp's block-loop counters are compared
# against unsigned bounds derived from image-size computations that are
# never negative, same rationale as the etcpak CLI's own sign-compare
# sites (see etcpak/src/buildfile).
# -Wno-return-type is deliberately not included here: unlike the others,
# it flags a real bug class (a non-void function that can fall through
# without returning), so the one instance we found (GetMulSel() in
# ProcessRGB.cpp) was patched instead of silenced. See ProcessRGB.cpp.patch.
# -Wno-stringop-overflow is left out for the same reason. GCC 14 -O3 on
# aarch64 flags selectors_temp1[i] in bc7enc.cpp's uber-level loop as a
# write past the end of a 16-byte array, because it cannot prove
# m_num_pixels <= 16. BC7 cells are a 4x4 block or a partition subset of
# one, so the bound always holds. The uber-level guard now includes it
# so the compiler can see it. See bc7enc.cpp.patch.
#
if ($cxx.class != 'msvc')
  cxx.coptions += -Wno-logical-not-parentheses \
                  -Wno-sign-compare           \
                  -Wno-unused-function        \
                  -Wno-unused-const-variable

# GCC has no -Wlogical-not-parentheses: it reports the same stuff59bits()/
# stuff58bits() sites (ProcessRGB.cpp) under the umbrella -Wparentheses
# instead, so the flag above is a silent no-op there and the warning
# still leaks through. Use the umbrella flag on GCC specifically rather
# than widen it for clang too, where the narrow flag already works.
#
if ($cxx.id == 'gcc')
  cxx.coptions += -Wno-parentheses

# -Wmacro-redefined (the '_bswap64' sites in Decode.cpp/bc7enc.cpp/
# ProcessRGB.cpp) is clang-only naming: GCC never recognizes -Wno-macro-
# redefined at all (its own redefined-macro diagnostic is unconditional,
# only -w turns it off), and passing an unrecognized -Wno-* to GCC prints
# a "may have been intended to silence earlier diagnostics" note the
# moment anything else in the file warns. Keep it clang-only. Match on
# id.type, not id: Apple's clang reports cxx.id as 'clang-apple', so
# id == 'clang' misses it even though it's the same flag dialect.
#
if ($cxx.id.type == 'clang')
  cxx.coptions += -Wno-macro-redefined

# Decode.cpp's DecodeT/DecodeTAlpha/DecodeH/DecodeHAlpha/DecodePlanar all
# pull small bit-fields out of a uint64_t block via shift-and-mask, so
# 'auto' deduces uint64_t locals that are always well within [0,319] in
# practice (masked to a handful of bits, optionally +/- a table entry
# capped at 64), then hands them to clampu8()/expand6()/expand7(), which
# take int32_t/uint32_t. MSVC is the only compiler that flags the
# narrowing (C4244); gcc/clang don't warn on this pattern at all.
#
if ($cxx.class == 'msvc')
  cxx.coptions += /wd4244

if ($cxx.target.class != 'windows')
  cxx.libs += -lm

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

if ($cxx.target.class != 'windows')
  lib{etcpak}: cxx.export.libs += -lm

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

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