# Upstream test/c/std programs. Each #include's the amalgamation and
# testlib.c (they do not link lib{wuffs}). Mimic tests stay off: they
# need giflib, libpng, zlib, etc.

# testlib.c uses unistd.h and sys/time.h. MinGW has those. MSVC does not.
#
msvc = ($cxx.target.system == 'win32-msvc')

# testlib walks up to this marker, then reads test/data/. tests/test/
# is a real directory (test/data/* are per-entry upstream symlinks),
# so ln -s of it gets a directory symlink on Windows (build2#549).
#
file{$out_root/wuffs-root-directory.txt}:
{{
  touch $path($>)
}}

$out_root/fsdir{test}:
% update
{{
  diag ln $>
  rm -f $out_root/test
  ln -s $posix_string([dir_path] $src_root/test) $out_root/test
}}
% clean
{{
  rm -f $out_root/test
}}

for t: c{*}
{
  n = $name($t)
  ./: exe{$n}: include = (!$msvc)
  exe{$n}: $t testscript
  exe{$n}: ../testlib/c{testlib}: include = adhoc
  exe{$n}: file{$out_root/wuffs-root-directory.txt}: include = adhoc
  exe{$n}: $out_root/fsdir{test}: include = adhoc
}

# testlib.c's 64MiB uninitialized globals land in __DATA,__common under
# Apple clang's -fcommon default. Darwin ld then warns that 0x8000
# alignment exceeds the 0x4000 segment maximum. -fno-common puts them
# in BSS instead. Local to these TUs (they #include testlib.c).
#
if ($c.target.class == 'macos')
  obje{*}: c.coptions += -fno-common

# wuffs_bzip2__decoder is ~4MiB (uint32_t f_bwt[1048576]) and the
# upstream tests stack-allocate it. Windows PE default stack is 1MiB.
# These tests are not built for MSVC (win32-msvc).
#
if ($c.target.system == 'mingw32')
  exe{*}: cc.loptions += -Wl,--stack,8388608

exe{*}: dist = false
c{*}: dist = false
testscript{*}: dist = false
