import libs = libetcpak%lib{etcpak} \
              libpng%lib{png}

if($cxx.target.system == 'win32-msvc')
  import libs += libgetopt_port%lib{getopt_port}

exe{etcpak}: {hxx h cxx c}{**} $libs

out_pfx = [dir_path] $out_root/src/
src_pfx = [dir_path] $src_root/src/

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

if ($cxx.target.system != 'win32-msvc')
  cxx.libs += -pthread

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

# Application.cpp's loop counters are compared against unsigned bounds
# derived from image-size computations that are never negative;
# BlockData.cpp's table59T58H is dead code and cnt is only used inside
# a DBGPRINT that compiles away in release builds; BitmapDownsampled.cpp
# captures more than it uses in a couple of lambdas and its LinearToSrgb
# is unused outside of it. All checked benign at their actual sites, not
# blanket-suppressed on the warning name alone.
#
if ($cxx.class != 'msvc')
  cxx.coptions += -Wno-sign-compare \
                  -Wno-unused-variable \
                  -Wno-unused-lambda-capture \
                  -Wno-unused-function

# -Wmacro-redefined (BlockData.cpp's '_bswap64', same story as libetcpak's
# Decode.cpp/ProcessRGB.cpp) is clang-only naming, matched on id.type so
# it also covers Apple's clang ('clang-apple'). See libetcpak/src/buildfile.
#
if ($cxx.id.type == 'clang')
  cxx.coptions += -Wno-macro-redefined

# BlockData.cpp calls the POSIX fileno() name, which MSVC's CRT flags as
# non-conformant in favor of _fileno(). Same function either way.
# Application.cpp's loop counters are the same benign sign-compare sites
# as above; MSVC has no equivalent to -Wno-sign-compare, so /wd4018 here.
#
if ($cxx.class == 'msvc')
  cxx.coptions += /wd4996 /wd4018

# clang targeting the MSVC ABI in its own (non-cl) driver mode still
# compiles against the MSVC CRT headers, so it hits the same fileno()
# deprecation as real MSVC above, but as a GNU-style diagnostic (MSVC's
# /wd4996 means nothing to it): -Wno-deprecated-declarations instead.
#
if ($cxx.class != 'msvc' && $cxx.target.system == 'win32-msvc')
  cxx.coptions += -Wno-deprecated-declarations
