import libdwarf = libdwarf%lib{dwarf}
import libs = libdwarf%lib{dwarf_private}
libs += $libdwarf

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

./: exe{dwarfdump}: conf{dwarfdump}@./ {h c}{** -dummy -tests/*} $libs

c.poptions =+ "-I$out_root" "-I$src_root" \
              "-I$out_base" "-I$src_base" \
              -D_GNU_SOURCE

conf{dwarfdump}@./: install = $install.data

# Smoke test: run against a pre-committed DWARF-carrying binary.
#
exe{dwarfdump}: file{dummyexecutable.debug}@./ testscript

# Unit tests
#
# One executable per upstream self-contained test (has its own main()).
# Add the dwarfdump specific tests (require dd internal hdrs)
for t: tests/c{*}
{
  ./: tests/exe{test-$name($t)}: h{**} $t $libs tests/testscript
  {
    test = true
    install = false
  }
}

# Tests requiring extra compilation units from the dwarfdump sources.
#
tests/exe{test-test_canonical}:  c{dd_safe_strcpy dd_canonical_append dd_esb}
tests/exe{test-test_esb}:        c{dd_esb dd_tsearchbal}
tests/exe{test-test_getopt}:     c{dd_getopt}
tests/exe{test-test_helpertree}: c{dd_helpertree dd_tsearchbal}
tests/exe{test-test_macrocheck}: c{dd_esb dd_tsearchbal}
tests/exe{test-test_makename}:   c{dd_esb dd_makename dd_tsearchbal}
tests/exe{test-test_regex}:      c{dd_regex}
tests/exe{test-test_sanitized}:  c{dd_esb dd_sanitized dd_utf8}

# dd_sanitized.c: #ifndef TESTING guards glflags-dependent paths that require
#                 a full dwarfdump runtime context.
# test_macrocheck.c: #includes dd_macrocheck.c directly, 'failcount' is guarded
#                    by #ifdef TESTING in that file.
#
obj{dd_esb dd_sanitized}:          c.poptions += -DTESTING
tests/obje{test_macrocheck}:       c.poptions += -DTESTING

# Don't install tests.
#
tests/: install = false
