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

# Compile the implementation as Objective-C on iOS, including Apple 32-bit
# ARM Darwin triples (arm.*).
#
ios = ($c.target.class == 'ios' || \
       ($c.target.vendor == 'apple' && $regex.match($c.target.cpu, 'arm.*')))

lib{miniaudio}: libul{miniaudio}: h{**} c{** -miniaudio} $impl_libs $intf_libs

libul{miniaudio}: c{miniaudio.c}: include = (!$ios)
libul{miniaudio}: m{miniaudio.c}: include = $ios
c{miniaudio.c}@./: dist = (!$ios)
m{miniaudio.c}@./: dist = $ios

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

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

# Amalgamated implementation: unused static helpers on backends that do
# not call them (gcc class includes Clang). -Wstringop-overflow is GNU
# GCC only, Clang diagnoses -Wno-stringop-overflow as unknown.
#
if ($c.class == 'gcc')
  c.coptions += -Wno-unused-function

if ($c.id == 'gcc')
  c.coptions += -Wno-stringop-overflow

# cl and clang-cl: uint64 WAV chunk size assigned to a uint32 loop count
# used only as a sanity check.
#
if ($c.class == 'msvc')
  c.coptions += /wd4244

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

# Export options.
#
lib{miniaudio}:
{
  c.export.poptions = "-I$out_root" "-I$src_root"
  c.export.libs = $intf_libs
}

# System libraries (upstream README). Not needed on Windows or macOS/iOS.
#
if (!$regex.match($c.target.class, '^(windows|macos|ios)'))
{
  c.libs += -pthread -lm
  lib{miniaudio}: c.export.libs += -pthread -lm
}

if ($c.target.class == 'linux' || $c.target.class == 'android')
{
  c.libs += -ldl
  lib{miniaudio}: c.export.libs += -ldl
}

# 32-bit ARM (arm.*) on Linux/Android needs libatomic (upstream CMake).
#
if (($c.target.class == 'linux' || $c.target.class == 'android') && \
    $regex.match($c.target.cpu, 'arm.*'))
{
  c.libs += -latomic
  lib{miniaudio}: c.export.libs += -latomic
}

# iOS must compile the implementation as Objective-C because the Core Audio
# backend includes AVFoundation.
#
if $ios
{
  c.libs += -lobjc
  lib{miniaudio}: c.export.libs += -lobjc
}

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

# Install into the miniaudio/ subdirectory of, say, /usr/include/
# recreating subdirectories.
#
h{*}:
{
  install         = include/miniaudio/
  install.subdirs = true
}
