intf_libs = # Interface dependencies. libsquish has none.
impl_libs = # Implementation dependencies. libsquish has none.

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

include $pub

pub_hdrs = $($pub/ pub_hdrs)

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

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

# Private headers and sources as well as dependencies.
#
libul{squish}: {hxx cxx}{**} $impl_libs $intf_libs

# singlecolourlookup.inl is textually #include'd by singlecolourfit.cpp
# rather than compiled on its own, so it matches no cxx{}/hxx{} pattern
# above. Declare it explicitly as a plain file so b dist and b install
# still see it as part of the source tree.
#
libul{squish}: inl{singlecolourlookup}@./
inl{singlecolourlookup}@./: install = false

# squish-simd.h.in is only consumed via the ad hoc predefs path below,
# so attach it explicitly for dist.
#
libul{squish}: file{squish-simd.h.in}@./
file{squish-simd.h.in}@./: install = false


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

# 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/

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

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

# SIMD acceleration: mirror whatever the compiler already targets rather
# than adding our own instruction-set flags (which would risk widening a
# consumer's binary beyond what they targeted). squish-simd.h.in is a
# private detection artifact, never installed or included by real source.
#
# HAVE_SSE2 needs the autoconf module's builtin check to reconcile MSVC
# (_M_X64/_M_IX86_FP) vs. GCC/Clang (__SSE2__). Altivec has no such
# cross-compiler split (PowerPC/GCC/Clang only), so __ALTIVEC__ is read
# directly as a plain compiler-predefined macro from the same compile,
# with no autoconf check needed.
#
[rule_hint=autoconf.in] h{squish-simd}: in{squish-simd}
h{squish-simd}: install = false

cxx.predefs.poptions = false

[rule_hint=cxx.predefs] buildfile{squish-simd}: h{squish-simd}
{
  cxx.predefs.macros = HAVE_SSE2@have_sse2 __ALTIVEC__@have_altivec
}

if ($build.meta_operation == 'perform')
{
  update buildfile{squish-simd}
  source $path(buildfile{squish-simd})

  have_sse2    = ($have_sse2    == 1 ? true : false)
  have_altivec = ($have_altivec == 1 ? true : false)
}
else
{
  have_sse2    = false
  have_altivec = false
}

if $have_sse2
  cxx.poptions += -DSQUISH_USE_SSE=2
elif $have_altivec
  cxx.poptions += -DSQUISH_USE_ALTIVEC=1

# Export options.
#
lib{squish}:
{
  cxx.export.poptions = "-I$out_pfx_inc" "-I$src_pfx_inc"
  cxx.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.
#
if $version.pre_release
  lib{squish}: bin.lib.version = "-$version.project_id"
else
  lib{squish}: bin.lib.version = "-$version.major.$version.minor"

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